00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Eav_Model_Mysql4_Entity_Attribute_Option extends Mage_Core_Model_Mysql4_Abstract
00035 {
00036 public function _construct()
00037 {
00038 $this->_init('eav/attribute_option', 'option_id');
00039 }
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 public function addOptionValueToCollection($collection, $attribute, $valueExpr) {
00051 $attributeCode = $attribute->getAttributeCode();
00052 $optionTable1 = $attributeCode . '_option_value_t1';
00053 $optionTable2 = $attributeCode . '_option_value_t2';
00054
00055 $collection->getSelect()
00056 ->joinLeft(
00057 array($optionTable1 => $this->getTable('eav/attribute_option_value')),
00058 "`{$optionTable1}`.`option_id`={$valueExpr}"
00059 . " AND `{$optionTable1}`.`store_id`='0'",
00060 array())
00061 ->joinLeft(
00062 array($optionTable2 => $this->getTable('eav/attribute_option_value')),
00063 "`{$optionTable2}`.`option_id`={$valueExpr}"
00064 . " AND `{$optionTable1}`.`store_id`='{$collection->getStoreId()}'",
00065 array($attributeCode => "IFNULL(`{$optionTable2}`.`value`, `{$optionTable1}`.`value`)")
00066 );
00067
00068 return $this;
00069 }
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 public function getFlatUpdateSelect(Mage_Eav_Model_Entity_Attribute_Abstract $attribute, $store, $hasValueField=true)
00080 {
00081 $attributeTable = $attribute->getBackend()->getTable();
00082 $attributeCode = $attribute->getAttributeCode();
00083
00084 $joinCondition = "`e`.`entity_id`=`t1`.`entity_id`";
00085 if ($attribute->getFlatAddChildData()) {
00086 $joinCondition .= " AND `e`.`child_id`=`t1`.`entity_id`";
00087 }
00088
00089 $valueExpr = new Zend_Db_Expr("IFNULL(t2.value, t1.value)");
00090 $select = $this->_getReadAdapter()->select()
00091 ->joinLeft(
00092 array('t1' => $attributeTable),
00093 $joinCondition,
00094 array()
00095 )
00096 ->joinLeft(
00097 array('t2' => $attributeTable),
00098 "`t2`.`entity_id`=`t1`.`entity_id`"
00099 . " AND `t1`.`entity_type_id`=`t2`.`entity_type_id`"
00100 . " AND `t1`.`attribute_id`=`t2`.`attribute_id`"
00101 . " AND `t2`.`store_id`={$store}",
00102 array($attributeCode => $valueExpr));
00103 if (($attribute->getFrontend()->getInputType() != 'multiselect') && $hasValueField) {
00104 $select->joinLeft(
00105 array('to1' => $this->getTable('eav/attribute_option_value')),
00106 "`to1`.`option_id`={$valueExpr}"
00107 . " AND `to1`.`store_id`='0'",
00108 array())
00109 ->joinLeft(
00110 array('to2' => $this->getTable('eav/attribute_option_value')),
00111 "`to2`.`option_id`={$valueExpr}"
00112 . " AND `to2`.`store_id`='{$store}'",
00113 array($attributeCode . '_value' => "IFNULL(`to2`.`value`, `to1`.`value`)")
00114 );
00115 }
00116 $select
00117 ->where('t1.entity_type_id=?', $attribute->getEntityTypeId())
00118 ->where('t1.attribute_id=?', $attribute->getId())
00119 ->where('t1.store_id=?', 0);
00120
00121 if ($attribute->getFlatAddChildData()) {
00122 $select->where("e.is_child=?", 0);
00123 }
00124 return $select;
00125 }
00126 }