/** * Prepare and Save Matched products for Rule * * @param Enterprise_TargetRule_Model_Rule $object * @return Enterprise_TargetRule_Model_Mysql4_Rule */ protected function _prepareRuleProducts($object) { $adapter = $this->_getWriteAdapter(); // remove old matched products $ruleId = $object->getId(); $adapter->delete($this->_getRuleProductsTable(), array('rule_id=?' => $ruleId)); // retrieve and save new matched product ids $chunk = array_chunk($object->getMatchingProductIds(), 1000); foreach ($chunk as $productIds) { $data = array(); foreach ($productIds as $productId) { $data[] = array('rule_id' => $ruleId, 'product_id' => $productId, 'store_id' => 0); } if ($data) { $adapter->insertMultiple($this->_getRuleProductsTable(), $data); } } return $this; }
/** * Prepare and Save Matched products for Rule * * @deprecated after 1.11.2.0 * * @param Enterprise_TargetRule_Model_Rule $object * * @return Enterprise_TargetRule_Model_Resource_Rule */ protected function _prepareRuleProducts($object) { $this->unbindRuleFromEntity($object->getId(), array(), 'product'); $this->bindRuleToEntity($object->getId(), $object->getMatchingProductIds(), 'product'); return $this; }
/** * Retrieve found product ids by Rule action conditions * If rule has cached select - get it * * @param Enterprise_TargetRule_Model_Rule $rule * @param Enterprise_TargetRule_Model_Index $object * @param int $limit * @param array $excludeProductIds * @return mixed */ protected function _getProductIdsByRule($rule, $object, $limit, $excludeProductIds = array()) { $rule->afterLoad(); /* @var $collection Mage_Catalog_Model_Resource_Product_Collection */ $collection = Mage::getResourceModel('catalog/product_collection')->setStoreId($object->getStoreId())->addPriceData($object->getCustomerGroupId()); Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection); $actionSelect = $rule->getActionSelect(); $actionBind = $rule->getActionSelectBind(); if (is_null($actionSelect)) { $actionBind = array(); $actionSelect = $rule->getActions()->getConditionForCollection($collection, $object, $actionBind); $rule->setActionSelect((string) $actionSelect)->setActionSelectBind($actionBind)->save(); } if ($actionSelect) { $collection->getSelect()->where($actionSelect); } if ($excludeProductIds) { $collection->addFieldToFilter('entity_id', array('nin' => $excludeProductIds)); } $select = $collection->getSelect(); $select->reset(Zend_Db_Select::COLUMNS); $select->columns('entity_id', 'e'); $select->limit($limit); $bind = $this->_prepareRuleActionSelectBind($object, $actionBind); $result = $this->_getReadAdapter()->fetchCol($select, $bind); return $result; }