Magento 如何获取所有使用特定属性的可配置产品?
我希望所有使用大小变化属性和大小变化属性类型的可配置产品都是下拉列表 请帮帮我Magento 如何获取所有使用特定属性的可配置产品?,magento,Magento,我希望所有使用大小变化属性和大小变化属性类型的可配置产品都是下拉列表 请帮帮我 提前谢谢。试试这个。。。这肯定行 $category_id = 4; $catagory_model = Mage::getModel('catalog/category')->load($category_id); //where $category_id is the id of the category $collection = Mage::getResourceModel('catalog/pro
提前谢谢。试试这个。。。这肯定行
$category_id = 4;
$catagory_model = Mage::getModel('catalog/category')->load($category_id); //where $category_id is the id of the category
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addAttributeToFilter('status', 1)->addAttributeToFilter('visibility', array(2, 4)); //only enabled product
$collection->addAttributeToSelect(array('name', 'url', 'small_image')); //add product attribute to be fetched
$collection->addAttributeToFilter('type_id', 'configurable');
$collection->addStoreFilter();
//$collection->load(true, true); // first parameter show sql query in output, second show sql query in var/log/syslog
if (!empty($collection)) {
foreach ($collection as $_product):
echo $_product->getName();
//echo get_class($this);
?>
<ul><li class="cell-enable a-center"><input type="checkbox" <input type="checkbox" value="new_slider" name="drives[]"><a><img width="40" height="40" onmouseout="productPreviewHide();" onmouseover="productPreview('<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(165, 165); ?>');" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(50, 50); ?>"></a></li>
</ul>
<?php
endforeach;
}
在
$collection->addAttributeToSelect(数组('name','url','small_image')旁边添加上述链接代码>现在您只能看到包含属性\u set\u id为40的产品。40是为鞋设置的属性ID。首先检查您需要的属性集是什么,收集这些属性集的ID,并将它们放置在select查询的数组中。如果只需要单个属性集,则不需要数组…请尝试以下代码
$attribute_code = "size";
$attribute_details = Mage::getSingleton("eav/config")->getAttribute('catalog_product', $attribute_code);
$attributeId = $attribute_details->getId(); // ret
//92 is attribute
$collection=Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->addFieldToFilter('type_id', 'configurable');
$collection->getSelect()->join( array('config'=> 'catalog_product_super_attribute'), 'config.product_id = e.entity_id and config.attribute_id=92', array('product_id'));
$collection->load();
echo count($collection);
foreach($collection as $pro){
echo "<pre>";
print_r($pro->getName());
echo "</pre>";
}
$attribute\u code=“size”;
$attribute\u details=Mage::getSingleton(“eav/config”)->getAttribute('catalog\u product',$attribute\u code);
$attributeId=$attribute_details->getId();//ret
//92是属性
$collection=Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->addFieldToFilter('type_id','configurable');
$collection->getSelect()->join(数组('config'=>'catalog\u product\u super\u attribute'),'config.product\u id=e.entity\u id和config.attribute\u id=92',数组('product\u id');
$collection->load();
回声计数(收集);
foreach($pro收款){
回声“;
打印($pro->getName());
回声“;
}
它不起作用,我需要属性id或名称中的所有可配置产品。您必须根据需要修改代码。只是复制粘贴不会给出您所需的答案。您需要将所需属性添加到选择筛选器。
$attribute_code = "size";
$attribute_details = Mage::getSingleton("eav/config")->getAttribute('catalog_product', $attribute_code);
$attributeId = $attribute_details->getId(); // ret
//92 is attribute
$collection=Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->addFieldToFilter('type_id', 'configurable');
$collection->getSelect()->join( array('config'=> 'catalog_product_super_attribute'), 'config.product_id = e.entity_id and config.attribute_id=92', array('product_id'));
$collection->load();
echo count($collection);
foreach($collection as $pro){
echo "<pre>";
print_r($pro->getName());
echo "</pre>";
}