Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 2
How to have a dropdown for the quantity
 
jaribu
Jr. Member
 
Total Posts:  27
Joined:  2008-01-22
 

Hello,

How to have a dropdown for the quantity of products in the frontend?
I am with a product configurable on the frontend and the customer must note the quantity chosen instead choose from the dropdown.
I had to change an option, but which?

Thanks in advance.

Sorry if my english is not correct.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 

Simplest solution to this is probably editing the HTML (phtml) directly.

YOu can find this qty box here (default install):

app\design\frontend\default\default\template\catalog\product\view\type\

In this directory you will find simple.phtml, grouped.phtml, configurable.phtml

simple.phtml has the qty box in there at line 57 (on mine). If you are going to change this:
1) Copy it and it’s folder structure and paste it into a custom theme so you aren’t hacking into “core” design (this is of course optional)
2) Make sure whatever kind of input you use (dropdown) is named and IDed the same way ("qty") as the qty box. Also the value if nothing is selected should still be:

value="<?php echo $this->getMinimalQty($_product) ?>"
3) If you don’t use the core design and are using a custom one, you will have to edit the XML for this:
app\design\frontend\default\default\layout\catalog.xml

find

<PRODUCT_TYPE_simple>
        <
reference name="product.info">
            <
block type="catalog/product_view_type_simple" name="product.info.simple" as="product_type_data" template="catalog/product/view/type/simple.phtml"/>
        </
reference>
    </
PRODUCT_TYPE_simple>
    <
PRODUCT_TYPE_configurable>
        <
reference name="product.info">
            <
block type="catalog/product_view_type_configurable" name="product.info.configurable" as="product_type_data" template="catalog/product/view/type/configurable.phtml"/>
        </
reference>
    </
PRODUCT_TYPE_configurable>
    <
PRODUCT_TYPE_grouped>
        <
reference name="product.info">
            <
block type="catalog/product_view_type_grouped" name="product.info.grouped" as="product_type_data" template="catalog/product/view/type/grouped.phtml"/>
        </
reference>
    </
PRODUCT_TYPE_grouped>

and change the template to your new phtml file location/name (for simple, configurable and/or grouped - depending on which ones you decide to edit)

 
Magento Community Magento Community
Magento Community
Magento Community
 
jaribu
Jr. Member
 
Total Posts:  27
Joined:  2008-01-22
 

OK thank you very much Nikefido, I will study it.
As against this strange, I have for the moment the theme default (no change) and before I had the dropdown for the quantity of product can be with the change of magento version?

 
Magento Community Magento Community
Magento Community
Magento Community
 
jaribu
Jr. Member
 
Total Posts:  27
Joined:  2008-01-22
 

I don’t find the solution.  confused
I want make as this great site : http://www.theclimbingshop.com/shop/mammut-samourai.html

 
Magento Community Magento Community
Magento Community
Magento Community
 
jaribu
Jr. Member
 
Total Posts:  27
Joined:  2008-01-22
 

OK it’s in app\design\frontend\default\default\template\catalogue\view\addtocart.phtml
I have change :

<input name="qty" type="text" class="input-text qty" id="qty" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>" /></span>
by :
<select name="qty" class="input-text qty" id="qty"
            <
option value="1">1</option
            <
option value="2">2</option
        </
select>

but how can I get a list of actual quantity of the product?
 
Magento Community Magento Community
Magento Community
Magento Community
 
Crazy Serb
Jr. Member
 
Total Posts:  12
Joined:  2008-07-23
 
jaribu - 12 August 2008 05:32 AM

OK it’s in app\design\frontend\default\default\template\catalogue\view\addtocart.phtml
I have change :

<input name="qty" type="text" class="input-text qty" id="qty" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>" /></span>
by :
<select name="qty" class="input-text qty" id="qty"
            <
option value="1">1</option
            <
option value="2">2</option
        </
select>

but how can I get a list of actual quantity of the product?

yeah, which function actually pulls the total quantity # for each item?

then we could just stick it in a for loop in that select dropdown option…

EDIT: just used this function -> http://www.magentocommerce.com/boards/viewthread/3980/

 
Magento Community Magento Community
Magento Community
Magento Community
 
