Example #1
0
 /**
  * Validate product attribute value for condition
  *
  * @param Varien_Object $object
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $attrCode = $this->getAttribute();
     if ('category_ids' == $attrCode) {
         return $this->validateAttribute($object->getAvailableInCategories());
     }
     if ('attribute_set_id' == $attrCode) {
         return $this->validateAttribute($object->getData($attrCode));
     }
     $oldAttrValue = $object->hasData($attrCode) ? $object->getData($attrCode) : null;
     $object->setData($attrCode, $this->_getAttributeValue($object));
     $result = $this->_validateProduct($object);
     $this->_restoreOldAttrValue($object, $oldAttrValue);
     return (bool) $result;
 }
Example #2
0
 /**
  * Validate product attrbute value for condition
  *
  * @param Varien_Object $object
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $attrCode = $this->getAttribute();
     if ('category_ids' == $attrCode) {
         return $this->validateAttribute($object->getAvailableInCategories());
     } elseif ('product_ids' == $attrCode) {
         return $this->validateAttribute($object->getId());
     } elseif (!isset($this->_entityAttributeValues[$object->getId()])) {
         $attr = $object->getResource()->getAttribute($attrCode);
         if ($attr && $attr->getBackendType() == 'datetime' && !is_int($this->getValue())) {
             $this->setValue(strtotime($this->getValue()));
             $value = strtotime($object->getData($attrCode));
             return $this->validateAttribute($value);
         }
         if ($attr && $attr->getFrontendInput() == 'multiselect') {
             $value = $object->getData($attrCode);
             $value = strlen($value) ? explode(',', $value) : array();
             return $this->validateAttribute($value);
         }
         return parent::validate($object);
     } else {
         $result = false;
         // any valid value will set it to TRUE
         // remember old attribute state
         $oldAttrValue = $object->hasData($attrCode) ? $object->getData($attrCode) : null;
         foreach ($this->_entityAttributeValues[$object->getId()] as $storeId => $value) {
             $attr = $object->getResource()->getAttribute($attrCode);
             if ($attr && $attr->getBackendType() == 'datetime') {
                 $value = strtotime($value);
             } else {
                 if ($attr && $attr->getFrontendInput() == 'multiselect') {
                     $value = strlen($value) ? explode(',', $value) : array();
                 }
             }
             $object->setData($attrCode, $value);
             $result |= parent::validate($object);
             if ($result) {
                 break;
             }
         }
         if (is_null($oldAttrValue)) {
             $object->unsetData($attrCode);
         } else {
             $object->setData($attrCode, $oldAttrValue);
         }
         return (bool) $result;
     }
 }
Example #3
0
 public function validate(Varien_Object $object)
 {
     $attr = $object->getResource()->getAttribute($this->getAttribute());
     if ($attr && $attr->getBackendType() == 'datetime' && !is_int($this->getValue())) {
         $this->setValue(strtotime($this->getValue()));
         $value = strtotime($object->getData($this->getAttribute()));
         return $this->validateAttribute($value);
     }
     if ($this->getAttribute() == 'category_ids') {
         return $this->validateAttribute($object->getAvailableInCategories());
     }
     if ($attr && $attr->getFrontendInput() == 'multiselect') {
         $value = $object->getData($this->getAttribute());
         if (!strlen($value)) {
             $value = array();
         } else {
             $value = split(',', $value);
         }
         return $this->validateAttribute($value);
     }
     return parent::validate($object);
 }
Example #4
0
 /**
  * Validate product attrbute value for condition.
  *
  * @param Varien_Object $object
  *
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $attrCode = $this->getAttribute();
     switch ($attrCode) {
         case 'category_ids':
             return $this->validateAttribute($object->getAvailableInCategories());
             break;
         case 'qty':
             $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($object->getId());
             return $this->validateAttribute($stockItem->getQty());
             break;
         case 'image_size':
         case 'small_image_size':
         case 'thumbnail_size':
             $imageCode = str_replace('_size', '', $attrCode);
             $imagePath = $object->getData($imageCode);
             $path = Mage::getBaseDir('media') . DS . 'catalog/product' . $imagePath;
             $size = 0;
             if (file_exists($path) && is_file($path)) {
                 $size = filesize($path);
             }
             return $this->validateAttribute($size);
             break;
         case 'php':
             $object = $object->load($object->getId());
             extract($object->getData());
             $expr = 'return ' . $this->getValue() . ';';
             $value = eval($expr);
             if ($this->getOperator() == '==') {
                 return $value;
             } else {
                 return !$value;
             }
             break;
         default:
             if (!isset($this->_entityAttributeValues[$object->getId()])) {
                 $attr = $object->getResource()->getAttribute($attrCode);
                 if ($attr && $attr->getBackendType() == 'datetime' && !is_int($this->getValue())) {
                     $this->setValue(strtotime($this->getValue()));
                     $value = strtotime($object->getData($attrCode));
                     return $this->validateAttribute($value);
                 }
                 if ($attr && $attr->getFrontendInput() == 'multiselect') {
                     $value = $object->getData($attrCode);
                     $value = strlen($value) ? explode(',', $value) : array();
                     return $this->validateAttribute($value);
                 }
                 return parent::validate($object);
             } else {
                 $result = false;
                 // any valid value will set it to TRUE
                 $oldAttrValue = $object->hasData($attrCode) ? $object->getData($attrCode) : null;
                 foreach ($this->_entityAttributeValues[$object->getId()] as $storeId => $value) {
                     $attr = $object->getResource()->getAttribute($attrCode);
                     if ($attr && $attr->getBackendType() == 'datetime') {
                         $value = strtotime($value);
                     } elseif ($attr && $attr->getFrontendInput() == 'multiselect') {
                         $value = strlen($value) ? explode(',', $value) : array();
                     }
                     $object->setData($attrCode, $value);
                     $result |= parent::validate($object);
                     if ($result) {
                         break;
                     }
                 }
                 if (is_null($oldAttrValue)) {
                     $object->unsetData($attrCode);
                 } else {
                     $object->setData($attrCode, $oldAttrValue);
                 }
                 return (bool) $result;
             }
             break;
     }
 }