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/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

namespace Magento\ConfigurableProduct\Model;

class ProductVariationsBuilder
{
    /**
     * @var \Magento\Framework\Api\AttributeValueFactory
     */
    private $customAttributeFactory;

    /**
     * @var \Magento\Catalog\Model\ProductFactory
     */
    protected $productFactory;

    /**
     * @var \Magento\ConfigurableProduct\Model\Product\Type\VariationMatrix
     */
    private $variationMatrix;

    /**
     * @param \Magento\Catalog\Model\ProductFactory $productFactory
     * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory
     * @param Product\Type\VariationMatrix $variationMatrix
     */
    public function __construct(
        \Magento\Catalog\Model\ProductFactory $productFactory,
        \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory,
        \Magento\ConfigurableProduct\Model\Product\Type\VariationMatrix $variationMatrix
    ) {
        $this->productFactory = $productFactory;
        $this->customAttributeFactory = $customAttributeFactory;
        $this->variationMatrix = $variationMatrix;
    }

    /**
     * Populate product with variation of attributes
     *
     * @param \Magento\Catalog\Api\Data\ProductInterface $product
     * @param array $attributes
     * @return \Magento\Catalog\Api\Data\ProductInterface[]
     */
    public function create(\Magento\Catalog\Api\Data\ProductInterface $product, $attributes)
    {
        $variations = $this->variationMatrix->getVariations($attributes);
        $products = [];
        foreach ($variations as $variation) {
            $price = $product->getPrice();
            /** @var \Magento\Catalog\Model\Product $item */
            $item = $this->productFactory->create();
            $item->setData($product->getData());

            $suffix = '';
            foreach ($variation as $attributeId => $valueInfo) {
                $suffix .= '-' . $valueInfo['value'];
                $customAttribute = $this->customAttributeFactory->create()
                    ->setAttributeCode($attributes[$attributeId]['attribute_code'])
                    ->setValue($valueInfo['value']);
                $customAttributes = array_merge(
                    $item->getCustomAttributes(),
                    [
                        $attributes[$attributeId]['attribute_code'] => $customAttribute
                    ]
                );
                $item->setData('custom_attributes', $customAttributes);
            }
            $item->setPrice($price);
            $item->setName($product->getName() . $suffix);
            $item->setSku($product->getSku() . $suffix);
            $item->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE);
            $products[] = $item;
        }
        return $products;
    }
}

Spamworldpro Mini