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

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

declare(strict_types=1);

namespace Magento\Shipping\Model\Rate;

use Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory;
use Magento\Store\Model\StoreManagerInterface;

/**
 * Carriers rates for different packages.
 */
class PackageResult extends Result
{
    /**
     * @var array
     */
    private $packageResults = [];

    /**
     * @var ErrorFactory
     */
    private $errorFactory;

    /**
     * @param StoreManagerInterface $storeManager
     * @param ErrorFactory $errorFactory
     */
    public function __construct(
        StoreManagerInterface $storeManager,
        ErrorFactory $errorFactory
    ) {
        parent::__construct($storeManager);
        $this->errorFactory = $errorFactory;
    }

    /**
     * Add result for a number of packages.
     *
     * @param Result $result
     * @param int $numberOfPackages
     * @return void
     */
    public function appendPackageResult(Result $result, int $numberOfPackages): void
    {
        $this->packageResults[] = ['packages' => $numberOfPackages, 'result' => $result];
    }

    /**
     * @inheritDoc
     */
    public function getAllRates()
    {
        //Process results for packages
        while ($resultData = array_shift($this->packageResults)) {
            /** @var Result $result */
            $result = $resultData['result'];
            $result->updateRatePrice($resultData['packages']);

            foreach ($result->getAllRates() as $currentRate) {
                foreach ($this->_rates as $rate) {
                    if ($rate->getMethod() === $currentRate->getMethod()) {
                        if ($rate === $currentRate) {
                            throw new \InvalidArgumentException('Same object received from carrier.');
                        }
                        $rate->setPrice($rate->getPrice() + $currentRate->getPrice());
                        continue 2;
                    }
                }
                //Rate does not exist
                $this->append($currentRate);
            }
        }

        return parent::getAllRates();
    }

    /**
     * @inheritDoc
     */
    public function getError()
    {
        if (!$this->_rates && !$this->packageResults) {
            $this->setError(true);
            $this->_rates[] = $this->errorFactory->create();
        } else {
            $this->getAllRates();
        }

        return parent::getError();
    }

    /**
     * @inheritDoc
     */
    public function getRateById($id)
    {
        $this->getAllRates();

        return parent::getRateById($id);
    }

    /**
     * @inheritDoc
     */
    public function getCheapestRate()
    {
        $this->getAllRates();

        return parent::getCheapestRate();
    }

    /**
     * @inheritDoc
     */
    public function getRatesByCarrier($carrier)
    {
        $this->getAllRates();

        return parent::getRatesByCarrier($carrier);
    }

    /**
     * @inheritDoc
     */
    public function asArray()
    {
        $this->getAllRates();

        return parent::asArray();
    }

    /**
     * @inheritDoc
     */
    public function sortRatesByPrice()
    {
        $this->getAllRates();

        return parent::sortRatesByPrice();
    }

    /**
     * @inheritDoc
     */
    public function updateRatePrice($packageCount)
    {
        $this->getAllRates();

        return parent::updateRatePrice($packageCount);
    }
}

Spamworldpro Mini