Skip to content

Commit 9b9bc72

Browse files
authored
Merge pull request #1417 from algolia/update/MAGE-760
MAGE-760 Fixed Tier price issue
2 parents d3fbc0c + 8742cc0 commit 9b9bc72

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

Helper/Entity/Product/PriceManager/ProductWithoutChildren.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Framework\Pricing\PriceCurrencyInterface;
1515
use Magento\Tax\Helper\Data as TaxHelper;
1616
use Magento\Tax\Model\Config as TaxConfig;
17+
use Magento\Catalog\Api\ScopedProductTierPriceManagementInterface;
1718

1819
abstract class ProductWithoutChildren
1920
{
@@ -46,6 +47,11 @@ abstract class ProductWithoutChildren
4647
*/
4748
protected $productloader;
4849

50+
/**
51+
* @var ScopedProductTierPriceManagementInterface
52+
*/
53+
private $productTierPrice;
54+
4955
protected $store;
5056
protected $baseCurrencyCode;
5157
protected $groups;
@@ -60,6 +66,7 @@ abstract class ProductWithoutChildren
6066
* @param TaxHelper $taxHelper
6167
* @param Rule $rule
6268
* @param ProductFactory $productloader
69+
* @param ScopedProductTierPriceManagementInterface $productTierPrice
6370
*/
6471
public function __construct(
6572
ConfigHelper $configHelper,
@@ -68,7 +75,8 @@ public function __construct(
6875
CatalogHelper $catalogHelper,
6976
TaxHelper $taxHelper,
7077
Rule $rule,
71-
ProductFactory $productloader
78+
ProductFactory $productloader,
79+
ScopedProductTierPriceManagementInterface $productTierPrice
7280
) {
7381
$this->configHelper = $configHelper;
7482
$this->customerGroupCollectionFactory = $customerGroupCollectionFactory;
@@ -77,6 +85,7 @@ public function __construct(
7785
$this->taxHelper = $taxHelper;
7886
$this->rule = $rule;
7987
$this->productloader = $productloader;
88+
$this->productTierPrice = $productTierPrice;
8089
}
8190

8291
/**
@@ -244,7 +253,7 @@ protected function getTierPrice(Product $product, $currencyCode, $withTax)
244253
$tierPrice = [];
245254
$tierPrices = [];
246255

247-
if (!is_null($product->getTierPrices())) {
256+
if (!empty($product->getTierPrices())) {
248257
$product->setData('website_id', $product->getStore()->getWebsiteId());
249258
$productTierPrices = $product->getTierPrices();
250259
foreach ($productTierPrices as $productTierPrice) {
@@ -259,6 +268,24 @@ protected function getTierPrice(Product $product, $currencyCode, $withTax)
259268
$productTierPrice->getValue()
260269
);
261270
}
271+
} else {
272+
/** @var Group $group */
273+
foreach ($this->groups as $group) {
274+
$customerGroupId = (int) $group->getData('customer_group_id');
275+
$productTierPrices = $this->productTierPrice->getList($product->getSku(), $customerGroupId);
276+
if(!empty($productTierPrices)) {
277+
foreach ($productTierPrices as $productTierPrice) {
278+
if (!isset($tierPrices[$productTierPrice->getCustomerGroupId()])) {
279+
$tierPrices[$productTierPrice->getCustomerGroupId()] = $productTierPrice->getValue();
280+
continue;
281+
}
282+
$tierPrices[$productTierPrice->getCustomerGroupId()] = min(
283+
$tierPrices[$productTierPrice->getCustomerGroupId()],
284+
$productTierPrice->getValue()
285+
);
286+
}
287+
}
288+
}
262289
}
263290

264291
/** @var Group $group */

0 commit comments

Comments
 (0)