Ejemplo n.º 1
0
        </div>
        <?php 
$res = get_all_orders();
?>

        <?php 
while ($row = mysql_fetch_array($res, MYSQL_BOTH)) {
    ?>

            <div class="description">
                <form method="post">
                <ul>
                    <li>
                        <select name="status">
                            <?php 
    foreach (OrderStatus::get() as $k => $v) {
        ?>
                                <option <?php 
        echo $k == $row['status'] ? 'selected' : '';
        ?>
 value="<?php 
        echo $k;
        ?>
"><?php 
        echo $v;
        ?>
</option>
                            <?php 
    }
    ?>
                        </select>
Ejemplo n.º 2
0
 /**
  * Import Orders
  *
  * @param string $lastUpdatedTime The datatime string
  *
  * @return B2BConnector
  */
 public function importOrders($lastUpdatedTime = '')
 {
     $totalItems = 0;
     $this->_log(0, get_class($this), 'starting ...', self::LOG_TYPE, 'start', __FUNCTION__);
     if (($lastUpdatedTime = trim($lastUpdatedTime)) === '') {
         $this->_log(0, get_class($this), 'Getting the last updated time', self::LOG_TYPE, '$lastUpdatedTime is blank', __FUNCTION__);
         // 			$lastImportTime = new UDate(SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_LAST_IMPORT_TIME), SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_TIMEZONE));
         $lastUpdatedTime = trim(SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_LAST_IMPORT_TIME));
     }
     //getting the lastest order since last updated time
     $orders = $this->getlastestOrders($lastUpdatedTime);
     $this->_log(0, get_class($this), 'Found ' . count($orders) . ' order(s) since "' . $lastUpdatedTime . '".', self::LOG_TYPE, '', __FUNCTION__);
     if (is_array($orders) && count($orders) > 0) {
         $transStarted = false;
         try {
             try {
                 Dao::beginTransaction();
             } catch (Exception $e) {
                 $transStarted = true;
             }
             foreach ($orders as $index => $order) {
                 $this->_log(0, get_class($this), 'Found order from Magento with orderNo = ' . trim($order->increment_id) . '.', self::LOG_TYPE, '', __FUNCTION__);
                 $order = $this->getOrderInfo(trim($order->increment_id));
                 if (!is_object($order)) {
                     $this->_log(0, get_class($this), 'Found no object from $order, next element!', self::LOG_TYPE, '$index = ' . $index, __FUNCTION__);
                     continue;
                 }
                 if (($status = trim($order->state)) === '') {
                     $this->_log(0, get_class($this), 'Found no state Elment from $order, next element!', self::LOG_TYPE, '$index = ' . $index, __FUNCTION__);
                     continue;
                 }
                 //saving the order
                 $orderDate = new UDate(trim($order->created_at), SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_TIMEZONE));
                 $orderDate->setTimeZone('UTC');
                 // 				$totalPaid = (!isset($order->total_paid) ? 0 : trim($order->total_paid));
                 $shippingAddr = $billingAddr = null;
                 if (($o = Order::getByOrderNo(trim($order->increment_id))) instanceof Order) {
                     //skip, if order exsits
                     $this->_log(0, get_class($this), 'Found order from DB, ID = ' . $o->getId(), self::LOG_TYPE, '$index = ' . $index, __FUNCTION__);
                     continue;
                     // 					$shippingAddr = $o->getShippingAddr();
                     // 					$billingAddr = $o->getBillingAddr();
                 }
                 $o = new Order();
                 $this->_log(0, get_class($this), 'Found no order from DB, create new', self::LOG_TYPE, '$index = ' . $index, __FUNCTION__);
                 $customer = Customer::create(isset($order->billing_address) && isset($order->billing_address->company) && trim($order->billing_address->company) !== '' ? trim($order->billing_address->company) : (isset($order->customer_firstname) ? trim($order->customer_firstname) . ' ' . trim($order->customer_lastname) : ''), '', trim($order->customer_email), $this->_createAddr($order->billing_address, $billingAddr), true, '', $this->_createAddr($order->shipping_address, $shippingAddr), isset($order->customer_id) ? trim($order->customer_id) : 0);
                 $o->setOrderNo(trim($order->increment_id))->setOrderDate(trim($orderDate))->setTotalAmount(trim($order->grand_total))->setStatus(strtolower($status) === 'canceled' ? OrderStatus::get(OrderStatus::ID_CANCELLED) : OrderStatus::get(OrderStatus::ID_NEW))->setIsFromB2B(true)->setShippingAddr($customer->getShippingAddress())->setBillingAddr($customer->getBillingAddress())->setCustomer($customer)->save();
                 $this->_log(0, get_class($this), 'Saved the order, ID = ' . $o->getId(), self::LOG_TYPE, '$index = ' . $index, __FUNCTION__);
                 $totalShippingCost = StringUtilsAbstract::getValueFromCurrency(trim($order->shipping_amount)) * 1.1;
                 //create order info
                 $this->_createOrderInfo($o, OrderInfoType::get(OrderInfoType::ID_CUS_NAME), trim($customer->getName()))->_createOrderInfo($o, OrderInfoType::get(OrderInfoType::ID_CUS_EMAIL), trim($customer->getEmail()))->_createOrderInfo($o, OrderInfoType::get(OrderInfoType::ID_QTY_ORDERED), intval(trim($order->total_qty_ordered)))->_createOrderInfo($o, OrderInfoType::get(OrderInfoType::ID_MAGE_ORDER_STATUS), trim($order->status))->_createOrderInfo($o, OrderInfoType::get(OrderInfoType::ID_MAGE_ORDER_STATE), trim($order->state))->_createOrderInfo($o, OrderInfoType::get(OrderInfoType::ID_MAGE_ORDER_TOTAL_AMOUNT), trim($order->grand_total))->_createOrderInfo($o, OrderInfoType::get(OrderInfoType::ID_MAGE_ORDER_SHIPPING_METHOD), trim($order->shipping_description))->_createOrderInfo($o, OrderInfoType::get(OrderInfoType::ID_MAGE_ORDER_SHIPPING_COST), $totalShippingCost)->_createOrderInfo($o, OrderInfoType::get(OrderInfoType::ID_MAGE_ORDER_PAYMENT_METHOD), !isset($order->payment) ? '' : (!isset($order->payment->method) ? '' : trim($order->payment->method)));
                 $this->_log(0, get_class($this), 'Updated order info', self::LOG_TYPE, '$index = ' . $index, __FUNCTION__);
                 //saving the order item
                 $totalItemCost = 0;
                 foreach ($order->items as $item) {
                     $this->_createItem($o, $item);
                     $totalItemCost = $totalItemCost * 1 + StringUtilsAbstract::getValueFromCurrency($item->row_total) * 1.1;
                 }
                 if (($possibleSurchargeAmount = $o->getTotalAmount() - $totalShippingCost - $totalItemCost) > 0 && ($product = Product::getBySku('surcharge')) instanceof Product) {
                     OrderItem::create($o, $product, $possibleSurchargeAmount, 1, $possibleSurchargeAmount);
                 }
                 //record the last imported time for this import process
                 SystemSettings::addSettings(SystemSettings::TYPE_B2B_SOAP_LAST_IMPORT_TIME, trim($order->created_at));
                 $this->_log(0, get_class($this), 'Updating the last updated time :' . trim($order->created_at), self::LOG_TYPE, '', __FUNCTION__);
                 $totalItems++;
             }
             if ($transStarted === false) {
                 Dao::commitTransaction();
             }
         } catch (Exception $e) {
             if ($transStarted === false) {
                 Dao::rollbackTransaction();
             }
             throw $e;
         }
     }
     $this->_log(0, get_class($this), $lastUpdatedTime . " => " . SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_LAST_IMPORT_TIME) . ' => ' . $totalItems, self::LOG_TYPE, '', __FUNCTION__);
     return $this;
 }
