/** * creating order info * * @param Order $order * @param OrderInfoType $type * @param string $value * * @return B2BConnector */ private function _createOrderInfo(Order $order, OrderInfoType $type, $value) { $items = OrderInfo::find($order, $type); if (count(OrderInfo::find($order, $type)) > 0) { foreach ($items as $item) { OrderInfo::create($order, $type, $value, $item); } } else { OrderInfo::create($order, $type, $value); } return $this; }
/** * (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)); } } } } } }