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 loop で、できれば 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

独自のモジュールを作成し、config.xml ファイルのタグ内に次の 2 つのイベントを追加します。

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

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 に答える