首页 文章

magento过滤器可通过子产品属性配置产品

提问于
浏览
1

在我的商店中,只有可配置的产品是可见的 . 简单的产品是隐藏的 . 每个可配置产品都有相关的简单产品 .

我想按子产品属性过滤可配置产品 .

例如,如果可配置产品子颜色为color = blue,则产品应在产品集合中加载

1 回答

  • 0
    $attributeCode = 'color';
    $attributeValue = 'Blue';
    
    $attribute = Mage::getSingleton('eav/config')
                    ->getAttribute('catalog_product', $attributeCode);
    
    if ($attribute->usesSource()) {
        $options = $attribute->getSource()->getAllOptions(false);
    }
    
    $attributeValueId = 0;
    foreach ($options as $option) {
        if ($option['label'] == $attributeValue) {
            $attributeValueId = $option['value'];
        }
    }
    
    $productId = YOUR_CONFIGURABLE_PRODUCT_ID; // ID of configurable product
    
    $product = Mage::getModel('catalog/product')->load($productId);
    
    $childProducts = Mage::getModel('catalog/product_type_configurable')                            
                        ->getUsedProductCollection($product)
                        ->addAttributeToSelect('*')
                        ->addAttributeToFilter($attributeCode, $attributeValueId);
    

    资料来源:Magento: Filter Configurable Product by Child Product’s Attribute

相关问题