/** * Retrieve related product collection assigned to product * * @throws Mage_Core_Exception * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */ public function getLinkCollection() { if (is_null($this->_linkCollection)) { switch ($this->getType()) { case Enterprise_TargetRule_Model_Rule::RELATED_PRODUCTS: $this->_linkCollection = $this->getProduct()->getRelatedProductCollection(); break; case Enterprise_TargetRule_Model_Rule::UP_SELLS: $this->_linkCollection = $this->getProduct()->getUpSellProductCollection(); break; default: Mage::throwException(Mage::helper('enterprise_targetrule')->__('Undefined Catalog Product List Type')); } $this->_addProductAttributesAndPrices($this->_linkCollection); Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_linkCollection); $this->_linkCollection->addAttributeToSort('position', 'ASC')->setFlag('do_not_use_category_id', true)->setPageSize($this->getPositionLimit()); $excludeProductIds = $this->getExcludeProductIds(); if ($excludeProductIds) { $this->_linkCollection->addAttributeToFilter('entity_id', array('nin' => $excludeProductIds)); } } return $this->_linkCollection; }
public function addAttributeToFilter($attribute, $condition = null, $joinType = 'inner') { switch ($attribute) { case 'rt.review_id': case 'rt.created_at': case 'rt.status_id': case 'rdt.title': case 'rdt.nickname': case 'rdt.detail': $conditionSql = $this->_getConditionSql($attribute, $condition); $this->getSelect()->where($conditionSql); return $this; break; case 'stores': $this->setStoreFilter($condition); return $this; break; case 'type': if ($condition == 1) { $this->getSelect()->where('rdt.customer_id IS NULL AND rdt.store_id = ?', Mage_Core_Model_App::ADMIN_STORE_ID); } elseif ($condition == 2) { $this->getSelect()->where('rdt.customer_id > 0'); } else { $this->getSelect()->where('rdt.customer_id IS NULL AND rdt.store_id <> ?', Mage_Core_Model_App::ADMIN_STORE_ID); } return $this; break; default: parent::addAttributeToFilter($attribute, $condition, $joinType); } return $this; }
/** * Applies filter values provided in URL to a given product collection * * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection * @return void */ protected function _applyToCollection($collection, $value = null) { if (isset($_GET['make']) || isset($_GET['number_plate'])) { if ($_GET['cat'] == '4') { $sess_str = Mage::getSingleton("core/session")->getSearchRimSize(); $sess_arr = array(); if ($sess_str != '') { $sess_arr = explode(',', $sess_str); for ($k = 0; $k < count($sess_arr); $k++) { $filters[] = array('attribute' => 'article_code', 'eq' => $sess_arr[$k]); } $collection->addAttributeToFilter($filters); } } else { if (isset($_GET['size'])) { $collection->addAttributeToFilter('short_size', array('eq' => $_GET['size'])); } } } //echo $collection->getSelect(); $this->_getResource()->applyToCollection($collection, $this, is_null($value) ? $this->getMSelectedValues() : $value); }