![]() 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/Ecombricks/InventoryInventoryCatalogPrice/Model/SourceItemPrice/ |
<?php /** * Copyright © eComBricks. All rights reserved. * See LICENSE.txt for license details. */ declare(strict_types=1); namespace Ecombricks\InventoryInventoryCatalogPrice\Model\SourceItemPrice; /** * Save source item prices */ class Save extends \Ecombricks\InventoryInventoryCatalog\Model\SourceItemOption\Save implements \Ecombricks\InventoryInventoryCatalogPrice\Api\SourceItemPrice\SaveInterface { /** * Product resource * * @var \Magento\Catalog\Model\ResourceModel\Product */ protected $productResource; /** * Product price indexer processor * * @var \Magento\Catalog\Model\Indexer\Product\Price\Processor */ protected $productPriceIndexerProcessor; /** * Constructor * * @param \Ecombricks\InventoryInventoryCatalogPrice\Model\ResourceModel\SourceItemPrice\Save $resource * @param \Ecombricks\InventoryInventoryCatalogPrice\Model\SourceItemPrice\Label $sourceItemOptionLabel * @param \Psr\Log\LoggerInterface $logger * @param \Magento\Catalog\Model\ResourceModel\Product $productResource * @param \Magento\Catalog\Model\Indexer\Product\Price\Processor $productPriceIndexerProcessor * @return void */ public function __construct( \Ecombricks\InventoryInventoryCatalogPrice\Model\ResourceModel\SourceItemPrice\Save $resource, \Ecombricks\InventoryInventoryCatalogPrice\Model\SourceItemPrice\Label $sourceItemOptionLabel, \Psr\Log\LoggerInterface $logger, \Magento\Catalog\Model\ResourceModel\Product $productResource, \Magento\Catalog\Model\Indexer\Product\Price\Processor $productPriceIndexerProcessor ) { $this->productResource = $productResource; $this->productPriceIndexerProcessor = $productPriceIndexerProcessor; parent::__construct( $resource, $sourceItemOptionLabel, $logger ); } /** * Get SKUs * * @param array $sourceItemOptions * @return array */ protected function getSkus(array $sourceItemOptions): array { $skus = []; foreach ($sourceItemOptions as $sourceItemOption) { $skus[] = $sourceItemOption->getSku(); } return $skus; } /** * Reindex products prices * * @param array $skus * @return \Ecombricks\InventoryInventoryCatalogPrice\Api\SourceItemPrice\SaveInterface */ protected function reindexProductsPrices(array $skus): \Ecombricks\InventoryInventoryCatalogPrice\Api\SourceItemPrice\SaveInterface { foreach ($skus as $sku) { $this->productPriceIndexerProcessor->reindexRow($this->productResource->getIdBySku($sku)); } return $this; } /** * Execute * * @param \Magento\InventoryInventoryCatalog\Api\Data\SourceItemOptionInterface[] $sourceItemOptions * @return \Ecombricks\InventoryInventoryCatalog\Api\SourceItemOption\SaveInterface */ public function execute(array $sourceItemOptions): \Ecombricks\InventoryInventoryCatalog\Api\SourceItemOption\SaveInterface { parent::execute($sourceItemOptions); $this->reindexProductsPrices($this->getSkus($sourceItemOptions)); return $this; } }