/**
  * @return ShippingInterface|null
  */
 public function create()
 {
     $shipping = null;
     if ($this->getOrderId()) {
         $this->order = $this->orderFactory->create()->load($this->getOrderId());
         if ($this->order->getEntityId()) {
             /** @var ShippingInterface $shipping */
             $shipping = $this->shippingFactory->create();
             $shippingAddress = $this->order->getShippingAddress();
             if ($shippingAddress) {
                 $shipping->setAddress($shippingAddress);
             }
             $shipping->setMethod($this->order->getShippingMethod());
             $shipping->setTotal($this->getTotal());
         }
     }
     return $shipping;
 }
Example #2
0
 /**
  * @param \Magento\Sales\Model\Order $order
  * @return array|null
  */
 public function getShippingData(\Magento\Sales\Model\Order $order)
 {
     if ($order->getShippingMethod()) {
         $shippingInclTax = (double) $order->getShippingInclTax();
         if ($shippingInclTax) {
             return ['name' => __('Shipping Method') . ': ' . $order->getShippingDescription(), 'unitPrice' => $shippingInclTax * 100, 'quantity' => 1];
         }
     }
     return null;
 }
Example #3
0
/**
 * 2016-03-14
 * @param O $order
 * @return string
 */
function df_order_shipping_title(O $order)
{
    /**
     * 2016-07-02
     * Метод @uses \Magento\Sales\Model\Order::getShippingMethod()
     * некорректно работает с параметром $asObject = true при отсутствии у заказа способа доставки
     * (такое может быть, в частности, когда заказ содержит только виртуальные товары):
     * list($carrierCode, $method) = explode('_', $shippingMethod, 2);
     * Здесь $shippingMethod равно null, что приводит к сбою
     * Notice: Undefined offset: 1 in app/code/Magento/Sales/Model/Order.php on line 1203
     * https://github.com/magento/magento2/blob/2.1.0/app/code/Magento/Sales/Model/Order.php#L1191-L1206
     * Поэтому сначала смотрим, имеется ли у заказа способ доставки,
     * вызывая @uses \Magento\Sales\Model\Order::getShippingMethod() с параметром $asObject = false:
     */
    /** @var string $result */
    $result = '';
    if ($order->getShippingMethod()) {
        /** @var string $code */
        $code = $order->getShippingMethod($asObject = true)['method'];
        if ($code) {
            $result = df_cfg(df_cc_path('carriers', $code, 'title'));
        }
    }
    return $result;
}