Jump to content

[SOLVED] Add quantity box to product listing


Recommended Posts

I have amended the below changes in Product-list.tpl to reflect the Quantity box in product list, This was suggested in forum Itself.

 

Before

{if ($product.allow_oosp || $product.quantity > 0)} <a class="button ajax_add_to_cart_button exclusive" rel="ajax_id_product_{$product.id_product|intval}" href="{$link->getPageLink('cart.php')}?add&id_product={$product.id_product|intval}{if isset($static_token)}&token={$static_token}{/if}" title="{l s='Add to cart'}">{l s='Add to cart'}</a>
{else}

 

As suggested I changed with below

 

{if ($product.allow_oosp OR $product.quantity > 0) && $product.customizable != 2}  {l s='Quantity :'}
		  <input type="text" name="ajax_qty_to_add_to_cart[{$product.id_product|intval}]" id="quantity_wanted_{$product.id_product|intval}" class="text" value="{if isset($quantityBackup)}{$quantityBackup|intval}{else}1{/if}" size="2" maxlength="3" />
   {l s='Add to cart'}
 {else}

 

With the above change i got quantity box in my product list but it disable the Add to Cart button and without that Quantity button is of no use.

Please help me to resolve the issue.

I have attached the screenshot of my product list to explain the situation better.

post-289968-0-56588400-1318823654_thumb.jpg

Link to comment
Share on other sites

  • 1 month later...

I have amended the below changes in Product-list.tpl to reflect the Quantity box in product list, This was suggested in forum Itself.

 

Before

{if ($product.allow_oosp || $product.quantity > 0)} <a class="button ajax_add_to_cart_button exclusive" rel="ajax_id_product_{$product.id_product|intval}" href="{$link->getPageLink('cart.php')}?add&id_product={$product.id_product|intval}{if isset($static_token)}&token={$static_token}{/if}" title="{l s='Add to cart'}">{l s='Add to cart'}</a>
{else}

 

As suggested I changed with below

 

{if ($product.allow_oosp OR $product.quantity > 0) && $product.customizable != 2}  {l s='Quantity :'}
		  <input type="text" name="ajax_qty_to_add_to_cart[{$product.id_product|intval}]" id="quantity_wanted_{$product.id_product|intval}" class="text" value="{if isset($quantityBackup)}{$quantityBackup|intval}{else}1{/if}" size="2" maxlength="3" />
   {l s='Add to cart'}
 {else}

 

With the above change i got quantity box in my product list but it disable the Add to Cart button and without that Quantity button is of no use.

Please help me to resolve the issue.

I have attached the screenshot of my product list to explain the situation better.

 

I have similar issue with version 1.4.5.1, may you please paste the exact final code which worked for you. I am using prestashop_new theme with Add to Cart Buttons

Link to comment
Share on other sites

May please provide the required code for version 1.4.5.1

 

We have following code in product-list.tpl file

 

 

{if ($product.allow_oosp || $product.quantity > 0)}

<a class="button ajax_add_to_cart_button exclusive" rel="ajax_id_product_{$product.id_product|intval}" href="{$link->getPageLink('cart.php')}?add&id_product={$product.id_product|intval}{if isset($static_token)}&token={$static_token}{/if}" title="{l s='Add to cart'}"><span></span>{l s='Add to cart'}</a><br />

{else}

<span class="exclusive"><span></span>{l s='Add to cart'}</span><br />

{/if}

 

 

Kindly provide the code to replace this, so that i can show quantity box directly in the product listing page. I am able to show box but add to cart button still accept quantity 1 with one click.

Link to comment
Share on other sites

  • 2 weeks later...

This is not a simple change, especially if you take into consideration the minimal quantity in PS 1.4+

We have created a module that lets you choose attributes + quantity from all product list pages http://www.prestashop.com/forums/index.php?/topic/79758-module-product-list-attributes-allow-customers-to-select-product-attributes-on-the-category-manufacturer-supplier-and-search-pages/

Link to comment
Share on other sites

  • 7 months later...

I managed to include the option to change the number but I do not sum to Cart, someone that can resolved this?

 

 

{if ($product.allow_oosp OR $product.quantity > 0) && $product.customizable != 2} {l s='Quantity :'}

<input type="text" name="ajax_qty_to_add_to_cart[{$product.id_product|intval}]" id="quantity_wanted_{$product.id_product|intval}" class="text" value="{if isset($quantityBackup)}{$quantityBackup|intval}{else}1{/if}" size="2" maxlength="3" />

