/** * This function returns the total cart amount * * Possible values for $type: * JeproshopCartModelCart::ONLY_PRODUCTS * JeproshopCartModelCart::ONLY_DISCOUNTS * JeproshopCartModelCart::BOTH * JeproshopCartModelCart::BOTH_WITHOUT_SHIPPING * JeproshopCartModelCart::ONLY_SHIPPING * JeproshopCartModelCart::ONLY_WRAPPING * JeproshopCartModelCart::ONLY_PRODUCTS_WITHOUT_SHIPPING * JeproshopCartModelCart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING * * @param boolean $withTaxes With or without taxes * @param integer $type Total type * @param null $products * @param null $carrier_id * @param boolean $use_cache Allow using cache of the method CartRule::getContextualValue * @return float Order total */ public function getOrderTotal($withTaxes = true, $type = JeproshopCartModelCart::BOTH, $products = null, $carrier_id = null, $use_cache = true) { if (!$this->cart_id) { return 0; } $type = (int) $type; $array_type = array(JeproshopCartModelCart::ONLY_PRODUCTS, JeproshopCartModelCart::ONLY_DISCOUNTS, JeproshopCartModelCart::BOTH, JeproshopCartModelCart::BOTH_WITHOUT_SHIPPING, JeproshopCartModelCart::ONLY_SHIPPING, JeproshopCartModelCart::ONLY_WRAPPING, JeproshopCartModelCart::ONLY_PRODUCTS_WITHOUT_SHIPPING, JeproshopCartModelCart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING); // Define virtual context to prevent case where the cart is not the in the global context $virtual_context = JeproshopContext::getContext()->cloneContext(); $virtual_context->cart = $this; if (!in_array($type, $array_type)) { die(Tools::displayError()); } $with_shipping = in_array($type, array(JeproshopCartModelCart::BOTH, JeproshopCartModelCart::ONLY_SHIPPING)); // if cart rules are not used if ($type == JeproshopCartModelCart::ONLY_DISCOUNTS && !JeproshopCartRuleModelCartRule::isFeaturePublished()) { return 0; } // no shipping cost if is a cart with only virtual products $virtual = $this->isVirtualCart(); if ($virtual && $type == JeproshopCartModelCart::ONLY_SHIPPING) { return 0; } if ($virtual && $type == JeproshopCartModelCart::BOTH) { $type = JeproshopCartModelCart::BOTH_WITHOUT_SHIPPING; } if ($with_shipping || $type == JeproshopCartModelCart::ONLY_DISCOUNTS) { if (is_null($products) && is_null($carrier_id)) { $shipping_fees = $this->getTotalShippingCost(null, (bool) $withTaxes); } else { $shipping_fees = $this->getPackageShippingCost($carrier_id, (bool) $withTaxes, null, $products); } } else { $shipping_fees = 0; } if ($type == JeproshopCartModelCart::ONLY_SHIPPING) { return $shipping_fees; } if ($type == JeproshopCartModelCart::ONLY_PRODUCTS_WITHOUT_SHIPPING) { $type = JeproshopCartModelCart::ONLY_PRODUCTS; } $param_product = true; if (is_null($products)) { $param_product = false; $products = $this->getProducts(); } if ($type == JeproshopCartModelCart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING) { foreach ($products as $key => $product) { if ($product->is_virtual) { unset($products[$key]); } } $type = JeproshopCartModelCart::ONLY_PRODUCTS; } $order_total = 0; if (JeproshopTaxModelTax::taxExcludedOption()) { $with_taxes = false; } foreach ($products as $product) { // products refer to the cart details if ($virtual_context->shop->shop_id != $product->shop_id) { $virtual_context->shop = new JeproshopShopModelShop((int) $product->shop_id); } if (JeproshopSettingModelSetting::getValue('PS_TAX_ADDRESS_TYPE') == 'address_invoice_id') { $address_id = (int) $this->address_invoice_id; } else { $address_id = (int) $product->address_delivery_id; } // Get delivery address of the product from the cart if (!JeproshopAddressModelAddress::addressExists($address_id)) { $address_id = null; } $null = null; if ($this->_taxCalculationMethod == COM_JEPROSHOP_TAX_EXCLUDED) { // Here taxes are computed only once the quantity has been applied to the product price $price = JeproshopProductModelProduct::getStaticPrice((int) $product->product_id, false, (int) $product->product_attribute_id, 2, null, false, true, $product->cart_quantity, false, (int) $this->customer_id ? (int) $this->customer_id : null, (int) $this->cart_id, $address_id, $null, true, true, $virtual_context); $total_ecotax = $product->ecotax * (int) $product->cart_quantity; $total_price = $price * (int) $product->cart_quantity; if ($withTaxes) { $product_tax_rate = (double) JeproshopTaxModelTax::getProductTaxRate((int) $product->product_id, (int) $address_id, $virtual_context); $product_eco_tax_rate = JeproshopTaxModelTax::getProductEcotaxRate((int) $address_id); $total_price = ($total_price - $total_ecotax) * (1 + $product_tax_rate / 100); $total_ecotax = $total_ecotax * (1 + $product_eco_tax_rate / 100); $total_price = JeproshopTools::roundPrice($total_price + $total_ecotax, 2); } } else { if ($withTaxes) { $price = JeproshopProductModelProduct::getStaticPrice((int) $product->product_id, true, (int) $product->product_attribute_id, 2, null, false, true, $product->cart_quantity, false, (int) $this->customer_id ? (int) $this->customer_id : null, (int) $this->cart_id, (int) $address_id ? (int) $address_id : null, $null, true, true, $virtual_context); } else { $price = JeproshopProductModelProduct::getStaticPrice((int) $product->product_id, false, (int) $product->product_attribute_id, 2, null, false, true, $product->cart_quantity, false, (int) $this->customer_id ? (int) $this->customer_id : null, (int) $this->cart_id, (int) $address_id ? (int) $address_id : null, $null, true, true, $virtual_context); } $total_price = JeproshopTools::roundPrice($price * (int) $product->cart_quantity, 2); } $order_total += $total_price; } $order_total_products = $order_total; if ($type == JeproshopCartModelCart::ONLY_DISCOUNTS) { $order_total = 0; } // Wrapping Fees $wrapping_fees = 0; if ($this->gift) { $wrapping_fees = JeproshopTools::convertPrice(JeproshopTools::roundPrice($this->getGiftWrappingPrice($withTaxes), 2), JeproshopCurrencyModelCurrency::getCurrencyInstance((int) $this->currency_id)); } if ($type == JeproshopCartModelCart::ONLY_WRAPPING) { return $wrapping_fees; } $order_total_discount = 0; if (!in_array($type, array(JeproshopCartModelCart::ONLY_SHIPPING, JeproshopCartModelCart::ONLY_PRODUCTS)) && JeproshopCartRuleModelCartRule::isFeaturePublished()) { // First, retrieve the cart rules associated to this "getOrderTotal" if ($with_shipping || $type == JeproshopCartModelCart::ONLY_DISCOUNTS) { $cart_rules = $this->getCartRules(JeproshopCartRuleModelCartRule::FILTER_ACTION_ALL); } else { $cart_rules = $this->getCartRules(CartRule::FILTER_ACTION_REDUCTION); // Cart Rules array are merged manually in order to avoid doubles foreach ($this->getCartRules(JeproshopCartRuleModelCartRule::FILTER_ACTION_GIFT) as $tmp_cart_rule) { $flag = false; foreach ($cart_rules as $cart_rule) { if ($tmp_cart_rule->cart_rule_id == $cart_rule->cart_rule_id) { $flag = true; } } if (!$flag) { $cart_rules[] = $tmp_cart_rule; } } } $id_address_delivery = 0; if (isset($products[0])) { $id_address_delivery = is_null($products) ? $this->address_delivery_id : $products[0]->address_delivery_id; } $package = array('id_carrier' => $carrier_id, 'id_address' => $id_address_delivery, 'products' => $products); // Then, calculate the contextual value for each one foreach ($cart_rules as $cart_rule) { // If the cart rule offers free shipping, add the shipping cost if (($with_shipping || $type == Cart::ONLY_DISCOUNTS) && $cart_rule['obj']->free_shipping) { $order_total_discount += Tools::ps_round($cart_rule['obj']->getContextualValue($with_taxes, $virtual_context, CartRule::FILTER_ACTION_SHIPPING, $param_product ? $package : null, $use_cache), 2); } // If the cart rule is a free gift, then add the free gift value only if the gift is in this package 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 the cart rule offers a reduction, the amount is prorated (with the products in the package) 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), 2); } } $order_total_discount = min(JeproshopTools::roundPrice($order_total_discount, 2), $wrapping_fees + $order_total_products + $shipping_fees); $order_total -= $order_total_discount; } if ($type == JeproshopCartModelCart::BOTH) { $order_total += $shipping_fees + $wrapping_fees; } if ($order_total < 0 && $type != JeproshopCartModelCart::ONLY_DISCOUNTS) { return 0; } if ($type == JeproshopCartModelCart::ONLY_DISCOUNTS) { return $order_total_discount; } return JeproshopTools::roundPrice((double) $order_total, 2); }
public static function getProductProperties($lang_id, $row, JeproshopContext $context = null) { if (!$row->product_id) { return false; } if ($context == null) { $context = JeproshopContext::getContext(); } // Product::getDefaultAttribute is only called if id_product_attribute is missing from the SQL query at the origin of it: // consider adding it in order to avoid unnecessary queries $row->allow_out_of_stock_ordering = JeproshopProductModelProduct::isAvailableWhenOutOfStock($row->out_of_stock); if (JeproshopCombinationModelCombination::isFeaturePublished() && (!isset($row->product_attribute_id) || !$row->product_attribute_id) && (isset($row->cache_default_attribute) && ($default_product_attribute_id = $row->cache_default_attribute) !== null || ($default_product_attribute_id = JeproshopProductModelProduct::getDefaultAttribute($row->product_id, !$row->allow_out_of_stock_ordering)))) { $row->product_attribute_id = $default_product_attribute_id; } if (!JeproshopCombinationModelCombination::isFeaturePublished() || !isset($row->product_attribute_id)) { $row->product_attribute_id = 0; } // Tax $useTax = JeproshopTaxModelTax::taxExcludedOption(); $cache_key = $row->product_id . '_' . $row->product_attribute_id . '_' . $lang_id . '_' . (int) $useTax; if (isset($row->product_pack_id)) { $cache_key .= '_pack_' . $row->product_pack_id; } if (isset(self::$_productPropertiesCache[$cache_key])) { return JeproshopTools::updateObjectData($row, self::$_productPropertiesCache[$cache_key]); } // Datas $row->category = JeproshopCategoryModelCategory::getLinkRewrite((int) $row->default_category_id, (int) $lang_id); $row->link = $context->controller->getProductLink((int) $row->product_id, $row->link_rewrite, $row->category, $row->ean13); $row->attribute_price = 0; if (isset($row->product_attribute_id) && $row->product_attribute_id) { $row->attribute_price = (double) JeproshopProductModelProduct::getProductAttributePrice($row->product_attribute_id); } $row->price_tax_exc = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, false, isset($row->product_attribute_id) && !empty($row->product_attribute_id) ? (int) $row->product_attribute_id : null, self::$_taxCalculationMethod == COM_JEPROSHOP_TAX_EXCLUDED ? 2 : 6); if (self::$_taxCalculationMethod == COM_JEPROSHOP_TAX_EXCLUDED) { $row->price_tax_exc = JeproshopTools::roundPrice($row->price_tax_exc, 2); $row->price = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, true, isset($row->product_attribute_id) && !empty($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 6); $row->price_without_reduction = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, false, isset($row->product_attribute_id) && !empty($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 2, null, false, false); } else { $row->price = JeproshopTools::roundPrice(JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, true, isset($row->product_attribute_id) && !empty($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 2), 2); $row->price_without_reduction = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, true, isset($row->product_attribute_id) && !empty($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 6, null, false, false); } $specific_prices = null; $row->reduction = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, (bool) $useTax, (int) $row->product_attribute_id, 6, null, true, true, 1, true, null, null, null, $specific_prices); $row->specific_prices = $specific_prices; $row->quantity = JeproshopProductModelProduct::getQuantity((int) $row->product_id, 0, isset($row->cache_is_pack) ? $row->cache_is_pack : null); $row->quantity_all_versions = $row->quantity; if ($row->product_attribute_id) { $row->quantity = JeproshopProductModelProduct::getQuantity((int) $row->product_id, $row->product_attribute_id, isset($row->cache_is_pack) ? $row->cache_is_pack : null); } $row->image_id = JeproshopProductModelProduct::defineProductImage($row, $lang_id); $row->features = JeproshopProductModelProduct::getFrontStaticFeatures((int) $lang_id, $row->product_id); $row->attachments = array(); if (!isset($row->cache_has_attachments) || $row->cache_has_attachments) { $row->attachments = JeproshopProductModelProduct::getStaticAttachments((int) $lang_id, $row->product_id); } $row->virtual = !isset($row->is_virtual) || $row->is_virtual ? 1 : 0; // Pack management $row->pack = !isset($row->cache_is_pack) ? JeproshopProductPack::isPack($row->product_id) : (int) $row->cache_is_pack; $row->packItems = $row->pack ? JeproshopProductPack::getItemTable($row->product_id, $lang_id) : array(); $row->no_pack_price = $row->pack ? JeproshopProductPack::noPackPrice($row->product_id) : 0; if ($row->pack && !JeproshopProductPack::isInStock($row->product_id)) { $row->quantity = 0; } $row->customization_required = false; if (isset($row->customizable) && $row->customizable && JeproshopCustomization::isFeaturePublished()) { if (count(JeproshopProductModelProduct::getStaticRequiredCustomizableFields((int) $row->product_id))) { $row->customization_required = true; } } $row = JeproshopProductModelProduct::getTaxesInformations($row, $context); self::$_productPropertiesCache[$cache_key] = $row; return self::$_productPropertiesCache[$cache_key]; }
private function initPriceForm() { if ($this->context == null) { $this->context = JeproshopContext::getContext(); } if ($this->product->product_id) { $shops = JeproshopShopModelShop::getShops(); $countries = JeproshopCountryModelCountry::getStaticCountries($this->context->language->lang_id); $groups = JeproshopGroupModelGroup::getStaticGroups($this->context->language->lang_id); $currencies = JeproshopCurrencyModelCurrency::getStaticCurrencies(); $attributes = $this->product->getAttributesGroups((int) $this->context->language->lang_id); $combinations = array(); if (count($attributes)) { foreach ($attributes as $attribute) { $combinations[$attribute->product_attribute_id] = new JObject(); $combinations[$attribute->product_attribute_id]->product_attribute_id = $attribute->product_attribute_id; if (!isset($combinations[$attribute->product_attribute_id]->attributes)) { $combinations[$attribute->product_attribute_id]->attributes = ''; } if (isset($combinations[$attribute->product_attribute_id])) { $combinations[$attribute->product_attribute_id]->attributes .= $attribute->attribute_name . ' - '; $combinations[$attribute->product_attribute_id]->price = JeproshopTools::displayPrice(JeproshopTools::convertPrice(JeproshopProductModelProduct::getStaticPrice((int) $this->product->product_id, false, $attribute->product_attribute_id), $this->context->currency), $this->context->currency); } } foreach ($combinations as $combination) { if (isset($combination->attributes)) { $combination->attributes = rtrim($combination->attributes, ' - '); } } } $specificPriceModificationForm = $this->displaySpecificPriceModificationForm($this->context->currency, $shops, $currencies, $countries, $groups); $this->assignRef('specific_price_modification_form', $specificPriceModificationForm); $this->assignRef('ecotax_tax_excluded', $this->product->ecotax); //$this->applyTaxToEcotax(); $this->assignRef('shops', $shops); /*$admin_one_shop = count($this->context->employee->getAssociatedShops()) == 1; $this->assignRef('admin_one_shop', $admin_one_shop); */ $this->assignRef('currencies', $currencies); $this->assignRef('currency', $this->context->currency); $this->assignRef('countries', $countries); $this->assignRef('groups', $groups); $this->assignRef('combinations', $combinations); $multiShop = JeproshopShopModelShop::isFeaturePublished(); $this->assignRef('multi_shop', $multiShop); } else { JError::raiseWarnig(JText::_('COM_JEPROSHOP_YOU_MUST_SAVE_THIS_PRODUCT_BEFORE_ADDING_SPECIFIC_PRICING_MESSAGE')); $this->product->tax_rules_group_id = JeproshopProductModelProduct::getTaxRulesMostUsedGroupId(); $this->assignRef('ecotax_tax_excluded', 0); } $use_tax = JeproshopSettingModelSetting::getValue('use_tax'); $this->assignRef('use_tax', $use_tax); $use_ecotax = JeproshopSettingModelSetting::getValue('use_eco_tax'); $this->assignRef('use_ecotax', $use_ecotax); $tax_rules_groups = JeproshopTaxRulesGroupModelTaxRulesGroup::getTaxRulesGroups(true); $this->assignRef('tax_rules_groups', $tax_rules_groups); $taxesRatesByGroup = JeproshopTaxRulesGroupModelTaxRulesGroup::getAssociatedTaxRatesByCountryId($this->context->country->country_id); $this->assignRef('taxesRatesByGroup', $taxesRatesByGroup); $ecotaxTaxRate = JeproshopTaxModelTax::getProductEcotaxRate(); $this->assignRef('ecotaxTaxRate', $ecotaxTaxRate); $tax_exclude_tax_option = JeproshopTaxModelTax::taxExcludedOption(); $this->assignRef('tax_exclude_tax_option', $tax_exclude_tax_option); $this->product->price = JeproshopTools::convertPrice($this->product->price, $this->context->currency, true, $this->context); if ($this->product->unit_price_ratio != 0) { $unit_price = JeproshopTools::roundPrice($this->product->price / $this->product->unit_price_ratio, 2); } else { $unit_price = 0; } $this->assignRef('unit_price', $unit_price); }
/** * Assign price and tax to the template */ protected function assignPriceAndTax() { $customer_id = isset($this->context->customer) ? (int) $this->context->customer->customer_id : 0; $group_id = (int) JeproshopGroupModelGroup::getCurrent()->group_id; $country_id = (int) $customer_id ? JeproshopCustomerModelCustomer::getCurrentCountry($customer_id) : JeproshopSettingModelSetting::getValue('default_country'); $group_reduction = JeproshopGroupReductionModelGroupReduction::getValueForProduct($this->product->product_id, $group_id); if ($group_reduction === false) { $group_reduction = JeproshopGroupModelGroup::getReduction((int) $this->context->cookie->customer_id) / 100; } // Tax $tax = (double) $this->product->getTaxesRate(new JeproshopAddressModelAddress((int) $this->context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')})); $this->assignRef('tax_rate', $tax); $product_price_with_tax = JeproshopProductModelProduct::getStaticPrice($this->product->product_id, true, null, 6); if (JeproshopProductModelProduct::$_taxCalculationMethod == COM_JEPROSHOP_TAX_INCLUDED) { $product_price_with_tax = JeproshopTools::roundPrice($product_price_with_tax, 2); } $product_price_without_eco_tax = (double) $product_price_with_tax - $this->product->ecotax; $ecotax_rate = (double) JeproshopTaxModelTax::getProductEcotaxRate($this->context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}); $ecotax_tax_amount = JeproshopTools::roundPrice($this->product->ecotax, 2); if (JeproshopProductModelProduct::$_taxCalculationMethod == COM_JEPROSHOP_TAX_INCLUDED && (int) JeproshopSettingModelSetting::getValue('use_tax')) { $ecotax_tax_amount = JeproshopTools::roundPrice($ecotax_tax_amount * (1 + $ecotax_rate / 100), 2); } $currency_id = (int) $this->context->cookie->currency_id; $product_id = (int) $this->product->product_id; $shop_id = $this->context->shop->shop_id; $quantity_discounts = JeproshopSpecificPriceModelSpecificPrice::getQuantityDiscounts($product_id, $shop_id, $currency_id, $country_id, $group_id, null, true, (int) $this->context->customer->customer_id); foreach ($quantity_discounts as &$quantity_discount) { if ($quantity_discount->product_attribute_id) { $combination = new JeproshopCombinationModelCombination((int) $quantity_discount->product_attribute_id); $attributes = $combination->getAttributesName((int) $this->context->language->lang_id); foreach ($attributes as $attribute) { $quantity_discount->attributes = $attribute->name . ' - '; } $quantity_discount->attributes = rtrim($quantity_discount->attributes, ' - '); } if ((int) $quantity_discount->currency_id == 0 && $quantity_discount->reduction_type == 'amount') { $quantity_discount->reduction = JeproshopTools::convertPriceFull($quantity_discount->reduction, null, JeproshopContext::getContext()->currency); } } $product_price = $this->product->getPrice(JeproshopProductModelProduct::$_taxCalculationMethod == COM_JEPROSHOP_TAX_INCLUDED, false); $address = new JeproshopAddressModelAddress($this->context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}); $quantity_discounts = $this->formatQuantityDiscounts($quantity_discounts, $product_price, (double) $tax, $ecotax_tax_amount); $this->assignRef('quantity_discounts', $quantity_discounts); $this->assignRef('ecotax_tax_included', $ecotax_tax_amount); $ecotax_tax_excluded = JeproshopTools::roundPrice($this->product->ecotax, 2); $this->assignRef('ecotax_tax_excluded', $ecotax_tax_excluded); $this->assignRef('ecotaxTax_rate', $ecotax_rate); $display_price = JeproshopSettingModelSetting::getValue('display_price'); $this->assignRef('display_price', $display_price); $product_price_without_eco_tax = (double) $product_price_without_eco_tax; $this->assignRef('product_price_without_ecotax', $product_price_without_eco_tax); $this->assignRef('group_reduction', $group_reduction); $no_tax = JeproshopTaxModelTax::taxExcludedOption() || !$this->product->getTaxesRate($address); $this->assignRef('no_tax', $no_tax); $ecotax = !count($this->errors) && $this->product->ecotax > 0 ? JeproshopTools::convertPrice((double) $this->product->ecotax) : 0; $this->assignRef('ecotax', $ecotax); $tax_enabled = JeproshopSettingModelSetting::getValue('use_tax'); $this->assignRef('tax_enabled', $tax_enabled); $customer_group_without_tax = JeproshopGroupModelGroup::getPriceDisplayMethod($this->context->customer->default_group_id); $this->assignRef('customer_group_without_tax', $customer_group_without_tax); }
/** * Get product price * * @param integer $product_id Product id * @param boolean $use_tax With taxes or not (optional) * @param integer $product_attribute_id Product attribute id (optional). * If set to false, do not apply the combination price impact. NULL does apply the default combination price impact. * @param integer $decimals Number of decimals (optional) * @param boolean $only_reduction Returns only the reduction amount * @param boolean $use_reduction Set if the returned amount will include reduction * @param integer $quantity Required for quantity discount application (default value: 1) * @param integer $customer_id Customer ID (for customer group reduction) * @param integer $cart_id Cart ID. Required when the cookie is not accessible (e.g., inside a payment module, a cron task...) * @param integer $address_id Customer address ID. Required for price (tax included) calculation regarding the guest localization * @param null $specific_price_output * @param boolean $with_ecotax insert ecotax in price output. * @param bool $use_group_reduction * @param JeproshopContext $context * @param bool $use_customer_price * @internal param int $divisor Useful when paying many time without fees (optional) * @internal param \variable_reference $specificPriceOutput . * If a specific price applies regarding the previous parameters, this variable is filled with the corresponding SpecificPrice object * @return float Product price */ public static function getStaticPrice($product_id, $use_tax = true, $product_attribute_id = null, $decimals = 6, $only_reduction = false, $use_reduction = true, $quantity = 1, $customer_id = null, $cart_id = null, $address_id = null, $specific_price_output = null, $with_ecotax = true, $use_group_reduction = true, JeproshopContext $context = null, $use_customer_price = true) { if (!$context) { $context = JeproshopContext::getContext(); } $cur_cart = $context->cart; if (!JeproshopTools::isBool($use_tax) || !JeproshopTools::isUnsignedInt($product_id)) { //die(Tools::displayError()); } // Initializations $group_id = (int) JeproshopGroupModelGroup::getCurrent()->group_id; // If there is cart in context or if the specified id_cart is different from the context cart id if (!is_object($cur_cart) || JeproshopTools::isUnsignedInt($cart_id) && $cart_id && $cur_cart->cart_id != $cart_id) { /* * When a user (e.g., guest, customer, Google...) is on Jeproshop, he has already its cart as the global (see /init.php) * When a non-user calls directly this method (e.g., payment module...) is on JeproShop, he does not have already it BUT knows the cart ID * When called from the back office, cart ID can be in-existent */ if (!$cart_id && !isset($context->employee)) { JError::raiseError(500, __FILE__ . ' ' . __LINE__); } $cur_cart = new JeproshopCartModelCart($cart_id); // Store cart in context to avoid multiple instantiations in BO if (!JeproshopTools::isLoadedObject($context->cart, 'cart_id')) { $context->cart = $cur_cart; } } $db = JFactory::getDBO(); $cart_quantity = 0; if ((int) $cart_id) { $cache_id = 'jeproshop_product_model_get_price_static_' . (int) $product_id . '_' . (int) $cart_id; $cart_qty = JeproshopCache::retrieve($cache_id); if (!JeproshopCache::isStored($cache_id) || $cart_qty != (int) $quantity) { $query = "SELECT SUM(" . $db->quoteName('quantity') . ") FROM " . $db->quoteName('#__jeproshop_cart_product'); $query .= " WHERE " . $db->quoteName('product_id') . " = " . (int) $product_id . " AND " . $db->quoteName('cart_id'); $query .= " = " . (int) $cart_id; $db->setQuery($query); $cart_quantity = (int) $db->loadResult(); JeproshopCache::store($cache_id, $cart_quantity); } $cart_quantity = JeproshopCache::retrieve($cache_id); } $currency_id = (int) JeproshopTools::isLoadedObject($context->currency, 'currency_id') ? $context->currency->currency_id : JeproshopSettingModelSetting::getValue('default_currency'); // retrieve address information $country_id = (int) $context->country->country_id; $state_id = 0; $zipcode = 0; if (!$address_id && JeproshopTools::isLoadedObject($cur_cart, 'cart_id')) { $address_id = $cur_cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}; } if ($address_id) { $address_info = JeproshopAddressModelAddress::getCountryAndState($address_id); if ($address_info->country_id) { $country_id = (int) $address_info->country_id; $state_id = (int) $address_info->state_id; $zipcode = $address_info->postcode; } } else { if (isset($context->customer->geolocation_country_id)) { $country_id = (int) $context->customer->geolocation_country_id; $state_id = (int) $context->customer->state_id; $zipcode = (int) $context->customer->postcode; } } if (JeproshopTaxModelTax::taxExcludedOption()) { $use_tax = false; } if ($use_tax != false && !empty($address_info->vat_number) && $address_info->country_id != JeproshopSettingModelSetting::getValue('vat_number_country') && JeproshopSettingModelSetting::getValue('vat_number_management')) { $use_tax = false; } if (is_null($customer_id) && JeproshopTools::isLoadedObject($context->customer, 'customer_id')) { $customer_id = $context->customer->customer_id; } return JeproshopProductModelProduct::priceCalculation($context->shop->shop_id, $product_id, $product_attribute_id, $country_id, $state_id, $zipcode, $currency_id, $group_id, $quantity, $use_tax, $decimals, $only_reduction, $use_reduction, $with_ecotax, $specific_price_output, $use_group_reduction, $customer_id, $use_customer_price, $cart_id, $cart_quantity); }