Beispiel #1
0
 /**
  * (non-PHPdoc)
  * @see BaseEntityAbstract::preSave()
  */
 public function preSave()
 {
     if (intVal($this->getActive()) === 1) {
         $sku = trim($this->getSku());
         $where = array('sku = ?');
         $params = array($sku);
         if (($id = trim($this->getId())) !== '') {
             $where[] = 'id != ?';
             $params[] = $id;
         }
         $exsitingSKU = self::countByCriteria(implode(' AND ', $where), $params);
         if ($exsitingSKU > 0) {
             throw new EntityException('The SKU(=' . $sku . ') is already exists!');
         }
         if ($this->attributeSet instanceof ProductAttributeSet && $this->attributeSet->getId() === '' || !$this->attributeSet instanceof ProductAttributeSet) {
             $this->setAttributeSet(ProductAttributeSet::get(ProductAttributeSet::ID_DEFAULT_ATTR_SET));
         }
     }
     if (($id = trim($this->getId())) !== '') {
         if (self::countByCriteria('id = ? and isKit = 1 and isKit != ?', array($id, $this->getIsKit())) > 0) {
             //changing isKit flag to be not a KIT
             if (count($kits = Kit::getAllByCriteria('productId = ?', array($id), true, 1, 1)) > 0) {
                 throw new EntityException('Can NOT change the flag IsKit, as there are kits like [' . $kits[0]->getBarcode() . '] for this product: ' . $this->getSku());
             }
         }
     }
 }
Beispiel #2
0
 /**
  * (non-PHPdoc)
  * @see BaseEntityAbstract::postSave()
  */
 public function postSave()
 {
     if ($this->getOrder() instanceof Order) {
         if (count($kits = Kit::getAllByCriteria('soldOnOrderId = ? and shippmentId is null', array($this->getOrder()->getId()))) > 0) {
             foreach ($kits as $kit) {
                 if (!$kit->getShippment() instanceof Shippment) {
                     $kit->setShippment($this)->save();
                 }
             }
         }
     }
 }
Beispiel #3
0
 /**
  * (non-PHPdoc)
  * @see BaseEntityAbstract::preSave()
  */
 public function preSave()
 {
     if (trim($this->getInvDate()) === '') {
         $this->setInvDate(Udate::zeroDate());
     }
     if (trim($this->getId()) !== '') {
         //status changed
         $originalOrder = self::get($this->getId());
         if ($originalOrder instanceof Order && $originalOrder->getStatus()->getId() !== $this->getStatus()->getId()) {
             $infoType = OrderInfoType::get(OrderInfoType::ID_MAGE_ORDER_STATUS_BEFORE_CHANGE);
             $orderInfos = OrderInfo::find($this, $infoType, false, 1, 1);
             $orderInfo = count($orderInfos) === 0 ? null : $orderInfos[0];
             OrderInfo::create($this, $infoType, $originalOrder->getStatus()->getId(), $orderInfo);
             $this->addLog('Changed Status from [' . $originalOrder->getStatus()->getName() . '] to [' . $this->getStatus() . ']', Log::TYPE_SYSTEM, 'Auto Log', get_class($this) . '::' . __FUNCTION__);
             //get the required kits qty
             if (in_array(intval($this->getStatus()->getId()), array(OrderStatus::ID_PICKED, OrderStatus::ID_SHIPPED))) {
                 $sql = "select sum(ord_item.qtyOrdered) `requiredQty`, ord_item.productId `productId`, pro.sku `sku` from orderitem ord_item inner join product pro on (pro.id = ord_item.productId and pro.isKit = 1) where ord_item.orderId = ? and ord_item.active = 1 group by pro.id";
                 $result = Dao::getResultsNative($sql, array($this->getId()), PDO::FETCH_ASSOC);
                 if (count($result) > 0) {
                     $errMsg = array();
                     foreach ($result as $row) {
                         $requiredQty = $row['requiredQty'];
                         $sku = $row['sku'];
                         if (($kitsCount = count($kits = Kit::getAllByCriteria('soldOnOrderId = ? and productId =? ', array($this->getId(), $row['productId'])))) < $requiredQty) {
                             $errMsg[] = 'Product (SKU=' . $sku . ') needs to be sold as a kit(req Qty=' . $requiredQty . ', providedQty=' . $kitsCount . '): ' . implode(', ', array_map(create_function('$a', 'return $a->getBarcode();'), $kits));
                         }
                     }
                     if (count($errMsg) > 0) {
                         throw new EntityException(implode('; ', $errMsg));
                     }
                 }
             }
         }
     }
 }