![](/img/trans.png)
[英]Get total number of products by brand with multiple categories with PHP and MySQL
[英]Magento - get all categories containing products by brand
我花了一些時間試圖解決這個問題,但無濟於事。 如果我有一系列頁面顯示了按制造商過濾的產品集合,並且我想在每個頁面的左列中進行導航,例如其中包含當前制造商的產品類別列表,我可以不使用一些極其緩慢的代碼來填充它嗎? (有數千種產品)。
我可以在循環中放入類似的內容,遍歷每個類別,查看每個類別返回的制造商是否有任何結果,但是考慮到有數百個類別,這將相當緩慢。
$category = $currentCategory;
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
$manufacturers = array();
foreach ($attributes as $attribute) {
if ($attribute->getAttributeCode() == 'manufacturer') {
$filterBlockName = 'catalog/layer_filter_attribute';
$result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
foreach($result->getItems() as $option) {
$manufacturers[$option->getValue()] = $option->getLabel();
}
}
}
如果有人有更好的主意,我將不勝感激。
添加自定義類別屬性allmanufacturers(http://inchoo.net/ecommerce/magento/how-to-add-new-custom-category-attribute-in-magento/)。
運行一個cron,它將檢查每個類別的所有產品,並檢查其制造商,並在此allmanufacturers中的客戶屬性中填充一個(,)分隔的制造商值。
現在,在您的代碼中,您只需要檢查特定制造商的“自定義類別屬性-allmanufacturers”值,然后填充左列。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.