如何在Magento EE中为Product属性选择选项标签添加类似匹配

时间:2016-04-04 09:34:12

标签: magento

我需要在Product属性(Color,Manufacturer ... 23属性,这是所有选择下拉类型)中添加类似关键字匹配,在Magento EE中使用'或','选择选项标签。和'条件。

虽然我已经搜索并找到了一些解决方案和不同的方法来获得结果,但我无法找到它不适合我的原因。

我添加了重写类来添加上面的过滤器选项

/*
 * Rewritten to add Match all|any filtering
 */
protected function _getProductCollection()
{
    if (is_null($this->_productCollection)) {
        $keyword = $this->getRequest()->getParam('keyword', '');
        $filterOption = $this->getRequest()->getParam('fo', '');
        $this->_productCollection = parent::_getProductCollection();
        if ($filterOption != '' && $keyword != '') {
            $filterableAttributesArray = $this->getFilterableAttributes();//Got all filterable select dropdown attributes with its attribute_id
            if ($filterableAttributesArray && count($filterableAttributesArray)) {
                $filterables = array();
                foreach ($filterableAttributesArray as $attr) {
                    $this->_productCollection->addAttributeToSelect($attr);
                    $filterables[] = array('attribute' => $attr, 'like' => '%' . "$keyword" . '%');
                }
                if ($filterOption == 'any') {
                    $this->_productCollection->addAttributeToFilter($filterables);
                } else {
                    foreach ($filterables as $attr_cond) {
                        $this->_productCollection->addAttributeToFilter($attr_cond);
                    }
                }
                $this->_productCollection->load();
            }
        }
        d((string)$this->_productCollection->getSelect());
    }
    return $this->_productCollection;
}

查询此信息 对于'或'条件

SELECT `e`.*, `cat_index`.`position` AS `cat_index_position`, `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_color`.`value` AS `color`, `at_manufacturer`.`value` AS `manufacturer` FROM `catalog_product_entity` AS `e`
 INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.visibility IN(2, 4) AND cat_index.category_id = '3'
 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
 INNER JOIN `catalog_product_entity_int` AS `at_color` ON (`at_color`.`entity_id` = `e`.`entity_id`) AND (`at_color`.`attribute_id` = '92') AND (`at_color`.`store_id` = 0)
 INNER JOIN `catalog_product_entity_int` AS `at_manufacturer` ON (`at_manufacturer`.`entity_id` = `e`.`entity_id`) AND (`at_manufacturer`.`attribute_id` = '81') AND (`at_manufacturer`.`store_id` = 0) 

WHERE((at_color.value LIKE'%blue%')或(at_manufacturer.value LIKE'%blue%'))

对于'和'条件

SELECT `e`.*, `cat_index`.`position` AS `cat_index_position`, `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_color`.`value` AS `color`, `at_manufacturer`.`value` AS `manufacturer` FROM `catalog_product_entity` AS `e`
 INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.visibility IN(2, 4) AND cat_index.category_id = '3'
 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
 INNER JOIN `catalog_product_entity_int` AS `at_color` ON (`at_color`.`entity_id` = `e`.`entity_id`) AND (`at_color`.`attribute_id` = '92') AND (`at_color`.`store_id` = 0)
 INNER JOIN `catalog_product_entity_int` AS `at_manufacturer` ON (`at_manufacturer`.`entity_id` = `e`.`entity_id`) AND (`at_manufacturer`.`attribute_id` = '81') AND (`at_manufacturer`.`store_id` = 0) 

WHERE((at_color.value LIKE'')AND(at_manufacturer.value LIKE''))

其Magento Enterprise Edition 1.13.1.0

这并没有给我结果 - 因为它不匹配属性选项标签而不是它的option_id如何解决这个问题?

0 个答案:

没有答案