Bobot dan Nilai Pengiriman Fedex tidak diatur saat membuat pesanan secara terprogram


12

Saya mencoba membuat pesanan secara terprogram menggunakan metode pengiriman FedEx. Metode lain berfungsi dengan baik. Ketika saya mengatur FedEx mendapatkan kesalahan seperti harap tentukan metode pengiriman. Setelah debugging saya tahu berat dan nilainya nol tetapi saya menyebutkan berat dan nilai produk.

Kode:

Buat.php

<?php
namespace yourmodule\namespace\Helper;
class Create extends \Magento\Framework\App\Helper\AbstractHelper
{
     /**
    * @param Magento\Framework\App\Helper\Context $context
    * @param Magento\Store\Model\StoreManagerInterface $storeManager
    * @param Magento\Catalog\Model\Product $product
    * @param Magento\Framework\Data\Form\FormKey $formKey $formkey,
    * @param Magento\Quote\Model\Quote $quote,
    * @param Magento\Customer\Model\CustomerFactory $customerFactory,
    * @param Magento\Sales\Model\Service\OrderService $orderService,
    */
    public function __construct(
        \Magento\Framework\App\Helper\Context $context,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Catalog\Model\Product $product,
        \Magento\Framework\Data\Form\FormKey $formkey,
        \Magento\Quote\Model\QuoteFactory $quote,
        \Magento\Quote\Model\QuoteManagement $quoteManagement,
        \Magento\Customer\Model\CustomerFactory $customerFactory,
        \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
        \Magento\Sales\Model\Service\OrderService $orderService,
        \Magento\Quote\Model\Quote\Address\Rate $shippingRate
    ) {
        $this->_storeManager = $storeManager;
        $this->_product = $product;
        $this->_formkey = $formkey;
        $this->quote = $quote;
        $this->quoteManagement = $quoteManagement;
        $this->customerFactory = $customerFactory;
        $this->customerRepository = $customerRepository;
        $this->orderService = $orderService;
        $this->shippingRate = $shippingRate;
        parent::__construct($context);
    }

    /**
     * Create Order On Your Store
     * 
     * @param array $orderData
     * @return array
     * 
    */
    public function createMageOrder($orderData) {
        $store=$this->_storeManager->getStore();
        $websiteId = $this->_storeManager->getStore()->getWebsiteId();
        $customer=$this->customerFactory->create();
        $customer->setWebsiteId($websiteId);
        $customer->loadByEmail($orderData['email']);// load customet by email address
        if(!$customer->getEntityId()){
            //If not avilable then create this customer 
            $customer->setWebsiteId($websiteId)
                    ->setStore($store)
                    ->setFirstname($orderData['shipping_address']['firstname'])
                    ->setLastname($orderData['shipping_address']['lastname'])
                    ->setEmail($orderData['email']) 
                    ->setPassword($orderData['email']);
            $customer->save();
        }
        $quote=$this->quote->create(); //Create object of quote
        $quote->setStore($store); //set store for which you create quote
        // if you have allready buyer id then you can load customer directly 
        $customer= $this->customerRepository->getById($customer->getEntityId());
        $quote->setCurrency();
        $quote->assignCustomer($customer); //Assign quote to customer

        //add items in quote
        foreach($orderData['items'] as $item){
            $product=$this->_product->load($item['product_id']);
            //$product->setPrice($item['price']);
             $product->setWeight(20);
            $quote->addProduct(
                $product,
                intval($item['qty'])
            );
        }

        //Set Address to quote
        $quote->getBillingAddress()->addData($orderData['shipping_address']);
        $quote->getShippingAddress()->addData($orderData['shipping_address']);

        // Collect Rates and Set Shipping & Payment Method

        $shippingAddress=$quote->getShippingAddress();

        /*$shippingAddress->setCollectShippingRates(true)
                        ->collectShippingRates()
                        ->setShippingMethod('fedex_FEDEX_GROUND'); //shipping method

        */
        //$this->shippingRate
          //  ->setCode('fedex_FEDEX_GROUND');
            //->getPrice(1);
        //$shippingAddress = $cart->getShippingAddress();
        //@todo set in order data
        $shippingAddress->setCollectShippingRates(true)
            ->collectShippingRates()
            ->setShippingMethod('fedex_FEDEX_GROUND'); //shipping method
        //$quote->getShippingAddress()->addShippingRate($this->shippingRate);       
        $quote->setPaymentMethod('checkmo'); //payment method
        $quote->setInventoryProcessed(false); //not effetc inventory
        $quote->save(); //Now Save quote and your quote is ready

        // Set Sales Order Payment
        $quote->getPayment()->importData(['method' => 'checkmo']);

        // Collect Totals & Save Quote
        $quote->collectTotals()->save();

        // Create Order From Quote
        $order = $this->quoteManagement->submit($quote);

        $order->setEmailSent(0);
        $increment_id = $order->getRealOrderId();
        if($order->getEntityId()){
            $result['order_id']= $order->getRealOrderId();
        }else{
            $result=['error'=>1,'msg'=>'Your custom message'];
        }
        return $result;
    }
}

