/**
  * Validate Address Rule Condition
  *
  * @param Varien_Object|Mage_Sales_Model_Order|Mage_Sales_Model_Quote $object
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     /* @var $object Mage_Sales_Model_Order|Mage_Sales_Model_Quote */
     //Get infos from billing address
     $toValidate = new Varien_Object();
     $customer_id = $object->getCustomerId();
     $orders_count = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('customer_id', $customer_id)->count();
     $toValidate->setOrdersCount($orders_count);
     $toValidate->setCustomerIsGuest(is_null($object->getCustomerIsGuest()) ? 0 : $object->getCustomerIsGuest());
     $toValidate->setDiffAddresses($this->_addressesesAreDifferent($object));
     $toValidate->setCustomerGroup($object->getCustomerGroupId());
     return parent::validate($toValidate);
 }
예제 #2
0
파일: Abstract.php 프로젝트: quyip8818/Mag
 /**
  * Validate product attrbute value for condition
  *
  * @param Varien_Object $object
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $attrCode = $this->getAttribute();
     if (!$object instanceof Mage_Catalog_Model_Product) {
         $object = Mage::getModel('catalog/product')->load($object->getId());
     }
     if ('category_ids' == $attrCode) {
         return $this->validateAttribute($object->getCategoryIds());
     } elseif (!isset($this->_entityAttributeValues[$object->getId()])) {
         if (!$object->getResource()) {
             return false;
         }
         $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;
     }
 }
예제 #3
0
파일: Order.php 프로젝트: sshegde123/wmp8
 public function validate(Varien_Object $order)
 {
     if ($this->getAttribute() == 'method') {
         return parent::validate($order->getPayment());
     }
     if (in_array($this->getAttribute(), array('postcode', 'region', 'region_id', 'country_id'))) {
         if ($order->getIsVirtual()) {
             $address = $order->getBillingAddress();
         } else {
             $address = $order->getShippingAddress();
         }
         $countryId = $address->getCountryId();
         if (!is_null($countryId)) {
             try {
                 $regions = Mage::getModel('directory/country')->loadByCode($countryId)->getRegions()->getData();
             } catch (Exception $e) {
                 Mage::log($e->getMessage());
             }
             if (count($regions) == 0) {
                 $address->setRegionId('0');
             }
         }
         return parent::validate($address);
     }
     return parent::validate($order);
 }
예제 #4
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);
 }
예제 #5
0
 /**
  * Validate product attrbute value for condition
  *
  * @param  Varien_Object $object Object
  * @return boolean True/False
  */
 public function validate(Varien_Object $object)
 {
     $attrCode = $this->getAttribute();
     if ('category_ids' == $attrCode) {
         return $this->validateAttribute($object->getAvailableInCategories());
     } 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;
         $oldAttrValue = $object->hasData($attrCode) ? $object->getData($attrCode) : null;
         foreach ($this->_entityAttributeValues[$object->getId()] as $storeId => $value) {
             $object->setData($attrCode, $value);
             $result = parent::validate($object);
             if ($result) {
                 break;
             }
         }
         if (null === $oldAttrValue) {
             $object->unsetData($attrCode);
         } else {
             $object->setData($attrCode, $oldAttrValue);
         }
         return (bool) $result;
     }
 }
예제 #6
0
 public function validate(Varien_Object $object)
 {
     if ($this->getAttribute() == 'sku') {
         $sku = explode(',', $this->getValue());
         foreach ($sku as $skuA) {
             foreach ($object->getSku() as $skuB) {
                 if ($skuA == $skuB) {
                     return true;
                 }
             }
         }
         return false;
     }
     if ($this->getAttribute() == 'category') {
         if (is_array($object->getCategories())) {
             foreach ($object->getCategories() as $key => $value) {
                 $result = $this->validateAttribute($value);
                 if ($result) {
                     return $result;
                 }
             }
         } else {
             return $this->validateAttribute($object->getCategories());
         }
     }
     return parent::validate($object);
 }
