sebsimappus Posted July 14, 2016 Share Posted July 14, 2016 (edited) Hello, I include in the sidebar-categories.tpl File cart a block for adding the coupon code in the shopping cart. The problem is that I would like the function {if $promotioncode} {else} {/ if} is functional. If someone has an idea thank you in advance Edited July 14, 2016 by sebsimappus cart, whmcs, promocode 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 15, 2016 Share Posted July 15, 2016 if memory serves, $promocode isn't an available variable in all steps of the cart, only some. what block of code are you using to add the coupon code option to the sidebar ? 0 Quote Link to comment Share on other sites More sharing options...
sebsimappus Posted July 15, 2016 Author Share Posted July 15, 2016 Hello, Thank you for your return, Yes i insert the code into the sidebar. If you have an idea. thank you in advance 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 15, 2016 Share Posted July 15, 2016 Thank you for your return, Yes i insert the code into the sidebar. what is the code you are using in the sidebar? 0 Quote Link to comment Share on other sites More sharing options...
sebsimappus Posted July 15, 2016 Author Share Posted July 15, 2016 Thanks for your feedback, Here is the code used <div class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title"><span class="fa fa-cut"></span> {$LANG.orderpromotioncode}</h3> </div> <div class="panel-body"> {if $promotioncode} <div class="form-group prepend-icon "> <label for="cardno" class="field-icon"> <i class="fa fa-ticket"></i> </label> <input type="text" class="field" value="{$promotioncode} - {$promotiondescription}" disabled=""> </div> <button type="submit" name="validatepromo" class="btn btn-block" onclick="removepromo(); return false" value="{$LANG.orderForm.removePromotionCode}"> {$LANG.orderForm.removePromotionCode} </button> {else} <div class="prepend-icon "> <label for="cardno" class="field-icon"> <i class="fa fa-ticket"></i> </label> <input type="text" name="promocode" id="promocode" onchange="applypromosidebar()" class="field" placeholder="{lang key="orderPromoCodePlaceholder"}" /> </div> {/if} </div> </div> 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 15, 2016 Share Posted July 15, 2016 The problem is that I would like the function {if $promotioncode} {else} {/ if} is functional. it can't be functional because 'sidebar-categories.tpl' doesn't have access to the $promotioncode variable - not all templates have access to all variables. if I were you, i'd give up trying to do this! 0 Quote Link to comment Share on other sites More sharing options...
sebsimappus Posted July 15, 2016 Author Share Posted July 15, 2016 yes I will, and with a hook file that would be possible? 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted July 15, 2016 Share Posted July 15, 2016 yes I will, and with a hook file that would be possible? probably yes 0 Quote Link to comment Share on other sites More sharing options...
sebsimappus Posted July 16, 2016 Author Share Posted July 16, 2016 Do you have an idea in the conception of hook file 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 16, 2016 Share Posted July 16, 2016 (edited) it's always worth remembering that you can't necessarily take code from one template, paste it in another template and expect it to work - it won't have access to any underlying PHP functions. the following code (modified from yours) would be functional in one sense - it will take a promotion code and add it to the cart... <div class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title"><span class="fa fa-cut"></span> {$LANG.orderpromotioncode}</h3> </div> <div class="panel-body"> {if $smarty.get.promocode} <div class="form-group prepend-icon "> <label for="cardno" class="field-icon"> <i class="fa fa-ticket"></i> </label> <input type="text" class="field" value="{$smarty.get.promocode}" disabled=""> </div> <div class="text-center"> <a href="{$smarty.server.PHP_SELF}?a=removepromo" class="btn btn-danger btn-block">{$LANG.orderForm.removePromotionCode}</a> </div> {else} <form name="form1" method="get" action="{$currentpagelinkback}promocode={$smarty.get.promocode}"> <div class="prepend-icon"> <label for="cardno" class="field-icon"> <i class="fa fa-ticket"></i> </label> <input type="text" name="promocode" id="promocode" onchange="applypromosidebar()" class="field" placeholder="{lang key="orderPromoCodePlaceholder"}" /> </div> </form> {/if} </div> </div> and now for the downsides... 1. when you enter the promotion code, no validation of it occurs - that would need a hook, probably to query the database - but if you're adding the promo code before starting the ordering process, it would only be able to check if the code exists, not if it can be applied to the future cart contents - that would only occur before checkout. 2. after entering the promocode, when you go to the next step of the order process, the value used in the sidebar is no longer available... so it appears the code is not longer in the cart, but it is - it's only a visual issue with the sidebar... I would guess the only way around that (if it's a problem for you) would be to modify the other forms to keep passing promocode, or take it's value from the Session array and modify the sidebar form to use either value... you could slightly get around that by specifying the promocode box to only be visible on the opening page of the order process (products.tpl)... that would hide the fact the variable is no longer available to the cart and allow the order process to continue... if they need to change the promo code, then can always do so at the view cart stage. {if $templatefile eq 'products'} <div class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title"><span class="fa fa-cut"></span> {$LANG.orderpromotioncode}</h3> </div> <div class="panel-body"> {if $smarty.get.promocode} <div class="form-group prepend-icon "> <label for="cardno" class="field-icon"> <i class="fa fa-ticket"></i> </label> <input type="text" class="field" value="{$smarty.get.promocode}" disabled=""> </div> <div class="text-center"> <a href="{$smarty.server.PHP_SELF}?a=removepromo" class="btn btn-danger btn-block">{$LANG.orderForm.removePromotionCode}</a> </div> {else} <form name="form1" method="get" action="{$currentpagelinkback}promocode={$smarty.get.promocode}"> <div class="prepend-icon"> <label for="cardno" class="field-icon"> <i class="fa fa-ticket"></i> </label> <input type="text" name="promocode" id="promocode" onchange="applypromosidebar()" class="field" placeholder="{lang key="orderPromoCodePlaceholder"}" /> </div> </form> {/if} </div> </div> {/if} but as I said previously, personally I wouldn't spend the required time trying to make this work beyond the above... it's not impossible, it would just take more effort that i'm prepared to give to it! Edited July 16, 2016 by brian! 0 Quote Link to comment Share on other sites More sharing options...
sebsimappus Posted July 17, 2016 Author Share Posted July 17, 2016 Thank you for your help damage the function is not possible, and yes it would be a shame to waste time on this. A big thank-you 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.