<a class="btn_cart ajax_add_to_cart_button" rel="ajax_id_product_{$product.id_product|intval}" href="{$link->getPageLink('cart.php')}?add&id_product={$product.id_product|intval}{if isset($static_token)}&token={$static_token}{/if}" title="{l s='Add to cart'}">{l s='Add to cart'}</a>

{else}

Edited by DrogPatria (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...

I'm also having issues with this. I've read multiple threads about this and tried every solution I can find, however everything ends up the same. I can create the box, but when I press "Add to cart" it only adds 1 in quantity, even if I write 5.

 

I've replaced the code in ajax-cart.js and added the .val().

I've added the quantity box to product-list.tpl

I've added some javascript to the top of product-list.tpl that someone suggested

I've made sure there is no duplicate ID's in the source code

 

I have also tried to add a alert("Hello World"); to the ajax-cart.js close to where the ajaxCart.add() is being called. However I do not get any alert. It almost seems as if the function is never called actually.

 

I'm running latest version of Prestashop.

 

My current code:

ajax-cart.js:

$('.ajax_add_to_cart_button').unbind('click').click(function(){
  var idProduct =  $(this).attr('rel').replace('ajax_id_product_', '');
  if ($(this).attr('disabled') != 'disabled')
   ajaxCart.add(idProduct, null, false, this, $('#quantity_wanted_'+idProduct).val());
  return false;
 });

 

product-list.tpl:

{if ($product.id_product_attribute == 0 || (isset($add_prod_display) && ($add_prod_display == 1))) && $product.available_for_order && !isset($restricted_country_mode) && $product.minimal_quantity == 1 && $product.customizable != 2 && !$PS_CATALOG_MODE}
 {if ($product.allow_oosp OR $product.quantity > 0) && $product.customizable != 2}
	 {l s='Quantity :'}
	 <input type="text" name="ajax_qty_to_add_to_cart[{$product.id_product|intval}]" id="quantity_wanted_{$product.id_product|intval}" class="text" value="{if isset($quantityBackup)}{$quantityBackup|intval}{else}1{/if}" size="2" maxlength="3" />


  <a class="button ajax_add_to_cart_button exclusive" rel="ajax_id_product_{$product.id_product|intval}" href="{$link->getPageLink('cart.php')}?add&id_product={$product.id_product|intval}{if isset($static_token)}&token={$static_token}{/if}" title="{l s='Add to cart'}"><span></span>{l s='Add to cart'}</a><br />
 {else}
  <span class="exclusive"><span></span>{l s='Add to cart'}</span><br />
 {/if}
   {/if}

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 5 weeks later...

I have tried to insert the code but in prestashop don't 1.5 work?

suggestions?

 

 

{if ($product.allow_oosp || $product.quantity > 0)}

{if isset($static_token)}

<a class="button ajax_add_to_cart_button exclusive" rel="ajax_id_product_{$product.id_product|intval}" href="{$link->getPageLink('cart',false, NULL, "add&id_product={$product.id_product|intval}&token={$static_token}", true)}" title="{l s='Add to cart'}"><span></span>{l s='Add to cart'}</a>

{else}

<a class="button ajax_add_to_cart_button exclusive" rel="ajax_id_product_{$product.id_product|intval}" href="{$link->getPageLink('cart',false, NULL, "add&id_product={$product.id_product|intval}", true)} title="{l s='Add to cart'}"><span></span>{l s='Add to cart'}</a>

{/if}

{else}

<span class="exclusive"><span></span>{l s='Add to cart'}</span><br />

{/if}

Edited by Marco BRUNO (see edit history)
Link to comment
Share on other sites

  • 1 month later...

I'm also having issues with this. I've read multiple threads about this and tried every solution I can find, however everything ends up the same. I can create the box, but when I press "Add to cart" it only adds 1 in quantity, even if I write 5.

 

I've replaced the code in ajax-cart.js and added the .val().

I've added the quantity box to product-list.tpl

I've added some javascript to the top of product-list.tpl that someone suggested

I've made sure there is no duplicate ID's in the source code

 

I have also tried to add a alert("Hello World"); to the ajax-cart.js close to where the ajaxCart.add() is being called. However I do not get any alert. It almost seems as if the function is never called actually.

 

I'm running latest version of Prestashop.

 

My current code:

ajax-cart.js:

$('.ajax_add_to_cart_button').unbind('click').click(function(){
  var idProduct =  $(this).attr('rel').replace('ajax_id_product_', '');
  if ($(this).attr('disabled') != 'disabled')
ajaxCart.add(idProduct, null, false, this, $('#quantity_wanted_'+idProduct).val());
  return false;
 });

 

product-list.tpl:

{if ($product.id_product_attribute == 0 || (isset($add_prod_display) && ($add_prod_display == 1))) && $product.available_for_order && !isset($restricted_country_mode) && $product.minimal_quantity == 1 && $product.customizable != 2 && !$PS_CATALOG_MODE}
 {if ($product.allow_oosp OR $product.quantity > 0) && $product.customizable != 2}
	 {l s='Quantity :'}
	 <input type="text" name="ajax_qty_to_add_to_cart[{$product.id_product|intval}]" id="quantity_wanted_{$product.id_product|intval}" class="text" value="{if isset($quantityBackup)}{$quantityBackup|intval}{else}1{/if}" size="2" maxlength="3" />


  <a class="button ajax_add_to_cart_button exclusive" rel="ajax_id_product_{$product.id_product|intval}" href="{$link->getPageLink('cart.php')}?add&id_product={$product.id_product|intval}{if isset($static_token)}&token={$static_token}{/if}" title="{l s='Add to cart'}"><span></span>{l s='Add to cart'}</a><br />
 {else}
  <span class="exclusive"><span></span>{l s='Add to cart'}</span><br />
 {/if}
{/if}

 

 

 

 

i'm using PS 1.4.7

following change in the ajax-cart.js worked for me

 

//for every 'add' buttons...
$('.ajax_add_to_cart_button').unbind('click').click(function(){
var idProduct =  $(this).attr('rel').replace('ajax_id_product_', '');
if ($(this).attr('disabled') != 'disabled')
ajaxCart.add(idProduct, null, false, this,$('#quantity_wanted_'+ idProduct).val());
//alert($('#quantity_wanted_'+ idProduct).val());
return false;
});

Link to comment
Share on other sites

  • 1 month later...

Hi,

 

I have tried this solution for my shop and it didn't work :wacko:. I am using 1.4.8.2 PS version. I have set an alert to ajax-cart.js file where I have made the change. I do not see that alert. I suppose that that the code I have changed is not called. Has someone some ideas what could go wrong? I have seen that there are other people that also have this problem. Thanks!

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...
  • 2 weeks later...
  • 2 weeks later...

Hello, i'm using presta shop 1.5 and works fine for me. Notice that I made some changes... I added else condition

 

{if ($product.id_product_attribute == 0 || (isset($add_prod_display) && ($add_prod_display == 1))) && $product.available_for_order && !isset($restricted_country_mode) && $product.minimal_quantity <= 1 && $product.customizable != 2 && !$PS_CATALOG_MODE}

...

 

{else}

{if ($product.id_product_attribute == 0 || (isset($add_prod_display) && ($add_prod_display == 1))) && !isset($restricted_country_mode) && $product.minimal_quantity > 1 && $product.customizable != 2 && !$PS_CATALOG_MODE}

<input type="hidden" name="ajax_qty_to_add_to_cart[{$product.id_product|intval}]" id="quantity_wanted_{$product.id_product|intval}" class="text" value="{if isset($quantityBackup)}{$quantityBackup|intval}{else}1{/if}" size="2" maxlength="3" />

{if isset($static_token)}

<a class="ajax_add_to_cart_button exclusive" rel="ajax_id_product_{$product.id_product|intval}" href="{$link->getPageLink('cart',false, NULL, "add&id_product={$product.id_product|intval}&token={$static_token}", true)}" title="{l s='Add to cart'}">{l s='Add to cart'}</a>

{else}

<a class="ajax_add_to_cart_button exclusive" rel="ajax_id_product_{$product.id_product|intval}" href="{$link->getPageLink('cart',false, NULL, "add&id_product={$product.id_product|intval}", true)} title="{l s='Add to cart'}">{l s='Add to cart'}</a>

{/if}

{/if}

 

Inside this new else I put the same If condition, but remove variable "available_for_order" and set $product.minimal_quantity > 1. These variables combined make disappear "add to cart" button.

Is important to remaining checks to ensure that the product is visible, which has no country restrictions, etc.

Link to comment
Share on other sites

  • 2 months later...
  • 1 year later...

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...