예제 #7
0
파일: Params.php 프로젝트: ntnhan220488/ggm
 public function validate(Varien_Object $object)
 {
     $customerId = $object->getQuote()->getCustomerId();
     if ($customerId) {
         $customer = Mage::getModel('customer/customer')->load($customerId);
         $datas = $customer->getData();
         return parent::validate($datas);
     }
     return false;
     //if ($object instanceof Mage_Sales_Model_Order && $order->getId())
     /*
             if ($datas = $object->getData()){
                 return parent::validate($object);
             } else {
                 return false;
             }*/
 }
예제 #8
0
파일: Params.php 프로젝트: ntnhan220488/ggm
 public function validate(Varien_Object $object)
 {
     /*$customerId = $object->getQuote()->getCustomerId();
       if ($customerId){
           $customer = Mage::getModel('customer/customer')->load($customerId);
           $address = $customer->getPrimaryBillingAddress();
       } else {
           return false;
       }*/
     //Mage_Checkout_Model_Cart
     //if ($object instanceof Mage_Sales_Model_Order && $order->getId())
     //print_r(Mage::helper('checkout/cart')->getCart());
     $customerId = $object->getQuote()->getCustomerId();
     if ($customerId) {
         $customer = Mage::getModel('customer/customer')->load($customerId);
         if ($address = $object->getPrimaryBillingAddress()) {
             return parent::validate($address);
         }
     }
     return false;
     /*if ($address = $object->getPrimaryBillingAddress()){
           return parent::validate($address);
       } else {
           return false;
       }*/
 }
 /**
  * @param Varien_Object $object
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $address = $object;
     if (!$address instanceof Mage_Sales_Model_Quote_Address) {
         if ($object->getQuote()->isVirtual()) {
             $address = $object->getQuote()->getBillingAddress();
         } else {
             $address = $object->getQuote()->getShippingAddress();
         }
     }
     $address->setCustomerGroupCondition($this->getValue());
     return parent::validate($address);
 }
 /**
  * Validate Address Rule Condition
  *
  * @param Varien_Object|Mage_Sales_Model_Order|Mage_Sales_Model_Quote $object
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $quote = $object;
     if (!$object instanceof Mage_Sales_Model_Quote) {
         $quote = Mage::getModel('sales/quote')->load($object->getQuoteId());
     }
     $address = $quote->getBillingAddress();
     //Get infos from billing address
     $toValidate = new Varien_Object();
     $toValidate->setBillingPostcode($address->getPostcode());
     $toValidate->setBillingRegion($address->getRegion());
     $toValidate->setBillingRegionId($address->getRegionId());
     $toValidate->setBillingCountryId($address->getCountryId());
     if (!$quote->isVirtual()) {
         //Get infos from shipping address
         $address = $quote->getShippingAddress();
     }
     $toValidate->setBaseSubtotal($address->getBaseSubtotal());
     $toValidate->setBaseGrandTotal($address->getBaseGrandTotal());
     $toValidate->setWeight($address->getWeight());
     $toValidate->setShippingMethod($address->getShippingMethod());
     $toValidate->setTotalQty($quote->getItemsQty());
     $toValidate->setBaseCurrencyCode($quote->getBaseCurrencyCode());
     $toValidate->setCreatedAt($this->_getFormatCreatedAt($object));
     return parent::validate($toValidate);
 }
예제 #11
0
 /**
  * Validate Address Rule Condition
  *
  * @param Varien_Object $object
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $address = $object;
     if (!$address instanceof Mage_Sales_Model_Quote_Address) {
         if ($object->getQuote()->isVirtual()) {
             $address = $object->getQuote()->getBillingAddress();
         } else {
             $address = $object->getQuote()->getShippingAddress();
         }
     }
     return parent::validate($address);
 }
 /**
  * Validate Address Rule Condition
  *
  * @param Varien_Object $object
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $customer = $object;
     if (!$customer instanceof Mage_Customer_Model_Customer) {
         $customer = $object->getQuote()->getCustomer();
         $attr = $this->getAttribute();
         if ($attr == 'membership_days') {
             $customer->setData($attr, Mage::helper('amrules')->getMembership($customer->getCreatedAt()));
         }
         if ($attr != 'entity_id' && !$customer->getData($attr)) {
             $address = $object->getQuote()->getBillingAddress();
             $customer->setData($attr, $address->getData($attr));
         }
     }
     return parent::validate($customer);
 }
예제 #13
0
 /**
  * Validate Address Rule Condition
  *
  * @param Varien_Object $object
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $customer = $object;
     if (!$customer instanceof Mage_Customer_Model_Customer) {
         $customer = $object->getQuote()->getCustomer();
         $attr = $this->getAttribute();
         if ($attr != 'entity_id' && !$customer->getData($attr)) {
             $address = $object->getQuote()->getBillingAddress();
             $customer->setData($attr, $address->getData($attr));
         }
     }
     return parent::validate($customer);
 }
예제 #14
0
 /**
  * Validate Address Rule Condition
  *
  * @param Varien_Object $object
  *
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $objectForParent = $object;
     $adressAttributes = array('weight', 'shipping_method', 'postcode', 'region', 'region_id', 'country_id');
     if ($this->getAttribute() == 'method') {
         $objectForParent = $object->getPayment();
     }
     if (in_array($this->getAttribute(), $adressAttributes)) {
         if ($object->isVirtual()) {
             $objectForParent = $object->getBillingAddress();
         } else {
             $objectForParent = $object->getShippingAddress();
         }
         try {
             $countryId = $objectForParent->getCountryId();
             if (!is_null($countryId)) {
                 $numOfCountryRegions = count(Mage::getModel('directory/country')->loadByCode($countryId)->getRegions()->getData());
                 if ($numOfCountryRegions == 0) {
                     $objectForParent->setRegionId('0');
                 }
             }
         } catch (Exception $e) {
             Mage::log('Exception: ' . $e->getMessage() . ' in ' . __CLASS__ . ' on line ' . __LINE__);
         }
     }
     return parent::validate($objectForParent);
 }
예제 #15
0
 /**
  * Validate product
  *
  * @param Varien_Object $object
  * @return bool
  */
 protected function _validateProduct($object)
 {
     return Mage_Rule_Model_Condition_Abstract::validate($object);
 }
