3

我为我的可配置产品设置了属性,我想在我的选择尺寸下拉列表中显示 L 尺寸的产品缺货

在此处输入图像描述 我得到了一个代码,但那是针对magento 1.4的,我正在使用magento 1.6

守则是

在 mage/catalog/block/product/view/type/configurable.php 中,在 ~85 行中你有这样的东西:

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(),
                    );

谁能告诉我根据 magento1.6 会有什么变化?

4

1 回答 1

-1

Create your own module, and in the config.xml file add these 2 events inside the tag:

<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>

Now create an observer inside app/code/local/Namespace/Module/Model/Observer.php

class Namespace_Module_Model_Observer {
    public function showOutOfStock($observer){
        Mage::helper('catalog/product')->setSkipSaleableCheck(true);
    }
}
于 2015-01-30T12:04:41.043 回答