public function addAttributeToSort($attribute, $dir = 'asc') { if (in_array($attribute, array('review_cnt', 'last_created', 'avg_rating', 'avg_rating_approved'))) { $this->getSelect()->order($attribute . ' ' . $dir); return $this; } return parent::addAttributeToSort($attribute, $dir); }
/** * 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; }
/** * Add attribute to sort order * * @param string $attribute * @param string $dir * @return Mage_Eav_Model_Entity_Collection_Abstract */ public function addAttributeToSort($attribute, $dir = 'asc') { /** * Position is not eav attribute (it is links attribute) so we cannot use default attributes to sort */ if ($attribute == 'position') { if ($this->_hasLinkFilter) { $this->getSelect()->order($attribute . ' ' . $dir); } } else { parent::addAttributeToSort($attribute, $dir); } return $this; }
/** * Add attribute to sort order * * @param string $attribute * @param string $dir * @return Mage_Eav_Model_Entity_Collection_Abstract */ public function addAttributeToSort($attribute, $dir = 'asc') { /* * position is not eav attributes so we cannot use default attributes to sort */ if ($attribute == 'position') { // dont sort by position, when creating product (#5090) if (!is_object($this->getProduct())) { return $this; } if (!$this->getProduct()->getId()) { return $this; } $this->getSelect()->order($attribute . ' ' . $dir); } else { parent::addAttributeToSort($attribute, $dir); } return $this; }