* @copyright 2016-2017 GFI Informatique, 2016-2017 TNT * @license https://opensource.org/licenses/MIT MIT License */ require_once _PS_MODULE_DIR_.'tntofficiel/tntofficiel.php'; require_once _PS_MODULE_DIR_.'tntofficiel/libraries/TNTOfficiel_Debug.php'; class TNTOfficiel_Cart { /** * Is shipping free for cart, through configuration. * * @param $objArgCart * @return bool */ public static function isCartShippingFree($objArgCart) { TNTOfficiel_Debug::log(array('msg' => '>>', 'file' => __FILE__, 'line' => __LINE__)); $arrConfigShipping = Configuration::getMultiple(array( 'PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_FREE_WEIGHT' )); // Load current TNT carrier object. $objCarrierTNT = TNTOfficiel_Carrier::loadGlobalCarrier(); // If TNT carrier object not available. if ($objCarrierTNT === null) { return true; } // If TNT carrier is inactive or free. if (!$objCarrierTNT->active || $objCarrierTNT->getShippingMethod() == Carrier::SHIPPING_METHOD_FREE) { return true; } // Get cart amount to reach for free shipping. $fltFreeFeesPrice = 0; if (isset($arrConfigShipping['PS_SHIPPING_FREE_PRICE'])) { $fltFreeFeesPrice = (float)Tools::convertPrice( (float)$arrConfigShipping['PS_SHIPPING_FREE_PRICE'], Currency::getCurrencyInstance((int)$objArgCart->id_currency) ); } // Free shipping if cart amount, inc. taxes, inc. product & discount, exc. shipping > PS_SHIPPING_FREE_PRICE if ($fltFreeFeesPrice > 0 && $objArgCart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, null, null, false) >= $fltFreeFeesPrice ) { return true; } // Free shipping if cart weight > PS_SHIPPING_FREE_WEIGHT if (isset($arrConfigShipping['PS_SHIPPING_FREE_WEIGHT']) && $objArgCart->getTotalWeight() >= (float)$arrConfigShipping['PS_SHIPPING_FREE_WEIGHT'] && (float)$arrConfigShipping['PS_SHIPPING_FREE_WEIGHT'] > 0 ) { return true; } return false; } /** * Get additional shipping cost for cart (exc. taxes). * * @param $objArgCart * @return float */ public static function getCartExtraShippingCost($objArgCart) { TNTOfficiel_Debug::log(array('msg' => '>>', 'file' => __FILE__, 'line' => __LINE__)); $fltShippingCost = 0; $arrProducts = $objArgCart->getProducts(); // If no product, no shipping extra cost. if (!count($arrProducts)) { return 0; } // If only virtual products in cart, no extra shipping cost. if ($objArgCart->isVirtualCart()) { return 0; } // If TNT carrier is free. $boolIsCartShippingFree = TNTOfficiel_Cart::isCartShippingFree($objArgCart); if ($boolIsCartShippingFree) { return 0; } // Load current TNT carrier object. $objCarrierTNT = TNTOfficiel_Carrier::loadGlobalCarrier(); // If TNT carrier object not available, no extra shipping cost. if ($objCarrierTNT === null) { return 0; } // Adding handling charges. $shipping_handling = Configuration::get('PS_SHIPPING_HANDLING'); if (isset($shipping_handling) && $objCarrierTNT->shipping_handling) { $fltShippingCost += (float)$shipping_handling; } // Adding additional shipping cost per product. foreach ($arrProducts as $product) { if (!$product['is_virtual']) { $fltShippingCost += $product['additional_shipping_cost'] * $product['cart_quantity']; } } $fltShippingCost = (float)Tools::convertPrice($fltShippingCost, Currency::getCurrencyInstance((int)$objArgCart->id_currency)); return $fltShippingCost; } }