/** * Checks if a Dejala carrier already exists */ public static function carrierExists($dejalaConfig) { global $cookie; $id_zone = 1; $moduleCountryIsoCode = strtoupper($dejalaConfig->country); $countryID = Country::getByIso($moduleCountryIsoCode); if (intval($countryID)) { $id_zone = Country::getIdZone($countryID); } $allCarriers = DejalaCarrierUtils::getCarriers(intval($cookie->id_lang), true, false, $id_zone, true); foreach ($allCarriers as $carrier) { if ($carrier['name'] == 'dejala' && $carrier['is_module'] == true) { return true; } } return false; }
/** * gets of a dejala carrier corresponding to $dejalaProduct */ public static function getDejalaCarrier($dejalaConfig, $dejalaProduct) { global $cookie; $electedCarrier = NULL; $totalCartWeight = floatval($dejalaProduct['max_weight']); if ($totalCartWeight <= 0) { $totalCartWeight = 3.99; } else { $totalCartWeight -= 0.01; } /** MFR090828 - compare to HT price (since DejalaCarrier has a tax_id) */ $vat_factor = 1 + $dejalaProduct['vat'] / 100; $priceTTC = round($dejalaProduct['price'] * $vat_factor + $dejalaProduct['margin'], 2); $priceHT = round($priceTTC / $vat_factor, 2); $productPrice = $priceHT; // MFR091130 - get id zone from the country used in the module (if the store zones were customized) // default (Europe) $id_zone = 1; $moduleCountryIsoCode = strtoupper($dejalaConfig->country); $countryID = Country::getByIso($moduleCountryIsoCode); if (intval($countryID)) { $id_zone = Country::getIdZone($countryID); } $allCarriers = DejalaCarrierUtils::getCarriers(intval($cookie->id_lang), true, false, $id_zone, true); $electedCarrier = NULL; foreach ($allCarriers as $carrier) { if ($carrier['name'] == 'dejala' && $carrier['range_behavior'] && Configuration::get('PS_SHIPPING_METHOD') && Carrier::checkDeliveryPriceByWeight($carrier['id_carrier'], $totalCartWeight, $id_zone)) { $mCarrier = new Carrier($carrier['id_carrier']); if ($productPrice == $mCarrier->getDeliveryPriceByWeight($totalCartWeight, $id_zone)) { if ($electedCarrier == NULL) { $electedCarrier = $mCarrier; } else { if ($mCarrier->id < $electedCarrier->id) { $electedCarrier = $mCarrier; } } } } } return $electedCarrier; }