public static function getOrderShippingCost($cartObject)
 {
     $cartData = BalticodeDpdData::getCartProductsWeight($cartObject);
     $totalCartWeight = array_sum($cartData['weight']);
     //Order is to heavy
     if ($totalCartWeight > self::$maxWeight) {
         return false;
     }
     $cartProductDimensions = BalticodeDpdData::getCartProductsDimensions($cartObject);
     $cartHeight = max($cartProductDimensions['height']);
     $cartWidth = max($cartProductDimensions['width']);
     $cartDepth = max($cartProductDimensions['depth']);
     $cartScope = ($cartHeight + $cartWidth) * 2 + $cartDepth;
     //Order is to Big
     if (max($cartHeight, $cartWidth, $cartDepth) > self::$maxLength || $cartScope > self::$maxScope) {
         return false;
     }
     if (Configuration::get(DynamicParcelDistribution::CONST_PREFIX . 'PICKUP_FREE_SHIPPING')) {
         //Enabled free shipping?
         if (BalticodeDpdData::getOrderPriceToral($cartObject) >= (double) Configuration::get(DynamicParcelDistribution::CONST_PREFIX . 'PICKUP_FREE_FROM')) {
             return (double) 0.0;
         }
     }
     return Configuration::get(DynamicParcelDistribution::CONST_PREFIX . 'PICKUP_PRICE');
 }
 /**
  * Grab Shipping default price
  *
  * @param  cart (object)
  * @param  string - Id carrier
  * @return float | boolean; float - price, false - cannot ship
  */
 public function getDefaultShippingCost(cart $cartObject, $id_carrier)
 {
     $carrier_type = DpdCarrierOptions::getCarrierType($id_carrier);
     // carrier | pickup
     if (!is_string($carrier_type)) {
         $this->log('getDefaultShippingCost -> carrier type is not correct, available (string) given: ' . gettype($carrier_type) . '; carrier id: ' . $id_carrier);
         return false;
     }
     $carrier_type = Tools::strtoupper($carrier_type);
     // CARRIER | PICKUP
     if ((int) Configuration::get(self::CONST_PREFIX . $carrier_type . '_SHOW_SIZE_RESTR')) {
         //Enabled Delivery restrictions?
         //Grab all restrictions
         $address = new Address($cartObject->id_address_delivery);
         $restrictions = Configuration::get(self::CONST_PREFIX . $carrier_type . '_PACKAGE_SIZE');
         if ($restrictions) {
             $carrier_package_size = array_values(unserialize(Configuration::get(self::CONST_PREFIX . $carrier_type . '_PACKAGE_SIZE')));
         } else {
             $carrier_package_size = array();
         }
         $productsShippingPrices = array();
         if (Configuration::get(self::CONST_PREFIX . $carrier_type . '_PRICE_PRIORITY')) {
             $cartData = BalticodeDpdData::getCartProductsWeight($cartObject);
             //Current restriction is for this country? if not, unset current option
             foreach ($carrier_package_size as $key => $carrier_package_size_option) {
                 if (BalticodeDpdData::recursiveArraySearch($address->id_country, $carrier_package_size_option) === false) {
                     unset($carrier_package_size[$key]);
                 }
             }
             $current_carrier_package_size = $carrier_package_size;
             foreach ($current_carrier_package_size as $line => $carrier_package_size_option) {
                 if ($carrier_package_size_option['weight'] >= array_sum($cartData['weight'])) {
                     unset($current_carrier_package_size[$line]);
                 }
             }
             if (count($current_carrier_package_size)) {
                 //if one or more
                 $carrier_package_size_max = array();
                 foreach ($current_carrier_package_size as $key => $carrier_package_size_option) {
                     $carrier_package_size_max[$key] = $carrier_package_size_option['weight'];
                 }
                 $id = array_keys($carrier_package_size_max, max($carrier_package_size_max));
                 $restriction = $current_carrier_package_size[$id[0]];
                 if ($restriction['free_from_price'] >= 0) {
                     //free shipping is enabled
                     if ($this->getOrderPriceToral($cartObject) >= $restriction['free_from_price']) {
                         return (double) 0.0;
                         //Return free shipping
                     }
                 }
                 if ($restriction['overweight_price'] != '-1') {
                     return $restriction['base_price'] + $restriction['overweight_price'];
                 }
                 //Return price of small weight plus overweight price
             }
             //If we not return price yet so we need to search again for biger weight
             $carrier_package_weight = $carrier_package_size;
             foreach ($carrier_package_weight as $key => $restriction) {
                 if ($restriction['weight'] <= array_sum($cartData['weight'])) {
                     unset($carrier_package_weight[$key]);
                 }
             }
             if (count($carrier_package_weight)) {
                 //Do we find some restrict
                 $carrier_package_size_min = array();
                 foreach ($carrier_package_weight as $key => $carrier_package_size_option) {
                     $carrier_package_size_min[$key] = $carrier_package_size_option['weight'];
                 }
                 $id = array_keys($carrier_package_size_min, min($carrier_package_size_min));
                 $restriction = $carrier_package_weight[$id[0]];
                 if ($restriction['free_from_price'] >= 0) {
                     //free shipping is enabled
                     if ($this->getOrderPriceToral($cartObject) >= $restriction['free_from_price']) {
                         return (double) 0.0;
                         //Return free shipping
                     }
                 }
                 return $restriction['base_price'];
             }
             //If nothing return before so we need return false and set this method not available
             return false;
         } else {
             //leave only for this country
             foreach ($carrier_package_size as $key => $carrier_package_size_option) {
                 $carrier_package_size[$key]['base_price'] = (double) $carrier_package_size_option['base_price'];
                 //String to float
                 $carrier_package_size[$key]['free_from_price'] = (double) $carrier_package_size_option['free_from_price'];
                 //String to float
                 $dimension = explode('X', Tools::strtoupper($carrier_package_size_option['dimensions']));
                 array_filter($dimension);
                 if (count($dimension) !== 3) {
                     //If wrong parsing skip this line
                     continue;
                 }
                 $carrier_package_size[$key]['dimensions'] = array('height' => trim($dimension[0]), 'width' => trim($dimension[1]), 'depth' => trim($dimension[2]), 'diagonal' => $this->getDiagonal($dimension[0], $dimension[1], $dimension[2]));
                 //Current restriction is for this country? if not, unset current option
                 if (BalticodeDpdData::recursiveArraySearch($address->id_country, $carrier_package_size_option) === false) {
                     unset($carrier_package_size[$key]);
                 }
             }
             if (!count($carrier_package_size)) {
                 //Do we not have any settings for this country?
                 return $this->getBaseShippingCost($cartObject, $carrier_type);
                 //Use Base settings
             }
             foreach (BalticodeDpdData::fliparrayList($this->getCartProductsDimensions($cartObject)) as $key => $product) {
                 $current_carrier_package_size = $carrier_package_size;
                 foreach ($current_carrier_package_size as $line => $carrier_package_size_option) {
                     if ($product['height'] < $carrier_package_size_option['dimensions']['height'] || $product['width'] < $carrier_package_size_option['dimensions']['width'] || $product['depth'] < $carrier_package_size_option['dimensions']['depth']) {
                         unset($current_carrier_package_size[$line]);
                     }
                 }
                 if (count($current_carrier_package_size)) {
                     //if one or more
                     $carrier_package_size_max = array();
                     foreach ($current_carrier_package_size as $key => $carrier_package_size_option) {
                         $carrier_package_size_max[$key] = $carrier_package_size_option['dimensions']['diagonal'];
                     }
                     $id = array_keys($carrier_package_size_max, max($carrier_package_size_max));
                     $restriction = $current_carrier_package_size[$id[0]];
                 } else {
                     //if no found so use first (current product can be 0 dimensions or is very small)
                     $carrier_package_size_min = array();
                     foreach ($carrier_package_size as $key => $carrier_package_size_option) {
                         $carrier_package_size_min[$key] = $carrier_package_size_option['dimensions']['diagonal'];
                     }
                     $id = array_keys($carrier_package_size_min, min($carrier_package_size_min));
                     $restriction = $carrier_package_size[$id[0]];
                 }
                 //Now we have ONE restrict for this product so apply this
                 $productShippingPrice = $this->getRescrictionPrice($product, $restriction, $this->getOrderPriceToral($cartObject));
                 if ($productShippingPrice === false) {
                     //If this product cant be ship disable carrier
                     return false;
                 } else {
                     $productsShippingPrices[] = $productShippingPrice;
                 }
             }
             $productsShippingPrices = BalticodeDpdData::fliparrayList($productsShippingPrices);
             $regularPrice = max($productsShippingPrices['regular']);
             $additionalPrice = array_sum($productsShippingPrices['additional']);
             $finalPrice = $regularPrice + $additionalPrice;
             return $finalPrice;
         }
     } else {
         return $this->getBaseShippingCost($cartObject, $carrier_type);
         //Use Base settings
     }
     return false;
 }
 public static function getRestrictionCost(cart $cartObject)
 {
     $address = new Address($cartObject->id_address_delivery);
     $restrictions = self::getRestrictions($address->id_country);
     $cartData = BalticodeDpdData::getCartProductsWeight($cartObject);
     $totalCartWeight = array_sum($cartData['weight']);
     $cartProductsDimensions = BalticodeDpdData::getCartProductsDimensions($cartObject);
     //leave only for this country
     foreach ($restrictions as $key => $carrier_package_size_option) {
         $restrictions[$key]['base_price'] = (double) $carrier_package_size_option['base_price'];
         //String to float
         $restrictions[$key]['free_from_price'] = (double) $carrier_package_size_option['free_from_price'];
         //String to float
         $dimension = explode('X', Tools::strtoupper($carrier_package_size_option['dimensions']));
         array_filter($dimension);
         if (count($dimension) !== 3) {
             //If wrong parsing skip this line
             continue;
         }
         $restrictions[$key]['height'] = trim($dimension[0]);
         $restrictions[$key]['width'] = trim($dimension[1]);
         $restrictions[$key]['depth'] = trim($dimension[2]);
         //Current restriction is for this country? if not, unset current option
         if (BalticodeDpdData::recursiveArraySearch($address->id_country, $carrier_package_size_option) === false) {
             unset($restrictions[$key]);
         }
     }
     $correctRestriction = array();
     foreach ($restrictions as $currentRestriction) {
         if ((double) $currentRestriction['weight'] < (double) $totalCartWeight) {
             //This currentRestriction is smaller that we have, so we test it allowed to overweight.
             if ($currentRestriction['overweight_price'] > -1) {
                 //Overweight is allowed?
                 if ((double) $currentRestriction['height'] < (double) max($cartProductsDimensions['height']) || (double) $currentRestriction['width'] < (double) max($cartProductsDimensions['width']) || (double) $currentRestriction['depth'] < (double) max($cartProductsDimensions['depth'])) {
                     //if this restriction is to smaller that we want)
                     if ((double) $currentRestriction['oversized_price'] > -1) {
                         //Oversize is allowed
                         $correctRestriction = $currentRestriction;
                     } else {
                         return false;
                         //oversize is not available
                     }
                 } else {
                     $correctRestriction = $currentRestriction;
                 }
             }
             continue;
             //Stop foreach we do not need smaller restrictions
         } else {
             if ((double) $currentRestriction['height'] < (double) max($cartProductsDimensions['height']) || (double) $currentRestriction['width'] < (double) max($cartProductsDimensions['width']) || (double) $currentRestriction['depth'] < (double) max($cartProductsDimensions['depth'])) {
                 //if this restriction is to big that we want
                 if ((double) $currentRestriction['oversized_price'] > -1) {
                     //Oversize is allowed?
                     $correctRestriction = $currentRestriction;
                 } else {
                     return false;
                     //oversize is not available
                 }
             } else {
                 if ((double) $currentRestriction['height'] >= (double) max($cartProductsDimensions['height']) || (double) $currentRestriction['width'] >= (double) max($cartProductsDimensions['width']) || (double) $currentRestriction['depth'] >= (double) max($cartProductsDimensions['depth'])) {
                     //if this restriction is to big that we want
                     $correctRestriction = $currentRestriction;
                 }
             }
         }
     }
     //We no not found any restriction by this cart so this method is not available... return false
     if (!count($correctRestriction)) {
         return false;
     }
     //Now we have one restriction, from where need get price
     if ($correctRestriction['free_from_price'] >= 0) {
         //If free shipping is allowed
         if (BalticodeDpdData::getOrderPriceToral($cartObject) >= $correctRestriction['free_from_price']) {
             return (double) 0.0;
             //Return free shipping
         }
     }
     $currentPrice = (double) $correctRestriction['base_price'];
     //Apply base price
     //Do we have overweight?
     if ((double) $currentRestriction['weight'] < (double) $totalCartWeight) {
         if ($currentRestriction['overweight_price'] > 0) {
             //Test again we accept overweight?
             $currentPrice += (double) $currentRestriction['overweight_price'];
             //Plus overweight price
         }
     }
     //Do we have oversize?
     if ((double) $currentRestriction['height'] < (double) max($cartProductsDimensions['height']) || (double) $currentRestriction['width'] < (double) max($cartProductsDimensions['width']) || (double) $currentRestriction['depth'] < (double) max($cartProductsDimensions['depth'])) {
         //if this restriction is to smaller that we want
         if ($currentRestriction['oversized_price'] > 0) {
             //Test again we accept oversize?
             $currentPrice += (double) $currentRestriction['oversized_price'];
             //Plus oversize price
         }
     }
     return $currentPrice;
     //Return final price
 }