Skip to content

Commit 99d8cf1

Browse files
committed
MC-18403: Pricing :: Product pricing schema
- Fix percent-based tier price
1 parent 95ac9f7 commit 99d8cf1

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

app/code/Magento/CatalogCustomerGraphQl/Model/Resolver/PriceTiers.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,17 @@ public function resolve(
102102

103103
$product = $value['model'];
104104
$productId = $product->getId();
105-
$productPrice = $this->priceProviderPool
106-
->getProviderByProductType($product->getTypeId())
107-
->getMinimalRegularPrice($product)
108-
->getValue();
109105
$this->tiers->addProductFilter($productId);
110106

111107
return $this->valueFactory->create(
112-
function () use ($productId, $productPrice, $context) {
113-
108+
function () use ($productId, $context) {
114109
/** @var StoreInterface $store */
115110
$store = $context->getExtensionAttributes()->getStore();
116111

112+
$productPrice = $this->tiers->getProductRegularPrice($productId) ?? 0.0;
117113
$tierPrices = $this->tiers->getProductTierPrices($productId) ?? [];
118114

115+
119116
return $this->formatProductTierPrices($tierPrices, $productPrice, $store);
120117
}
121118
);

app/code/Magento/CatalogCustomerGraphQl/Model/Resolver/Product/Price/Tiers.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
1313
use Magento\Customer\Model\GroupManagement;
1414
use Magento\Catalog\Api\Data\ProductTierPriceInterface;
15+
use Magento\CatalogGraphQl\Model\Resolver\Product\Price\ProviderPool as PriceProviderPool;
1516

1617
/**
1718
* Get product tier price information
@@ -28,6 +29,11 @@ class Tiers
2829
*/
2930
private $productResource;
3031

32+
/**
33+
* @var PriceProviderPool
34+
*/
35+
private $priceProviderPool;
36+
3137
/**
3238
* @var bool
3339
*/
@@ -36,7 +42,7 @@ class Tiers
3642
/**
3743
* @var int
3844
*/
39-
private $customerGroupId = GroupManagement::CUST_GROUP_ALL;
45+
private $customerGroupId = GroupManagement::CUST_GROUP_ALL;
4046

4147
/**
4248
* @var array
@@ -51,15 +57,18 @@ class Tiers
5157
/**
5258
* @param CollectionFactory $collectionFactory
5359
* @param ProductResource $productResource
60+
* @param PriceProviderPool $priceProviderPool
5461
* @param int $customerGroupId
5562
*/
5663
public function __construct(
5764
CollectionFactory $collectionFactory,
5865
ProductResource $productResource,
66+
PriceProviderPool $priceProviderPool,
5967
$customerGroupId
6068
) {
6169
$this->collectionFactory = $collectionFactory;
6270
$this->productResource = $productResource;
71+
$this->priceProviderPool = $priceProviderPool;
6372
$this->customerGroupId = $customerGroupId;
6473
}
6574

@@ -91,6 +100,26 @@ public function getProductTierPrices($productId): ?array
91100
return $this->products[$productId]->getTierPrices();
92101
}
93102

103+
/**
104+
* Get product regular price by ID
105+
*
106+
* @param int $productId
107+
* @return float|null
108+
*/
109+
public function getProductRegularPrice($productId): ?float
110+
{
111+
if (!$this->isLoaded()) {
112+
$this->load();
113+
}
114+
115+
if (empty($this->products[$productId])) {
116+
return null;
117+
}
118+
$product = $this->products[$productId];
119+
$priceProvider = $this->priceProviderPool->getProviderByProductType($product->getTypeId());
120+
return $priceProvider->getMinimalRegularPrice($product)->getValue();
121+
}
122+
94123
/**
95124
* Check if collection has been loaded
96125
*
@@ -112,6 +141,8 @@ private function load(): void
112141
/** @var Collection $productCollection */
113142
$productCollection = $this->collectionFactory->create();
114143
$productCollection->addFieldToFilter($productIdField, ['in' => $this->filterProductIds]);
144+
$productCollection->addAttributeToSelect('price');
145+
$productCollection->load();
115146
$productCollection->addTierPriceDataByGroupId($this->customerGroupId);
116147

117148
foreach ($productCollection as $product) {

0 commit comments

Comments
 (0)