Ejemplo n.º 3
0
 public function clearETA($sender, $param)
 {
     $results = $errors = array();
     try {
         if (!isset($param->CallbackParameter->item_id) || !($item = OrderItem::get($param->CallbackParameter->item_id)) instanceof OrderItem) {
             throw new Exception('System Error: invalid order item provided!');
         }
         if (!isset($param->CallbackParameter->comments) || ($comments = trim($param->CallbackParameter->comments)) === '') {
             $comments = '';
         }
         Dao::beginTransaction();
         //saving the order item
         $item->setETA(UDate::zeroDate())->addComment('Clearing the ETA: ' . $comments);
         $order = $item->getOrder();
         $sku = $item->getProduct()->getSku();
         $order->addComment('Clearing the ETA for product (' . $sku . '): ' . $comments, Comments::TYPE_PURCHASING);
         $item->save();
         //check to see whether we need to update the order as well
         $allChecked = true;
         foreach ($order->getOrderItems() as $orderItems) {
             if (trim($orderItems->getETA()) !== trim(UDate::zeroDate())) {
                 $allChecked = false;
             }
         }
         if ($allChecked === true) {
             $order->addComment('Auto Push this order status from [' . $order->getStatus() . '] to [' . OrderStatus::ID_ETA . '], as the last ETA cleared', Comments::TYPE_SYSTEM);
             $order->setStatus(OrderStatus::get(OrderStatus::ID_STOCK_CHECKED_BY_PURCHASING));
         }
         $order->save();
         $results = $item->getJson();
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Ejemplo n.º 4
0
 /**
  * saveOrder
  *
  * @param unknown $sender
  * @param unknown $param
  *
  * @throws Exception
  *
  */
 public function saveOrder($sender, $param)
 {
     $results = $errors = array();
     try {
         Dao::beginTransaction();
         $customer = Customer::get(trim($param->CallbackParameter->customer->id));
         if (!$customer instanceof Customer) {
             throw new Exception('Invalid Customer passed in!');
         }
         if (!isset($param->CallbackParameter->applyTo) || ($applyTo = trim($param->CallbackParameter->applyTo)) === '' || !in_array($applyTo, CreditNote::getApplyToTypes())) {
             throw new Exception('Invalid Apply To passed in!');
         }
         if (isset($param->CallbackParameter->creditNoteId) && ($creditNote = CreditNote::get(trim($param->CallbackParameter->creditNoteId))) instanceof CreditNote) {
             $creditNote = $creditNote;
         } else {
             if (isset($param->CallbackParameter->orderId) && ($order = Order::get(trim($param->CallbackParameter->orderId))) instanceof Order) {
                 $creditNote = CreditNote::createFromOrder($order, $customer, trim($param->CallbackParameter->description));
             } else {
                 $creditNote = CreditNote::create($customer, trim($param->CallbackParameter->description));
             }
         }
         $creditNote->setShippingValue(isset($param->CallbackParameter->totalShippingCost) ? StringUtilsAbstract::getValueFromCurrency($param->CallbackParameter->totalShippingCost) : 0);
         if (isset($param->CallbackParameter->shippingAddr)) {
             $shippAddress = Address::create($param->CallbackParameter->shippingAddr->street, $param->CallbackParameter->shippingAddr->city, $param->CallbackParameter->shippingAddr->region, $param->CallbackParameter->shippingAddr->country, $param->CallbackParameter->shippingAddr->postCode, $param->CallbackParameter->shippingAddr->contactName, $param->CallbackParameter->shippingAddr->contactNo);
             $customer->setShippingAddress($shippAddress);
         }
         $printItAfterSave = false;
         if (isset($param->CallbackParameter->printIt)) {
             $printItAfterSave = intval($param->CallbackParameter->printIt) === 1 ? true : false;
         }
         if (isset($param->CallbackParameter->comments)) {
             $comments = trim($param->CallbackParameter->comments);
             $creditNote->addComment($comments, Comments::TYPE_SALES);
         }
         $totalPaymentDue = $creditNote->getShippingValue();
         $hasShipped = $creditNote->getOrder() instanceof Order && Shippment::countByCriteria('orderId = ?', array($creditNote->getOrder()->getId())) > 0;
         $creditNoteItemsMap = array();
         foreach ($param->CallbackParameter->items as $item) {
             if (!($product = Product::get(trim($item->product->id))) instanceof Product) {
                 throw new Exception('Invalid Product passed in!');
             }
             $unitPrice = StringUtilsAbstract::getValueFromCurrency(trim($item->unitPrice));
             $qtyOrdered = trim($item->qtyOrdered);
             $totalPrice = StringUtilsAbstract::getValueFromCurrency(trim($item->totalPrice));
             $itemDescription = trim($item->itemDescription);
             $active = trim($item->valid);
             $totalPaymentDue += $totalPrice;
             if (is_numeric($item->creditNoteItemId) && !CreditNoteItem::get(trim($item->creditNoteItemId)) instanceof CreditNoteItem) {
                 throw new Exception('Invalid Credit Note Item passed in');
             }
             $unitCost = $product->getUnitCost();
             $orderItem = null;
             if (isset($item->orderItemId) && ($orderItem = OrderItem::get(trim($item->orderItemId))) instanceof OrderItem) {
                 $unitCost = $orderItem->getUnitCost();
             }
             $creditNoteItem = is_numeric($item->creditNoteItemId) ? CreditNoteItem::get(trim($item->creditNoteItemId))->setActive($active)->setProduct($product)->setQty($qtyOrdered)->setUnitPrice($unitPrice)->setItemDescription($itemDescription)->setUnitCost($unitCost)->setTotalPrice($totalPrice)->save() : ($orderItem instanceof OrderItem ? CreditNoteItem::createFromOrderItem($creditNote, $orderItem, $qtyOrdered, $unitPrice, $itemDescription, $unitCost, $totalPrice) : CreditNoteItem::create($creditNote, $product, $qtyOrdered, $unitPrice, $itemDescription, $unitCost, $totalPrice));
             if (intval($creditNoteItem->getActive()) === 1) {
                 if (!isset($creditNoteItemsMap[$product->getId()])) {
                     $creditNoteItemsMap[$product->getId()] = 0;
                 }
                 $creditNoteItemsMap[$product->getId()] += $qtyOrdered;
             }
             //if we are not creating from a order, or there are shippments for this order then
             if (!$creditNote->getOrder() instanceof Order || $hasShipped === true) {
                 switch (trim($item->stockData)) {
                     case 'StockOnHand':
                         $product->returnedIntoSOH($qtyOrdered, $creditNoteItem->getUnitCost(), '', $creditNoteItem);
                         break;
                     case 'StockOnRMA':
                         $product->returnedIntoRMA($qtyOrdered, $creditNoteItem->getUnitCost(), '', $creditNoteItem);
                         break;
                     default:
                         throw new Exception('System Error: NO where to transfer the stock: ' . trim($item->stockData) . ' for product(SKU=' . $product->getSku() . ').');
                 }
             } else {
                 //revert all the shipped stock
                 foreach (OrderItem::getAllByCriteria('ord_item.orderId = ? and ord_item.isShipped = 1', array($creditNote->getOrder()->getId())) as $orderItem) {
                     $orderItem->setIsShipped(false)->save();
                 }
                 //revert all the picked stock
                 foreach (OrderItem::getAllByCriteria('ord_item.orderId = ? and ord_item.isPicked = 1', array($creditNote->getOrder()->getId())) as $orderItem) {
                     $orderItem->setIsPicked(false)->save();
                 }
             }
         }
         if (($paymentMethod = PaymentMethod::get(trim($param->CallbackParameter->paymentMethodId))) instanceof PaymentMethod) {
             $creditNote->setTotalPaid($totalPaidAmount = $param->CallbackParameter->totalPaidAmount)->addPayment($paymentMethod, $totalPaidAmount);
         }
         $creditNote->setTotalValue($totalPaymentDue)->setApplyTo($applyTo)->save();
         //if need to check half credited orders
         if ($creditNote->getOrder() instanceof Order && $hasShipped === false) {
             $orderItemMap = array();
             foreach ($order->getOrderItems() as $orderItem) {
                 $productId = $orderItem->getProduct()->getId();
                 if (!isset($orderItemMap[$productId])) {
                     $orderItemMap[$productId] = 0;
                 }
                 $orderItemMap[$productId] += $orderItem->getQtyOrdered();
             }
             //figure out the difference
             foreach ($creditNoteItemsMap as $productId => $qty) {
                 if (isset($orderItemMap[$productId])) {
                     if ($orderItemMap[$productId] <= $qty) {
                         //credited more than orderred
                         unset($orderItemMap[$productId]);
                     } else {
                         //credited less then ordered
                         $orderItemMap[$productId] = $orderItemMap[$productId] - $qty;
                     }
                 }
             }
             $orderItemMap = array_filter($orderItemMap);
             if (count($orderItemMap) > 0) {
                 //there are difference
                 $creditNote->creditFullOrder();
                 $newOrder = Order::create($creditNote->getOrder()->getCustomer(), $creditNote->getOrder()->getType() === 'INVOICE' ? Order::TYPE_ORDER : $creditNote->getOrder()->getType(), null, 'Spliting order because of partial credit note(CreditNoteNo:.' . $creditNote->getCreditNoteNo() . ') created', null, $creditNote->getOrder()->getOrderDate(), false, $creditNote->getOrder()->getShippingAddr(), $creditNote->getOrder()->getBillingAddr(), $creditNote->getOrder()->getPassPaymentCheck(), $creditNote->getOrder()->getPONo(), $creditNote->getOrder())->addComment('Created because of partial credit from ');
                 $totalAmount = 0;
                 foreach ($orderItemMap as $productId => $qty) {
                     $orderItems = OrderItem::getAllByCriteria('productId = ? and orderId = ?', array($productId, $creditNote->getOrder()->getId()), true, 1, 1);
                     if (count($orderItems) > 0) {
                         $totalAmount += $orderItems[0]->getUnitPrice() * $qty;
                     }
                     $newOrder->addItem($orderItems[0]->getProduct(), $orderItems[0]->getUnitPrice(), $qty, $orderItems[0]->getTotalPrice(), $orderItems[0]->getMageOrderId(), $orderItems[0]->getEta(), $orderItems[0]->getItemDescription());
                 }
                 if (count($shippingMethods = $creditNote->getOrder()->getInfo(OrderInfoType::ID_MAGE_ORDER_SHIPPING_METHOD)) > 0) {
                     $newOrder->addInfo(OrderInfoType::ID_MAGE_ORDER_SHIPPING_METHOD, $shippingMethods[0], true);
                 }
                 if (count($shippingCost = $creditNote->getOrder()->getInfo(OrderInfoType::ID_MAGE_ORDER_SHIPPING_COST)) > 0) {
                     $newOrder->addInfo(OrderInfoType::ID_MAGE_ORDER_SHIPPING_COST, $shippingCost[0], true);
                     $totalAmount += StringUtilsAbstract::getValueFromCurrency($shippingCost[0]);
                 }
                 $results['newOrder'] = $newOrder->setTotalAmount($totalAmount)->save()->getJson();
                 $creditNote->getOrder()->setStatus(OrderStatus::get(OrderStatus::ID_CANCELLED))->save()->addComment('This ' . $creditNote->getOrder()->getType() . ' is CANCELED, because of partial credit (CreditNoteNo:<a href="/creditnote/' . $creditNote->getId() . '.html" target="_BLANK">' . $creditNote->getCreditNoteNo() . '</a>) is created and a new ' . $newOrder->getType() . ' (<a href="/orderdetails/' . $newOrder->getId() . '.html?blanklayout=1">' . $newOrder->getOrderNo() . '</a>) is created for the diference.', Comments::TYPE_MEMO);
             } else {
                 $creditNote->getOrder()->setStatus(OrderStatus::get(OrderStatus::ID_CANCELLED))->save()->addComment('This ' . $creditNote->getOrder()->getType() . ' is CANCELED, because of full credit (CreditNoteNo:<a href="/creditnote/' . $creditNote->getId() . '.html" target="_BLANK">' . $creditNote->getCreditNoteNo() . '</a>) is created.', Comments::TYPE_MEMO);
             }
         }
         $results['item'] = $creditNote->getJson();
         $results['redirectURL'] = '/creditnote/' . $creditNote->getId() . '.html?' . $_SERVER['QUERY_STRING'];
         if ($printItAfterSave === true) {
             $results['printURL'] = '/print/creditnote/' . $creditNote->getId() . '.html?pdf=1';
         }
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage() . '<pre>' . $ex->getTraceAsString() . '</pre>';
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Ejemplo n.º 5
0
 /**
  * cancelOrder
  *
  * @param unknown $sender
  * @param unknown $param
  *
  * @throws Exception
  *
  */
 public function cancelOrder($sender, $param)
 {
     $results = $errors = array();
     try {
         Dao::beginTransaction();
         if (!isset($param->CallbackParameter->orderId) || !($order = Order::get($param->CallbackParameter->orderId)) instanceof Order) {
             throw new Exception('Invalid Order to CANCEL!');
         }
         if (!isset($param->CallbackParameter->reason) || !($reason = trim($param->CallbackParameter->reason)) === '') {
             throw new Exception('An reason for CANCELLING this ' . $order->getType() . ' is needed!');
         }
         $order->setStatus(OrderStatus::get(OrderStatus::ID_CANCELLED))->save()->addComment($msg = $order->getType() . ' is cancelled: ' . $reason, Comments::TYPE_SALES)->addLog($msg, Log::TYPE_SYSTEM, 'AUTO_GEN', __CLASS__ . '::' . __FUNCTION__);
         $results['item'] = $order->getJson();
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Ejemplo n.º 6
0
 /**
  *
  * @param unknown $sender
  * @param unknown $params
  * @throws Exception
  */
 public function addPayment($sender, $param)
 {
     $results = $errors = array();
     try {
         Dao::beginTransaction();
         if (!isset($param->CallbackParameter->againstEntity) || !isset($param->CallbackParameter->againstEntity->entity) || !isset($param->CallbackParameter->againstEntity->entityId) || ($entityName = trim($param->CallbackParameter->againstEntity->entity)) === '' || !($entity = $entityName::get(trim($param->CallbackParameter->againstEntity->entityId))) instanceof $entityName) {
             throw new Exception('System Error: invalid Order or CreditNote provided. Can NOT get any payments at all.');
         }
         if (!$entity instanceof Order && !$entity instanceof CreditNote) {
             throw new Exception('System Error: you can ONLY add payments for a Order or a CreditNote');
         }
         if (!isset($param->CallbackParameter->payment) || !isset($param->CallbackParameter->payment->paidAmount) || ($paidAmount = StringUtilsAbstract::getValueFromCurrency(trim($param->CallbackParameter->payment->paidAmount))) === '' || !is_numeric($paidAmount)) {
             throw new Exception('System Error: invalid Paid Amount passed in!');
         }
         if (!isset($param->CallbackParameter->payment->payment_method_id) || ($paymentMethodId = trim($param->CallbackParameter->payment->payment_method_id)) === '' || !($paymentMethod = PaymentMethod::get($paymentMethodId)) instanceof PaymentMethod) {
             throw new Exception('System Error: invalid Payment Method passed in!');
         }
         $notifyCust = isset($param->CallbackParameter->payment->notifyCust) && intval($param->CallbackParameter->payment->notifyCust) === 1 ? true : false;
         $extraComment = '';
         if (!isset($param->CallbackParameter->payment->extraComments) || ($extraComment = trim($param->CallbackParameter->payment->extraComments)) === '') {
             throw new Exception('Some comments for this payment is required.');
         }
         //save the payment
         $newPayment = null;
         $entity = $entity->addPayment($paymentMethod, $paidAmount, $extraComment, new UDate(), $newPayment);
         $results['item'] = $newPayment->getJson();
         //notify the customer
         if ($entity instanceof Order && $notifyCust === true && $entity->getIsFromB2B() === true) {
             $notificationMsg = trim(OrderNotificationTemplateControl::getMessage('paid', $entity));
             if ($notificationMsg !== '') {
                 B2BConnector::getConnector(B2BConnector::CONNECTOR_TYPE_ORDER, SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_WSDL), SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_USER), SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_KEY))->changeOrderStatus($entity, OrderStatus::get(OrderStatus::ID_PICKED)->getMageStatus(), $notificationMsg, true);
                 $comments = 'An email notification contains payment checked info has been sent to customer for: ' . $entity->getStatus()->getName();
                 Comments::addComments($entity, $comments, Comments::TYPE_SYSTEM);
             }
         }
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Ejemplo n.º 7
0
 /**
  *
  * @param Customer    $customer
  * @param string      $orderNo
  * @param OrderStatus $status
  * @param string      $orderDate
  * @param string      $type
  * @param string      $isFromB2B
  * @param Address     $shipAddr
  * @param Address     $billAddr
  */
 public static function create(Customer $customer, $type = self::TYPE_ORDER, $orderNo = null, $comments = '', OrderStatus $status = null, $orderDate = null, $isFromB2B = false, Address $shipAddr = null, Address $billAddr = null, $passPaymentCheck = false, $poNo = '', Order $cloneFrom = null)
 {
     $order = new Order();
     $order->setOrderNo(trim($orderNo))->setCustomer($customer)->setStatus($status instanceof OrderStatus ? $status : OrderStatus::get(OrderStatus::ID_NEW))->setOrderDate(trim($orderDate) === '' ? trim(new UDate()) : trim($orderDate))->setIsFromB2B($isFromB2B)->setType(trim($type) === '' ? self::TYPE_ORDER : trim($type))->setShippingAddr($shipAddr instanceof Address ? $shipAddr : $customer->getShippingAddress())->setBillingAddr($billAddr instanceof Address ? $billAddr : $customer->getBillingAddress())->setPassPaymentCheck($passPaymentCheck)->setPONo(trim($poNo));
     if ($cloneFrom instanceof Order) {
         $counts = intval(OrderInfo::countByCriteria('value = ? and typeId = ?', array($cloneFrom->getOrderNo(), OrderInfoType::ID_CLONED_FROM_ORDER_NO)));
         $newOrderNo = $cloneFrom->getOrderNo() . '-' . ($counts + 1);
         $order->setOrderNo($newOrderNo);
         $cloneFrom->addComment($msg = 'A new order has been clone from this order:' . $newOrderNo, Comments::TYPE_SYSTEM)->addLog($msg, Log::TYPE_SYSTEM);
     }
     $order->save();
     if ($cloneFrom instanceof Order) {
         $order->addInfo(OrderInfoType::ID_CLONED_FROM_ORDER_NO, $cloneFrom->getOrderNo(), true)->addComment($msg = 'Cloned from Order:' . $cloneFrom->getOrderNo(), Comments::TYPE_SYSTEM)->addLog($msg, Comments::TYPE_SYSTEM);
     }
     $order->addComment($comments, Comments::TYPE_NORMAL)->addInfo(OrderInfoType::ID_CUS_EMAIL, $customer->getEmail())->addInfo(OrderInfoType::ID_CUS_NAME, $customer->getName())->addLog('Order (OrderNo.=' . $order->getOrderNo() . ') created with status: ' . $order->getStatus()->getName(), Log::TYPE_SYSTEM, 'Auto Log', __CLASS__ . '::' . __FUNCTION__);
     return $order;
 }