I have attribute set for my configurable products
i want to show out of stock for the L size of product in my select size drop down
i got a code for this but that is for magento 1.4 and am using magento 1.6
the Code is
in mage/catalog/block/product/view/type/configurable.php, in line ~85 you have something like this :
foreach ($this->getAllowAttributes() as $attribute) {
$productAttribute = $attribute->getProductAttribute();
$attributeValue = $product->getData($productAttribute->getAttributeCode());
if (!isset($options[$productAttribute->getId()])) {
$options[$productAttribute->getId()] = array();
}
if (!isset($options[$productAttribute->getId()][$attributeValue])) {
$options[$productAttribute->getId()][$attributeValue] = array();
}
$options[$productAttribute->getId()][$attributeValue][] = $productId;
}
so, in that foreach loop , preferably right after the foreach line, insert this code:
$options['qty'][$product -> getAttributeText($productAttribute->getName())] = floor($product->getStockItem()->getQty());
after, in line ~128 you have something like this:
$info['options'][] = array(
'id' => $value['value_index'],
'label' => $value['label'] ,
'price' => $this->_preparePrice($value['pricing_value'], $value['is_percent']),
'products' => isset($options[$attributeId][$value['value_index']]) ? $options[$attributeId][$value['value_index']] : array(),
);
replace it with this :
$info['options'][] = array(
'id' => $value['value_index'],
'label' => ($options['qty'][$value['label']] <= 0) ? $value['label'] . ' * out of stock' : $value['label'] . " * (".$options['qty'][$value['label']]." in stock)",
'price' => $this->_preparePrice($value['pricing_value'], $value['is_percent']),
'products' => isset($options[$attributeId][$value['value_index']]) ? $options[$attributeId][$value['value_index']] : array(),
);
can anyone please tell me what will be changes according to magento1.6 ?
Best Answer
Create your own module, and in the config.xml file add these 2 events inside the tag:
Now create an observer inside app/code/local/Namespace/Module/Model/Observer.php