Skip to content

Commit

Permalink
Merge pull request #125 from magently/hotfix/63007-sale-price-for-gro…
Browse files Browse the repository at this point in the history
…uped

Fix sale price for grouped products
  • Loading branch information
carlosescri authored Sep 12, 2019
2 parents 12c785a + d93ee8e commit f1a6698
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions app/code/community/Doofinder/Feed/Model/Map/Product/Grouped.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
}
}

0 comments on commit f1a6698

Please sign in to comment.