Jump to content

coupon code in sidebar cart


Recommended Posts

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 by sebsimappus
cart, whmcs, promocode
Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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>

FOm6UAv.png

 

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 by brian!
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated