* @copyright Magavenue * @license http://www.opensource.org/licenses/osl-3.0.php Open-source licence 3.0 * @category modules * * @note If you want to customize the module, contact us at contact@magavenue.com */ use PrestaShop\PrestaShop\Adapter\ServiceLocator; class Cart extends CartCore { /* * module: installmentpayment * date: 2019-09-17 10:56:31 * version: 1.0.24 */ public function getSummaryDetails($id_lang = null, $refresh = false) { $summary = $this->getSummaryDetailsInstallment($id_lang, $refresh); if (!Module::isEnabled('freelivery')) { return $summary; } if (!isset(Context::getContext()->cart)) { return $summary; } $ps_free_price = Tools::convertPrice(Configuration::get('PS_SHIPPING_FREE_PRICE'), Currency::getCurrencyInstance(Context::getContext()->cart->id_currency)); $total = $summary['total_products_wt']; if ((int) Configuration::get('FREELIVERY_CALCULATION_RULE')) { $total += $summary['total_discounts']; } $ps_remaining = $ps_free_price - $total; $freelivery_remaining = isset($GLOBALS['freelivery_remaining']) ? $GLOBALS['freelivery_remaining'] : false; if ($summary['total_shipping'] == 0 || ($total >= $ps_free_price && $ps_free_price > 0)) { $summary['freelivery_remaining'] = 0; } elseif ($ps_remaining < $freelivery_remaining && $ps_free_price > 0) { $summary['freelivery_remaining'] = $ps_remaining; } else { $summary['freelivery_remaining'] = (float) $freelivery_remaining; } $summary['free_ship'] = $summary['freelivery_remaining'] > 0 ? 0 : 1; // Can't set to true/false because of old 1.6 versions return $summary; } /* * module: installmentpayment * date: 2019-09-17 10:56:31 * version: 1.0.24 */ public function getPackageShippingCost($id_carrier = null, $use_tax = true, Country $default_country = null, $product_list = null, $id_zone = null) { $_GET['id_cart_freelivery'] = $this->id; return parent::getPackageShippingCost($id_carrier, $use_tax, $default_country, $product_list, $id_zone); } /* * module: installmentpayment * date: 2019-09-17 10:56:31 * version: 1.0.24 */ public static function debugBacktraceUrl($start = 0, $limit = null) { $backtrace = debug_backtrace(); array_shift($backtrace); for ($i = 0; $i < $start; ++$i) { array_shift($backtrace); } $data = array(); $i = 0; foreach ($backtrace as $id => $trace) { if ((int) $limit && ( ++$i > $limit)) { break; } $relative_file = (isset($trace['file'])) ? 'in /' . ltrim(str_replace(array(_PS_ROOT_DIR_, '\\'), array('', '/'), $trace['file']), '/') : ''; $current_line = (isset($trace['line'])) ? ':' . $trace['line'] : ''; $fileName = ((isset($trace['class'])) ? $trace['class'] : '') . ((isset($trace['type'])) ? $trace['type'] : '') . $trace['function']; $data[$relative_file] = $fileName; } return $data; } /** * This function returns the total cart amount * * Possible values for $type: * Cart::ONLY_PRODUCTS * Cart::ONLY_DISCOUNTS * Cart::BOTH * Cart::BOTH_WITHOUT_SHIPPING * Cart::ONLY_SHIPPING * Cart::ONLY_WRAPPING * Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING * Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING * * @param bool $withTaxes With or without taxes * @param int $type Total type * @param bool $use_cache Allow using cache of the method CartRule::getContextualValue * @return float Order total */ /* * module: installmentpayment * date: 2019-09-17 10:56:31 * version: 1.0.24 */ public function getOrderTotal($with_taxes = true, $type = Cart::BOTH, $products = null, $id_carrier = null, $use_cache = true, $gross = false, $small = false) { $address_factory = ServiceLocator::get('\\PrestaShop\\PrestaShop\\Adapter\\AddressFactory'); $price_calculator = ServiceLocator::get('\\PrestaShop\\PrestaShop\\Adapter\\Product\\PriceCalculator'); $configuration = ServiceLocator::get('\\PrestaShop\\PrestaShop\\Core\\ConfigurationInterface'); $ps_tax_address_type = $configuration->get('PS_TAX_ADDRESS_TYPE'); $ps_use_ecotax = $configuration->get('PS_USE_ECOTAX'); $ps_round_type = $configuration->get('PS_ROUND_TYPE'); $ps_ecotax_tax_rules_group_id = $configuration->get('PS_ECOTAX_TAX_RULES_GROUP_ID'); $pre_commande = false; $backtrace = $this->debugBacktraceUrl(); $i = 1; //$compute_precision = $configuration->get('_PS_PRICE_COMPUTE_PRECISION_'); TheCoreDev : correction de l'anomalie 0000014 soumise le 09/01/2020 $compute_precision = _PS_PRICE_COMPUTE_PRECISION_; foreach ($backtrace as $backtracekey => $backtracevalue) { if ($i == 1 && strpos($backtracekey, '/modules/') !== false && (int) Configuration::get('ACOMPTE_CHOICE') == 1 || $i == 1 && strpos($backtracekey, '/modules/') !== false && isset(Context::getContext()->cookie->installmentpayment_type) && (int) Context::getContext()->cookie->installmentpayment_type > 0) { $small = true; } $i++; } if (!$this->id) { return 0; } $type = (int) $type; $array_type = array( Cart::ONLY_PRODUCTS, Cart::ONLY_DISCOUNTS, Cart::BOTH, Cart::BOTH_WITHOUT_SHIPPING, Cart::ONLY_SHIPPING, Cart::ONLY_WRAPPING, Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING, Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING, ); $virtual_context = Context::getContext()->cloneContext(); $virtual_context->cart = $this; if (!in_array($type, $array_type)) { die(Tools::displayError()); } $with_shipping = in_array($type, array(Cart::BOTH, Cart::ONLY_SHIPPING)); if ($type == Cart::ONLY_DISCOUNTS && !CartRule::isFeatureActive()) { return 0; } $virtual = $this->isVirtualCart(); if ($virtual && $type == Cart::ONLY_SHIPPING) { return 0; } if ($virtual && $type == Cart::BOTH) { $type = Cart::BOTH_WITHOUT_SHIPPING; } if ($with_shipping || $type == Cart::ONLY_DISCOUNTS) { if (is_null($products) && is_null($id_carrier)) { $shipping_fees = $this->getTotalShippingCost(null, (bool) $with_taxes); } else { $shipping_fees = $this->getPackageShippingCost((int) $id_carrier, (bool) $with_taxes, null, $products); } } else { $shipping_fees = 0; } if ($type == Cart::ONLY_SHIPPING) { return $shipping_fees; } if ($type == Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING) { $type = Cart::ONLY_PRODUCTS; } $param_product = true; if (is_null($products)) { $param_product = false; $products = $this->getProducts(); } if ($type == Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING) { foreach ($products as $key => $product) { if ($product['is_virtual']) { unset($products[$key]); } } $type = Cart::ONLY_PRODUCTS; } $order_total = 0; if (Tax::excludeTaxeOption()) { $with_taxes = false; } $products_total = array(); $ecotax_total = 0; foreach ($products as $product) { if ($virtual_context->shop->id != $product['id_shop']) { $virtual_context->shop = new Shop((int) $product['id_shop']); } if ($ps_tax_address_type == 'id_address_invoice') { $id_address = (int) $this->id_address_invoice; } else { $id_address = (int) $product['id_address_delivery']; } // Get delivery address of the product from the cart if (!$address_factory->addressExists($id_address)) { $id_address = null; } $null = null; $price = $price_calculator->getProductPrice( (int) $product['id_product'], $with_taxes, (int) $product['id_product_attribute'], 6, null, false, true, $product['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, $id_address, $null, $ps_use_ecotax, true, $virtual_context ); $address = $address_factory->findOrCreate($id_address, true); if ($with_taxes) { $id_tax_rules_group = Product::getIdTaxRulesGroupByIdProduct((int) $product['id_product'], $virtual_context); $tax_calculator = TaxManagerFactory::getManager($address, $id_tax_rules_group)->getTaxCalculator(); } else { $id_tax_rules_group = 0; } if (in_array($ps_round_type, array(Order::ROUND_ITEM, Order::ROUND_LINE))) { if (!isset($products_total[$id_tax_rules_group])) { $products_total[$id_tax_rules_group] = 0; } } elseif (!isset($products_total[$id_tax_rules_group . '_' . $id_address])) { $products_total[$id_tax_rules_group . '_' . $id_address] = 0; } switch ($ps_round_type) { case Order::ROUND_TOTAL: $products_total[$id_tax_rules_group . '_' . $id_address] += $price * (int) $product['cart_quantity']; break; case Order::ROUND_LINE: $product_price = $price * $product['cart_quantity']; $products_total[$id_tax_rules_group] += Tools::ps_round($product_price, $compute_precision); break; case Order::ROUND_ITEM: default: $product_price = $price; $products_total[$id_tax_rules_group] += Tools::ps_round($product_price, $compute_precision) * (int) $product['cart_quantity']; break; } } foreach ($products_total as $key => $price) { $order_total += $price; } $order_total_products = $order_total; if ($type == Cart::ONLY_DISCOUNTS) { $order_total = 0; } $wrapping_fees = 0; $include_gift_wrapping = (!$configuration->get('PS_ATCP_SHIPWRAP') || $type !== Cart::ONLY_PRODUCTS); if ($this->gift && $include_gift_wrapping) { $wrapping_fees = Tools::convertPrice(Tools::ps_round($this->getGiftWrappingPrice($with_taxes), $compute_precision), Currency::getCurrencyInstance((int) $this->id_currency)); } if ($type == Cart::ONLY_WRAPPING) { return $wrapping_fees; } $order_total_discount = 0; $order_shipping_discount = 0; if (!in_array($type, array(Cart::ONLY_SHIPPING, Cart::ONLY_PRODUCTS)) && CartRule::isFeatureActive()) { if ($with_shipping || $type == Cart::ONLY_DISCOUNTS) { $cart_rules = $this->getCartRules(CartRule::FILTER_ACTION_ALL); } else { $cart_rules = $this->getCartRules(CartRule::FILTER_ACTION_REDUCTION); foreach ($this->getCartRules(CartRule::FILTER_ACTION_GIFT) as $tmp_cart_rule) { $flag = false; foreach ($cart_rules as $cart_rule) { if ($tmp_cart_rule['id_cart_rule'] == $cart_rule['id_cart_rule']) { $flag = true; } } if (!$flag) { $cart_rules[] = $tmp_cart_rule; } } } $id_address_delivery = 0; if (isset($products[0])) { $id_address_delivery = (is_null($products) ? $this->id_address_delivery : $products[0]['id_address_delivery']); } $package = array('id_carrier' => $id_carrier, 'id_address' => $id_address_delivery, 'products' => $products); $flag = false; foreach ($cart_rules as $cart_rule) { if (($with_shipping || $type == Cart::ONLY_DISCOUNTS) && $cart_rule['obj']->free_shipping && !$flag) { $order_shipping_discount = (float) Tools::ps_round($cart_rule['obj']->getContextualValue($with_taxes, $virtual_context, CartRule::FILTER_ACTION_SHIPPING, ($param_product ? $package : null), $use_cache), $compute_precision); $flag = true; } if ((int) $cart_rule['obj']->gift_product) { $in_order = false; if (is_null($products)) { $in_order = true; } else { foreach ($products as $product) { if ($cart_rule['obj']->gift_product == $product['id_product'] && $cart_rule['obj']->gift_product_attribute == $product['id_product_attribute']) { $in_order = true; } } } if ($in_order) { $order_total_discount += $cart_rule['obj']->getContextualValue($with_taxes, $virtual_context, CartRule::FILTER_ACTION_GIFT, $package, $use_cache); } } if ($cart_rule['obj']->reduction_percent > 0 || $cart_rule['obj']->reduction_amount > 0) { $order_total_discount += Tools::ps_round($cart_rule['obj']->getContextualValue($with_taxes, $virtual_context, CartRule::FILTER_ACTION_REDUCTION, $package, $use_cache), $compute_precision); } } $order_total_discount = min(Tools::ps_round($order_total_discount, 2), (float) $order_total_products) + (float) $order_shipping_discount; $order_total -= $order_total_discount; } if ($type == Cart::BOTH) { $order_total += $shipping_fees + $wrapping_fees; } if ($order_total < 0 && $type != Cart::ONLY_DISCOUNTS) { return 0; } if ($type == Cart::ONLY_DISCOUNTS) { return $order_total_discount; } $page_name = Dispatcher::getInstance()->getController(); $pages_name = array(); $controllers = Dispatcher::getControllers(_PS_FRONT_CONTROLLER_DIR_); foreach ($controllers as $key => $value) { if ($key != 'orderconfirmation' && $key != 'pagenotfound') { $pages_name[] = $key; } } $groups = Db::getInstance()->executeS('SELECT id_group FROM ' . _DB_PREFIX_ . 'customer_group WHERE id_customer = ' . (int) Context::getContext()->customer->id); $groupIdsTakenFromDb = Configuration::get('ACOMPTE_GROUP'); $selectedgroups = @unserialize($groupIdsTakenFromDb); if ($selectedgroups === false && $selectedgroups !== 'b:0;') { $selectedgroups = array(); } $group_accepted = false; foreach ($groups as $group) { if (in_array($group['id_group'], $selectedgroups)) { $group_accepted = true; break; } } $categoryIdsTakenFromDb = Configuration::get('ACOMPTE_CATS'); $selectedcategories = @unserialize($categoryIdsTakenFromDb); if ($selectedcategories === false && $selectedcategories !== 'b:0;') { $selectedcategories = array(); } if ($group_accepted && ($type == Cart::BOTH || ($virtual && $type == Cart::BOTH_WITHOUT_SHIPPING)) && ((float) Configuration::get('ACOMPTE_MIN_AMOUNT') == 0 || $order_total > (float) Configuration::get('ACOMPTE_MIN_AMOUNT')) && !empty($selectedcategories)) { if (is_array($this->_products) && !empty($this->_products)) { foreach ($this->_products as $product) { if (in_array((int) $product['id_category_default'], $selectedcategories)) { $pre_commande = true; break; } else { $sql = 'SELECT id_product FROM `' . _DB_PREFIX_ . 'category_product` WHERE `id_product` = ' . (int) $product['id_product'] . ' AND `id_category` IN ('; foreach ($selectedcategories as $category) { $sql .= (int) $category . ','; } $sql = rtrim($sql, ',') . ')'; if (Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql)) { $pre_commande = true; break; } } } } if ($pre_commande && ((isset(Context::getContext()->cookie->installmentpayment_type) && (int) Context::getContext()->cookie->installmentpayment_type > 0) || (int) Configuration::get('ACOMPTE_CHOICE') == 1 || $page_name == 'installmentpayment')) { if (((!in_array($page_name, $pages_name) || (($page_name == 'order' && Tools::getValue('step') == 3) || $page_name == 'order-opc')) && !$gross) || $small) { if ((int) Configuration::get('ACOMPTE_TOTALTYPE') != 0 || (int) Configuration::get('ACOMPTE_SHIPPING') != 0) { $order_total = 0; if ((int) Configuration::get('ACOMPTE_TOTALTYPE') == 0) { foreach ($products_total as $key => $price) { if (Configuration::get('PS_ROUND_TYPE') == Order::ROUND_TOTAL) { $tmp = explode('_', $key); $address = Address::initialize((int) $tmp[1], true); $tax_calculator = TaxManagerFactory::getManager($address, $tmp[0])->getTaxCalculator(); $order_total += Tools::ps_round($price + $tax_calculator->getTaxesTotalAmount($price), _PS_PRICE_COMPUTE_PRECISION_); } else { $order_total += $price; } } } else { foreach ($products as $product) { // products refer to the cart details if ($virtual_context->shop->id != $product['id_shop']) { $virtual_context->shop = new Shop((int) $product['id_shop']); } if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') { $id_address = (int) $this->id_address_invoice; } else { $id_address = (int) $product['id_address_delivery']; // Get delivery address of the product from the cart } if (!Address::addressExists($id_address)) { $id_address = null; } $dummy = false; $price = Product::getPriceStatic( (int) $product['id_product'], false, (int) $product['id_product_attribute'], 6, null, false, true, $product['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, $id_address, $dummy, false, true, $virtual_context ); $order_total += $price * $product['cart_quantity']; } } if ((int) Configuration::get('ACOMPTE_SHIPPING') == 0) { $order_total += $shipping_fees + $wrapping_fees; } }//else if (Module::isEnabled('installmentpayment')) { $id_defaultgroup = Db::getInstance()->executeS('SELECT id_default_group FROM ' . _DB_PREFIX_ . 'customer WHERE id_customer = ' . (int)Context::getContext()->customer->id); if (is_array($id_defaultgroup)) { $id_defaultgroup = $id_defaultgroup[0]['id_default_group']; } $sql = 'SELECT price FROM `' . _DB_PREFIX_ . 'installmentpayment_group` WHERE id_group=' . (int)$id_defaultgroup; $data = Db::getInstance()->getRow($sql); if (!empty($data) && ($data['price'] != '')) { $order_total = $order_total - ($order_total * (100 - $data['price']) / 100); } else { if ((int)Configuration::get('ACOMPTE_TYPE') == 1) { if ($order_total > (float)Configuration::get('ACOMPTE_PERCENTAGE')) { $order_total = (float)Configuration::get('ACOMPTE_PERCENTAGE'); } } else { $order_total = $order_total - ($order_total * (100 - Configuration::get('ACOMPTE_PERCENTAGE')) / 100); } } } } if ($page_name == 'installmentpayment' || (isset(Context::getContext()->cookie->installmentpayment_id_order) && !empty(Context::getContext()->cookie->installmentpayment_id_order))) { if (Tools::getValue('select') != '') { Context::getContext()->cookie->__set('installmentpayment_id_order', (int) Tools::getValue('select')); } $order = new Order((int) Context::getContext()->cookie->installmentpayment_id_order); $sql = 'SELECT * FROM `' . _DB_PREFIX_ . 'installmentpayment` WHERE id_cart=' . (int) $order->id_cart; $installment = Db::getInstance()->getRow($sql); if (isset($installment['rest']) && (float) $installment['rest'] > 0) { $rest_paid = $installment['rest']; $order_total = $rest_paid; } } } } return Tools::ps_round((float) $order_total, _PS_PRICE_COMPUTE_PRECISION_); } /* * module: installmentpayment * date: 2019-09-17 10:56:31 * version: 1.0.24 */ public function getOrderTotalGross($with_taxes = true, $type = Cart::BOTH, $products = null, $id_carrier = null, $use_cache = true, $small = false) { return $this->getOrderTotal($with_taxes, $type, $products, $id_carrier, $use_cache, true); } /* * module: installmentpayment * date: 2019-09-17 10:56:31 * version: 1.0.24 */ public function getOrderTotalSmall($with_taxes = true, $type = Cart::BOTH, $products = null, $id_carrier = null, $use_cache = true, $small = true) { return $this->getOrderTotal($with_taxes, $type, $products, $id_carrier, $use_cache, true, true); } /** * Return useful informations for cart * * @return array Cart details */ /* * module: installmentpayment * date: 2019-09-17 10:56:31 * version: 1.0.24 */ public function getSummaryDetailsInstallment($id_lang = null, $refresh = false) { $context = Context::getContext(); if (!$id_lang) { $id_lang = $context->language->id; } $delivery = new Address((int) $this->id_address_delivery); $invoice = new Address((int) $this->id_address_invoice); $formatted_addresses = array( 'delivery' => AddressFormat::getFormattedLayoutData($delivery), 'invoice' => AddressFormat::getFormattedLayoutData($invoice) ); $base_total_tax_inc = $this->getOrderTotalGross(true); $base_total_tax_exc = $this->getOrderTotalGross(false); $total_tax = $base_total_tax_inc - $base_total_tax_exc; if ($total_tax < 0) { $total_tax = 0; } $currency = new Currency($this->id_currency); $products = $this->getProducts($refresh); $gift_products = array(); $cart_rules = $this->getCartRules(); $total_shipping = $this->getTotalShippingCost(); $total_shipping_tax_exc = $this->getTotalShippingCost(null, false); $total_products_wt = $this->getOrderTotalGross(true, Cart::ONLY_PRODUCTS); $total_products = $this->getOrderTotalGross(false, Cart::ONLY_PRODUCTS); $total_discounts = $this->getOrderTotalGross(true, Cart::ONLY_DISCOUNTS); $total_discounts_tax_exc = $this->getOrderTotalGross(false, Cart::ONLY_DISCOUNTS); foreach ($cart_rules as &$cart_rule) { if ($cart_rule['free_shipping'] && (empty($cart_rule['code']) || preg_match('/^' . CartRule::BO_ORDER_CODE_PREFIX . '[0-9]+/', $cart_rule['code']))) { $cart_rule['value_real'] -= $total_shipping; $cart_rule['value_tax_exc'] -= $total_shipping_tax_exc; $cart_rule['value_real'] = Tools::ps_round($cart_rule['value_real'], (int) $context->currency->decimals * _PS_PRICE_COMPUTE_PRECISION_); $cart_rule['value_tax_exc'] = Tools::ps_round($cart_rule['value_tax_exc'], (int) $context->currency->decimals * _PS_PRICE_COMPUTE_PRECISION_); if ($total_discounts > $cart_rule['value_real']) { $total_discounts -= $total_shipping; } if ($total_discounts_tax_exc > $cart_rule['value_tax_exc']) { $total_discounts_tax_exc -= $total_shipping_tax_exc; } $total_shipping = 0; $total_shipping_tax_exc = 0; } if ($cart_rule['gift_product']) { foreach ($products as $key => &$product) { if (empty($product['gift']) && $product['id_product'] == $cart_rule['gift_product'] && $product['id_product_attribute'] == $cart_rule['gift_product_attribute']) { $total_products_wt = Tools::ps_round($total_products_wt - $product['price_wt'], (int) $context->currency->decimals * _PS_PRICE_COMPUTE_PRECISION_); $total_products = Tools::ps_round($total_products - $product['price'], (int) $context->currency->decimals * _PS_PRICE_COMPUTE_PRECISION_); $total_discounts = Tools::ps_round($total_discounts - $product['price_wt'], (int) $context->currency->decimals * _PS_PRICE_COMPUTE_PRECISION_); $total_discounts_tax_exc = Tools::ps_round($total_discounts_tax_exc - $product['price'], (int) $context->currency->decimals * _PS_PRICE_COMPUTE_PRECISION_); $cart_rule['value_real'] = Tools::ps_round($cart_rule['value_real'] - $product['price_wt'], (int) $context->currency->decimals * _PS_PRICE_COMPUTE_PRECISION_); $cart_rule['value_tax_exc'] = Tools::ps_round($cart_rule['value_tax_exc'] - $product['price'], (int) $context->currency->decimals * _PS_PRICE_COMPUTE_PRECISION_); $product['total_wt'] = Tools::ps_round($product['total_wt'] - $product['price_wt'], (int) $currency->decimals * _PS_PRICE_COMPUTE_PRECISION_); $product['total'] = Tools::ps_round($product['total'] - $product['price'], (int) $currency->decimals * _PS_PRICE_COMPUTE_PRECISION_); $product['cart_quantity'] --; if (!$product['cart_quantity']) { unset($products[$key]); } $gift_product = $product; $gift_product['cart_quantity'] = 1; $gift_product['price'] = 0; $gift_product['price_wt'] = 0; $gift_product['total_wt'] = 0; $gift_product['total'] = 0; $gift_product['gift'] = true; $gift_products[] = $gift_product; break; // One gift product per cart rule } } } } foreach ($cart_rules as $key => &$cart_rule) { if ((float) $cart_rule['value_real'] == 0 && (int) $cart_rule['free_shipping'] == 0) { unset($cart_rules[$key]); } } return array( 'delivery' => $delivery, 'delivery_state' => State::getNameById($delivery->id_state), 'invoice' => $invoice, 'invoice_state' => State::getNameById($invoice->id_state), 'formattedAddresses' => $formatted_addresses, 'products' => array_values($products), 'gift_products' => $gift_products, 'discounts' => array_values($cart_rules), 'is_virtual_cart' => (int) $this->isVirtualCart(), 'total_discounts' => $total_discounts, 'total_discounts_tax_exc' => $total_discounts_tax_exc, 'total_wrapping' => $this->getOrderTotalGross(true, Cart::ONLY_WRAPPING), 'total_wrapping_tax_exc' => $this->getOrderTotalGross(false, Cart::ONLY_WRAPPING), 'total_shipping' => $total_shipping, 'total_shipping_tax_exc' => $total_shipping_tax_exc, 'total_products_wt' => $total_products_wt, 'total_products' => $total_products, 'total_price' => $base_total_tax_inc, 'total_tax' => $total_tax, 'total_price_without_tax' => $base_total_tax_exc, 'is_multi_address_delivery' => $this->isMultiAddressDelivery() || ((int) Tools::getValue('multi-shipping') == 1), 'free_ship' => $total_shipping ? 0 : 1, 'carrier' => new Carrier($this->id_carrier, $id_lang), ); } /** * Return cart products * * @result array Products */ /* * module: installmentpayment * date: 2019-09-17 10:56:31 * version: 1.0.24 */ public function getProducts($refresh = false, $id_product = false, $id_country = null, $fullInfos = true) { if (Dispatcher::getInstance()->getController() != "pagenotfound" || strpos($_SERVER['REQUEST_URI'], '/modules/paypal') === false) { return parent::getProducts(); } if (!$this->id) { return array(); } if ($this->_products !== null && !$refresh) { if (is_int($id_product)) { foreach ($this->_products as $product) { if ($product['id_product'] == $id_product) { return array($product); } } return array(); } return $this->_products; } $sql = new DbQuery(); $sql->select('cp.`id_product_attribute`, cp.`id_product`, cp.`quantity` AS cart_quantity, cp.id_shop, pl.`name`, p.`is_virtual`, pl.`description_short`, pl.`available_now`, pl.`available_later`, product_shop.`id_category_default`, p.`id_supplier`, p.`id_manufacturer`, product_shop.`on_sale`, product_shop.`ecotax`, product_shop.`additional_shipping_cost`, product_shop.`available_for_order`, product_shop.`price`, product_shop.`active`, product_shop.`unity`, product_shop.`unit_price_ratio`, stock.`quantity` AS quantity_available, p.`width`, p.`height`, p.`depth`, stock.`out_of_stock`, p.`weight`, p.`date_add`, p.`date_upd`, IFNULL(stock.quantity, 0) as quantity, pl.`link_rewrite`, cl.`link_rewrite` AS category, CONCAT(LPAD(cp.`id_product`, 10, 0), LPAD(IFNULL(cp.`id_product_attribute`, 0), 10, 0), IFNULL(cp.`id_address_delivery`, 0)) AS unique_id, cp.id_address_delivery, product_shop.advanced_stock_management, ps.product_supplier_reference supplier_reference, IFNULL(sp.`reduction_type`, 0) AS reduction_type'); $sql->from('cart_product', 'cp'); $sql->leftJoin('product', 'p', 'p.`id_product` = cp.`id_product`'); $sql->innerJoin('product_shop', 'product_shop', '(product_shop.`id_shop` = cp.`id_shop` AND product_shop.`id_product` = p.`id_product`)'); $sql->leftJoin('product_lang', 'pl', ' p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . (int) $this->id_lang . Shop::addSqlRestrictionOnLang('pl', 'cp.id_shop')); $sql->leftJoin('category_lang', 'cl', ' product_shop.`id_category_default` = cl.`id_category` AND cl.`id_lang` = ' . (int) $this->id_lang . Shop::addSqlRestrictionOnLang('cl', 'cp.id_shop')); $sql->leftJoin('product_supplier', 'ps', 'ps.`id_product` = cp.`id_product` AND ps.`id_product_attribute` = cp.`id_product_attribute` AND ps.`id_supplier` = p.`id_supplier`'); $sql->leftJoin('specific_price', 'sp', 'sp.`id_product` = cp.`id_product`'); // AND 'sp.`id_shop` = cp.`id_shop` $sql->join(Product::sqlStock('cp', 'cp')); $sql->where('cp.`id_cart` = ' . (int) $this->id); if ($id_product) { $sql->where('cp.`id_product` = ' . (int) $id_product); } $sql->where('p.`id_product` IS NOT NULL'); $sql->groupBy('unique_id'); $sql->orderBy('cp.`date_add`, p.`id_product`, cp.`id_product_attribute` ASC'); if (Customization::isFeatureActive()) { $sql->select('cu.`id_customization`, cu.`quantity` AS customization_quantity'); $sql->leftJoin('customization', 'cu', 'p.`id_product` = cu.`id_product` AND cp.`id_product_attribute` = cu.`id_product_attribute` AND cu.`id_cart` = ' . (int) $this->id); } else { $sql->select('NULL AS customization_quantity, NULL AS id_customization'); } if (Combination::isFeatureActive()) { $sql->select(' product_attribute_shop.`price` AS price_attribute, product_attribute_shop.`ecotax` AS ecotax_attr, IF (IFNULL(pa.`reference`, \'\') = \'\', p.`reference`, pa.`reference`) AS reference, (p.`weight`+ pa.`weight`) weight_attribute, IF (IFNULL(pa.`ean13`, \'\') = \'\', p.`ean13`, pa.`ean13`) AS ean13, IF (IFNULL(pa.`upc`, \'\') = \'\', p.`upc`, pa.`upc`) AS upc, pai.`id_image` as pai_id_image, il.`legend` as pai_legend, IFNULL(product_attribute_shop.`minimal_quantity`, product_shop.`minimal_quantity`) as minimal_quantity, IF(product_attribute_shop.wholesale_price > 0, product_attribute_shop.wholesale_price, product_shop.`wholesale_price`) wholesale_price '); $sql->leftJoin('product_attribute', 'pa', 'pa.`id_product_attribute` = cp.`id_product_attribute`'); $sql->leftJoin('product_attribute_shop', 'product_attribute_shop', '(product_attribute_shop.`id_shop` = cp.`id_shop` AND product_attribute_shop.`id_product_attribute` = pa.`id_product_attribute`)'); $sql->leftJoin('product_attribute_image', 'pai', 'pai.`id_product_attribute` = pa.`id_product_attribute`'); $sql->leftJoin('image_lang', 'il', 'il.`id_image` = pai.`id_image` AND il.`id_lang` = ' . (int) $this->id_lang); } else { $sql->select( 'p.`reference` AS reference, p.`ean13`, p.`upc` AS upc, product_shop.`minimal_quantity` AS minimal_quantity, product_shop.`wholesale_price` wholesale_price' ); } $result = Db::getInstance()->executeS($sql); $products_ids = array(); $pa_ids = array(); if ($result) { foreach ($result as $row) { $products_ids[] = $row['id_product']; $pa_ids[] = $row['id_product_attribute']; } } Product::cacheProductsFeatures($products_ids); Cart::cacheSomeAttributesLists($pa_ids, $this->id_lang); $this->_products = array(); if (empty($result)) { return array(); } $cart_shop_context = Context::getContext()->cloneContext(); foreach ($result as &$row) { if (isset($row['ecotax_attr']) && $row['ecotax_attr'] > 0) { $row['ecotax'] = (float) $row['ecotax_attr']; } $row['stock_quantity'] = (int) $row['quantity']; $row['quantity'] = (int) $row['cart_quantity']; if (isset($row['id_product_attribute']) && (int) $row['id_product_attribute'] && isset($row['weight_attribute'])) { $row['weight'] = (float) $row['weight_attribute']; } if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') { $address_id = (int) $this->id_address_invoice; } else { $address_id = (int) $row['id_address_delivery']; } if (!Address::addressExists($address_id)) { $address_id = null; } if ($cart_shop_context->shop->id != $row['id_shop']) { $cart_shop_context->shop = new Shop((int) $row['id_shop']); } $address = Address::initialize($address_id, true); $id_tax_rules_group = Product::getIdTaxRulesGroupByIdProduct((int) $row['id_product'], $cart_shop_context); $tax_calculator = TaxManagerFactory::getManager($address, $id_tax_rules_group)->getTaxCalculator(); if (!Tools::getIsset('specific_price_output')) { $specific_price_output = array(); } $row['price'] = Product::getPriceStatic( (int) $row['id_product'], false, isset($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null, 6, null, false, true, $row['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, $address_id, $specific_price_output, false, true, $cart_shop_context ); switch (Configuration::get('PS_ROUND_TYPE')) { case Order::ROUND_TOTAL: $row['total'] = $row['price'] * (int) $row['cart_quantity']; $row['total_wt'] = $tax_calculator->addTaxes($row['price']) * (int) $row['cart_quantity']; break; case Order::ROUND_LINE: $row['total'] = Tools::ps_round($row['price'] * (int) $row['cart_quantity'], _PS_PRICE_COMPUTE_PRECISION_); $row['total_wt'] = Tools::ps_round($tax_calculator->addTaxes($row['price']) * (int) $row['cart_quantity'], _PS_PRICE_COMPUTE_PRECISION_); break; case Order::ROUND_ITEM: default: $row['total'] = Tools::ps_round($row['price'], _PS_PRICE_COMPUTE_PRECISION_) * (int) $row['cart_quantity']; $row['total_wt'] = Tools::ps_round($tax_calculator->addTaxes($row['price']), _PS_PRICE_COMPUTE_PRECISION_) * (int) $row['cart_quantity']; break; } $row['price_wt'] = $tax_calculator->addTaxes($row['price']); $row['description_short'] = Tools::nl2br($row['description_short']); if (!isset($row['pai_id_image']) || $row['pai_id_image'] == 0) { $cache_id = 'Cart::getProducts_' . '-pai_id_image-' . (int) $row['id_product'] . '-' . (int) $this->id_lang . '-' . (int) $row['id_shop']; if (!Cache::isStored($cache_id)) { $row2 = Db::getInstance()->getRow(' SELECT image_shop.`id_image` id_image, il.`legend` FROM `' . _DB_PREFIX_ . 'image` i JOIN `' . _DB_PREFIX_ . 'image_shop` image_shop ON (i.id_image = image_shop.id_image AND image_shop.cover=1 AND image_shop.id_shop=' . (int) $row['id_shop'] . ') LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $this->id_lang . ') WHERE i.`id_product` = ' . (int) $row['id_product'] . ' AND image_shop.`cover` = 1'); Cache::store($cache_id, $row2); } $row2 = Cache::retrieve($cache_id); if (!$row2) { $row2 = array('id_image' => false, 'legend' => false); } else { $row = array_merge($row, $row2); } } else { $row['id_image'] = $row['pai_id_image']; $row['legend'] = $row['pai_legend']; } $row['reduction_applies'] = ($specific_price_output && (float) $specific_price_output['reduction']); $row['quantity_discount_applies'] = ($specific_price_output && $row['cart_quantity'] >= (int) $specific_price_output['from_quantity']); $row['id_image'] = Product::defineProductImage($row, $this->id_lang); $row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']); $row['features'] = Product::getFeaturesStatic((int) $row['id_product']); if (array_key_exists($row['id_product_attribute'] . '-' . $this->id_lang, self::$_attributesLists)) { $row = array_merge($row, self::$_attributesLists[$row['id_product_attribute'] . '-' . $this->id_lang]); } $row = Product::getTaxesInformations($row, $cart_shop_context); $this->_products[] = $row; } $categoryIdsTakenFromDb = Configuration::get('ACOMPTE_CATS'); $selectedcategories = @unserialize($categoryIdsTakenFromDb); if ($selectedcategories === false && $selectedcategories !== 'b:0;') { $selectedcategories = array(); } $pre_commande = false; if (is_array($this->_products) && !empty($this->_products)) { //&& count($this->_products)>0 foreach ($this->_products as $product) { if (in_array((int) $product['id_category_default'], $selectedcategories)) { $pre_commande = true; break; } else { $sql = 'SELECT id_product FROM `' . _DB_PREFIX_ . 'category_product` WHERE `id_product` = ' . (int) $product['id_product'] . ' AND `id_category` IN ('; foreach ($selectedcategories as $category) { $sql .= (int) $category . ','; } $sql = rtrim($sql, ',') . ')'; if (Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql)) { $pre_commande = true; break; } } } } if (!$pre_commande) { return parent::getProducts(); } $order_total = $this->getOrderTotal(true); $price_wt = $this->getOrderTotal(true); $this->_products = array(); $row['cart_quantity'] = 1; $row['price_wt'] = $price_wt; $row['name'] = 'Acompte'; $row['attributes'] = ''; $row['id_product1'] = ''; $id_defaultgroup = Db::getInstance()->executeS('SELECT id_default_group FROM ' . _DB_PREFIX_ . 'customer WHERE id_customer = ' . (int) Context::getContext()->customer->id); if(is_array($id_defaultgroup)) { $id_defaultgroup = $id_defaultgroup[0]['id_default_group']; } $sql = 'SELECT price FROM `' . _DB_PREFIX_ . 'installmentpayment_group` WHERE id_group=' . (int) $id_defaultgroup; $data = Db::getInstance()->getRow($sql); if(!empty($data)){ $row['description_short'] = "Pourcentage " . $data['price'] . '%'; } else { if ((int) Configuration::get('ACOMPTE_TYPE') == 1) { if ($order_total > (float) Configuration::get('ACOMPTE_PERCENTAGE')) { $row['description_short'] = "Acompte " . Configuration::get('ACOMPTE_PERCENTAGE'); } } else { $row['description_short'] = "Pourcentage " . Configuration::get('ACOMPTE_PERCENTAGE') . '%'; } } $this->_products[] = $row; return $this->_products; } /** * Return shipping total for the cart * * @param array $delivery_option Array of the delivery option for each address * @param booleal $use_tax * @param Country $default_country * @return float Shipping total */ /* * module: installmentpayment * date: 2019-09-17 10:56:31 * version: 1.0.24 */ public function getTotalShippingCost($delivery_option = null, $use_tax = true, Country $default_country = null) { if (Dispatcher::getInstance()->getController() != "pagenotfound") { return parent::getTotalShippingCost($delivery_option, $use_tax, $default_country); } return 0; } }