14
14
use Magento \Framework \Pricing \PriceCurrencyInterface ;
15
15
use Magento \Tax \Helper \Data as TaxHelper ;
16
16
use Magento \Tax \Model \Config as TaxConfig ;
17
+ use Magento \Catalog \Api \ScopedProductTierPriceManagementInterface ;
17
18
18
19
abstract class ProductWithoutChildren
19
20
{
@@ -46,6 +47,11 @@ abstract class ProductWithoutChildren
46
47
*/
47
48
protected $ productloader ;
48
49
50
+ /**
51
+ * @var ScopedProductTierPriceManagementInterface
52
+ */
53
+ private $ productTierPrice ;
54
+
49
55
protected $ store ;
50
56
protected $ baseCurrencyCode ;
51
57
protected $ groups ;
@@ -60,6 +66,7 @@ abstract class ProductWithoutChildren
60
66
* @param TaxHelper $taxHelper
61
67
* @param Rule $rule
62
68
* @param ProductFactory $productloader
69
+ * @param ScopedProductTierPriceManagementInterface $productTierPrice
63
70
*/
64
71
public function __construct (
65
72
ConfigHelper $ configHelper ,
@@ -68,7 +75,8 @@ public function __construct(
68
75
CatalogHelper $ catalogHelper ,
69
76
TaxHelper $ taxHelper ,
70
77
Rule $ rule ,
71
- ProductFactory $ productloader
78
+ ProductFactory $ productloader ,
79
+ ScopedProductTierPriceManagementInterface $ productTierPrice
72
80
) {
73
81
$ this ->configHelper = $ configHelper ;
74
82
$ this ->customerGroupCollectionFactory = $ customerGroupCollectionFactory ;
@@ -77,6 +85,7 @@ public function __construct(
77
85
$ this ->taxHelper = $ taxHelper ;
78
86
$ this ->rule = $ rule ;
79
87
$ this ->productloader = $ productloader ;
88
+ $ this ->productTierPrice = $ productTierPrice ;
80
89
}
81
90
82
91
/**
@@ -244,7 +253,7 @@ protected function getTierPrice(Product $product, $currencyCode, $withTax)
244
253
$ tierPrice = [];
245
254
$ tierPrices = [];
246
255
247
- if (!is_null ($ product ->getTierPrices ())) {
256
+ if (!empty ($ product ->getTierPrices ())) {
248
257
$ product ->setData ('website_id ' , $ product ->getStore ()->getWebsiteId ());
249
258
$ productTierPrices = $ product ->getTierPrices ();
250
259
foreach ($ productTierPrices as $ productTierPrice ) {
@@ -259,6 +268,24 @@ protected function getTierPrice(Product $product, $currencyCode, $withTax)
259
268
$ productTierPrice ->getValue ()
260
269
);
261
270
}
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
+ }
262
289
}
263
290
264
291
/** @var Group $group */
0 commit comments