示例#1
0
 private function serializeToArray(CustomerOrder $order)
 {
     $array = array();
     $array['ID'] = $order->getID();
     $array['totalAmount'] = $order->totalAmount->get();
     $array['isCancelled'] = (int) $order->isCancelled->get();
     $array['status'] = (int) $order->status->get();
     $array['shipments'] = array();
     foreach ($order->getShipments() as $shipment) {
         $shippingServiceArray = null;
         if ($shipment->shippingService->get() && (int) $shipment->shippingService->get()->getID()) {
             $shippingServiceArray = $shipment->shippingService->get()->toArray();
         } else {
             $shippingService = unserialize($shipment->shippingServiceData->get());
             $shippingServiceArray = null;
             if (is_object($shippingService)) {
                 $shippingService->setApplication($order->getApplication());
                 $shippingServiceArray = $shippingService->toArray();
             }
         }
         $array['shipments'][$shipment->getID()] = array('ID' => $shipment->getID(), 'status' => (int) $shipment->status->get(), 'ShippingService' => $shippingServiceArray);
     }
     $array['items'] = array();
     foreach ($order->getOrderedItems() as $item) {
         $array['items'][$item->getID()] = array('ID' => $item->getID(), 'shipmentID' => $item->shipment->get() ? $item->shipment->get()->getID() : null, 'count' => (int) $item->count->get(), 'price' => $item->price->get(), 'Product' => array('ID' => (int) $item->getProduct()->getID(), 'sku' => $item->getProduct()->sku->get(), 'name' => $item->getProduct()->getName($order->getApplication()->getDefaultLanguageCode()), 'isDownloadable' => (int) $item->getProduct()->isDownloadable()), 'Shipment' => $item->shipment->get() && isset($array['shipments'][$item->shipment->get()->getID()]) ? $array['shipments'][$item->shipment->get()->getID()] : array('ID' => 0));
     }
     // @todo: dirty fix
     if ($order->shippingAddress->get()) {
         if ($order->shippingAddress->get()->state->get()) {
             $order->shippingAddress->get()->state->get()->load();
         }
         $array['ShippingAddress'] = $order->shippingAddress->get()->toArray();
     } else {
         $array['ShippingAddress'] = array();
     }
     if ($order->billingAddress->get()) {
         if ($order->billingAddress->get()->state->get()) {
             $order->billingAddress->get()->state->get()->load();
         }
         $array['BillingAddress'] = $order->billingAddress->get()->toArray();
     } else {
         $array['BillingAddress'] = array();
     }
     return $array;
 }
示例#2
0
 /**
  * @return RequestValidator
  */
 private function buildCartValidator(CustomerOrder $order, $options)
 {
     unset($_SESSION['optionError']);
     $validator = $this->getValidator("cartValidator", $this->request);
     foreach ($order->getOrderedItems() as $item) {
         $this->buildItemValidation($validator, $item, $options, $item->getID());
     }
     if ($this->config->get('CHECKOUT_CUSTOM_FIELDS') == 'CART_PAGE') {
         $order->getSpecification()->setValidation($validator, true);
     }
     if ($this->isTosInCartPage()) {
         $validator->addCheck('tos', new IsNotEmptyCheck($this->translate('_err_agree_to_tos')));
     }
     return $validator;
 }
示例#3
0
 /**
  *  Merge two orders into one
  */
 public function merge(CustomerOrder $order)
 {
     foreach ($order->getOrderedItems() as $item) {
         $order->moveItem($item, $this);
     }
     $this->mergeItems();
 }