public function getDeliveryTimeAvailable($deliveryShippinCity) { $deliverySettings = Configuration::get(self::CONST_PREFIX . 'DELIVERY_TIME') === false ? array_values(BalticodeDpdData::fliparrayList(unserialize(self::$defaultValues['DELIVERY_TIME']))) : array_values(unserialize(Configuration::get(self::CONST_PREFIX . 'DELIVERY_TIME'))); if ($deliverySettings === false) { //Not set any times return self::$delivery_time; } $line = BalticodeDpdData::recursiveArraySearch(trim(Tools::strtolower($deliveryShippinCity)), $this->arrayChangeValueCase($deliverySettings)); if ($line !== false) { self::$delivery_time = array_intersect_key(self::$delivery_time, array_flip($deliverySettings[$line]['time'])); } else { self::$delivery_time = array(); } return $this; }
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 }