在magento中显示可配置产品的缺货
我已经为我的可配置产品设置了属性 我想在“选择尺码”下拉列表中显示L尺码的产品缺货 我有一个代码,但这是为magento 1.4和我使用的magento 1.6 代码是 在mage/catalog/block/product/view/type/configurable.php中,第85行中有如下内容:在magento中显示可配置产品的缺货,magento,Magento,我已经为我的可配置产品设置了属性 我想在“选择尺码”下拉列表中显示L尺码的产品缺货 我有一个代码,但这是为magento 1.4和我使用的magento 1.6 代码是 在mage/catalog/block/product/view/type/configurable.php中,第85行中有如下内容: foreach ($this->getAllowAttributes() as $attribute) { $productAttribute = $at
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;
}
因此,在该foreach循环中,最好在foreach行之后插入以下代码:
$options['qty'][$product -> getAttributeText($productAttribute->getName())] = floor($product->getStockItem()->getQty());
在第128行之后,您将看到以下内容:
$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(),
);
$info['options'][]=数组(
'id'=>$value['value\u index'],
'label'=>$value['label'],
“价格”=>$this->\u准备价格($value['pricing\u value'],$value['is\u percent']),
'products'=>isset($options[$attributeId][$value['value\u index']])?$options[$attributeId][$value['value\u index']]:数组(),
);
将其替换为以下内容:
$info['options'][]=数组(
'id'=>$value['value\u index'],
“label”=>($options['qty'][$value['label']]]$this->\u preparePrice($value['pricing\u value'],$value['is\u percent']),
'products'=>isset($options[$attributeId][$value['value\u index']])?$options[$attributeId][$value['value\u index']]:数组(),
);
有人能告诉我根据magento1.6会有什么变化吗?创建您自己的模块,并在config.xml文件中在标记内添加以下两个事件:
<events>
<controller_action_layout_render_before_catalog_product_view>
<observers>
<namespace_module>
<class>module/observer</class>
<method>showOutOfStock</method>
</namespace_module>
</observers>
</controller_action_layout_render_before_catalog_product_view>
<controller_action_layout_render_before_checkout_cart_configure>
<observers>
<namespace_module>
<class>module/observer</class>
<method>showOutOfStock</method>
</namespace_module>
</observers>
</controller_action_layout_render_before_checkout_cart_configure>
</events>
这一条对我很有用:别忘了阅读这一条:此解决方案存在问题。请参阅此处:
class Namespace_Module_Model_Observer {
public function showOutOfStock($observer){
Mage::helper('catalog/product')->setSkipSaleableCheck(true);
}
}