Spamworldpro Mini Shell
Spamworldpro


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/Model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/wyomind/msicustomattributes/Model/CustomAttributeValueProcessor.php
<?php

/**
 * Copyright © 2020 Wyomind. All rights reserved.
 * See LICENSE.txt for license details.
 */
declare (strict_types=1);
namespace Wyomind\MsiCustomAttributes\Model;

use Magento\Framework\Locale\ResolverInterface;
use Wyomind\MsiCustomAttributes\Model\CustomAttribute\Repository;
use Wyomind\MsiCustomAttributes\Helper\CustomAttribute;
use Wyomind\MsiCustomAttributes\Api\Data\CustomAttributeValueInterface;
use Wyomind\MsiCustomAttributes\Model\CustomAttributeValueFactory;
use Wyomind\MsiCustomAttributes\Model\ResourceModel\CustomAttributeValue\CollectionFactory;
/**
 * Process source item configuration.
 */
class CustomAttributeValueProcessor
{
    /**
     * @var CustomAttributeValueFactory
     */
    protected $customAttributeValueFactory;
    public $customAttributeRepository;
    public $resolver;
    /**
     * @var CollectionFactory
     */
    protected $collectionFactory;
    public function __construct(
        \Wyomind\MsiCustomAttributes\Helper\Delegate $wyomind,
        /** @delegation off */
        CustomAttributeValueFactory $customAttributeValueFactory,
        /** @delegation off */
        CollectionFactory $collectionFactory
    )
    {
        $wyomind->constructor($this, $wyomind, __CLASS__);
        $this->customAttributeValueFactory = $customAttributeValueFactory;
        $this->collectionFactory = $collectionFactory;
    }
    /**
     * Process configuration
     *
     * @param string $sku
     * @param array $sourceItemsData
     * @return void
     * @throws \Exception
     * @SuppressWarnings(PHPMD.LongVariable)
     */
    public function process($sku, array $sourceItemsData)
    {
        foreach ($sourceItemsData as $sourceItemData) {
            $customAttributes = $this->customAttributeRepository->list();
            foreach ($customAttributes as $customAttribute) {
                if (isset($sourceItemData[CustomAttributeValueInterface::SOURCE_CODE])) {
                    $value = [];
                    if (!isset($sourceItemData[$customAttribute->getCode()])) {
                        $sourceItemData[$customAttribute->getCode()] = null;
                    }
                    $value[CustomAttributeValueInterface::SOURCE_CODE] = $sourceItemData[CustomAttributeValueInterface::SOURCE_CODE];
                    $value[CustomAttributeValueInterface::SKU] = $sku;
                    $value[CustomAttributeValueInterface::ATTRIBUTE_ID] = $customAttribute->getAttributeId();
                    if ($customAttribute->getType() == CustomAttribute::TYPE_DATE) {
                        $date = null;
                        if (!empty($sourceItemData[$customAttribute->getCode()])) {
                            $date = date('Y-m-d', (new \IntlDateFormatter($this->resolver->getLocale(), \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE))->parse($sourceItemData[$customAttribute->getCode()]));
                        }
                        $value[CustomAttributeValueInterface::VALUE] = $date;
                    } else {
                        $value[CustomAttributeValueInterface::VALUE] = $sourceItemData[$customAttribute->getCode()];
                    }
                    $collectionFactory = $this->collectionFactory->create();
                    $valueId = $collectionFactory->getValueId($value[CustomAttributeValueInterface::SKU], $value[CustomAttributeValueInterface::SOURCE_CODE], $value[CustomAttributeValueInterface::ATTRIBUTE_ID]);
                    $value[CustomAttributeValueInterface::VALUE_ID] = $valueId;
                    $customAttributeValue = $this->customAttributeValueFactory->create();
                    $customAttributeValue->addData($value);
                    $customAttributeValue->save($value);
                }
            }
        }
    }
}

Spamworldpro Mini