![]() 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/Model/ResourceModel/SourceItemOption/ |
<?php /** * Copyright © eComBricks. All rights reserved. * See LICENSE.txt for license details. */ declare(strict_types=1); namespace Ecombricks\InventoryInventoryCatalog\Model\ResourceModel\SourceItemOption; /** * Assign source item options resource */ class Assign { /** * Connection provider * * @var \Ecombricks\Framework\Model\ResourceModel\Db\ConnectionProvider */ protected $connectionProvider; /** * Is source item management allowed for product type * * @var \Magento\InventoryConfigurationApi\Model\IsSourceItemManagementAllowedForProductTypeInterface */ protected $isSourceItemManagementAllowedForProductType; /** * Get product types by SKUs * * @var \Magento\InventoryCatalogApi\Model\GetProductTypesBySkusInterface */ protected $getProductTypesBySkus; /** * Table name * * @var string */ protected $tableName; /** * Constructor * * @param \Ecombricks\Framework\Model\ResourceModel\Db\ConnectionProvider $connectionProvider * @param \Magento\InventoryCatalogApi\Model\GetProductTypesBySkusInterface $getProductTypesBySkus * @param \Magento\InventoryConfigurationApi\Model\IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType * @param string $tableName * @return void */ public function __construct( \Ecombricks\Framework\Model\ResourceModel\Db\ConnectionProvider $connectionProvider, \Magento\InventoryCatalogApi\Model\GetProductTypesBySkusInterface $getProductTypesBySkus, \Magento\InventoryConfigurationApi\Model\IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType, string $tableName ) { $this->connectionProvider = $connectionProvider; $this->isSourceItemManagementAllowedForProductType = $isSourceItemManagementAllowedForProductType; $this->getProductTypesBySkus = $getProductTypesBySkus; $this->tableName = $tableName; } /** * Execute * * @param array $skus * @param array $sources * @return $this */ public function execute(array $skus, array $sources) { $table = $this->connectionProvider->getTable($this->tableName); $connection = $this->connectionProvider->getConnection(); $productTypes = $this->getProductTypesBySkus->execute($skus); foreach ($productTypes as $sku => $productType) { if (!$this->isSourceItemManagementAllowedForProductType->execute($productType)) { continue; } foreach ($sources as $sourceCode) { $connection->insertOnDuplicate( $table, [ \Ecombricks\InventoryInventoryCatalog\Api\Data\SourceItemOptionInterface::SOURCE_CODE => $sourceCode, \Ecombricks\InventoryInventoryCatalog\Api\Data\SourceItemOptionInterface::SKU => $sku, \Ecombricks\InventoryInventoryCatalog\Api\Data\SourceItemOptionInterface::VALUE => null, ], [ \Ecombricks\InventoryInventoryCatalog\Api\Data\SourceItemOptionInterface::VALUE => null, ] ); } } return $this; } }