Jump to content

option: add to cart or contact button


mgulyaev
 Share

Recommended Posts

hello everyone,

I'm trying to find a solution for selling two types of products, one with "add to cart" and second with "contact button" in the place of "add to cart".
Does anyone have any ideas how to do it?

Share this post


Link to post
Share on other sites

There are a couple of ways you could do this. If you don't have any free products on your site, you could set the price of the products you want to be "Contact us" to $0, otherwise you could put it in another product field like the "location" field. You can then change line 304 of product.tpl from:

quantity == 0} style="display:none;"{/if} id="add_to_cart" class="buttons_bottom_block"><input type="submit" name="Submit" value="{l s='Add to cart'}" class="exclusive" /></p>



to:

quantity == 0} style="display:none;"{/if} id="add_to_cart" class="buttons_bottom_block">{if $product->getPrice(true, $smarty.const.NULL, 2, $smarty.const.NULL, true) == 0}
<a href="{$base_dir_ssl}contact-form.php" class="exclusive">{l s='Contact us'}{else}<input type="submit" name="Submit" value="{l s='Add to cart'}" class="exclusive" />{/if}



This code should display a "Contact us" button when the price is 0. If you need free products, you could instead enter something in the product's location field if you aren't already using it and use {$product->location} to check value of it.

Share this post


Link to post
Share on other sites

thank you rocky for the reply.

Ok, using PrestaShop 1.3.1 I went to theme/prestashop/product.ptl

And on line 283 is the code:

quantity == 0} style="display:none;"{/if} id="add_to_cart" class="buttons_bottom_block"><input type="submit" name="Submit" value="{l s='Add to cart'}" class="exclusive" /></p>



after replacing it with:

quantity == 0} style="display:none;"{/if} id="add_to_cart" class="buttons_bottom_block">{if $product->getPrice(true, $smarty.const.NULL, 2, $smarty.const.NULL, true) == 0}
{l s='Contact us'}{else}<input type="submit" name="Submit" value="{l s='Add to cart'}{/if}" class="exclusive" />{/if}



setting price to $0.00 didn't change "add to cart" to "contact us" it still shows $0.00 price and when going to the product page it doesn't show the product.

Share this post


Link to post
Share on other sites

I accidentally had an extra {/if} in my code above. I've now removed it and tested my code and it works fine. A green "Contact us" button is displayed on the product page that links to the contact form. You'll need to make a similar change to product-list.tpl and modules/homefeatured/homefeatured.tpl.

Share this post


Link to post
Share on other sites

  • 3 weeks later...

rocky what about my problem? It's possible i made something wrong? Or this modification is not compatible with prestashop 1.3.1?

I think i followed the exact steps as you say but all the products shows the "contact us" button even not-free products.

Thanks in advance

Share this post


Link to post
Share on other sites

A green "Contact Us" appears on the product page that links to the contact form. Have to make a similar change in the modules of the product, list.tpl/ homefeatured / homefeatured.tpl. These is one of the great facility to do these.

Share this post


Link to post
Share on other sites

I just tested this code once again on my PrestaShop v1.3.1 shop and it is working fine. On the product page, the button says "Contact Us" on my test product with a price of $0 and "Add to cart" on all products with a price greater than $0. Of course, the buttons are all "Add to cart" on the product listings and other pages. I don't understand why it wouldn't work for you.

Share this post


Link to post
Share on other sites

I haven't tested the code in product-list.tpl, only in product.tpl. The product listing has the products as arrays instead of objects like in product.tpl, so the same code won't work in product-list.tpl.

Try changing line 22 of product-list.tpl in your theme's directory (in PrestaShop v1.3.1) from:

<a class="button ajax_add_to_cart_button exclusive" rel="ajax_id_product_{$product.id_product|intval}" href="{$base_dir}cart.php?add&id_product={$product.id_product|intval}&token={$static_token}" title="{l s='Add to cart'}">{l s='Add to cart'}



to:

{if $product.price == 0}<a href="{$base_dir}contact-form.php" class="exclusive">{l s='Contact us'}{else}<a class="button ajax_add_to_cart_button exclusive" rel="ajax_id_product_{$product.id_product|intval}" href="{$base_dir}cart.php?add&id_product={$product.id_product|intval}&token={$static_token}" title="{l s='Add to cart'}">{l s='Add to cart'}{/if}



