예제 #1
0
 public function validate(Varien_Object $object)
 {
     $product = Mage::getModel('catalog/product')->setStoreId($object->getStoreId())->load($object->getProductId());
     $this->_entityAttributeValues[$product->getId()][$product->getStoreId()] = $product->getData($this->getAttribute());
     // Required since 1.8.0.0 // Old: $this->getValue() //
     #var_dump($this->getAttribute(), $product->getData($this->getAttribute()), parent::validateAttribute($product));
     return parent::validate($product);
 }
예제 #2
0
 /**
  * Validate Product Rule Condition
  *
  * @param Varien_Object $object
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $product = false;
     if ($object->getProduct() instanceof Mage_Catalog_Model_Product) {
         $product = $object->getProduct();
     } else {
         $product = Mage::getModel('catalog/product')->load($object->getProductId());
     }
     $product->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getBaseRowTotal());
     return parent::validate($product);
 }
예제 #3
0
 /**
  * Validate Product Rule Condition
  *
  * @param Varien_Object $object
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $op = $this->getOperator();
     $product = false;
     if ($object->getProduct() instanceof Mage_Catalog_Model_Product) {
         $product = $object->getProduct();
     } else {
         $product = Mage::getModel('catalog/product')->load($object->getProductId());
     }
     $product->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getBaseRowTotal());
     if (!$product->getData($this->getAttribute()) && ($op != '==' || $op != '!=') && $this->getAttribute() != 'category_ids') {
         return false;
     }
     return parent::validate($product);
 }
예제 #4
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;
     }
 }
예제 #5
0
 /**
  * Validate Product Rule Condition
  *
  * @param Varien_Object $object
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $op = $this->getOperator();
     $product = false;
     if ($object->getProduct() instanceof Mage_Catalog_Model_Product) {
         $product = $object->getProduct();
     } else {
         $product = Mage::getModel('catalog/product')->load($object->getProductId());
     }
     $product->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getBaseRowTotal());
     //Validate with attribute is is_new
     if ($this->getAttribute() == 'is_new') {
         $result = true;
         if (!$product->getNewsFromDate() && !$product->getNewsToDate()) {
             $result = false;
         } else {
             $today = new DateTime(date('Y-m-d 00:00:00'));
             if ($from = $product->getNewsFromDate()) {
                 $fromNewDate = new DateTime($from);
                 if ($today < $fromNewDate) {
                     $result = false;
                 }
             }
             if ($to = $product->getNewsToDate()) {
                 $toNewDate = new DateTime($to);
                 if ($today > $toNewDate) {
                     $result = false;
                 }
             }
         }
         $value = $this->getValueParsed();
         if ($value == 0) {
             $result = !$result;
         }
         return $result;
     }
     //validate with attribute is is_special
     if ($this->getAttribute() == 'is_special') {
         $result = true;
         if (!$product->getSpecialPrice()) {
             $result = false;
         } else {
             $today = new DateTime(date('Y-m-d 00:00:00'));
             if (!($from = $product->getSpecialFromDate())) {
                 $fromNewDate = $today;
             } else {
                 $fromNewDate = new DateTime($from);
             }
             if (!($to = $product->getSpecialToDate())) {
                 $toNewDate = $today;
             } else {
                 $toNewDate = new DateTime($to);
             }
             if ($today < $fromNewDate || $toNewDate < $today) {
                 $result = false;
             }
             $value = $this->getValueParsed();
             if ($value == 0) {
                 $result = !$result;
             }
             return $result;
         }
     }
     //validate with attribute is qty
     if ($this->getAttribute() == 'qty') {
         $result = true;
         $qty = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty();
         $value = $this->getValueParsed();
         switch ($op) {
             case '==':
             case '!=':
                 $result = $qty == $value;
                 break;
             case '>=':
             case '<':
                 $result = $qty >= $value;
                 break;
             case '<=':
             case '>':
                 $result = $qty <= $value;
                 break;
         }
         if ($op == '!=' || $op == '<' || $op == '>') {
             $result = !$result;
         }
         return $result;
     }
     //validate with attribute is qty
     if ($this->getAttribute() == 'out_of_stock') {
         $result = true;
         if ($product->isSaleable()) {
             $result = false;
         }
         if ($this->getValueParsed() == 0) {
             $result = !$result;
         }
         return $result;
     }
     //validate best seller
     if ($this->getAttribute() == 'best_seller') {
         $result = true;
         $value = $this->getValueParsed();
         // Get Best Seller product
         $storeId = Mage::app()->getStore()->getId();
         if (Mage::registry('bestSelletListId')) {
             $bestSellerId = Mage::registry('bestSelletListId');
         } else {
             $products = Mage::getResourceModel('reports/product_collection')->addOrderedQty()->setStoreId($storeId)->addStoreFilter($storeId)->setOrder('ordered_qty', 'desc')->setPageSize($value);
             Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
             //Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
             $bestSellerId = array();
             foreach ($products as $p) {
                 $bestSellerId[] = $p->getId();
             }
             if (!empty($bestSellerId)) {
                 Mage::register('bestSelletListId', $bestSellerId);
             }
         }
         if (!count($bestSellerId)) {
             $result = false;
         } else {
             $childProducts = null;
             if ($product->getTypeId() == 'configurable') {
                 $childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);
             } elseif ($product->getTypeId() == 'grouped') {
                 $childProducts = Mage::getModel('catalog/product_type_grouped')->getAssociatedProducts($product);
             } elseif ($product->getTypeId() == 'bundle') {
                 $childProducts = $product->getTypeInstance(true)->getSelectionsCollection($product->getTypeInstance(true)->getOptionsIds($product), $product);
             } else {
                 if (!in_array($product->getId(), $bestSellerId)) {
                     return false;
                 }
             }
             $flag = 0;
             if (isset($childProducts)) {
                 foreach ($childProducts as $c) {
                     if (in_array($c->getId(), $bestSellerId)) {
                         $flag = 1;
                         break;
                     }
                 }
             }
             if ($flag == 0) {
                 $result = false;
             }
         }
         return $result;
     }
     if (!$product->getData($this->getAttribute()) && ('!=' == $op || '>' == $op || '<' == $op || '!{}' == $op || '!()' == $op)) {
         return false;
     }
     return parent::validate($product);
 }
 /**
  * Validate Product Rule Condition
  *
  * @param Varien_Object $object
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $product = Mage::getModel('catalog/product')->load($object->getProductId())->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getRowTotal());
     return parent::validate($product);
 }
예제 #7
0
 public function validate(Varien_Object $object)
 {
     $product = Mage::getModel('catalog/product')->load($object->getProductId());
     #var_dump($this->getAttribute(), $product->getData($this->getAttribute()), parent::validateAttribute($product));
     return parent::validate($product);
 }