Public Member Functions | |
getCatalogHelper () | |
loadLabel ($attribute) | |
loadPrices ($attribute) | |
saveLabel ($attribute) | |
savePrices ($attribute) | |
Protected Member Functions | |
_construct () | |
Protected Attributes | |
$_labelTable | |
$_priceTable |
Definition at line 35 of file Attribute.php.
_construct | ( | ) | [protected] |
Inititalize connection and define tables
Reimplemented from Mage_Core_Model_Resource_Abstract.
Definition at line 55 of file Attribute.php.
00056 { 00057 $this->_init('catalog/product_super_attribute', 'product_super_attribute_id'); 00058 $this->_labelTable = $this->getTable('catalog/product_super_attribute_label'); 00059 $this->_priceTable = $this->getTable('catalog/product_super_attribute_pricing'); 00060 }
getCatalogHelper | ( | ) |
Retrieve Catalog Helper
Definition at line 67 of file Attribute.php.
00068 { 00069 return Mage::helper('catalog'); 00070 }
loadLabel | ( | $ | attribute | ) |
Load attribute labels
Mage_Eav_Model_Entity_Attribute_Abstract | $attribute |
Definition at line 79 of file Attribute.php.
loadPrices | ( | $ | attribute | ) |
Load prices
Mage_Eav_Model_Entity_Attribute_Abstract | $attribute |
Definition at line 91 of file Attribute.php.
saveLabel | ( | $ | attribute | ) |
Save Custom labels for Attribute name
Mage_Eav_Model_Entity_Attribute_Abstract | $attribute |
Definition at line 102 of file Attribute.php.
00103 { 00104 $select = $this->_getWriteAdapter()->select() 00105 ->from($this->_labelTable, 'value_id') 00106 ->where('product_super_attribute_id=?', $attribute->getId()) 00107 ->where('store_id=?', (int)$attribute->getStoreId()); 00108 if ($valueId = $this->_getWriteAdapter()->fetchOne($select)) { 00109 $this->_getWriteAdapter()->update($this->_labelTable,array('value'=>$attribute->getLabel()), 00110 $this->_getWriteAdapter()->quoteInto('value_id=?', $valueId) 00111 ); 00112 } 00113 else { 00114 $this->_getWriteAdapter()->insert($this->_labelTable, array( 00115 'product_super_attribute_id' => $attribute->getId(), 00116 'store_id' => (int) $attribute->getStoreId(), 00117 'value' => $attribute->getLabel() 00118 )); 00119 } 00120 return $this; 00121 }
savePrices | ( | $ | attribute | ) |
Save Options prices (Depends from price save scope)
Mage_Eav_Model_Entity_Attribute_Abstract | $attribute |
Definition at line 129 of file Attribute.php.
00130 { 00131 $newValues = $attribute->getValues(); 00132 00133 $oldValues = array(); 00134 $valueIndexes = array(); 00135 $select = $this->_getWriteAdapter()->select() 00136 ->from($this->_priceTable) 00137 ->where('product_super_attribute_id=?', $attribute->getId()); 00138 $query = $this->_getWriteAdapter()->query($select); 00139 while ($row = $query->fetch()) { 00140 $key = join('-', array($row['website_id'], $row['value_index'])); 00141 $oldValues[$key] = $row; 00142 } 00143 00144 $delete = array(); 00145 $insert = array(); 00146 $update = array(); 00147 00148 foreach ($newValues as $value) { 00149 $valueIndexes[$value['value_index']] = $value['value_index']; 00150 } 00151 00152 if ($this->getCatalogHelper()->isPriceGlobal()) { 00153 foreach ($oldValues as $row) { 00154 if (!isset($valueIndexes[$row['value_index']])) { 00155 $delete[] = $row['value_id']; 00156 continue; 00157 } 00158 } 00159 foreach ($newValues as $value) { 00160 $valueObject = new Varien_Object($value); 00161 $key = join('-', array(0, $value['value_index'])); 00162 00163 $pricingValue = $valueObject->getPricingValue(); 00164 if ($pricingValue == '' || is_null($pricingValue)) { 00165 $pricingValue = null; 00166 } 00167 else { 00168 $pricingValue = Mage::app()->getLocale()->getNumber($pricingValue); 00169 } 00170 // update 00171 if (isset($oldValues[$key])) { 00172 $oldValue = $oldValues[$key]; 00173 $update[$oldValue['value_id']] = array( 00174 'pricing_value' => $pricingValue, 00175 'is_percent' => intval($valueObject->getIsPercent()) 00176 ); 00177 } 00178 // insert 00179 else { 00180 if (!empty($value['pricing_value'])) { 00181 $insert[] = array( 00182 'product_super_attribute_id' => $attribute->getId(), 00183 'value_index' => $valueObject->getValueIndex(), 00184 'is_percent' => intval($valueObject->getIsPercent()), 00185 'pricing_value' => $pricingValue, 00186 'website_id' => 0 00187 ); 00188 } 00189 } 00190 } 00191 } 00192 else { 00193 $websiteId = Mage::app()->getStore($attribute->getStoreId())->getWebsiteId(); 00194 foreach ($oldValues as $row) { 00195 if (!isset($valueIndexes[$row['value_index']])) { 00196 $delete[] = $row['value_id']; 00197 continue; 00198 } 00199 } 00200 foreach ($newValues as $value) { 00201 $valueObject = new Varien_Object($value); 00202 $key = join('-', array($websiteId, $value['value_index'])); 00203 00204 $pricingValue = $valueObject->getPricingValue(); 00205 if ($pricingValue == '' || is_null($pricingValue)) { 00206 $pricingValue = null; 00207 } 00208 else { 00209 $pricingValue = Mage::app()->getLocale()->getNumber($pricingValue); 00210 } 00211 00212 // update 00213 if (isset($oldValues[$key])) { 00214 $oldValue = $oldValues[$key]; 00215 00216 if ($websiteId && $valueObject->getUseDefaultValue()) { 00217 $delete[] = $oldValue['value_id']; 00218 } 00219 else { 00220 $update[$oldValue['value_id']] = array( 00221 'pricing_value' => $pricingValue, 00222 'is_percent' => intval($valueObject->getIsPercent()) 00223 ); 00224 } 00225 } 00226 // insert 00227 else { 00228 if ($websiteId && $valueObject->getUseDefaultValue()) { 00229 continue; 00230 } 00231 $insert[] = array( 00232 'product_super_attribute_id' => $attribute->getId(), 00233 'value_index' => $valueObject->getValueIndex(), 00234 'is_percent' => intval($valueObject->getIsPercent()), 00235 'pricing_value' => $pricingValue, 00236 'website_id' => $websiteId 00237 ); 00238 } 00239 $key = join('-', array(0, $value['value_index'])); 00240 if (!isset($oldValues[$key])) { 00241 $insert[] = array( 00242 'product_super_attribute_id' => $attribute->getId(), 00243 'value_index' => $valueObject->getValueIndex(), 00244 'is_percent' => 0, 00245 'pricing_value' => null, 00246 'website_id' => 0 00247 ); 00248 } 00249 } 00250 } 00251 00252 if (!empty($delete)) { 00253 $where = $this->_getWriteAdapter()->quoteInto('value_id IN(?)', $delete); 00254 $this->_getWriteAdapter()->delete($this->_priceTable, $where); 00255 } 00256 00257 if (!empty($update)) { 00258 foreach ($update as $valueId => $valueData) { 00259 $where = $this->_getWriteAdapter()->quoteInto('value_id=?', $valueId); 00260 $this->_getWriteAdapter()->update($this->_priceTable, $valueData, $where); 00261 } 00262 } 00263 00264 if (!empty($insert)) { 00265 foreach ($insert as $valueData) { 00266 $this->_getWriteAdapter()->insert($this->_priceTable, $valueData); 00267 } 00268 } 00269 00270 return $this; 00271 }
$_labelTable [protected] |
Definition at line 42 of file Attribute.php.
$_priceTable [protected] |
Definition at line 49 of file Attribute.php.