예제 #16
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 'is_salable':
             $value = $object->isSalable();
             $object->setIsSalable($value);
             return $this->validateAttribute($value);
             break;
         case 'status_parent':
             $parentProduct = Mage::getSingleton('feedexport/feed_generator_pattern_product')->getParentProduct($object);
             $value = $parentProduct->getStatus();
             return $this->validateAttribute($value);
             break;
         case 'image':
         case 'small_image':
         case 'thumbnail':
             $value = $object->getData($attrCode);
             if ('' === $value || 'no_selection' === $value) {
                 $value = null;
             }
             return $this->validateAttribute($value);
             break;
         case 'category_ids':
             return $this->validateAttribute($object->getAvailableInCategories());
             break;
         case 'qty':
             if ($object->getTypeId() == 'configurable') {
                 $totalQty = 0;
                 $childs = $object->getTypeInstance()->getChildrenIds($object->getId());
                 $childs = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('entity_id', array('in' => $childs[0]))->joinField('qty', 'cataloginventory/stock_item', 'qty', 'product_id = entity_id', '{{table}}.stock_id = 1', 'left');
                 foreach ($childs as $child) {
                     # if product enabled
                     if ($child->getStatus() == 1) {
                         $totalQty += $child->getQty();
                     }
                 }
                 return $this->validateAttribute($totalQty);
             } else {
                 $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($object->getId());
                 return $this->validateAttribute($stockItem->getQty());
             }
             break;
         case 'is_in_stock':
             $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($object->getId());
             return $this->validateAttribute($stockItem->getIsInStock());
             break;
         case 'manage_stock':
             $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($object->getId());
             $m = 0;
             if ($stockItem->getManageStock()) {
                 $m = 1;
             }
             return $this->validateAttribute($m);
             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);
                     } 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;
             }
             break;
     }
 }
예제 #17
0
 /**
  * Validate Address Rule Condition
  *
  * @param Varien_Object $object
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $address = $object;
     if (!$address instanceof Mage_Sales_Model_Quote_Address) {
         if ($object->getQuote()->isVirtual()) {
             $address = $object->getQuote()->getBillingAddress();
         } else {
             $address = $object->getQuote()->getShippingAddress();
         }
     }
     if ('payment_method' == $this->getAttribute() && !$address->hasPaymentMethod()) {
         $address->setPaymentMethod($object->getQuote()->getPayment()->getMethod());
     }
     return parent::validate($address);
 }
예제 #18
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;
     }
 }