Skip to content

Commit 5839fdd

Browse files
committed
MAGE-760 Fixed Tier price issue
1 parent 58a428f commit 5839fdd

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
/**
@@ -243,7 +252,7 @@ protected function getTierPrice(Product $product, $currencyCode, $withTax)
243252
$tierPrice = [];
244253
$tierPrices = [];
245254

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

263290
/** @var Group $group */

0 commit comments

Comments
 (0)