if (!empty($variant)) {
$variant = $this->roundInternal($this->_currencyDisplay->convertCurrencyTo((int) $this->productCurrency, doubleval($variant),true));
$basePriceShopCurrency = $basePriceShopCurrency + $variant;
$this->productPrices['basePrice'] = $this->productPrices['basePriceVariant'] = $basePriceShopCurrency;
} Delete it completely.if (empty($this->productPrices['basePriceVariant'])) {
$this->productPrices['basePriceVariant'] = $this->productPrices['basePrice'];
}
/* ============================================================
FIX: Correct handling of variant/modifier prices in VirtueMart
------------------------------------------------------------
VM incorrectly adds variant price to the base product price
BEFORE applying discount rules. This causes the variant to be
discounted, which is mathematically wrong.
Here we calculate the variant separately and add it *after*
discounts and tax calculations – which is the correct logic.
============================================================ */
// 1. Convert variant price to shop currency but DO NOT add it to base price
$variantNet = 0.0;
if (!empty($variant)) {
// Variant net amount converted to shop currency
$variantNet = $this->roundInternal(
$this->_currencyDisplay->convertCurrencyTo(
(int)$this->productCurrency,
(double)$variant,
true
)
);
}
// 2. After VM finished discount calculations, add the variant
if (!empty($variantNet)) {
// Calculate VAT on variant separately
$variantGross = $variantNet;
// Apply VAT/TAX rules to variant
if (!empty($this->rules['Tax'])) {
$variantGross = $this->roundInternal(
$this->executeCalculation($this->rules['Tax'], $variantGross, true),
'salesPrice'
);
}
if (!empty($this->rules['VatTax'])) {
$variantGross = $this->roundInternal(
$this->executeCalculation($this->rules['VatTax'], $variantGross, true),
'salesPrice'
);
}
// Update priceWithoutTax (variantNet)
if (isset($this->productPrices['priceWithoutTax'])) {
$this->productPrices['priceWithoutTax'] += $variantNet;
}
// Update VAT amount (difference between gross and net)
if (isset($this->productPrices['taxAmount'])) {
$this->productPrices['taxAmount'] += ($variantGross - $variantNet);
}
// Add variant to final salesPrice (correct placement)
if (isset($this->productPrices['salesPrice'])) {
$this->productPrices['salesPrice'] += $variantGross;
}
// Add variant to unit price if packaging is used
if (!empty($product->product_packaging) && $product->product_packaging != '0.0000') {
$this->productPrices['unitPrice'] = $this->productPrices['salesPrice'] / $product->product_packaging;
}
// Save modifier for output
$this->productPrices['variantModification'] = $variantNet;
}
/* ========================= END OF FIX ============================ */
Page created in 0.062 seconds with 9 queries.