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:
$simpleProduct = null;
foreach ($_item->getQuote()->getAllItems() as $simpleItem){
if ($simpleItem->getParentId() == $_item->getId()){
$simpleProduct = $simpleItem->getProduct();
break;
}
}
if ($simpleProduct){
//work your magic with $simpleProduct
}
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 be getParentItemId()
. Here is the code from my checkout/cart/item/default.phtml
file:
$simpleProduct = $this->getProduct();
if ($this->getProduct()->getTypeId() == 'configurable') {
foreach ($_item->getQuote()->getAllItems() as $simpleItem){
if ($simpleItem->getParentItemId() == $_item->getId()){
$simpleProduct = $simpleItem->getProduct();
break;
}
}
}
$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($simpleProduct);
$min_sale_qty = (int)$stockItem->getData('min_sale_qty');
$total_qyt = (int)$stockItem->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 endfor;?>
</select>
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.
As stated my Mahalakshmi the file of interest is
/magento/module-checkout/view/frontend/web/template/minicart/item/default.html
Make a copy of this file into your custom theme so file is overridden e.g.
app/design/frontend/Vendor/Theme/Magento_Checkout/web/template/minicart/item/default.html
You can then make some basic modifications to this file outlined below.
Disable the Quantity Box
Add disabled attribute to the input box like below:
<input data-bind="attr: {
id: 'cart-item-'+item_id+'-qty',
'data-cart-item': item_id,
'data-item-qty': qty,
'data-cart-item-id': product_sku
}, value: qty"
type="number"
size="4"
disabled
class="item-qty cart-item-qty">
This was around line 74 for me on version 2.2.1.
Add logic to enable quantity box
<a data-bind="attr: {onclick: 'document.getElementById(\'cart-item-'+item_id+'-qty\').disabled = false;'}" class="action edit">
<span data-bind="i18n: 'Edit'"></span>
</a>
I replaced the data-bind attribute with a new action here to enable the quantity box in relation to the quantity that needed to be edited. This was at about line 98 for me.
Best Answer
In your custom module, do following steps.
After this,
Clear all your browser cache and check. This should work.