Esempio n. 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;
 }
Esempio n. 2
0
 public function shippingMethods()
 {
     // shipping methods won't be displayed if custom fields are not filled
     $this->config->setRuntime('CHECKOUT_CUSTOM_FIELDS', 'SHIPPING_METHOD_STEP');
     $this->setAnonAddresses();
     $tempShipping = false;
     if (!$this->order->shippingAddress->get()) {
         $this->order->shippingAddress->set($this->order->billingAddress->get() ? $this->order->billingAddress->get() : SessionOrder::getEstimateAddress());
         $tempShipping = true;
     }
     $tempBilling = false;
     if (!$this->order->billingAddress->get()) {
         $this->order->billingAddress->set($this->order->shippingAddress->get());
         $tempBilling = true;
     }
     foreach ($this->order->getShipments() as $shipment) {
         $shipment->setAvailableRates(null);
         $shipment->shippingAddress->set($this->order->shippingAddress->get());
     }
     $response = $this->shipping();
     //var_dump($response->get());exit;
     $this->order->serializeShipments();
     if ($tempShipping) {
         $this->order->shippingAddress->setNull();
     }
     if ($tempBilling) {
         $this->order->billingAddress->setNull();
     }
     $this->order->save();
     $this->config->setRuntime('CHECKOUT_CUSTOM_FIELDS', self::CUSTOM_FIELDS_STEP);
     return $this->postProcessResponse($response);
 }