9 use Magento\Sales\Api\Data\ShippingInterfaceFactory;
11 use Magento\Sales\Api\Data\TotalInterfaceFactory;
13 use Magento\Sales\Model\OrderFactory;
24 private $orderId =
null;
34 private $orderFactory;
39 private $shippingFactory;
44 private $totalFactory;
54 OrderFactory $orderFactory,
55 ShippingInterfaceFactory $shippingFactory,
56 TotalInterfaceFactory $totalFactory
58 $this->orderFactory = $orderFactory;
59 $this->shippingFactory = $shippingFactory;
60 $this->totalFactory = $totalFactory;
69 $this->orderId = $orderId;
75 public function create()
78 if ($this->getOrderId()) {
79 $this->order = $this->orderFactory->create()->load($this->getOrderId());
80 if ($this->order->getEntityId()) {
82 $shipping = $this->shippingFactory->create();
87 $shipping->setMethod($this->order->getShippingMethod());
88 $shipping->setTotal($this->getTotal());
97 private function getOrderId()
99 return $this->orderId;
105 private function getTotal()
108 $total = $this->totalFactory->create();
109 $total->setBaseShippingAmount($this->order->getBaseShippingAmount());
110 $total->setBaseShippingCanceled($this->order->getBaseShippingCanceled());
111 $total->setBaseShippingDiscountAmount($this->order->getBaseShippingDiscountAmount());
112 $total->setBaseShippingDiscountTaxCompensationAmnt($this->order->getBaseShippingDiscountTaxCompensationAmnt());
113 $total->setBaseShippingInclTax($this->order->getBaseShippingInclTax());
114 $total->setBaseShippingInvoiced($this->order->getBaseShippingInvoiced());
115 $total->setBaseShippingRefunded($this->order->getBaseShippingRefunded());
116 $total->setBaseShippingTaxAmount($this->order->getBaseShippingTaxAmount());
117 $total->setBaseShippingTaxRefunded($this->order->getBaseShippingTaxRefunded());
118 $total->setShippingAmount($this->order->getShippingAmount());
119 $total->setShippingCanceled($this->order->getShippingCanceled());
120 $total->setShippingDiscountAmount($this->order->getShippingDiscountAmount());
121 $total->setShippingDiscountTaxCompensationAmount($this->order->getShippingDiscountTaxCompensationAmount());
122 $total->setShippingInclTax($this->order->getShippingInclTax());
123 $total->setShippingInvoiced($this->order->getShippingInvoiced());
124 $total->setShippingRefunded($this->order->getShippingRefunded());
125 $total->setShippingTaxAmount($this->order->getShippingTaxAmount());
126 $total->setShippingTaxRefunded($this->order->getShippingTaxRefunded());
__construct(OrderFactory $orderFactory, ShippingInterfaceFactory $shippingFactory, TotalInterfaceFactory $totalFactory)