![]() 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/old/vendor/wyomind/msicustomattributes/Observer/MsiStockManagement/ |
<?php /** * Copyright © 2020 Wyomind. All rights reserved. * See LICENSE.txt for license details. */ /** * Copyright © 2020 Wyomind. All rights reserved. * See LICENSE.txt for license details. */ namespace Wyomind\MsiCustomAttributes\Observer\MsiStockManagement; use Magento\Framework\Event\Observer; /** * Class SourceformSave * @package Wyomind\MsiCustomAttributes\Observer\MsiStockManagement */ class SourceformSave implements \Magento\Framework\Event\ObserverInterface { public $repository; /** * @var \Wyomind\MsiCustomAttributes\Model\CustomAttributeValueFactory */ public $customAttributeValueFactory; public $customAttributeValueProcessor; public function __construct( \Wyomind\MsiCustomAttributes\Helper\Delegate $wyomind, /** @delegation off */ \Wyomind\MsiCustomAttributes\Model\CustomAttributeValueFactory $customAttributeValueFactory ) { $wyomind->constructor($this, $wyomind, __CLASS__); $this->customAttributeValueFactory = $customAttributeValueFactory; } /** * @param Observer $observer * @throws \Exception */ public function execute(Observer $observer) { $data = $observer->getEvent()->getPost(); foreach ($data as $productId => $productData) { $sendData = []; if (!isset($productData->source) || !isset($productData->sku)) { continue; } foreach ((array) $productData->source as $productSourcecode => $productSourceData) { // convert object into array to get attribute as a key $attributes = $this->repository->list(); foreach ($attributes as $attribute) { if (isset($productSourceData->{$attribute->getCode()})) { $sendData[$attribute->getCode()] = $productSourceData->{$attribute->getCode()}; $sendData["source_code"] = $productSourcecode; } } $this->customAttributeValueProcessor->process($productData->sku, [$sendData]); } } } }