PrestaShop Forum

The best place in the world to ask questions about PrestaShop and get advice from our passionate community!

PrestaShop Forum

Jump to content

 

[SOLVED] Add quantity box to product listing

47 replies to this topic
#1
ramar

    PrestaShop Newbie

  • Members
  • Pip
  • 0 posts
Hi, i would be gratefull for some help if anyone has done this before.

I want to add a quantity box to the product listing pages (similar to on the full view product page.

I have copied the following code from product.tpl to product-list.tpl, and have managed to get the quantity box to show up, but no matter what value i put in the quantity box, when i add to cart, it only add one item.

In product-list.tpl i have added the following:

 <!-- add to cart form-->
<form id="buy_block" action="{$base_dir}cart.php" method="post">

<!-- quantity wanted -->

quantity == 0) || $virtual} style="display:none;"{/if}>

<input type="text" name="qty" id="quantity_wanted" class="text" value="{if isset($quantityBackup)}{$quantityBackup|intval}{else}1{/if}" size="2" maxlength="3" />


</form>


and then edited the follwing:

{l s='Add to cart'}


If anyone has any idea how to do this i would really appreciate it. Im sure it cant be that difficult.

#2
lauriou

    PrestaShop Newbie

  • Members
  • Pip
  • 8 posts
Hi
Did you get it working?
as I am try to do the same thing
Cheers
Serge

#3
ningu

    PrestaShop Apprentice

  • Members
  • PipPip
  • 297 posts
A way to do this, with 2 modifications.

This works only when Ajax is activated in BlockCart module configuration.

In the theme directory, file product-list.tpl, replace :
{if ($product.allow_oosp OR $product.quantity > 0) && $product.customizable != 2}
{l s='Add to cart'}
{else}
BY (2 lines inserted)
{if ($product.allow_oosp OR $product.quantity > 0) && $product.customizable != 2}

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


In the module blockcart, file ajax-cart.js, in the first block " for every 'add' buttons.", replace :
ajaxCart.add(idProduct, null, false, this);
BY
ajaxCart.add(idProduct, null, false, this, $('#quantity_wanted_'+idProduct));


#4
lauriou

    PrestaShop Newbie

  • Members
  • Pip
  • 8 posts
Hi
I can't get it to work.
I can't see how the value from the <input> text for the quantity can be grabed without to submit the form?
Still thinking!
Serge

#5
ningu

    PrestaShop Apprentice

  • Members
  • PipPip
  • 297 posts
This is javascript that gets the value from the text and set it into the form request.

Is your site online so that I can check ? send me in PM

#6
ixotype

    PrestaShop Newbie

  • Members
  • Pip
  • 2 posts
Thanks ningu. It works great.

At the first time I can't get it to work but i made a change in your code.

Where you put:
ajaxCart.add(idProduct, null, false, this, $('#quantity_wanted_'+idProduct));

I changed:
ajaxCart.add(idProduct, null, false, this, $('#quantity_wanted_'+idProduct).val());

Thanks a lot

#7
lauriou

    PrestaShop Newbie

  • Members
  • Pip
  • 8 posts
got it to work.
.val() is needed!
Thanks a lot guys
Serge

#8
Axari

    PrestaShop Apprentice

  • Members
  • PipPip
  • 47 posts
Just wanted to say thank you. Been trying to do this for a month or more now. Appreciate everyone taking the time to share!

#9
teoze

    PrestaShop Newbie

  • Members
  • Pip
  • 4 posts
modul theme ?



In product-list.tpl i have added the following:
------------------------------------------------------------------------------------------

{if ($product.allow_oosp OR $product.quantity > 0) && $product.customizable != 2}
{l s='Add to cart'}
{else}


reaple

{if ($product.allow_oosp OR $product.quantity > 0) && $product.customizable != 2}

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






---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
in the module blockcart, file ajax-cart.js

ajaxCart.add(idProduct, null, false, this); 



reaple


ajaxCart.add(idProduct, null, false, this, $('#quantity_wanted_'+idProduct)); 


---------------------------------------------------------------------------------
---------------------------------------------------------------------------------

esoes :) help me pls

#10
saifur

    PrestaShop Newbie

  • Members
  • Pip
  • 1 posts
change product-list.tp according to the previous reply and

in the module blockcart, file ajax-cart.js
ajaxCart.add(idProduct, null, false, this); 


Replace with
ajaxCart.add(idProduct, null, false, this, $('#quantity_wanted_'+idProduct).val()); 


It is working

#11
Abh

    PrestaShop Apprentice

  • Members
  • PipPip
  • 467 posts
GOD! I thought i'd never be able to to this, thank you guys!

#12
Ciscowrig

    PrestaShop Apprentice

  • Members
  • PipPip
  • 97 posts
EDIT: I found that this is a bug with the wishlist block. Unrelated to the code posted here.


The items are not getting added to the order detail on order.php.

What do I need to add there? They are coming through in the final order though.

Attached Files



#13
luca.lb

    PrestaShop Apprentice

  • Members
  • PipPip
  • 28 posts
I've add a field in database with granularity quanitity:
exemple

DVD-R Verbatim in spindle 25pk. I've the price for single DVDs, 0.20€ but the customers need to add block of 25pz. The granularity is 25

I want that if the user does not put 25pz or multiple (50,27,100,125 etc.) comes out an alert with an error message.

how do I do?

#14
fernando fischer

    PrestaShop Newbie

  • Members
  • Pip
  • 9 posts
hi guys i due this but do not work on my server any idea what i could be doing wrong
thank you

#15
fernando fischer

    PrestaShop Newbie

  • Members
  • Pip
  • 9 posts
hi every one .... i got it , the code works for me , i believe that i was doing someting wrong at the first
thank you
IT WORKS !!!!!!!!!!

#16
Rod

    PrestaShop Apprentice

  • Members
  • PipPip
  • 56 posts
it works.Great. Then how can I add combinations on product list???

#17
Rod

    PrestaShop Apprentice

  • Members
  • PipPip
  • 56 posts

From 1264488718:

change product-list.tp according to the previous reply and

in the module blockcart, file ajax-cart.js
ajaxCart.add(idProduct, null, false, this); 


Replace with
ajaxCart.add(idProduct, null, false, this, $('#quantity_wanted_'+idProduct).val()); 


It is working


Do this again.

#18
Start Online Design

    PrestaShop Newbie

  • Members
  • Pip
  • 22 posts
yeah it works really great. Thanks a lot!

#19
Kex

    PrestaShop Newbie

  • Members
  • Pip
  • 3 posts
Aloha. it's very simple but very usable...except one thing - in the box i writing for example 10 pcs, clicking add to cart and ajax adding only1 pcs. What the hell??? Installed and checked already 20 times and i need you help wisemen ! I'm using prestashop 1.3.1.

#20
Kex

    PrestaShop Newbie

  • Members
  • Pip
  • 3 posts

From 1282150532:

Aloha. it's very simple but very usable...except one thing - in the box i writing for example 10 pcs, clicking add to cart and ajax adding only1 pcs. What the hell??? Installed and checked already 20 times and i need you help wisemen ! I'm using prestashop 1.3.1.


after this reply, my damn cart now working pretty well...something mistic, but cart working...yessssss