Log debug FedEx:

array (
  'request' => 
  array (
    'WebAuthenticationDetail' => 
    array (
      'UserCredential' => 
      array (
        'Key' => '****',
        'Password' => '****',
      ),
    ),
    'ClientDetail' => 
    array (
      'AccountNumber' => 'XXXXXX',
      'MeterNumber' => '****',
    ),
    'Version' => 
    array (
      'ServiceId' => 'crs',
      'Major' => '10',
      'Intermediate' => '0',
      'Minor' => '0',
    ),
    'RequestedShipment' => 
    array (
      'DropoffType' => 'REGULAR_PICKUP',
      'ShipTimestamp' => '2017-06-27T06:09:23+00:00',
      'PackagingType' => 'YOUR_PACKAGING',
      'TotalInsuredValue' => 
      array (
        'Amount' => 0,
        'Currency' => 'USD',
      ),
      'Shipper' => 
      array (
        'Address' => 
        array (
          'PostalCode' => '90034',
          'CountryCode' => 'US',
        ),
      ),
      'Recipient' => 
      array (
        'Address' => 
        array (
          'PostalCode' => '11701',
          'CountryCode' => 'US',
          'Residential' => false,
          'City' => 'Ave Forest Hills',
        ),
      ),
      'ShippingChargesPayment' => 
      array (
        'PaymentType' => 'SENDER',
        'Payor' => 
        array (
          'AccountNumber' => 'XXXXX',
          'CountryCode' => 'US',
        ),
      ),
      'CustomsClearanceDetail' => 
      array (
        'CustomsValue' => 
        array (
          'Amount' => 0,
          'Currency' => 'USD',
        ),
      ),
      'RateRequestTypes' => 'LIST',
      'PackageCount' => '1',
      'PackageDetail' => 'INDIVIDUAL_PACKAGES',
      'RequestedPackageLineItems' => 
      array (
        0 => 
        array (
          'Weight' => 
          array (
            'Value' => 0.0,
            'Units' => 'LB',
          ),
          'GroupPackageCount' => 1,
        ),
      ),
      'ServiceType' => 'SMART_POST',
      'SmartPostDetail' => 
      array (
        'Indicia' => 'PRESORTED_STANDARD',
        'HubId' => NULL,
      ),
    ),
  ),
  'result' => 
  stdClass::__set_state(array(
     'HighestSeverity' => 'ERROR',
     'Notifications' => 
    stdClass::__set_state(array(
       'Severity' => 'ERROR',
       'Source' => 'crs',
       'Code' => '809',
       'Message' => 'Package 1 - Weight is missing or invalid. ',
       'LocalizedMessage' => 'Package 1 - Weight is missing or invalid. ',
       'MessageParameters' => 
      stdClass::__set_state(array(
         'Id' => 'PACKAGE_INDEX',
         'Value' => '1',
      )),
    )),
     'Version' => 
    stdClass::__set_state(array(
       'ServiceId' => 'crs',
       'Major' => 10,
       'Intermediate' => 0,
       'Minor' => 0,
    )),
  )),
) {"is_exception":false} []

Data pesanan:

$orderData = [
     'email'        => 'ram10test@gmail.com', //buyer email id
     'shipping_address' =>[
            'firstname'    => 'Ramki ', //address Details
            'lastname'     => 'ram',
                    'street' => '10119 Ascan Ave Forest Hills',
                    'city' => 'Ave Forest Hills',
            'country_id' => 'US',
            'region' => '43',
            'postcode' => '11701',
            'telephone' => 'XXXX',
            'fax' => '32423',
            'save_in_address_book' => 1
                 ],
   'items'=> [ //array of product which order you want to create
              ['product_id'=>'2','qty'=>1]
            ]
];

Tolong bantu saya dalam hal ini saya mencoba flat rate dan pengiriman gratis itu berfungsi tetapi FedEx tidak berfungsi.


1
Anda telah menetapkan berat dalam suatu produk yang sempurna tetapi Anda belum menetapkan berat paket penawaran. Karena Fedex ini Mengembalikan berat paket kutipan yang tidak valid. dengan hormat mengatur bobot sebelum memanggil fungsi "-> collectShippingRates ()" dan kembali -periksa
mudit-cedcommerce

Sudahkah Anda memeriksa nilai berat produk yang disimpan dalam basis data?
Anas Mansuri

Jawaban:


0

Buka katalog, pilih produk dan tambahkan bobot di bidang atribut berat.

Dengan menggunakan situs kami, Anda mengakui telah membaca dan memahami Kebijakan Cookie dan Kebijakan Privasi kami.
Licensed under cc by-sa 3.0 with attribution required.