2014-09-03 86 views
1

首先,向大家問好,併爲我可憐的英語道歉!Magento - 平板產品/類別開啓時如何使用多個類別過濾產品集合

我要篩選使用多個類別的產品集合,這是我的代碼:

$collection = Mage::getModel('catalog/product') 
         ->getCollection() 
         ->addAttributeToSelect('*') 
         ->addMinimalPrice() 
         ->addFinalPrice() 
         ->addTaxPercents() 
         ->addTierPriceData() 
         ->addUrlRewrite() 
         ->setStoreId($this->_storeId) 
         ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left') 
         ->addAttributeToFilter('category_id', $categoryIds); 

$ categoryIds是返回數組( '在'=>陣列(1,2,3,4,5, 6,7,8)

它工作得很好,但是當我打開使用平面目錄類別/使用平面目錄產品實在不行。

請幫幫我。

------編輯----

我通過echo $ collection-> getSelect()打印sql。 SQL沒有「where」條件?

SELECT 1 AS `status`, `e`.`entity_id`, `e`.`type_id`, `e`.`attribute_set_id`, 
`e`.`name`, `e`.`short_description`, `e`.`price`, `e`.`special_price`, 
`e`.`special_from_date`, `e`.`special_to_date`, `e`.`small_image`, `e`.`thumbnail`, 
`e`.`news_from_date`, `e`.`news_to_date`, `e`.`url_key`, `e`.`required_options`, 
`e`.`image_label`, `e`.`small_image_label`, `e`.`thumbnail_label`, `e`.`msrp_enabled`, 
`e`.`msrp_display_actual_price_type`, `e`.`msrp`, `e`.`tax_class_id`, 
`e`.`price_type`, `e`.`weight_type`, `e`.`price_view`, `e`.`shipment_type`, 
`e`.`links_purchased_separately`, `e`.`links_exist`, `e`.`groupdeal_status`, 
`e`.`groupdeal_datetime_from`, `e`.`groupdeal_datetime_to`, `e`.`entity_id`, 
`e`.`attribute_set_id`, `e`.`type_id`, `e`.`cost`, `e`.`created_at`, 
`e`.`gift_message_available`, `e`.`has_options`, `e`.`image_label`, 
`e`.`is_recurring`, `e`.`links_exist`, `e`.`links_purchased_separately`, 
`e`.`links_title`, `e`.`msrp`, `e`.`msrp_display_actual_price_type`, 
`e`.`msrp_enabled`, `e`.`name`, `e`.`news_from_date`, `e`.`news_to_date`, `e`.`price`, 
`e`.`price_type`, `e`.`price_view`, `e`.`recurring_profile`, `e`.`required_options`, 
`e`.`shipment_type`, `e`.`short_description`, `e`.`sku`, `e`.`sku_type`, 
`e`.`small_image`, `e`.`small_image_label`, `e`.`special_from_date`, 
`e`.`special_price`, `e`.`special_to_date`, `e`.`tax_class_id`, `e`.`thumbnail`, 
`e`.`thumbnail_label`, `e`.`updated_at`, `e`.`url_key`, `e`.`url_path`, 
`e`.`visibility`, `e`.`weight`, `e`.`weight_type`, `e`.`groupdeal_datetime_from`, 
`e`.`groupdeal_datetime_to`, `e`.`groupdeal_status`, `price_index`.`price`, 
`price_index`.`tax_class_id`, `price_index`.`final_price`, IF(price_index.tier_price 
IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), 
price_index.min_price) AS `minimal_price`, `price_index`.`min_price`, 
`price_index`.`max_price`, `price_index`.`tier_price`, `at_category_id`.`category_id` 
FROM `catalog_product_flat_1` AS `e` INNER JOIN `catalog_product_index_price` AS 
`price_index` ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' 
AND price_index.customer_group_id = 0 LEFT JOIN `catalog_category_product` AS 
`at_category_id` ON (at_category_id.`product_id`=e.entity_id) 
+0

您是否成功重新索引數據? – 2014-09-03 10:13:08

+0

是的,我did.I重新索引數據後開啓使用平面目錄類別/使用平面目錄產品。 – 2014-09-03 10:20:52

+0

您的catalog_product_flat_1的內容是什麼?它填寫正確嗎? – 2014-09-03 10:30:23

回答

1

我有類似的問題,幾乎相同的實現,解決方法是將其中過濾器添加到您的收藏這樣的:

 
$collection->getSelect()->where('at_category_id.category_id IN (?)', $arrayCatIds); 

,並刪除當前

->addAttributeToFilter('category_id', $categoryIds);
和你做。

相關問題