Magento Forum

   
Page 1 of 2
How do I show the quantity box when browsing a category? 
 
Moose
Jr. Member
 
Total Posts:  9
Joined:  2007-09-25
 

When viewing products in the category view, I would like to be able to have a “Quantity” box that allows the user to enter the quantity needed before clicking the “Add to Cart” button. How can I show this?

Image Attachments
screenshot_03.gif
 
Magento Community Magento Community
Magento Community
Magento Community
 
ramedia
Member
 
Total Posts:  70
Joined:  2008-05-17
 

Try adding:

<span class="qty-box"><label for="qty"><?php echo $this->__('Qty') ?>:</label>

to the app> design> frontend > default > yourtemplate > template > catalog > list.phtml page.  You’ll have to add it twice, once for grid view and once for list view.  You also have to have quantity defined for the product and already viewable on the actual product detail page.

Let me know if that works.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moose
Jr. Member
 
Total Posts:  9
Joined:  2007-09-25
 

I tried it, and it shows the label but does not render the actual text field for quantity.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ramedia
Member
 
Total Posts:  70
Joined:  2008-05-17
 

Do you see a quantity box on the actual product page?

 
Magento Community Magento Community
Magento Community
Magento Community
 
ramedia
Member
 
Total Posts:  70
Joined:  2008-05-17
 

try this:

<input name="cart[<?php echo $_item->getId() ?>][qty]” value="<?php echo $this->getQty() ?>” size="4" class="input-text qty” maxlength="8" />

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moose
Jr. Member
 
Total Posts:  9
Joined:  2007-09-25
 

No good. It throws an error:

Fatal error:  Call to a member function getId() on a non-object in /app/design/frontend/default/default/template/catalog/product/list.phtml

 
Magento Community Magento Community
Magento Community
Magento Community
 
ramedia
Member
 
Total Posts:  70
Joined:  2008-05-17
 

Let’s try to add quantity to the list view:

/app/design/frontend/default/default/layout/catalog.xml

under:
<reference name="content">
<block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">

put:
<action method="addAttribute"><attribute>quantity</attribute></action>

 
Magento Community Magento Community
Magento Community
Magento Community
 
XjSv
Member
 
Avatar
Total Posts:  38
Joined:  2008-08-19
Ridgewood, NY
 

sooooooo none of the above solutions work......anyone got any ideas or r we just gonna leave this thread like this.......like what the hell right…

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moose
Jr. Member
 
Total Posts:  9
Joined:  2007-09-25
 

FYI I never found a solution to this.

 
Magento Community Magento Community
Magento Community
Magento Community
 
XjSv
Member
 
Avatar
Total Posts:  38
Joined:  2008-08-19
Ridgewood, NY
 

DAMMMM cus i would really use a solution to this. any updates pls post them.  >:(

 
Magento Community Magento Community
Magento Community
Magento Community
 
pastanislas
Member
 
Total Posts:  46
Joined:  2008-07-29
 

up, i’m still looking for it.. anyone ?
ty

 
Magento Community Magento Community
Magento Community
Magento Community
 
pezomatic
Sr. Member
 
Avatar
Total Posts:  190
Joined:  2008-11-05
 

Has anyone been able to get this to work?

 
Magento Community Magento Community
Magento Community
Magento Community
 
nebil
Jr. Member
 
Total Posts:  1
Joined:  2008-04-07
 

<?php if($_product->isSaleable()): ?>
<form action="<?php echo $this->getAddToCartUrl($_product) ?>” method="post" id="product_addtocart_form_<?php echo $_product->getId(); ?>">
<input name="qty" type="text" class="input-text qty” id="qty" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>” /></td>
<a href="#" onclick="productAddToCartForm_<?php echo $_product->getId(); ?>.submit()">Add to cart</a> </form>
<?php endif; ?>
<script type="text/javascript\">
var productAddToCartForm_<?php echo $_product->getId(); ?> = new VarienForm(’product_addtocart_form_<?php echo $_product->getId(); ?>’);
productAddToCartForm_<?php echo $_product->getId(); ?>.submit = function(){
if (this.validator.validate()) {
this.form.submit();
}
}.bind(productAddToCartForm_<?php echo $_product->getId(); ?>);
</script>

try this one inside the ‘for’ loop

 
Magento Community Magento Community
Magento Community
Magento Community
 
pastanislas
Member
 
Total Posts:  46
Joined:  2008-07-29
 

Woooo Thank you man this is definiteley working !!!
I just re-post the code cause there’s problem with quotes (maybe you pasted you code from word ?)

<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId(); ?>">
<
input name="qty" type="text" class="input-text qty" id="qty" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>" />
<
button class="button" onclick="productAddToCartForm_<?php echo $_product->getId(); ?>.submit()"><span><?php echo $this->__('Add to Cart'?></span></button>
</
form>
<
script type="text/javascript">
var 
productAddToCartForm_<?php echo $_product->getId(); ?> = new VarienForm('product_addtocart_form_<?php echo $_product->getId(); ?>');
productAddToCartForm_<?php echo $_product->getId(); ?>.submit = function(){
if (this.validator.validate()) {
this
.form.submit();
}
}
.bind(productAddToCartForm_<?php echo $_product->getId(); ?>);
</script>

Thank you again wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
neogecko
Jr. Member
 
Total Posts:  15
Joined:  2008-09-12
 

Which file did you add this code to, to make it work?

Nevermind - I put it in the list.phtml. The same file mentioned earlier in this thread.

nebil - thank you very much

 
Magento Community Magento Community
Magento Community
Magento Community
 
pezomatic
Sr. Member
 
Avatar
Total Posts:  190
Joined:  2008-11-05
 
nebil - 13 November 2008 12:56 AM

<?php if($_product->isSaleable()): ?>
<form action="<?php echo $this->getAddToCartUrl($_product) ?>” method="post" id="product_addtocart_form_<?php echo $_product->getId(); ?>">
<input name="qty" type="text" class="input-text qty” id="qty" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>” /></td>
<a href="#" onclick="productAddToCartForm_<?php echo $_product->getId(); ?>.submit()">Add to cart</a> </form>
<?php endif; ?>
<script type="text/javascript\">
var productAddToCartForm_<?php echo $_product->getId(); ?> = new VarienForm(’product_addtocart_form_<?php echo $_product->getId(); ?>’);
productAddToCartForm_<?php echo $_product->getId(); ?>.submit = function(){
if (this.validator.validate()) {
this.form.submit();
}
}.bind(productAddToCartForm_<?php echo $_product->getId(); ?>);
</script>

try this one inside the ‘for’ loop

You say to try this code inside the “for” loop. Can you please explain what that means?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 1 of 2