/** * @test * @doNotIndexAll * @dataProvider dataProvider */ public function filterByAtts(Mage_Catalog_Model_Product $currentProduct, $atts, $ids) { $this->_joinedAttributes = array(); $collection = Mage::getModel('catalog/product')->getCollection(); foreach ($atts as $at) { //var_dump($at['att']); $value = $at['att'] == 'category_ids' ? $currentProduct->getCategory()->getId() : $currentProduct->getData($at['att']); $sql = AW_Autorelated_Model_Blocks_Rule::prepareSqlForAtt($at['att'], &$this->_joinedAttributes, $collection, $at['condition'], $value); $collection->getSelect()->where($sql); } //$collection->getSelect()->where('e.entity_id IN(' . implode(',',$ids) . ')'); $this->assertType('array', $collection->getColumnValues('entity_id')); }
public function filterByAtts(Mage_Catalog_Model_Product $currentProduct, $atts, $ids = null) { $this->_joinedAttributes = array(); $collection = $this->_collection; $rule = new AW_Autorelated_Model_Blocks_Rule(); foreach ($atts as $at) { /* * collect category ids related to product * If category is anchor we should implode all of its subcategories as value * If it's not we should get only its id * If there is no category in product, get all categories product is in */ if ($at['att'] == 'category_ids') { $category = $currentProduct->getCategory(); if ($category instanceof Varien_Object) { if ($category->getIsAnchor()) { $value = $category->getAllChildren(); } else { $value = $category->getId(); } } else { $value = implode(',', $currentProduct->getCategoryIds()); $value = !empty($value) ? $value : null; } } else { $value = $currentProduct->getData($at['att']); } if (!$value) { $collection = NULL; return false; } $sql = $rule->prepareSqlForAtt($at['att'], $this->_joinedAttributes, $collection, $at['condition'], $value); if ($sql) { $collection->getSelect()->where($sql); } } if ($ids) { $collection->getSelect()->where('e.entity_id IN(' . implode(',', $ids) . ')'); } $collection->getSelect()->group('e.entity_id'); return $collection->getAllIds(); }