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/magento/module-configurable-product/Model/Product/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/magento/module-configurable-product/Model/Product/ReadHandler.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\ConfigurableProduct\Model\Product;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\ConfigurableProduct\Helper\Product\Options\Loader;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\Framework\EntityManager\Operation\ExtensionInterface;

/**
 * Class ReadHandler
 */
class ReadHandler implements ExtensionInterface
{
    /**
     * @var Loader
     */
    private $optionLoader;

    /**
     * ReadHandler constructor
     *
     * @param Loader $optionLoader
     */
    public function __construct(Loader $optionLoader)
    {
        $this->optionLoader = $optionLoader;
    }

    /**
     * @param object $entity
     * @param array $arguments
     * @return object
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function execute($entity, $arguments = [])
    {
        if ($entity->getTypeId() !== Configurable::TYPE_CODE) {
            return $entity;
        }

        $extensionAttributes = $entity->getExtensionAttributes();

        $extensionAttributes->setConfigurableProductLinks($this->getLinkedProducts($entity));
        $extensionAttributes->setConfigurableProductOptions($this->optionLoader->load($entity));

        $entity->setExtensionAttributes($extensionAttributes);

        return $entity;
    }

    /**
     * Get linked to configurable simple products
     *
     * @param ProductInterface $product
     * @return int[]
     */
    private function getLinkedProducts(ProductInterface $product)
    {
        /** @var Configurable $typeInstance */
        $typeInstance = $product->getTypeInstance();
        $childrenIds = $typeInstance->getChildrenIds($product->getId());

        if (isset($childrenIds[0])) {
            return $childrenIds[0];
        } else {
            return [];
        }
    }
}

Spamworldpro Mini