/** * Return useful informations for cart * * @param null $lang_id * @param bool $refresh * @return array Cart details */ public function getSummaryDetails($lang_id = null, $refresh = false) { $context = JeproshopContext::getContext(); $app = JFactory::getApplication(); if (!$lang_id) { $lang_id = $context->language->lang_id; } $delivery = new JeproshopAddressModelAddress((int) $this->address_delivery_id); $invoice = new JeproshopAddressModelAddress((int) $this->address_invoice_id); // New layout system with personalization fields $formatted_addresses = array('delivery' => JeproshopAddressFormatModelAddressFormat::getFormattedLayoutData($delivery), 'invoice' => JeproshopAddressFormatModelAddressFormat::getFormattedLayoutData($invoice)); $base_total_tax_inc = $this->getOrderTotal(true); $base_total_tax_exc = $this->getOrderTotal(false); $total_tax = $base_total_tax_inc - $base_total_tax_exc; if ($total_tax < 0) { $total_tax = 0; } $currency = new JeproshopCurrencyModelCurrency($this->currency_id); $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->getOrderTotal(true, JeproshopCartModelCart::ONLY_PRODUCTS); $total_products = $this->getOrderTotal(false, JeproshopCartModelCart::ONLY_PRODUCTS); $total_discounts = $this->getOrderTotal(true, JeproshopCartModelCart::ONLY_DISCOUNTS); $total_discounts_tax_exc = $this->getOrderTotal(false, JeproshopCartModelCart::ONLY_DISCOUNTS); // The cart content is altered for display foreach ($cart_rules as &$cart_rule) { // If the cart rule is automatic (without any code) and include free shipping, it should not be displayed as a cart rule but only set the shipping cost to 0 if ($cart_rule->free_shipping && (empty($cart_rule->code) || preg_match('/^' . JeproshopCartRuleModelCartRule::JEPROSHOP_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 = JeproshopValidator::roundPrice($cart_rule->value_real, (int) $context->currency->decimals * COM_JEPROSHOP_PRICE_DISPLAY_PRECISION); $cart_rule->value_tax_exc = JeproshopValidator::roundPrice($cart_rule->value_tax_exc, (int) $context->currency->decimals * COM_JEPROSHOP_PRICE_DISPLAY_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; } // Update total shipping $total_shipping = 0; $total_shipping_tax_exc = 0; } if ($cart_rule->gift_product) { foreach ($products as $key => &$product) { if (empty($product->gift) && $product->product_id == $cart_rule->gift_product && $product->product_attribute_id == $cart_rule->gift_product_attribute) { // Update total products $total_products_wt = JeproshopValidator::roundPrice($total_products_wt - $product->price_wt, (int) $context->currency->decimals * COM_JEPROSHOP_PRICE_DISPLAY_PRECISION); $total_products = JeproshopValidator::roundPrice($total_products - $product->price, (int) $context->currency->decimals * COM_JEPROSHOP_PRICE_DISPLAY_PRECISION); // Update total discounts $total_discounts = JeproshopValidator::roundPrice($total_discounts - $product->price_wt, (int) $context->currency->decimals * COM_JEPROSHOP_PRICE_DISPLAY_PRECISION); $total_discounts_tax_exc = JeproshopValidator::roundPrice($total_discounts_tax_exc - $product->price, (int) $context->currency->decimals * COM_JEPROSHOP_PRICE_DISPLAY_PRECISION); // Update cart rule value $cart_rule->value_real = JeproshopValidator::roundPrice($cart_rule->value_real - $product->price_wt, (int) $context->currency->decimals * COM_JEPROSHOP_PRICE_DISPLAY_PRECISION); $cart_rule->value_tax_exc = JeproshopValidator::roundPrice($cart_rule->value_tax_exc - $product->price, (int) $context->currency->decimals * COM_JEPROSHOP_PRICE_DISPLAY_PRECISION); // Update product quantity $product->total_wt = JeproshopValidator::roundPrice($product->total_wt - $product->price_wt, (int) $currency->decimals * COM_JEPROSHOP_PRICE_DISPLAY_PRECISION); $product->total = JeproshopValidator::roundPrice($product->total - $product->price, (int) $currency->decimals * COM_JEPROSHOP_PRICE_DISPLAY_PRECISION); $product->cart_quantity--; if (!$product->cart_quantity) { unset($products[$key]); } // Add a new product line $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 ($cart_rule->value_real == 0) { unset($cart_rules[$key]); } } $summary = new JObject(); $summary->set('delivery', $delivery); $summary->set('delivery_state', JeproshopStateModelState::getNameById($delivery->state_id)); $summary->set('invoice', $invoice); $summary->set('invoice_state', JeproshopStateModelState::getNameById($invoice->state_id)); $summary->set('formattedAddresses', $formatted_addresses); $summary->set('products', array_values($products)); $summary->set('gift_products', $gift_products); $summary->set('discounts', array_values($cart_rules)); $summary->set('is_virtual_cart', (int) $this->isVirtualCart()); $summary->set('total_discounts', $total_discounts); $summary->set('total_discounts_tax_exc', $total_discounts_tax_exc); $summary->set('total_wrapping', $this->getOrderTotal(true, JeproshopCartModelCart::ONLY_WRAPPING)); $summary->set('total_wrapping_tax_exc', $this->getOrderTotal(false, JeproshopCartModelCart::ONLY_WRAPPING)); $summary->set('total_shipping', $total_shipping); $summary->set('total_shipping_tax_exc', $total_shipping_tax_exc); $summary->set('total_products_wt', $total_products_wt); $summary->set('total_products', $total_products); $summary->set('total_price', $base_total_tax_inc); $summary->set('total_tax', $total_tax); $summary->set('total_price_without_tax', $base_total_tax_exc); $summary->set('is_multi_address_delivery', $this->isMultiAddressDelivery() || (int) $app->input->get('multi-shipping') == 1); $summary->set('free_ship', $total_shipping ? 0 : 1); $summary->set('carrier', new JeproshopCarrierModelCarrier($this->carrier_id, $lang_id)); return $summary; }
/** * Marked as deprecated but should not throw any "deprecated" message * This function is used in order to keep front office backward compatibility 14 -> 1.5 * (Order History) * * @deprecated */ public function setProductPrices(&$row) { $tax_calculator = JeproshopOrderDetailModelOrderDetail::getStaticTaxCalculator((int) $row->order_detail_id); $row->tax_calculator = $tax_calculator; $row->tax_rate = $tax_calculator->getTotalRate(); $row->product_price = JeproshopValidator::roundPrice($row->unit_price_tax_excl, 2); $row->product_price_with_tax = JeproshopValidator::roundPrice($row->unit_price_tax_incl, 2); $group_reduction = 1; if ($row->group_reduction > 0) { $group_reduction = 1 - $row->group_reduction / 100; } $row->product_price_with_tax_but_ecotax = $row->product_price_with_tax - $row->ecotax; $row->total_with_tax = $row->total_price_tax_incl; $row->total_price = $row->total_price_tax_excl; }