Пример #1
0
 /**
  * Calculate delivery rate for given carrier and basket content
  * 
  * @param  Array  $basket              Basket content 
  * @param  int    $carrier_id          Carrier id
  * @param  int    $country_id          Delivery Country id
  * @return Array                       Delivery rate and VAT
  */
 function calculateDeliveryForCountry($basket, $carrier_id, $country_id, $promotion_detail)
 {
     //if there is a product with vat rate > 0, add vat to the shipping
     $add_vat = $this->findVATEligibility($basket);
     require_once 'models/ecommerce/ecommerce_delivery_carrier.php';
     $Delivery_Carrier = new ecommerce_delivery_carrier();
     // first check if there are restricted items in the basket
     if (!$this->checkDeliveryRestrictions($basket, $country_id)) {
         return false;
     }
     // check if the delivery is available for given order value and weight
     $price = $Delivery_Carrier->getDeliveryRate($carrier_id, $basket['sub_total']['price'], $basket['total_weight_gross']);
     // false means method is not available for given weight and amount
     if ($price === false) {
         return false;
     }
     // zero weight means free delivery
     if ($basket['total_weight_gross'] == 0) {
         return $this->getFreeDelivery();
     }
     // check free delivery promotion
     require_once 'models/ecommerce/ecommerce_promotion.php';
     $Promotion = new ecommerce_promotion();
     $Promotion->setCacheable(false);
     if ($Promotion->freeDeliveryAvailable($carrier_id, $country_id, $promotion_detail)) {
         return $this->getFreeDelivery($basket['total_weight_gross']);
     }
     return array('value_net' => sprintf("%0.2f", $price), 'weight' => $basket['total_weight_gross'], 'vat_rate' => $add_vat, 'vat' => $price * $add_vat / 100, 'value' => sprintf("%0.2f", $price * ($add_vat + 100) / 100));
 }