Public Member Functions | |
getAttributeObject () | |
loadAttributeOptions () | |
getValueOption ($option=null) | |
getValueSelectOptions () | |
getValueAfterElementHtml () | |
getAttributeElement () | |
collectValidatedAttributes ($productCollection) | |
getInputType () | |
getValueElementType () | |
getValueElement () | |
getValueElementChooserUrl () | |
getExplicitApply () | |
loadArray ($arr) | |
validate (Varien_Object $object) | |
Protected Member Functions | |
_addSpecialAttributes (array &$attributes) |
Definition at line 28 of file Product.php.
_addSpecialAttributes | ( | array &$ | attributes | ) | [protected] |
Add special attributes
array | $attributes |
Reimplemented in Mage_SalesRule_Model_Rule_Condition_Product.
Definition at line 54 of file Product.php.
00055 { 00056 $attributes['attribute_set_id'] = Mage::helper('catalogrule')->__('Attribute Set'); 00057 $attributes['category_ids'] = Mage::helper('catalogrule')->__('Category'); 00058 }
collectValidatedAttributes | ( | $ | productCollection | ) |
Collect validated attributes
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection | $productCollection |
Definition at line 194 of file Product.php.
00195 { 00196 $attributes = $this->getRule()->getCollectedAttributes(); 00197 $attributes[$this->getAttribute()] = true; 00198 $this->getRule()->setCollectedAttributes($attributes); 00199 $productCollection->addAttributeToSelect($this->getAttribute(), 'left'); 00200 return $this; 00201 }
getAttributeElement | ( | ) |
Retrieve attribute element
Reimplemented from Mage_Rule_Model_Condition_Abstract.
Definition at line 181 of file Product.php.
00182 { 00183 $element = parent::getAttributeElement(); 00184 $element->setShowAsText(true); 00185 return $element; 00186 }
getAttributeObject | ( | ) |
Retrieve attribute object
Definition at line 35 of file Product.php.
00036 { 00037 try { 00038 $obj = Mage::getSingleton('eav/config') 00039 ->getAttribute('catalog_product', $this->getAttribute()); 00040 } 00041 catch (Exception $e) { 00042 $obj = new Varien_Object(); 00043 $obj->setEntity(Mage::getResourceSingleton('catalog/product')) 00044 ->setFrontendInput('text'); 00045 } 00046 return $obj; 00047 }
getExplicitApply | ( | ) |
Retrieve Explicit Apply
Definition at line 303 of file Product.php.
00304 { 00305 switch ($this->getAttribute()) { 00306 case 'sku': case 'category_ids': 00307 return true; 00308 } 00309 if (is_object($this->getAttributeObject())) { 00310 switch ($this->getAttributeObject()->getFrontendInput()) { 00311 case 'date': 00312 return true; 00313 } 00314 } 00315 return false; 00316 }
getInputType | ( | ) |
Retrieve input type
Reimplemented from Mage_Rule_Model_Condition_Abstract.
Definition at line 208 of file Product.php.
00209 { 00210 if ($this->getAttribute()==='attribute_set_id') { 00211 return 'select'; 00212 } 00213 if (!is_object($this->getAttributeObject())) { 00214 return 'string'; 00215 } 00216 switch ($this->getAttributeObject()->getFrontendInput()) { 00217 case 'select': 00218 return 'select'; 00219 00220 case 'multiselect': 00221 return 'multiselect'; 00222 00223 case 'date': 00224 return 'date'; 00225 00226 default: 00227 return 'string'; 00228 } 00229 }
getValueAfterElementHtml | ( | ) |
Retrieve after element HTML
Definition at line 160 of file Product.php.
00161 { 00162 $html = ''; 00163 00164 switch ($this->getAttribute()) { 00165 case 'sku': case 'category_ids': 00166 $image = Mage::getDesign()->getSkinUrl('images/rule_chooser_trigger.gif'); 00167 break; 00168 } 00169 00170 if (!empty($image)) { 00171 $html = '<a href="javascript:void(0)" class="rule-chooser-trigger"><img src="' . $image . '" alt="" class="v-middle rule-chooser-trigger" title="' . Mage::helper('rule')->__('Open Chooser') . '" /></a>'; 00172 } 00173 return $html; 00174 }
getValueElement | ( | ) |
Retrieve value element
Reimplemented from Mage_Rule_Model_Condition_Abstract.
Definition at line 264 of file Product.php.
00265 { 00266 $element = parent::getValueElement(); 00267 if (is_object($this->getAttributeObject())) { 00268 switch ($this->getAttributeObject()->getFrontendInput()) { 00269 case 'date': 00270 $element->setImage(Mage::getDesign()->getSkinUrl('images/grid-cal.gif')); 00271 break; 00272 } 00273 } 00274 00275 return $element; 00276 }
getValueElementChooserUrl | ( | ) |
Retrieve value element chooser URL
Definition at line 283 of file Product.php.
00284 { 00285 $url = false; 00286 switch ($this->getAttribute()) { 00287 case 'sku': case 'category_ids': 00288 $url = 'adminhtml/promo_widget/chooser' 00289 .'/attribute/'.$this->getAttribute(); 00290 if ($this->getJsFormObject()) { 00291 $url .= '/form/'.$this->getJsFormObject(); 00292 } 00293 break; 00294 } 00295 return $url!==false ? Mage::helper('adminhtml')->getUrl($url) : ''; 00296 }
getValueElementType | ( | ) |
Retrieve value element type
Reimplemented from Mage_Rule_Model_Condition_Abstract.
Definition at line 236 of file Product.php.
00237 { 00238 if ($this->getAttribute()==='attribute_set_id') { 00239 return 'select'; 00240 } 00241 if (!is_object($this->getAttributeObject())) { 00242 return 'text'; 00243 } 00244 switch ($this->getAttributeObject()->getFrontendInput()) { 00245 case 'select': 00246 return 'select'; 00247 00248 case 'multiselect': 00249 return 'multiselect'; 00250 00251 case 'date': 00252 return 'date'; 00253 00254 default: 00255 return 'text'; 00256 } 00257 }
getValueOption | ( | $ | option = null |
) |
Retrieve value by option
mixed | $option |
Definition at line 94 of file Product.php.
00095 { 00096 if (!$this->getData('value_option')) { 00097 if ($this->getAttribute()==='attribute_set_id') { 00098 $entityTypeId = Mage::getSingleton('eav/config') 00099 ->getEntityType('catalog_product')->getId(); 00100 $options = Mage::getResourceModel('eav/entity_attribute_set_collection') 00101 ->setEntityTypeFilter($entityTypeId) 00102 ->load() 00103 ->toOptionHash(); 00104 $this->setData('value_option', $options); 00105 } elseif (is_object($this->getAttributeObject()) && $this->getAttributeObject()->usesSource()) { 00106 if ($this->getAttributeObject()->getFrontendInput() == 'multiselect') { 00107 $addEmptyOption = false; 00108 } else { 00109 $addEmptyOption = true; 00110 } 00111 00112 $optionsArr = $this->getAttributeObject()->getSource()->getAllOptions($addEmptyOption); 00113 $options = array(); 00114 foreach ($optionsArr as $o) { 00115 if (is_array($o['value'])) { 00116 00117 } else { 00118 $options[$o['value']] = $o['label']; 00119 } 00120 } 00121 $this->setData('value_option', $options); 00122 } 00123 } 00124 return $this->getData('value_option'.(!is_null($option) ? '/'.$option : '')); 00125 }
getValueSelectOptions | ( | ) |
Retrieve select option values
Reimplemented from Mage_Rule_Model_Condition_Abstract.
Definition at line 132 of file Product.php.
00133 { 00134 if (!$this->getData('value_select_options')) { 00135 if ($this->getAttribute()==='attribute_set_id') { 00136 $entityTypeId = Mage::getSingleton('eav/config') 00137 ->getEntityType('catalog_product')->getId(); 00138 $options = Mage::getResourceModel('eav/entity_attribute_set_collection') 00139 ->setEntityTypeFilter($entityTypeId) 00140 ->load()->toOptionArray(); 00141 $this->setData('value_select_options', $options); 00142 } elseif (is_object($this->getAttributeObject()) && $this->getAttributeObject()->usesSource()) { 00143 if ($this->getAttributeObject()->getFrontendInput() == 'multiselect') { 00144 $addEmptyOption = false; 00145 } else { 00146 $addEmptyOption = true; 00147 } 00148 $optionsArr = $this->getAttributeObject()->getSource()->getAllOptions($addEmptyOption); 00149 $this->setData('value_select_options', $optionsArr); 00150 } 00151 } 00152 return $this->getData('value_select_options'); 00153 }
loadArray | ( | $ | arr | ) |
Load array
array | $arr |
Reimplemented from Mage_Rule_Model_Condition_Abstract.
Definition at line 324 of file Product.php.
00325 { 00326 $this->setAttribute(isset($arr['attribute']) ? $arr['attribute'] : false); 00327 $attribute = $this->getAttributeObject(); 00328 00329 if ($attribute && $attribute->getBackendType() == 'decimal') { 00330 $arr['value'] = isset($arr['value']) ? Mage::app()->getLocale()->getNumber($arr['value']) : false; 00331 $arr['is_value_parsed'] = isset($arr['is_value_parsed']) ? Mage::app()->getLocale()->getNumber($arr['is_value_parsed']) : false; 00332 } 00333 00334 return parent::loadArray($arr); 00335 }
loadAttributeOptions | ( | ) |
Load attribute options
Reimplemented from Mage_Rule_Model_Condition_Abstract.
Definition at line 65 of file Product.php.
00066 { 00067 $productAttributes = Mage::getResourceSingleton('catalog/product') 00068 ->loadAllAttributes() 00069 ->getAttributesByCode(); 00070 00071 $attributes = array(); 00072 foreach ($productAttributes as $attribute) { 00073 /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */ 00074 if (!$attribute->isAllowedForRuleCondition() || !$attribute->getIsUsedForPriceRules()) { 00075 continue; 00076 } 00077 $attributes[$attribute->getAttributeCode()] = $attribute->getFrontendLabel(); 00078 } 00079 00080 $this->_addSpecialAttributes($attributes); 00081 00082 asort($attributes); 00083 $this->setAttributeOption($attributes); 00084 00085 return $this; 00086 }
validate | ( | Varien_Object $ | object | ) |
Validate product attrbute value for condition
Varien_Object | $object |
Reimplemented from Mage_Rule_Model_Condition_Abstract.
Reimplemented in Mage_SalesRule_Model_Rule_Condition_Product.
Definition at line 343 of file Product.php.
00344 { 00345 $attr = $object->getResource()->getAttribute($this->getAttribute()); 00346 if ($attr && $attr->getBackendType()=='datetime' && !is_int($this->getValue())) { 00347 $this->setValue(strtotime($this->getValue())); 00348 $value = strtotime($object->getData($this->getAttribute())); 00349 return $this->validateAttribute($value); 00350 } 00351 00352 if ($this->getAttribute() == 'category_ids') { 00353 return $this->validateAttribute($object->getAvailableInCategories()); 00354 } 00355 00356 if ($attr && $attr->getFrontendInput() == 'multiselect') { 00357 $value = $object->getData($this->getAttribute()); 00358 if (!strlen($value)) { 00359 $value = array(); 00360 } else { 00361 $value = split(',', $value); 00362 } 00363 return $this->validateAttribute($value); 00364 } 00365 00366 return parent::validate($object); 00367 }