/** * Add Join with option value for collection select * * @param Mage_Eav_Model_Entity_Collection_Abstract $collection * @param Mage_Eav_Model_Entity_Attribute $attribute * @param Zend_Db_Expr $valueExpr * * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Option */ public function addOptionValueToCollection($collection, $attribute, $valueExpr) { $adminStore = Mage_Core_Model_App::ADMIN_STORE_ID; $attributeCode = $attribute->getAttributeCode(); $optionTable1 = $attributeCode . '_option_value_t1'; $optionTable2 = $attributeCode . '_option_value_t2'; $collection->getSelect()->joinLeft(array($optionTable1 => $this->getTable('eav/attribute_option_value')), "`{$optionTable1}`.`option_id`={$valueExpr}" . " AND `{$optionTable1}`.`store_id`='{$adminStore}'", $collection->getStoreId() != $adminStore ? array() : array($attributeCode . '_value' => "{$optionTable1}.value")); if ($collection->getStoreId() != $adminStore) { $collection->getSelect()->joinLeft(array($optionTable2 => $this->getTable('eav/attribute_option_value')), "`{$optionTable2}`.`option_id`={$valueExpr}" . " AND `{$optionTable1}`.`store_id`='{$collection->getStoreId()}'", array($attributeCode . '_value' => "IFNULL(`{$optionTable2}`.`value`, `{$optionTable1}`.`value`)")); } return $this; }
/** * Add Join with option value for collection select * * @param Mage_Eav_Model_Entity_Collection_Abstract $collection * @param Mage_Eav_Model_Entity_Attribute $attribute * @param Zend_Db_Expr $valueExpr * * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Option */ public function addOptionValueToCollection($collection, $attribute, $valueExpr) { $attributeCode = $attribute->getAttributeCode(); $optionTable1 = $attributeCode . '_option_value_t1'; $optionTable2 = $attributeCode . '_option_value_t2'; $collection->getSelect()->joinLeft(array($optionTable1 => $this->getTable('eav/attribute_option_value')), "`{$optionTable1}`.`option_id`={$valueExpr}" . " AND `{$optionTable1}`.`store_id`='0'", array())->joinLeft(array($optionTable2 => $this->getTable('eav/attribute_option_value')), "`{$optionTable2}`.`option_id`={$valueExpr}" . " AND `{$optionTable1}`.`store_id`='{$collection->getStoreId()}'", array($attributeCode => "IFNULL(`{$optionTable2}`.`value`, `{$optionTable1}`.`value`)")); return $this; }
/** * Add Join with option value for collection select * * @param Mage_Eav_Model_Entity_Collection_Abstract $collection * @param Mage_Eav_Model_Entity_Attribute $attribute * @param Zend_Db_Expr $valueExpr * @return Mage_Eav_Model_Resource_Entity_Attribute_Option */ public function addOptionValueToCollection($collection, $attribute, $valueExpr) { $adapter = $this->_getReadAdapter(); $attributeCode = $attribute->getAttributeCode(); $optionTable1 = $attributeCode . '_option_value_t1'; $optionTable2 = $attributeCode . '_option_value_t2'; $tableJoinCond1 = "{$optionTable1}.option_id={$valueExpr} AND {$optionTable1}.store_id=0"; $tableJoinCond2 = $adapter->quoteInto("{$optionTable2}.option_id={$valueExpr} AND {$optionTable2}.store_id=?", $collection->getStoreId()); $valueExpr = $adapter->getCheckSql("{$optionTable2}.value_id IS NULL", "{$optionTable1}.value", "{$optionTable2}.value"); $collection->getSelect()->joinLeft(array($optionTable1 => $this->getTable('eav/attribute_option_value')), $tableJoinCond1, array())->joinLeft(array($optionTable2 => $this->getTable('eav/attribute_option_value')), $tableJoinCond2, array($attributeCode => $valueExpr)); return $this; }
/** * Add Value Sort To Collection Select * * @param Mage_Eav_Model_Entity_Collection_Abstract $collection * @param string $dir direction * @return Mage_Eav_Model_Entity_Attribute_Source_Abstract */ public function addValueSortToCollection($collection, $dir = 'asc') { $attributeCode = $this->getAttribute()->getAttributeCode(); $attributeId = $this->getAttribute()->getId(); $attributeTable = $this->getAttribute()->getBackend()->getTable(); if ($this->getAttribute()->isScopeGlobal()) { $tableName = $attributeCode . '_t'; $collection->getSelect()->joinLeft(array($tableName => $attributeTable), "e.entity_id={$tableName}.entity_id" . " AND {$tableName}.attribute_id='{$attributeId}'" . " AND {$tableName}.store_id='0'", array()); $valueExpr = $tableName . '.value'; } else { $valueTable1 = $attributeCode . '_t1'; $valueTable2 = $attributeCode . '_t2'; $collection->getSelect()->joinLeft(array($valueTable1 => $attributeTable), "e.entity_id={$valueTable1}.entity_id" . " AND {$valueTable1}.attribute_id='{$attributeId}'" . " AND {$valueTable1}.store_id='0'", array())->joinLeft(array($valueTable2 => $attributeTable), "e.entity_id={$valueTable2}.entity_id" . " AND {$valueTable2}.attribute_id='{$attributeId}'" . " AND {$valueTable2}.store_id='{$collection->getStoreId()}'", array()); $valueExpr = $collection->getConnection()->getCheckSql($valueTable2 . '.value_id > 0', $valueTable2 . '.value', $valueTable1 . '.value'); } $collection->getSelect()->order($valueExpr . ' ' . $dir); return $this; }
/** * Add Value Sort To Collection Select * * @param Mage_Eav_Model_Entity_Collection_Abstract $collection * @param string $dir * * @return Mage_Eav_Model_Entity_Attribute_Source_Table */ public function addValueSortToCollection($collection, $dir = Varien_Db_Select::SQL_ASC) { $valueTable1 = $this->getAttribute()->getAttributeCode() . '_t1'; $valueTable2 = $this->getAttribute()->getAttributeCode() . '_t2'; $collection->getSelect()->joinLeft(array($valueTable1 => $this->getAttribute()->getBackend()->getTable()), "e.entity_id={$valueTable1}.entity_id" . " AND {$valueTable1}.attribute_id='{$this->getAttribute()->getId()}'" . " AND {$valueTable1}.store_id=0", array())->joinLeft(array($valueTable2 => $this->getAttribute()->getBackend()->getTable()), "e.entity_id={$valueTable2}.entity_id" . " AND {$valueTable2}.attribute_id='{$this->getAttribute()->getId()}'" . " AND {$valueTable2}.store_id='{$collection->getStoreId()}'", array()); $valueExpr = $collection->getSelect()->getAdapter()->getCheckSql("{$valueTable2}.value_id > 0", "{$valueTable2}.value", "{$valueTable1}.value"); Mage::getResourceModel('eav/entity_attribute_option')->addOptionValueToCollection($collection, $this->getAttribute(), $valueExpr); $collection->getSelect()->order("{$this->getAttribute()->getAttributeCode()} {$dir}"); return $this; }
/** * Add Value Sort To Collection Select * * @param Mage_Eav_Model_Entity_Collection_Abstract $collection * @param string $dir * * @return Mage_Eav_Model_Entity_Attribute_Source_Table */ public function addValueSortToCollection($collection, $dir = 'asc') { $adminStore = Mage_Core_Model_App::ADMIN_STORE_ID; $valueTable1 = $this->getAttribute()->getAttributeCode() . '_t1'; $valueTable2 = $this->getAttribute()->getAttributeCode() . '_t2'; $collection->getSelect()->joinLeft(array($valueTable1 => $this->getAttribute()->getBackend()->getTable()), "`e`.`entity_id`=`{$valueTable1}`.`entity_id`" . " AND `{$valueTable1}`.`attribute_id`='{$this->getAttribute()->getId()}'" . " AND `{$valueTable1}`.`store_id`='{$adminStore}'", array()); if ($collection->getStoreId() != $adminStore) { $collection->getSelect()->joinLeft(array($valueTable2 => $this->getAttribute()->getBackend()->getTable()), "`e`.`entity_id`=`{$valueTable2}`.`entity_id`" . " AND `{$valueTable2}`.`attribute_id`='{$this->getAttribute()->getId()}'" . " AND `{$valueTable2}`.`store_id`='{$collection->getStoreId()}'", array()); $valueExpr = new Zend_Db_Expr("IF(`{$valueTable2}`.`value_id`>0, `{$valueTable2}`.`value`, `{$valueTable1}`.`value`)"); } else { $valueExpr = new Zend_Db_Expr("`{$valueTable1}`.`value`"); } Mage::getResourceModel('eav/entity_attribute_option')->addOptionValueToCollection($collection, $this->getAttribute(), $valueExpr); $collection->getSelect()->order("{$this->getAttribute()->getAttributeCode()}_value {$dir}"); return $this; }
/** * Add Value Sort To Collection Select * * @param Mage_Eav_Model_Entity_Collection_Abstract $collection * @param string $dir direction * @return Mage_Eav_Model_Entity_Attribute_Source_Abstract */ public function addValueSortToCollection($collection, $dir = 'asc') { if ($this->getAttribute()->isScopeGlobal()) { $tableName = $this->getAttribute()->getAttributeCode() . '_t'; $collection->getSelect()->joinLeft(array($tableName => $this->getAttribute()->getBackend()->getTable()), "`e`.`entity_id`=`{$tableName}`.`entity_id`" . " AND `{$tableName}`.`attribute_id`='{$this->getAttribute()->getId()}'" . " AND `{$tableName}`.`store_id`='0'", array()); $valueExpr = $tableName . '.value'; } else { $valueTable1 = $this->getAttribute()->getAttributeCode() . '_t1'; $valueTable2 = $this->getAttribute()->getAttributeCode() . '_t2'; $collection->getSelect()->joinLeft(array($valueTable1 => $this->getAttribute()->getBackend()->getTable()), "`e`.`entity_id`=`{$valueTable1}`.`entity_id`" . " AND `{$valueTable1}`.`attribute_id`='{$this->getAttribute()->getId()}'" . " AND `{$valueTable1}`.`store_id`='0'", array())->joinLeft(array($valueTable2 => $this->getAttribute()->getBackend()->getTable()), "`e`.`entity_id`=`{$valueTable2}`.`entity_id`" . " AND `{$valueTable2}`.`attribute_id`='{$this->getAttribute()->getId()}'" . " AND `{$valueTable2}`.`store_id`='{$collection->getStoreId()}'", array()); $valueExpr = new Zend_Db_Expr("IFNULL(`{$valueTable2}`.`value`, `{$valueTable1}`.`value`)"); } $collection->getSelect()->order($valueExpr . ' ' . $dir); return $this; }
/** * Add Value Sort To Collection Select * * @param Mage_Eav_Model_Entity_Collection_Abstract $collection * @param string $dir * * @return Mage_Eav_Model_Entity_Attribute_Source_Table */ public function addValueSortToCollection($collection, $dir = 'asc') { $valueTable1 = $this->getAttribute()->getAttributeCode() . '_t1'; $valueTable2 = $this->getAttribute()->getAttributeCode() . '_t2'; $collection->getSelect()->joinLeft(array($valueTable1 => $this->getAttribute()->getBackend()->getTable()), "`e`.`entity_id`=`{$valueTable1}`.`entity_id`" . " AND `{$valueTable1}`.`attribute_id`='{$this->getAttribute()->getId()}'" . " AND `{$valueTable1}`.`store_id`='0'", array())->joinLeft(array($valueTable2 => $this->getAttribute()->getBackend()->getTable()), "`e`.`entity_id`=`{$valueTable2}`.`entity_id`" . " AND `{$valueTable2}`.`attribute_id`='{$this->getAttribute()->getId()}'" . " AND `{$valueTable2}`.`store_id`='{$collection->getStoreId()}'", array()); $valueExpr = new Zend_Db_Expr("IFNULL(`{$valueTable2}`.`value`, `{$valueTable1}`.`value`)"); Mage::getResourceModel('eav/entity_attribute_option')->addOptionValueToCollection($collection, $this->getAttribute(), $valueExpr); $collection->getSelect()->order("{$this->getAttribute()->getAttributeCode()} {$dir}"); return $this; }