Thejosh13
Sr. Member
 
Total Posts:  252
Joined:  2008-06-23
 

I also would like to have the QTY select option as a drop down with default set to 1 ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Glitchy
Jr. Member
 
Total Posts:  17
Joined:  2008-02-05
 
Thejosh13 - 19 September 2008 07:45 AM

I also would like to have the QTY select option as a drop down with default set to 1 ?

Add the selected parameter to the first option:
<option value="1" selected>1</option>

 
Magento Community Magento Community
Magento Community
Magento Community
 
fabdel
Jr. Member
 
Total Posts:  16
Joined:  2008-08-29
 

To have the select drop-down with the current quantity,

i’ve replace

<input name="qty" type="text" class="input-text qty" id="qty" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>" />

By

<select name="test">
  
<?php $i 1 ?>
  <?php 
do { ?>
    
<option value="<?php echo $i?>">
      
<?php echo $i?>
      <?php $i
++ ?>
    
</option>
    
<?php } while ($i <= (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()) ?>
</select>

I have now to make an adaptative <select>, which will be linked with options in configurable products.them.

 
Magento Community Magento Community
Magento Community
Magento Community
 
till
Member
 
Total Posts:  58
Joined:  2007-12-17
 

My issue was slightly different, we only allow quantities in 100’s.

In app/design/frontend/default/<TEMPLATE>/catalog/product/view/addtocart.phtml:

<select class="input-text qty" name="qty" id="qty">
<?php
// show dropdown instead of textfield
$total Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
for (
$x=100$x<=$total$x=$x+100{
    
echo '<option value="' $x '">' $x '</option>';
}
?>
</select>

Problem is, you should also keep in mind to add your cart cause otherwise people manipulate the quantity directly over there.

So, do almost the same in app/design/frontend/default/<TEMPLATE>/template/checkout/cart/item/default.phtml:

<select class="input-text qty" name="cart[<?php echo $_item->getId() ?>][qty]" id="qty">
<?php
// show dropdown instead of textfield in cart
$total Mage::getModel('cataloginventory/stock_item')->loadByProduct($this->getProduct())->getQty();
for (
$x=100$x<=$total$x=$x+100{
    $selected 
'';
    if (
$x == $this->getQty()) {
        $selected 
.= ' selected="selected"';
     
}
     
echo '<option value="' $x '"' $selected '>' $x '</option>';
}
?>
</select>
 
Magento Community Magento Community
Magento Community
Magento Community
 
till
Member
 
Total Posts:  58
Joined:  2007-12-17
 

I should add that you either add similar logic to app/design/frontend/default/<TEMPLATE>/template/catalog/product/list.phtml. Otherwise people will still be able to add quantities of less than whatever you want to the cart.

I’m trying to work this into a helper and a tutorial. Maybe I’ll figure out how to package a module and make it run.

 
Magento Community Magento Community
Magento Community
Magento Community
 
weston
Jr. Member
 
Total Posts:  5
Joined:  2008-03-01
 

Code works great, but i changed it so it shows the “Maximum Qty Allowed in Shopping Cart”, which is a much better solution.

<select name="test">
  
<?php $i 1 ?>
  <?php 
do { ?>
    
<option value="<?php echo $i?>">
      
<?php echo $i?>
      <?php $i
++ ?>
    
</option>
    
<?php } while ($i <= (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getMaxSaleQty()) ?>
</select>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Johnny Love
Jr. Member
 
Total Posts:  3
Joined:  2008-11-17
NH USA
 

Hello,

Thank you for the code sample. I found the first snippet to work fine in
magento\app\design\frontend\default\template\template\catalog\product\view\addtocart.phtml

I needed to had a drop down box with quantity’s of 1/2 lbs. so I modified your code to look like:

<span class="qty-box"><label for="qty"><?php echo $this->__(''?></label>
            <
select class="input-text qty" name="qty" id="qty" style="width:5.5em";>
                
<?php
                
// show dropdown instead of textfield
                
$total Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
                for (
$x=0.5$x<=12$x=$x+0.5{
                    
echo '<option value="' $x '">' $x '  lbs.</option>';
                
}
                ?>
            
</select
        </
span>

OK, so it works fine for the individual items. When I tried to make the changes on:

\magento\app\design\frontend\default\template\template\catalog\product\list.phtml

so that I can have a drop down select quantity feature on the product list pages, I cant seem to make it work.

I would also be great to have the same feature in the cart itself.

Anyone with any suggestions or help would be greatly appreciated.

Thank you
question

till - 23 October 2008 06:33 AM

My issue was slightly different, we only allow quantities in 100’s.

In app/design/frontend/default/<TEMPLATE>/catalog/product/view/addtocart.phtml:

<select class="input-text qty" name="qty" id="qty">
<?php
// show dropdown instead of textfield
$total Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
for (
$x=100$x<=$total$x=$x+100{
    
echo '<option value="' $x '">' $x '</option>';
}
?>
</select>

Problem is, you should also keep in mind to add your cart cause otherwise people manipulate the quantity directly over there.

So, do almost the same in app/design/frontend/default/<TEMPLATE>/template/checkout/cart/item/default.phtml:
<select class="input-text qty" name="cart[<?php echo $_item->getId() ?>][qty]" id="qty">
<?php
// show dropdown instead of textfield in cart
$total Mage::getModel('cataloginventory/stock_item')->loadByProduct($this->getProduct())->getQty();
for (
$x=100$x<=$total$x=$x+100{
    $selected 
'';
    if (
$x == $this->getQty()) {
        $selected 
.= ' selected="selected"';
     
}
     
echo '<option value="' $x '"' $selected '>' $x '</option>';
}
?>
</select>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Digital Intouch
Jr. Member
 
Total Posts:  4
Joined:  2009-02-28
 

Hi All..

Im a newbie to the MAGENTO world.
But I manged to develop a shopping cart without problems till i found a product that is bit difficult to manage. The tread I’m reading is related to that, but could someone experience guide us how to do it more simple way.

Questions : Adding QTY as drop down for configurable products.

Example: I develped a site which provide printing services: Example product is a BUSINESS CARD - It has configurable / attributes
SIZE OPTIONS / COLOUR OPTIONS and NEED TO LIST THE QTY as a drop down in QTY 500, 1000, 2000, 5000 etc

( THERE IS NO INVENTORY AT ALL ATTACHED WITH THESE PRODUCTS)

Could you let us know a easy way to achive this

 
Magento Community Magento Community
Magento Community
Magento Community
 
InitechDesign
Sr. Member
 
Total Posts:  88
Joined:  2008-11-12
 
Digital Intouch - 30 May 2009 09:19 AM

Hi All..

Im a newbie to the MAGENTO world.
But I manged to develop a shopping cart without problems till i found a product that is bit difficult to manage. The tread I’m reading is related to that, but could someone experience guide us how to do it more simple way.

Questions : Adding QTY as drop down for configurable products.

Example: I develped a site which provide printing services: Example product is a BUSINESS CARD - It has configurable / attributes
SIZE OPTIONS / COLOUR OPTIONS and NEED TO LIST THE QTY as a drop down in QTY 500, 1000, 2000, 5000 etc

( THERE IS NO INVENTORY AT ALL ATTACHED WITH THESE PRODUCTS)

Could you let us know a easy way to achive this

@ Digital Intouch
I’m working on the same type of project (business cards, flyers, etc...). I created a configurable product and made the quantity’s and card stock and 1 or 2 sided show as the different options within the configured product. I just started this so I don’t know if it is going to work or not. Let me know if you come up with a better solution.

Brian

 
Magento Community Magento Community
Magento Community
Magento Community
 
Digital Intouch
Jr. Member
 
Total Posts:  4
Joined:  2009-02-28
 

Hi All,

I have managed to add the QTY drop down as mentioned above in both product detailed view and also at checkout ( its shows the drop down without any value). my question is: HOW CAN I GET THE DESIRED QTY ON THE DROP DOWN.

Example of a product:

BUSINESS CARD / CONFIGURABLE

Select : Colour
Select: Folding options
Select : Proof

QTY DROP DOWN SHOULD BE : ( 100, 250, 500, 1000, 2000, 5000 )

Could any one guide me how to achive this.

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