![]() 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/InventoryInventoryCatalog/Observer/Model/SourceItemOption/ |
<?php /** * Copyright © eComBricks. All rights reserved. * See LICENSE.txt for license details. */ declare(strict_types=1); namespace Ecombricks\InventoryInventoryCatalog\Observer\Model\SourceItemOption; /** * Process source item options */ class Process implements \Magento\Framework\Event\ObserverInterface { /** * Is source item management allowed for product type * * @var \Magento\InventoryConfigurationApi\Model\IsSourceItemManagementAllowedForProductTypeInterface */ protected $isSourceItemManagementAllowedForProductType; /** * Is single source mode * * @var \Magento\InventoryCatalogApi\Model\IsSingleSourceModeInterface */ protected $isSingleSourceMode; /** * Default source provider * * @var \Magento\InventoryCatalogApi\Api\DefaultSourceProviderInterface */ protected $defaultSourceProvider; /** * Source item options processor * * @var \Ecombricks\InventoryInventoryCatalog\Model\SourceItemOption\Processor */ protected $sourceItemOptionsProcessor; /** * Surce item option value data key * * @var \Ecombricks\InventoryInventoryCatalog\Model\SourceItemOption\ValueDataKey */ protected $sourceItemOptionValueDataKey; /** * Constructor * * @param \Magento\InventoryConfigurationApi\Model\IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType * @param \Magento\InventoryCatalogApi\Model\IsSingleSourceModeInterface $isSingleSourceMode * @param \Magento\InventoryCatalogApi\Api\DefaultSourceProviderInterface $defaultSourceProvider * @param \Ecombricks\InventoryInventoryCatalog\Model\SourceItemOption\Processor $sourceItemOptionsProcessor * @param \Ecombricks\InventoryInventoryCatalog\Model\SourceItemOption\ValueDataKey $sourceItemOptionValueDataKey * @return void */ public function __construct( \Magento\InventoryConfigurationApi\Model\IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType, \Magento\InventoryCatalogApi\Model\IsSingleSourceModeInterface $isSingleSourceMode, \Magento\InventoryCatalogApi\Api\DefaultSourceProviderInterface $defaultSourceProvider, \Ecombricks\InventoryInventoryCatalog\Model\SourceItemOption\Processor $sourceItemOptionsProcessor, \Ecombricks\InventoryInventoryCatalog\Model\SourceItemOption\ValueDataKey $sourceItemOptionValueDataKey ) { $this->isSourceItemManagementAllowedForProductType = $isSourceItemManagementAllowedForProductType; $this->isSingleSourceMode = $isSingleSourceMode; $this->defaultSourceProvider = $defaultSourceProvider; $this->sourceItemOptionsProcessor = $sourceItemOptionsProcessor; $this->sourceItemOptionValueDataKey = $sourceItemOptionValueDataKey; } /** * Execute * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { $event = $observer->getEvent(); $product = $event->getProduct(); if ($this->isSourceItemManagementAllowedForProductType->execute($product->getTypeId()) === false) { return $this; } $request = $event->getController()->getRequest(); $sourceItemOptionsData = []; if ($this->isSingleSourceMode->execute()) { $valueDataKey = $this->sourceItemOptionValueDataKey->getKey(); $sourceItemOptionsData[] = [ \Ecombricks\InventoryInventoryCatalog\Api\Data\SourceItemOptionInterface::SOURCE_CODE => $this->defaultSourceProvider->getCode(), $valueDataKey => null, $valueDataKey.'_use_default' => 1, ]; } else { $sources = $request->getParam('sources', []); if (isset($sources['assigned_sources']) && is_array($sources['assigned_sources'])) { $sourceItemOptionsData = $sources['assigned_sources']; } } $this->sourceItemOptionsProcessor->execute($product->getData(\Magento\Catalog\Api\Data\ProductInterface::SKU), $sourceItemOptionsData); return $this; } }