如何在自定义运输模块中设置 Fedex Career?

How to set Fedex Career in custom shipping module?

FedEx 模块的 Carrier.php 在我们 Magento 商店的自定义运输模块中得到扩展。我正在寻找一种将 FedEx 承运人设置为“自定义运输”的方法,如下所示。

我似乎没有从 class 右侧 returns 方法对象数组中找到方法。请帮我找到它。我试着用 $fedex_results->getAllRates() 做,但没有发生。

<?php

namespace Perfectmakeupmirrors\CustomShipping\Model\Carrier;

use Magento\Quote\Model\Quote\Address\RateRequest;
use Magento\Shipping\Model\Carrier\AbstractCarrier;
use Magento\Shipping\Model\Carrier\CarrierInterface;
use Perfectmakeupmirrors\PmmFedex\Model\PmmFedexCarrier;

/**
 * Custom shipping model
 */
class Customshipping extends AbstractCarrier implements CarrierInterface
{
    const FEDEX_METHODS = [
        'EUROPE_FIRST_INTERNATIONAL_PRIORITY' => 'Europe First Priority',
        'FEDEX_1_DAY_FREIGHT' => '1 Day Freight',
        'FEDEX_2_DAY_FREIGHT' => '2 Day Freight',
        'FEDEX_2_DAY' => '2 Day',
        'FEDEX_2_DAY_AM' => '2 Day AM',
        'FEDEX_3_DAY_FREIGHT' => '3 Day Freight',
        'FEDEX_EXPRESS_SAVER' => 'Express Saver',
        'FEDEX_GROUND' => 'Ground',
        'FIRST_OVERNIGHT' => 'First Overnight',
        'GROUND_HOME_DELIVERY' => 'Home Delivery',
        'INTERNATIONAL_ECONOMY' => 'International Economy',
        'INTERNATIONAL_ECONOMY_FREIGHT' => 'Intl Economy Freight',
        'INTERNATIONAL_FIRST' => 'International First',
        'INTERNATIONAL_GROUND' => 'International Ground',
        'INTERNATIONAL_PRIORITY' => 'International Priority',
        'INTERNATIONAL_PRIORITY_FREIGHT' => 'Intl Priority Freight',
        'PRIORITY_OVERNIGHT' => 'Priority Overnight',
        'SMART_POST' => 'Smart Post',
        'STANDARD_OVERNIGHT' => 'Standard Overnight',
        'FEDEX_FREIGHT' => 'Freight',
        'FEDEX_NATIONAL_FREIGHT' => 'National Freight'
    ];
    const SHIPPING_STANDARD = 'STD';
    const SHIPPING_2ND_DAY = '2DY';
    const SHIPPING_OVERNIGHT = 'ON';
    protected $_shipping_mode_strings = array(
        self::SHIPPING_STANDARD => 'Standard Ground',
        self::SHIPPING_2ND_DAY => 'Second Day',
        self::SHIPPING_OVERNIGHT => 'Next Day Air',
    );

    /**
     * @var string
     */
    protected $_code = 'customshipping';

    /**
     * @var bool
     */
    protected $_isFixed = true;

    /**
     * @var \Magento\Shipping\Model\Rate\ResultFactory
     */
    private $rateResultFactory;

    /**
     * @var \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory
     */
    private $rateMethodFactory;

    /**
     * @var \Perfectmakeupmirrors\CustomShipping\Helper\Data
     */
    private $helper;

    /**
     * @var \Psr\Log\LoggerInterface
     */
    protected $_logger;

    private $carrierFedex;

    /**
     * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
     * @param \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory
     * @param \Psr\Log\LoggerInterface $logger
     * @param \Magento\Shipping\Model\Rate\ResultFactory $rateResultFactory
     * @param \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $rateMethodFactory
     * @param array $data
     */
    public function __construct(
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory,
        \Psr\Log\LoggerInterface $logger,
        \Magento\Shipping\Model\Rate\ResultFactory $rateResultFactory,
        \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $rateMethodFactory,
        \Perfectmakeupmirrors\CustomShipping\Helper\Data $helper,
        \Perfectmakeupmirrors\PmmFedex\Model\PmmFedexCarrier $carrierFedex,
        array $data = []
    ) {
        parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);

        $this->rateResultFactory = $rateResultFactory;
        $this->rateMethodFactory = $rateMethodFactory;
        $this->carrierFedex = $carrierFedex;
        $this->_logger = $logger;
        $this->helper = $helper;
    }

    /**
     * Custom Shipping Rates Collector
     *
     * @param RateRequest $request
     * @return \Magento\Shipping\Model\Rate\Result|bool
     */
    public function collectRates(RateRequest $request)
    {
        if (!$this->getConfigFlag('active')) {
            return false;
        }

        
        $this->_logger->info("Start of Custom Shipping collectRates");
        if ($request->getDestCountryId() == "CA") {
            $this->_logger->info("Country ID: " . $request->getDestCountryId());
            $fedex_results = $this->carrierFedex->collectRates($request);
            // $this->_logger->info("Fedex Rate " . $fedex_rate);
            // 1. Get the array of method objects from $fedex_results object           
            //$this->_logger->info($fedex_results->getAllRates()); 
            
            // 2. Get the array of methods objects.


            // 3. Loop through the array of method objects to set carrier.
            return $fedex_results;
            // Assemble FedEx methods.
            

        }

用这个看看是否有帮助。

$method->setCarrier($this->_code);