Jump to content

Possible If Statement for checkout button?


DomsAdmin

Recommended Posts

Soheil:

 

Good Day!

Thank you for your interest in my coding issue. Shokino provided me with the code below for adding the checkout button to the blockuserinfo module which I would like to only displays once item(s) are added to the cart. The issue is that I don't have any idea on how and just where to place the code below and if there is anything else to add to this code for it to work correctly...If possible please help with suggestions. Thanks for all of your timely additions to the forum!

 

Domsadmin

 

 

1. you need assign smarty variable in the module PHP file

 

$smarty->assign('numberOfProducts', $cart->nbProducts());

 

2. Then use this variable in tpl file

 

{if $numberOfProducts > 0}

 

........

 

{/if}

Link to comment
Share on other sites

you would edit the modules\blockuserinfo\blockuserinfo.tpl template, and add the "if" statement where ever you want the add button to appear.

 

no need to add the other smarty assign. the blockuserinfo module already does this

'cart_qties' => $cart->nbProducts(),

 

just change you if statement to

{if $cart_qties > 0}

  • Like 1
Link to comment
Share on other sites

Bellini13:

 

Thank you for the suggestion. However what I am trying to do is have the actual button hidden when there aren't any products in the cart and to only display when products are placed into the cart.

 

 

 

The code below is already part of my blockuserinfo.tpl file:

 

'cart_qties' => $cart->nbProducts(),

 

just change you if statement to

 

{if $cart_qties > 0}

Any suggestions?

Link to comment
Share on other sites

Thanks, amazing suggestion Bellini13!

Is it possible if you can please explain how I would put the button code inside the if statement? Here is the button code below from the blockcart module:

 

-Button Code-

 

<a href="{$link->getPageLink("$order_process.php", true)}{if $order_process == 'order'}?step=1{/if}" id="button_order_cart" class="button_small" title="{l s='Check out' mod='blockcart'}">{l s='Check out' mod='blockcart'}</a>

 

-Here is the section of the blockuserinfo.tpl code that I believe the button code should go:

 

<span class="ajax_cart_quantity{if $cart_qties == 0} hidden{/if}">{$cart_qties}</span>

<span class="ajax_cart_product_txt{if $cart_qties != 1} hidden{/if}">{l s='product' mod='blockuserinfo'}</span>

<span class="ajax_cart_product_txt_s{if $cart_qties < 2} hidden{/if}">{l s='products' mod='blockuserinfo'}</span>

<span class="ajax_cart_no_product{if $cart_qties > 0} hidden{/if}">{l s='(empty)' mod='blockuserinfo'}</span>

 

The question is (if this is the correct section of blockuserinfo.tpl code) is where and how to place the button code?

Link to comment
Share on other sites

i can't tell you where to place the button, where ever you decide to place the button, it would look like this.

 

{if $cart_qties > 0}
<a href="{$link->getPageLink("$order_process.php", true)}{if $order_process == 'order'}?step=1{/if}" id="button_order_cart" class="button_small" title="{l s='Check out' mod='blockcart'}">{l s='Check out' mod='blockcart'}</a>
{/if} 

  • Like 1
Link to comment
Share on other sites

Bellini13 The suggestion works!

However when the item(s) are placed into cart the checkout button appears and the page is automatically directed to the checkout page. Is there any way to make the checkout button appear and only direct you to the checkout page after the button is pressed when ready to proceed with checkout?

Link to comment
Share on other sites

confirm your product settings. go into the back office, go to the preferences | products section. scroll down and locate the "Re-direction after adding product to cart" option. change it to "previous page"

 

also ,do you know if you have the ajax cart setting enabled?

  • Like 2
Link to comment
Share on other sites

I just confirmed my settings. I am running my cart with ajax enabled. I noticed that it says that the "previous page" redirection is only available on the non-ajax cart. Is there a way around this if I would still like to use the ajax enabled cart?

Link to comment
Share on other sites

We're getting closer, thanks!

That last suggestion seems to work, however when I empty the shopping cart the checkout button doesn't disappear and I also noticed that sometimes when I add product(s) to the shopping cart the checkout button doesn't appear for certain products.

 

Any suggestions on how to remedy these issues?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...