![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/cartforge.co/vendor/magento/module-quote/Model/Product/Plugin/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Quote\Model\Product\Plugin; use Magento\Catalog\Api\Data\TierPriceInterface; use Magento\Catalog\Api\TierPriceStorageInterface; use Magento\Quote\Model\ResourceModel\Quote; use Magento\Catalog\Model\ProductIdLocatorInterface; /** * UpdateQuote Plugin Class */ class UpdateQuote { /** * Quote Resource * * @var Quote */ private $resource; /** * Product ID locator. * * @var ProductIdLocatorInterface */ private $productIdLocator; /** * Construct Method for updateQuote Plugin * * @param Quote $resource * @param ProductIdLocatorInterface $productIdLocator */ public function __construct( \Magento\Quote\Model\ResourceModel\Quote $resource, \Magento\Catalog\Model\ProductIdLocatorInterface $productIdLocator ) { $this->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)); } }