0
で選択されたマルチselect属性によってカテゴリとフィルタからすべての製品、私はこのように私のMagentoの1.9のインストール(それぞれのオプション付き)で2つのマルチ選択の属性があります。ロードMagentoの
を作る
- メーカー
- メーカーB
- メーカーC
モデル
- 種類以上が "作る" と "モデル" があります
- タイプB
- タイプC
私はいくつかの製品を持っています。
特定のカテゴリのすべての商品を読み込み、Magentoで特定のマルチ選択属性オプションを選択した商品でフィルタするにはどうすればよいですか?製品は持って
// Mini-config
$make_attribute_code = 'make';
$model_attribute_code = 'model';
$filter_by_make = 'Manufacturer A';
$filter_by_model = 'Type A';
$load_from_category = 10117;
// Parse attribute option id of "Make"
$make_option_id = null;
$makeAttributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product', $make_attribute_code);
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($makeAttributeId);
$attributeOptions = $attribute ->getSource()->getAllOptions();
foreach ($attributeOptions as $attributeOption) {
if (trim($attributeOption['label']) == $filter_by_make) {
$make_option_id = (int)trim($attributeOption['value']);
break;
}
}
// Parse attribute option id of "Model"
$model_option_id = null;
$modelAttributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product', $model_attribute_code);
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($modelAttributeId);
$attributeOptions = $attribute ->getSource()->getAllOptions();
foreach ($attributeOptions as $attributeOption) {
if (trim($attributeOption['label']) == $filter_by_model) {
$model_option_id = (int)trim($attributeOption['value']);
break;
}
}
// Load category products having selected "Make" & "Model"
$products = Mage::getModel('catalog/category')
->load($load_from_category)
->getProductCollection()
->addAttributeToSelect('*')
->addAttributeToFilter(array(array('attribute' => $make_attribute_code, 'eq' => $make_option_id)))
->addAttributeToFilter(array(array('attribute' => $model_attribute_code, 'eq' => $model_option_id)))
->joinField(
'qty',
'cataloginventory/stock_item',
'qty',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left'
);
1つしかない場合、「作る」と:
make = [Manufacturer A] and [Manufacturer C]
model = [Type A] and [Type B]
これは私がこれまでにしようとしているものです:私はこのようなシナリオが存在する場所の製品をロードしようとしています
「モデル」オプションが選択されていると、表示されているように見えます。何か案は?
あなたは、コードを使用して何をしたいですか? –