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
/**
@@ -243,7 +252,7 @@ protected function getTierPrice(Product $product, $currencyCode, $withTax)
243
252
$ tierPrice = [];
244
253
$ tierPrices = [];
245
254
246
- if (!is_null ($ product ->getTierPrices ())) {
255
+ if (!empty ($ product ->getTierPrices ())) {
247
256
$ product ->setData ('website_id ' , $ product ->getStore ()->getWebsiteId ());
248
257
$ productTierPrices = $ product ->getTierPrices ();
249
258
foreach ($ productTierPrices as $ productTierPrice ) {
@@ -258,6 +267,24 @@ protected function getTierPrice(Product $product, $currencyCode, $withTax)
258
267
$ productTierPrice ->getValue ()
259
268
);
260
269
}
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
+ }
261
288
}
262
289
263
290
/** @var Group $group */
0 commit comments