コード例 #1
0
 /**
  * Set shipping information to quote
  *
  * @param OrderInjectable $order
  * @throws \Exception
  */
 protected function setShippingInformation(OrderInjectable $order)
 {
     if (!$order->hasData('shipping_method')) {
         return;
     }
     $url = $this->url . '/shipping-information';
     list($carrier, $method) = explode('_', $order->getShippingMethod());
     $address = $order->hasData('shipping_address_id') ? $order->getShippingAddressId() : $order->getBillingAddressId();
     unset($address['default_billing']);
     unset($address['default_shipping']);
     foreach (array_keys($this->mappingData) as $key) {
         if (isset($address[$key])) {
             $address[$key] = $this->mappingData[$key][$address[$key]];
         }
     }
     $data = ['addressInformation' => ['shippingAddress' => $address, 'shippingMethodCode' => $method, 'shippingCarrierCode' => $carrier]];
     $this->webapiTransport->write($url, $data, WebapiDecorator::POST);
     $response = json_decode($this->webapiTransport->read(), true);
     $this->webapiTransport->close();
     if (!isset($response['payment_methods'], $response['totals'])) {
         $this->eventManager->dispatchEvent(['webapi_failed'], [$response]);
         throw new \Exception('Could not set shipping method to quote!');
     }
 }
コード例 #2
0
ファイル: Webapi.php プロジェクト: whoople/magento2-testing
 /**
  * Set shipping method to quote.
  *
  * @param OrderInjectable $order
  * @return void
  * @throws \Exception
  */
 protected function setShippingMethod(OrderInjectable $order)
 {
     if (!$order->hasData('shipping_method')) {
         return;
     }
     $url = $this->url . '/selected-shipping-method';
     list($carrier, $method) = explode('_', $order->getShippingMethod());
     $data = ["carrierCode" => $carrier, "methodCode" => $method];
     $this->webapiTransport->write($url, $data, WebapiDecorator::PUT);
     $response = json_decode($this->webapiTransport->read(), true);
     $this->webapiTransport->close();
     if ($response !== true) {
         $this->eventManager->dispatchEvent(['webapi_failed'], [$response]);
         throw new \Exception('Could not set shipping method to quote!');
     }
 }