From d93ee8e5edd0b81d8ea05e7c2829c11d9e3cfa07 Mon Sep 17 00:00:00 2001 From: Roman Ludwicki Date: Tue, 10 Sep 2019 13:41:52 +0200 Subject: [PATCH] Fix sale price for grouped products refs #63007 Change-Id: Idf27e7b50a3206cf6c9bbc182bdb5e1b2c4748b0 --- .../Feed/Model/Map/Product/Grouped.php | 48 +++++++++++++++---- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/app/code/community/Doofinder/Feed/Model/Map/Product/Grouped.php b/app/code/community/Doofinder/Feed/Model/Map/Product/Grouped.php index 5edc5671..4f10efdf 100644 --- a/app/code/community/Doofinder/Feed/Model/Map/Product/Grouped.php +++ b/app/code/community/Doofinder/Feed/Model/Map/Product/Grouped.php @@ -21,14 +21,17 @@ class Doofinder_Feed_Model_Map_Product_Grouped /** * Grouped products doesn't have special price. * + * @param string $field + * * @return float */ public function getProductPrice($field) { - $price = $this->getMinPrice($this->getProduct()); + $price = $this->getMinPrice($this->getProduct(), $field); - if ($price <= 0) + if ($price <= 0) { $this->skip = true; + } return $price; } @@ -38,23 +41,52 @@ public function calcGroupPrice($product) $price = 0.0; $associates = $product->getTypeInstance()->getAssociatedProducts(); - foreach ($associates as $associatedProduct) + foreach ($associates as $associatedProduct) { $price += $associatedProduct->getPrice(); + } return $price; // Total price } - public function getMinPrice($product) + /** + * @param Mage_Catalog_Model_Product $product + * @param string $field + * + * @return float|mixed|null + */ + public function getMinPrice($product, $field = 'price') { $price = null; foreach ($product->getTypeInstance()->getAssociatedProducts() as $ap) { - if ($price === null) - $price = $ap->getPrice(); - else - $price = min($price, $ap->getPrice()); + if ($price === null) { + $price = $this->getPriceByField($ap, $field); + } else { + $price = min($price, $this->getPriceByField($ap, $field)); + } } return $price === null ? 0.0 : $price; } + + /** + * Get product price according to field + * + * @param Mage_Catalog_Model_Product $product + * @param string $field + * + * @return float|null + */ + private function getPriceByField($product, $field) + { + switch ($field) { + case 'price': + return $product->getPrice(); + + case 'sale_price': + default: + $salePrice = $product->getPriceModel()->getFinalPrice(null, $product); + return $product->getPrice() <= $salePrice ? null : $salePrice; + } + } }