首先,大家好,为我可怜的英语道歉!
我想使用多个类别过滤产品系列,这是我的代码:
$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没有"其中"条件??
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 :(得分:2)
我有类似的问题,几乎相同的实现,解决方案将添加到您的集合的过滤器,如下所示:
$collection->getSelect()->where('at_category_id.category_id IN (?)', $arrayCatIds);
并删除当前
->addAttributeToFilter('category_id', $categoryIds);,您就完成了。