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-bundle/Plugin/Quote/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/magento/module-bundle/Plugin/Quote/UpdateBundleQuoteItemOptions.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
declare(strict_types=1);

namespace Magento\Bundle\Plugin\Quote;

use Magento\Bundle\Model\Product\Type;
use Magento\Bundle\Model\Quote\Item\Option;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\Quote\Item;
use Magento\Quote\Model\QuoteManagement;

/**
 * Update bundle selection custom options
 */
class UpdateBundleQuoteItemOptions
{
    /**
     * @var Option
     */
    private $option;

    /**
     * @param Option $option
     */
    public function __construct(
        Option $option
    ) {
        $this->option = $option;
    }

    /**
     * Update bundle selection custom options before order is placed
     *
     * @param QuoteManagement $subject
     * @param Quote $quote
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function beforeSubmit(
        QuoteManagement $subject,
        Quote $quote,
        array $orderData = []
    ): void {
        foreach ($quote->getAllVisibleItems() as $quoteItem) {
            if ($quoteItem->getProductType() === Type::TYPE_CODE) {
                $options = $this->option->getSelectionOptions($quoteItem->getProduct());
                foreach ($quoteItem->getChildren() as $childItem) {
                    /** @var Item $childItem */
                    $customOption = $childItem->getOptionByCode('selection_id');
                    $selectionId = $customOption ? $customOption->getValue() : null;
                    if ($selectionId && isset($options[$selectionId])) {
                        $childItem->setOptions($options[$selectionId]);
                    }
                }
            }
        }
    }
}

Spamworldpro Mini