diff --git a/vendor/magento/module-catalog-customer-graph-ql/Model/Resolver/PriceTiers.php b/vendor/magento/module-catalog-customer-graph-ql/Model/Resolver/PriceTiers.php index efba88ff154..3c6cc849081 100644 --- a/vendor/magento/module-catalog-customer-graph-ql/Model/Resolver/PriceTiers.php +++ b/vendor/magento/module-catalog-customer-graph-ql/Model/Resolver/PriceTiers.php @@ -19,7 +19,6 @@ use Magento\Framework\GraphQl\Query\Resolver\ValueFactory; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Framework\Pricing\PriceCurrencyInterface; -use Magento\Store\Api\Data\StoreInterface; /** * Resolver for price_tiers @@ -125,6 +124,10 @@ class PriceTiers implements ResolverInterface return []; } + if (!$product->getTierPrices()) { + return []; + } + $productId = (int)$product->getId(); $this->tiers->addProductFilter($productId); @@ -152,7 +155,8 @@ class PriceTiers implements ResolverInterface array $tierPrices, string $currencyCode ): array { - + $this->formatAndFilterTierPrices = []; + $this->tierPricesQty = []; foreach ($tierPrices as $key => $tierPrice) { $tierPrice->setValue($this->priceCurrency->convertAndRound($tierPrice->getValue())); $this->formatTierPrices($productPrice, $currencyCode, $tierPrice); diff --git a/vendor/magento/module-quote/Model/Product/Plugin/UpdateQuote.php b/vendor/magento/module-quote/Model/Product/Plugin/UpdateQuote.php new file mode 100644 index 00000000000..3d41a5398c8 --- /dev/null +++ b/vendor/magento/module-quote/Model/Product/Plugin/UpdateQuote.php @@ -0,0 +1,103 @@ +resource = $resource; + $this->productIdLocator = $productIdLocator; + } + + /** + * Update the quote trigger_recollect column is 1 when product price is changed through API. + * + * @param TierPriceStorageInterface $subject + * @param $result + * @param $prices + * @return array + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterUpdate( + TierPriceStorageInterface $subject, + $result, + $prices + ): array { + $this->resource->markQuotesRecollect($this->retrieveAffectedProductIdsForPrices($prices)); + return $result; + + } + + /** + * Retrieve affected product IDs for prices. + * + * @param TierPriceInterface[] $prices + * @return array + */ + private function retrieveAffectedProductIdsForPrices(array $prices): array + { + $skus = array_unique( + array_map( + function (TierPriceInterface $price) { + return $price->getSku(); + }, + $prices + ) + ); + + return $this->retrieveAffectedIds($skus); + } + + /** + * Retrieve affected product IDs. + * + * @param array $skus + * @return array + */ + private function retrieveAffectedIds(array $skus): array + { + $affectedIds = []; + + foreach ($this->productIdLocator->retrieveProductIdsBySkus($skus) as $productId) { + $affectedIds[] = array_keys($productId); + } + + return array_unique(array_merge([], ...$affectedIds)); + } +} \ No newline at end of file diff --git a/vendor/magento/module-quote/etc/di.xml b/vendor/magento/module-quote/etc/di.xml index f66001e7789..c71bf64c878 100644 --- a/vendor/magento/module-quote/etc/di.xml +++ b/vendor/magento/module-quote/etc/di.xml @@ -98,6 +98,9 @@ + + +