robetus Posted April 26, 2020 Share Posted April 26, 2020 In the viewcart.tpl I have: {if $product.productinfo.gid eq "2" && $cartitems > 1} <div class="text-right"> <div class="support-box red-support-box"> One item per order </div> <br /> <a href="cart.php" class="btn btn-link btn-continue-shopping" id="continueShopping"> {$LANG.orderForm.continueShopping} </a> </div> {else} <div class="text-right"> <a href="cart.php?a=checkout" class="btn btn-success btn-lg btn-checkout{if $cartitems == 0} disabled{/if}" id="checkout"> {$LANG.orderForm.checkout} <i class="fa fa-arrow-right"></i> </a><br /> <a href="cart.php" class="btn btn-link btn-continue-shopping" id="continueShopping"> {$LANG.orderForm.continueShopping} </a> </div> {/if} It works but as soon as a different product is added from a different product group it does not work. Is there any way with smarty that I can limit a product group to only have one product from that group in the cart at a time? Maybe I need a hook, but I wanted to ask to see if anyone knew how to do with smarty syntax. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 27, 2020 Share Posted April 27, 2020 15 hours ago, robetus said: It works but as soon as a different product is added from a different product group it does not work. Is there any way with smarty that I can limit a product group to only have one product from that group in the cart at a time? one way to do it would be to split this into two parts - first in the existing $products foreach loop (~ line 90), you create a Smarty counter variable that increases each time it finds a product from GID X in the cart... {foreach $products as $num => $product} {if $product.productinfo.gid eq "2"}{assign var=productcounter value=$productcounter+1}{/if} that gives you a $productcounter variable that will tell you how many products from GID=2 are in the cart... and then where you previously had... {if $product.productinfo.gid eq "2" && $cartitems > 1} you can change that to... {if $productcounter gt 1} which should mean that if there is more than 1 product from group #2 in the cart, then it will throw your "1 Item" error message and disable the checkout button... also, if $productcounter is more than 1, then you also know that there is more than one product in the cart, so $cartitems would always be more than 1 too. you could trim that entire IF statement down in size if you had to... <div class="text-right"> {if $productcounter gt 1} <div class="support-box red-support-box">One item per order</div> {/if} <a href="cart.php?a=checkout&e=false" class="btn btn-success btn-lg btn-checkout{if $cartitems == 0 OR $productcounter gt 1} disabled{/if}" id="checkout"> {$LANG.orderForm.checkout} <i class="fa fa-arrow-right"></i> </a><br /> <a href="cart.php" class="btn btn-link btn-continue-shopping" id="continueShopping"> {$LANG.orderForm.continueShopping} </a> <div> 15 hours ago, robetus said: Maybe I need a hook, but I wanted to ask to see if anyone knew how to do with smarty syntax. you might ultimately need a hook as the one obvious flaw in your Smarty method is that the user can change the url in the browser from cart.php?a=view to cart.php?a=checkout and thus totally bypass your condition checks (even if the checkout button is disabled or hidden)! 🙄 will most WHMCS users know that they can do that in the browser ? probably not. you could duplicate the foreach $products loop in the checkout.tpl template - not all of it, just the bit that makes the counter... {foreach $products as $num => $product} {if $product.productinfo.gid eq "2"}{assign var=productcounter value=$productcounter+1}{/if} {/foreach} and then disable the checkout button if there is more than one product from your specified product group in the cart... <button type="submit" id="btnCompleteOrder" class="btn btn-primary btn-lg disable-on-click spinner-on-click{if $captcha}{$captcha->getButtonClass($captchaForm)}{/if}"{if $cartitems==0 or $productcounter gt 1}disabled="disabled"{/if}> 1 Quote Link to comment Share on other sites More sharing options...
robetus Posted April 28, 2020 Author Share Posted April 28, 2020 Worked perfectly as always @brian! I modified the checkout to not show the button at all and the same message as in the viewcart but it worked perfectly. Thank you for that.  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.