To do the same with featured products, you'll need to edit line 21 of modules/homefeatured/homefeatured.tpl (in PrestaShop v1.3.1):

<a class="exclusive ajax_add_to_cart_button" rel="ajax_id_product_{$product.id_product}" href="{$base_dir}cart.php?qty=1&id_product={$product.id_product}&token={$static_token}&add" title="{l s='Add to cart' mod='homefeatured'}">{l s='Add to cart' mod='homefeatured'}



and change it to:

{if $product.price == 0}<a href="{$base_dir}contact-form.php" class="exclusive">{l s='Contact us' mod='homefeatured'}{else}<a class="exclusive ajax_add_to_cart_button" rel="ajax_id_product_{$product.id_product}" href="{$base_dir}cart.php?qty=1&id_product={$product.id_product}&token={$static_token}&add" title="{l s='Add to cart' mod='homefeatured'}">{l s='Add to cart' mod='homefeatured'}{/if}

Share this post


Link to post
Share on other sites

I don't understand either. In my product list, every product has the "contact us" green button even the prices > 0

I will research it again but i'm pretty sure i did it right :-(


Sorry, I mean in the "product page" not the product-list.tpl

I have deleted the "add cart button" in my product list and homefeatured so the problems i have are only with the product page.


Right now the thing is if i use your code using the $product-getprice variable i get a 'Contact us' button for ALL products even the prices > 0. But if i use the $product->location variable instead all works perfectly so i leave it like that 'cause this is even better solution for me than using the prices. Thank you very much and sorry for the bother.

By the way rocky, i see you are something like a god-code of prestashop. I have this problem for weeks and didn't find anybody who can help me, can you take a look on it please? I would be VERY grateful. Thanks!

http://www.prestashop.com/forums/viewthread/64921/configuring___using_prestashop/playing_with_categories_block

Share this post


Link to post
Share on other sites

  • 4 weeks later...

Hi!
i tested this link with $product->location as Rocky said,and it is succesfull.but when i tryed with another link :
http://localhost/rest/category.php?id_category=5


prestashop answers that

1 error

1. the field location is invalid

it seems that some special characters are not allowed

how can i put the link to add to cart button?i am not a developer and i do not know how to code it

Share this post


Link to post
Share on other sites

Rocky if you are seeing this……….If any other can help…..!

Another problem came over.

When i put the code with {$product->location} in product.tpl its ok with the referance.It sees it

But when i put the code in the product-list.tpl it doesnt see the referance.How to put it to see it?

Thanks

Share this post


Link to post
Share on other sites

Hi Rocky,

your instructions are perfect for me, but there is a problem with the PACKS, in the individual items there is no problem, but in the items that are a PACK in the homepage the button is right "add to cart", but when you click to view the item...then the button change to "contact us"!.
Please could you tell me where is the bug or problem? I check this with the prestashop v.1.2.5 and with the v.1.2.3 and the problem is the same.
Thank you very much.

Share this post


Link to post
Share on other sites

Thank you rocky, but I can not fix it, works perfect except in the pack which are composed of several items in the store. I do not know much programming and I'm lost. If anyone can simulate this and create an item that is made up of several of the store (pack), perhaps could help me. I searched for other solutions to clear the button "add to cart" items or gifts with a value of 0 euros and this is the best, but it only fails the Pack. Thank you again.

Share this post


Link to post
Share on other sites

I've had another look, but I can't figure out why you are having a problem. I created a pack in my PrestaShop v1.3.1 installation. It seems it calls product-list.tpl to create a list of the products in the pack at the bottom of the product page. If you change product-list.tpl like in my code above, then the button should be the same on both the product listings and pack listings.

Share this post


Link to post
Share on other sites

I repeated the process again, I created a new Pack, and still have the same problem. rocky this issue is very important to me, I have several gifts listed in the store and the customers can freely add to cart, I'm going crazy. The problem is only with the packs, on the main page are good, but when you see the article, see the 'contact us' rather than the 'add to cart' How I can fix it?. My prestashop version is 1.2.3. thanks

Share this post


Link to post
Share on other sites

  • 1 month later...

Thanks a lot!!! after various hours it works!!!
(sorry for my bad english)
Now one more question, we have to put price 0 to activate that button, but is there any way to not display the price 0 in the shop? I mean the client will see the product without any price (but still 0 in the back office)

Best regards,
And thanks a lot!

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More