raybeenas Posted April 14, 2016 Share Posted April 14, 2016 (edited) Hello! I'm sorry for my horrible english! I have a problem with combination impact price and specific price. For example here: the product is 3.150,00 €, with 30% discount become 2.205,00 €. If I choiche attribute "Pianetto di lavoro inox" with value "Sì - 170,00€", price become 3.320,00€, but with discount become 2.324,00 €. I wish the attribute price was applied to the sum granted ((3.150-30%)+170) and not to the gross ((3.150+170)-30%). Is it possible? Thanks in advance!!! Edited April 15, 2016 by raybeenas (see edit history) Link to comment Share on other sites More sharing options...
something394124 Posted April 14, 2016 Share Posted April 14, 2016 Update to version 1.6.1.5 if you have not done that yet. That fixed a problem with combined products with group reductions or something in those lanes. Regards Link to comment Share on other sites More sharing options...
raybeenas Posted April 15, 2016 Author Share Posted April 15, 2016 Thanks d3m0t3x, but this fix not resolved my problem. How can I add the price of the attribute to the product already granted? Link to comment Share on other sites More sharing options...
raybeenas Posted April 15, 2016 Author Share Posted April 15, 2016 Ok, I resolved in part: in classes/Product.php, in function "priceCalculation", I moved this code: if (is_array($result) && (!$specific_price || !$specific_price['id_product_attribute'] || $specific_price['price'] < 0)) { $attribute_price = Tools::convertPrice($result['attribute_price'] !== null ? (float)$result['attribute_price'] : 0, $id_currency); // If you want the default combination, please use NULL value instead if ($id_product_attribute !== false) { $price += $attribute_price; } } at the end of the function, before: $price = Tools::ps_round($price, $decimals); In this way, when I add product to cart, price is correct. But in product page, when attribute value change, price is wrong (it is still calculated on the base price), so I have to edit the file "product.js" to resolve the problem. If anyone has any suggestions expose them as well. Link to comment Share on other sites More sharing options...
raybeenas Posted April 15, 2016 Author Share Posted April 15, 2016 SOLVED!!! I modified Product.php and product.js and that's all!!! Product.php: in function "priceCalculation" move this code: // Attribute price if (is_array($result) && (!$specific_price || !$specific_price['id_product_attribute'] || $specific_price['price'] < 0)) { $attribute_price = Tools::convertPrice($result['attribute_price'] !== null ? (float)$result['attribute_price'] : 0, $id_currency); // If you want the default combination, please use NULL value instead if ($id_product_attribute !== false) { $price += $attribute_price; } } // Tax $address->id_country = $id_country; $address->id_state = $id_state; $address->postcode = $zipcode; $tax_manager = TaxManagerFactory::getManager($address, Product::getIdTaxRulesGroupByIdProduct((int)$id_product, $context)); $product_tax_calculator = $tax_manager->getTaxCalculator(); // Add Tax if ($use_tax) { $price = $product_tax_calculator->addTaxes($price); } before: if ($only_reduc) { return Tools::ps_round($specific_price_reduction, $decimals); } product.js: modify function "updatePrice" in this way: function updatePrice() { // Get combination prices var combID = $('#idCombination').val(); var combination = combinationsFromController[combID]; if (typeof combination == 'undefined') return; // Set product (not the combination) base price var basePriceWithoutTax = +productPriceTaxExcluded; var basePriceWithTax = +productPriceTaxIncluded; var priceWithGroupReductionWithoutTax = 0; priceWithGroupReductionWithoutTax = basePriceWithoutTax * (1 - groupReduction); // Apply combination price impact (only if there is no specific price) // 0 by default, +x if price is inscreased, -x if price is decreased var priceWithDiscountsWithoutTax = basePriceWithoutTax; var priceWithDiscountsWithTax = basePriceWithTax; if (default_eco_tax) { // combination.ecotax doesn't modify the price but only the display priceWithDiscountsWithoutTax = priceWithDiscountsWithoutTax + default_eco_tax * (1 + ecotaxTax_rate / 100); priceWithDiscountsWithTax = priceWithDiscountsWithTax + default_eco_tax * (1 + ecotaxTax_rate / 100); basePriceWithTax = basePriceWithTax + default_eco_tax * (1 + ecotaxTax_rate / 100); basePriceWithoutTax = basePriceWithoutTax + default_eco_tax * (1 + ecotaxTax_rate / 100); } // Apply specific price (discount) // We only apply percentage discount and discount amount given before tax // Specific price give after tax will be handled after taxes are added if (combination.specific_price && combination.specific_price.reduction > 0) { if (combination.specific_price.reduction_type == 'amount') { if (typeof combination.specific_price.reduction_tax !== 'undefined' && combination.specific_price.reduction_tax === "0") { var reduction = combination.specific_price.reduction; if (combination.specific_price.id_currency == 0) reduction = reduction * currencyRate * (1 - groupReduction); priceWithDiscountsWithoutTax -= reduction; priceWithDiscountsWithTax -= reduction * (taxRate/100 + 1); } } else if (combination.specific_price.reduction_type == 'percentage') { console.log(combination); priceWithDiscountsWithoutTax = priceWithDiscountsWithoutTax * (1 - +combination.specific_price.reduction); priceWithDiscountsWithTax = priceWithDiscountsWithTax * (1 - +combination.specific_price.reduction); } } priceWithDiscountsWithoutTax = priceWithDiscountsWithoutTax + +combination.price; priceWithDiscountsWithTax = priceWithDiscountsWithTax + +combination.price * (taxRate/100 + 1); // Apply Tax if necessary if (noTaxForThisProduct || customerGroupWithoutTax) { basePriceDisplay = basePriceWithoutTax; priceWithDiscountsDisplay = priceWithDiscountsWithoutTax; } else { basePriceDisplay = basePriceWithTax; priceWithDiscountsDisplay = priceWithDiscountsWithTax; } // If the specific price was given after tax, we apply it now if (combination.specific_price && combination.specific_price.reduction > 0) { if (combination.specific_price.reduction_type == 'amount') { if (typeof combination.specific_price.reduction_tax === 'undefined' || (typeof combination.specific_price.reduction_tax !== 'undefined' && combination.specific_price.reduction_tax === '1')) { var reduction = combination.specific_price.reduction; if (typeof specific_currency !== 'undefined' && specific_currency && parseInt(combination.specific_price.id_currency) && combination.specific_price.id_currency != currency.id) reduction = reduction / currencyRate; else if(!specific_currency) reduction = reduction * currencyRate; if (typeof groupReduction !== 'undefined' && groupReduction > 0) reduction *= 1 - parseFloat(groupReduction); priceWithDiscountsDisplay -= reduction; // We recalculate the price without tax in order to keep the data consistency priceWithDiscountsWithoutTax = priceWithDiscountsDisplay - reduction * ( 1/(1+taxRate/100) ); } } } console.log("prezzo scontato: "+priceWithDiscountsWithoutTax); if (priceWithDiscountsDisplay < 0) { priceWithDiscountsDisplay = 0; } // Compute discount value and percentage // Done just before display update so we have final prices if (basePriceDisplay != priceWithDiscountsDisplay) { var discountValue = basePriceDisplay - priceWithDiscountsDisplay; var discountPercentage = (1-(priceWithDiscountsDisplay/basePriceDisplay))*100; } var unit_impact = +combination.unit_impact; if (productUnitPriceRatio > 0 || unit_impact) { if (unit_impact) { baseUnitPrice = productBasePriceTaxExcl / productUnitPriceRatio; unit_price = baseUnitPrice + unit_impact; if (!noTaxForThisProduct || !customerGroupWithoutTax) unit_price = unit_price * (taxRate/100 + 1); } else unit_price = priceWithDiscountsDisplay / productUnitPriceRatio; } /* Update the page content, no price calculation happens after */ // Hide everything then show what needs to be shown $('#reduction_percent').hide(); $('#reduction_amount').hide(); $('#old_price, #old_price_display, #old_price_display_taxes').hide(); $('.price-ecotax').hide(); $('.unit-price').hide(); if (priceWithDiscountsDisplay > 0) { $('#our_price_display').text(formatCurrency(priceWithDiscountsDisplay, currencyFormat, currencySign, currencyBlank)).trigger('change'); } else { $('#our_price_display').text(formatCurrency(0, currencyFormat, currencySign, currencyBlank)).trigger('change'); } // If the calculated price (after all discounts) is different than the base price // we show the old price striked through if (priceWithDiscountsDisplay.toFixed(2) != basePriceDisplay.toFixed(2)) { $('#old_price_display span.price').text(formatCurrency(basePriceDisplay, currencyFormat, currencySign, currencyBlank)); $('#old_price, #old_price_display, #old_price_display_taxes').removeClass('hidden').show(); // Then if it's not only a group reduction we display the discount in red box if (priceWithDiscountsWithoutTax != priceWithGroupReductionWithoutTax) { if (combination.specific_price.reduction_type == 'amount') { $('#reduction_amount_display').html('-' + formatCurrency(discountValue, currencyFormat, currencySign, currencyBlank)); $('#reduction_amount').show(); } else { var toFix = 2; if ((parseFloat(discountPercentage).toFixed(2) - parseFloat(discountPercentage).toFixed(0)) == 0) toFix = 0; $('#reduction_percent_display').html('-' + parseFloat(discountPercentage).toFixed(toFix) + '%'); $('#reduction_percent').show(); } } } // Green Tax (Eco tax) // Update display of Green Tax if (default_eco_tax) { ecotax = default_eco_tax; // If the default product ecotax is overridden by the combination if (combination.ecotax) ecotax = +combination.ecotax; if (!noTaxForThisProduct) ecotax = ecotax * (1 + ecotaxTax_rate/100) $('#ecotax_price_display').text(formatCurrency(ecotax * currencyRate, currencyFormat, currencySign, currencyBlank)); $('.price-ecotax').show(); } // Unit price are the price per piece, per Kg, per m² // It doesn't modify the price, it's only for display if (productUnitPriceRatio > 0) { $('#unit_price_display').text(formatCurrency(unit_price * currencyRate, currencyFormat, currencySign, currencyBlank)); $('.unit-price').show(); } if (noTaxForThisProduct || customerGroupWithoutTax) updateDiscountTable(priceWithDiscountsWithoutTax); else updateDiscountTable(priceWithDiscountsWithTax); } Yeah!!! 1 Link to comment Share on other sites More sharing options...
gruppopegaso Posted April 16, 2016 Share Posted April 16, 2016 Tried this it doesn't work for me Link to comment Share on other sites More sharing options...
Arakiss Posted April 20, 2016 Share Posted April 20, 2016 Nope, is not working for me either Link to comment Share on other sites More sharing options...
gruppopegaso Posted May 10, 2016 Share Posted May 10, 2016 Any news? Link to comment Share on other sites More sharing options...
erouvier29 Posted June 4, 2016 Share Posted June 4, 2016 Cf https://www.prestashop.com/forums/topic/533092-product-price-in-product-detail-page-different-to-popup-cart/ Link to comment Share on other sites More sharing options...
mma87 Posted June 1, 2017 Share Posted June 1, 2017 this solution work for me. maybe your issue is due that you don't modify the right product.js have you try to edit the product.js in your theme folder? Matteo Link to comment Share on other sites More sharing options...
ballashop Posted September 18, 2017 Share Posted September 18, 2017 Hi, what about to calculate Impact on unit price? I do not understand how prestashop make the calculation. it add VAT on Impact on unit price within combination. I'm going to crazy! thanks for any reply Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now