Hello
I am using magento 1.7.0.2 CE. I need to display a dropdown for product quantity to allow a user to select quantity from the dropdown on cart page. I have added a code in checkout/cart/item/default.phtml
for the same which is,
<?php echo $min_sale_qty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($this->getProduct())->getData('min_sale_qty');
$total_qyt = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($this->getProduct())->getQty();
?>
<select name="cart[<?php echo $_item->getId() ?>][qty]">
<?php for($i = $min_sale_qty; $i <= $total_qyt; $i = $i + $min_sale_qty)
{
?>
<option value="<?php echo $i?>" <?php echo ($i == $this->getQty())? "selected=selected": ""; ?>>
<?php echo $i?>
</option>
<?php }?>
</select>
This code displays the dropdown correctly for simple products. But when I add configurable product to my cart, It displays me dropdown without any option to select.
Can anyone help me with it? Thanks in Advance.
Best Answer
This happens because the configurable product does not have minimum sale qty and a total qty.
You need to get the simple product that is represented by the configurable product and get the values from it. Try this:
I didn't test, but it seams like the way to go.I've tested and this works for me. I was close. Instead of
getParentId()
it should begetParentItemId()
. Here is the code from mycheckout/cart/item/default.phtml
file:I'm almost sure that there is an other way of getting the simple product and avoid the
foreach
loop but this will do for now.