예제 #1
0
 /**
  * Import from an entity
  *
  * @param mixed|object
  * @return Discount
  */
 public function importEntity($entity)
 {
     $id = $entity->getId();
     $name = $entity->getName();
     $as = $entity->getAs();
     $to = $entity->getTo();
     $value = $entity->getValue();
     $isCompound = $entity->getIsCompound();
     $isPreTax = $entity->getIsPreTax();
     $isAuto = $entity->getIsAuto();
     $isStopper = $entity->getIsStopper();
     $priority = $entity->getPriority();
     $couponCode = $entity->getCouponCode();
     $startDatetime = strtotime($entity->getStartDatetime());
     $endDatetime = strtotime($entity->getEndDatetime());
     $maxQty = $entity->getMaxQty();
     $maxAmount = $entity->getMaxAmount();
     $isMaxPerItem = $entity->getIsMaxPerItem();
     $toItems = array();
     // won't know this until we validate conditions
     $toShipments = array();
     // won't know this until we validate conditions
     $this->_id = $id;
     $this->_name = $name;
     $this->_as = $as;
     $this->_to = $to;
     $this->_value = $value;
     $this->_maxQty = $maxQty;
     $this->_maxAmount = $maxAmount;
     $this->_isMaxPerItem = $isMaxPerItem;
     $this->_isCompound = $isCompound;
     $this->_isProportional = $isProportional;
     $this->_isPreTax = $isPreTax;
     $this->_isAuto = $isAuto;
     $this->_isStopper = $isStopper;
     $this->_priority = $priority;
     $this->_couponCode = $couponCode;
     $this->_items = $toItems;
     $this->_shipments = $toShipments;
     $this->_startDatetime = $startDatetime;
     $this->_endDatetime = $endDatetime;
     $preCondition = new DiscountConditionCompare();
     $preCondition->importEntity($entity->getPreconditions());
     $targetCondition = new DiscountConditionCompare();
     $targetCondition->importEntity($entity->getTargetConditions());
     $this->_preConditionCompare = $preCondition;
     $this->_targetConditionCompare = $targetCondition;
     return $this;
 }
예제 #2
0
파일: Item.php 프로젝트: luoshulin/falcon
 /**
  * Check if this item validates a tree of conditions
  *
  * @param DiscountConditionCompare
  * @return bool
  */
 public function isValidConditionCompare(DiscountConditionCompare $compare)
 {
     return $compare->isValid($this);
 }
예제 #3
0
 /**
  * Import object from stdClass
  *
  * @param stdClass
  * @param bool
  * @return DiscountConditionCompare
  */
 public function importStdClass($obj, $reset = true)
 {
     if ($reset) {
         $this->reset();
     }
     $op = isset($obj->op) ? $obj->op : '';
     $isNot = (bool) isset($obj->is_not) ? $obj->is_not : false;
     $left = null;
     $right = null;
     $leftData = isset($obj->left) ? $obj->left : null;
     $rightData = isset($obj->right) ? $obj->right : null;
     $conditions = isset($obj->conditions) ? $obj->conditions : array();
     if (is_array($leftData) || $leftData instanceof stdClass) {
         if (isset($leftData['op']) || isset($leftData->op)) {
             //we have DiscountConditionCompare data
             if ($leftData instanceof stdClass) {
                 $left = new DiscountConditionCompare();
                 $left->importStdClass($leftData);
             } else {
                 if (is_array($leftData)) {
                     $left = new DiscountConditionCompare();
                     $left->importJson(json_encode($leftData));
                 }
             }
         } else {
             //we have DiscountCondition data
             if ($leftData instanceof stdClass) {
                 $left = new DiscountCondition();
                 $left->importStdClass($leftData);
             } else {
                 if (is_array($leftData)) {
                     $left = new DiscountCondition();
                     $left->importJson(json_encode($leftData));
                 }
             }
         }
     }
     if (is_array($rightData) || $rightData instanceof stdClass) {
         if (isset($rightData['op']) || isset($rightData->op)) {
             //we have DiscountConditionCompare data
             if ($rightData instanceof stdClass) {
                 $right = new DiscountConditionCompare();
                 $right->importStdClass($rightData);
             } else {
                 if (is_array($rightData)) {
                     $right = new DiscountConditionCompare();
                     $right->importJson(json_encode($rightData));
                 }
             }
         } else {
             //we have DiscountCondition data
             if ($rightData instanceof stdClass) {
                 $right = new DiscountCondition();
                 $right->importStdClass($rightData);
             } else {
                 if (is_array($rightData)) {
                     $right = new DiscountCondition();
                     $right->importJson(json_encode($rightData));
                 }
             }
         }
     }
     if ((is_array($conditions) || $conditions instanceof stdClass) && count($conditions) > 0) {
         foreach ($conditions as $data) {
             if (isset($data->op) || is_array($data) && isset($data['op'])) {
                 //we have DiscountConditionCompare data
                 $compare = new DiscountConditionCompare();
                 if ($data instanceof stdClass) {
                     $compare->importStdClass($data);
                     $this->addCondition($compare);
                 } else {
                     if (is_array($data)) {
                         $compare->importJson(json_encode($data));
                         $this->addCondition($compare);
                     }
                 }
             } else {
                 //we have DiscountCondition data
                 $condition = new DiscountCondition();
                 if ($data instanceof stdClass) {
                     $condition->importStdClass($data);
                     $this->addCondition($condition);
                 } else {
                     if (is_array($data)) {
                         $condition->importJson(json_encode($data));
                         $this->addCondition($condition);
                     }
                 }
             }
         }
     }
     $this->setOp($op)->setIsNot($isNot)->setLeftCondition($left)->setRightCondition($right)->setConditions($conditions);
     return $this;
 }