Пример #1
0
 private function estimateShippingCost()
 {
     if (!$this->config->get('ENABLE_SHIPPING_ESTIMATE')) {
         return false;
     }
     $estimateAddress = SessionOrder::getEstimateAddress();
     $this->order->shippingAddress->set($estimateAddress);
     $unselected = array();
     $isShippingEstimated = false;
     foreach ($this->order->getShipments() as $shipment) {
         if (!$shipment->getSelectedRate()) {
             $cheapest = $cheapestRate = null;
             $rates = $shipment->getShippingRates();
             foreach ($rates as $rate) {
                 $price = $rate->getAmountByCurrency($this->order->getCurrency());
                 if (!$cheapestRate || $price < $cheapest) {
                     $cheapestRate = $rate;
                     $cheapest = $price;
                 }
             }
             if ($cheapestRate) {
                 $shipment->setRateId($cheapestRate->getServiceID());
                 $unselected[] = $shipment;
                 $isShippingEstimated = true;
             }
         }
     }
     $this->order->getTotal(true);
     foreach ($unselected as $shipment) {
         $shipment->setRateId(null);
     }
     return $isShippingEstimated;
 }
Пример #2
0
 public function applyToOrder(CustomerOrder $order)
 {
     $amount = $order->getCurrency()->convertAmount(CustomerOrder::getApplication()->getDefaultCurrency(), $this->getDiscountAmount($order->totalAmount->get()));
     $orderDiscount = OrderDiscount::getNewInstance($order);
     $orderDiscount->amount->set($amount);
     $orderDiscount->description->set($this->parentCondition->getParam('name_lang'));
     $order->registerOrderDiscount($orderDiscount);
 }
Пример #3
0
 public static function setOrder(CustomerOrder $order)
 {
     $session = new Session();
     $session->set('CustomerOrder', $order->getID());
     $currency = $order->getCurrency();
     $currID = $currency->getID();
     $total = $order->getTotal();
     $orderArray = array('total' => array($currID => $total));
     $orderArray['formattedTotal'] = array($currID => $currency->getFormattedPrice($orderArray['total'][$currID]));
     $orderArray['basketCount'] = $order->getShoppingCartItemCount();
     $orderArray['currencyID'] = $currID;
     $isOrderable = $order->isOrderable();
     $orderArray['isOrderable'] = is_bool($isOrderable) ? $isOrderable : false;
     $items = array();
     foreach ($order->getPurchasedItems() as $item) {
         $items[] = $item->toArray();
     }
     $orderArray['items'] = new RuleOrderContainer($items);
     $orderArray['items']->setCoupons($order->getCoupons());
     $orderArray['items']->setTotal($total);
     $session->set('orderData', $orderArray);
 }
Пример #4
0
 protected function getOrderValues(CustomerOrder $order)
 {
     $orderArray = array('total' => $order->getTotal());
     $currID = $order->getCurrency()->getID();
     $orderArray['currencyID'] = $currID;
     $orderArray['formattedTotal'] = $order->getCurrency()->getFormattedPrice($orderArray['total']);
     $orderArray['basketCount'] = $order->getShoppingCartItemCount();
     $isOrderable = isset($GLOBALS['isOrderable']) ? $GLOBALS['isOrderable'] : $order->isOrderable();
     $GLOBALS['isOrderable'] = $isOrderable;
     $orderArray['isOrderable'] = is_bool($isOrderable) ? $isOrderable : false;
     $orderArray['isShippingRequired'] = $order->isShippingRequired();
     return $orderArray;
 }