我有以下网址" wool-thread.php?manufacturer = 153"
我想从网址
获取产品数量即。产品计入具有制造属性" 153"
的类别答案 0 :(得分:0)
您需要按制造商属性过滤产品集合。这是工作代码。
$products = Mage::getModel('catalog/product')->getCollection();
$products->addAttributeToSelect('manufacturer');
$products->addFieldToFilter(array(
array('attribute'=>'manufacturer', 'eq'=> $option_id,
)));
$products->joinField(
'stock_status',
'cataloginventory/stock_status',
'stock_status',
'product_id=entity_id', array(
'stock_status' => Mage_CatalogInventory_Model_Stock_Status::STATUS_IN_STOCK,
'website_id' => Mage::app()->getWebsite()->getWebsiteId(),
)
);
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
$pro_count = $products->count();
其中Option id是制造商ID。在你的例子中它是153。 它将返回已过滤的已启用产品,可见产品和库存产品的集合。之后计算产品。
答案 1 :(得分:0)
您可以使用以下内容:
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('manufacturer');
$collection->addCategoryFilter(Mage::registry('current_category'));
$collection->addAttributeToFilter('manufacturer',array('eq'=>'153'));
echo $collection->count();
或
$products = Mage::getModel('catalog/category')->load(Mage::registry('current_category'))
->getProductCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('manufacturer', array('eq' => 153));
然后
$usedAttributeValues = array_unique($products->getColumnValues($attributeCode));
$attributeModel = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attributeCode);
$usedAttributeValues = $attributeModel->getSource()->getOptionText(
implode(',', $usedAttributeValues)
);
请参阅https://magento.stackexchange.com/a/4039/9489了解getSize的使用情况或收集数据。