From a443574b6adb9fb65c1f4e06b0b420966928ee2b Mon Sep 17 00:00:00 2001 From: akkushopJK Date: Tue, 8 Feb 2022 22:09:09 +0100 Subject: [PATCH] Possible fix for https://github.com/lengow/plugin-shopware/issues/3 use pseudoPrice for discount calc and pricebeforediscount --- Components/LengowProduct.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Components/LengowProduct.php b/Components/LengowProduct.php index 2212558..125ab57 100755 --- a/Components/LengowProduct.php +++ b/Components/LengowProduct.php @@ -514,18 +514,23 @@ private function getPrices() { $detailPrice = $this->getDetailPrice(); $tax = $this->article->getTax() ? $this->article->getTax()->getTax() : 0; - // get original price before discount + // get price $priceExclTax = $detailPrice ? $detailPrice->getPrice() : 0; $priceInclTax = $priceExclTax * (100 + $tax) / 100; - // get price with discount - $discount = $detailPrice ? $detailPrice->getPercent() : 0; - $discountPriceExclTax = $priceExclTax * (1 - ($discount / 100)); - $discountPriceInclTax = $discountPriceExclTax * (100 + $tax) / 100; + // get price before discount + $beforeDiscountPriceExclTax = $priceExclTax; + $beforeDiscountPriceInclTax = $priceInclTax; + $discount = $detailPrice && $detailPrice->getPseudoPrice() > 0 && $priceExclTax > 0 && $detailPrice->getPseudoPrice() > $priceExclTax ? ((($detailPrice->getPseudoPrice()-$priceExclTax)/$detailPrice->getPseudoPrice())*100) : 0; + if ($discount > 0) { + $beforeDiscountPriceExclTax = $detailPrice ? $detailPrice->getPseudoPrice() : 0; + $beforeDiscountPriceInclTax = $beforeDiscountPriceExclTax * (100 + $tax) / 100; + } + return array( - 'price_excl_tax' => round($discountPriceExclTax, 2), - 'price_incl_tax' => round($discountPriceInclTax, 2), - 'price_before_discount_excl_tax' => round($priceExclTax, 2), - 'price_before_discount_incl_tax' => round($priceInclTax, 2), + 'price_excl_tax' => round($priceExclTax, 2), + 'price_incl_tax' => round($priceInclTax, 2), + 'price_before_discount_excl_tax' => round($beforeDiscountPriceExclTax, 2), + 'price_before_discount_incl_tax' => round($beforeDiscountPriceInclTax, 2), 'discount_percent' => $discount, ); }