|
11 | 11 | );
|
12 | 12 |
|
13 | 13 | /** @var $product \Magento\Catalog\Model\Product */
|
14 |
| -$product = $objectManager->create('Magento\Catalog\Model\Product'); |
| 14 | +$product = $objectManager->create(\Magento\Catalog\Model\Product::class); |
15 | 15 | $product->setTypeId('virtual')
|
16 | 16 | ->setId(1)
|
17 | 17 | ->setAttributeSetId(4)
|
|
31 | 31 |
|
32 | 32 | $addressData = include __DIR__ . '/address_data.php';
|
33 | 33 |
|
34 |
| -$billingAddress = $objectManager->create('Magento\Quote\Model\Quote\Address', ['data' => $addressData]); |
| 34 | +$billingAddress = $objectManager->create(\Magento\Quote\Model\Quote\Address::class, ['data' => $addressData]); |
35 | 35 | $billingAddress->setAddressType('billing');
|
36 | 36 |
|
37 | 37 | $shippingAddress = clone $billingAddress;
|
38 | 38 | $shippingAddress->setId(null)->setAddressType('shipping');
|
39 | 39 | $shippingAddress->setShippingMethod('flatrate_flatrate');
|
40 | 40 |
|
41 | 41 | /** @var $quote \Magento\Quote\Model\Quote */
|
42 |
| -$quote = $objectManager->create('Magento\Quote\Model\Quote'); |
43 |
| -$quote->setCustomerIsGuest( |
44 |
| - true |
45 |
| -)->setStoreId( |
46 |
| - $objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getId() |
47 |
| -)->setReservedOrderId( |
48 |
| - '100000001' |
49 |
| -)->setBillingAddress( |
50 |
| - $billingAddress |
51 |
| -)->setShippingAddress( |
52 |
| - $shippingAddress |
53 |
| -)->addProduct( |
54 |
| - $product, |
55 |
| - 10 |
56 |
| -); |
| 42 | +$quote = $objectManager->create(\Magento\Quote\Model\Quote::class); |
| 43 | +$quote->setCustomerEmail('admin@example.com'); |
| 44 | +$quote->setCustomerIsGuest(true); |
| 45 | +$quote->setStoreId($objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)->getStore()->getId()); |
| 46 | +$quote->setReservedOrderId('100000001'); |
| 47 | +$quote->setBillingAddress($billingAddress); |
| 48 | +$quote->setShippingAddress($shippingAddress); |
57 | 49 | $quote->getPayment()->setMethod('checkmo');
|
58 | 50 | $quote->getShippingAddress()->setShippingMethod('flatrate_flatrate');
|
59 |
| -$quote->save(); |
60 |
| - |
61 | 51 | $quote->getShippingAddress()->setCollectShippingRates(true);
|
62 | 52 | $quote->getShippingAddress()->collectShippingRates();
|
63 |
| -$quote->collectTotals(); |
64 |
| -$quote->save(); |
65 | 53 |
|
66 |
| -$quote->setCustomerEmail('admin@example.com'); |
67 |
| -$quoteManagement = $objectManager->create('\Magento\Quote\Api\CartManagementInterface'); |
| 54 | +/** @var \Magento\Quote\Api\CartRepositoryInterface $quoteRepository */ |
| 55 | +$quoteRepository = $objectManager->create(\Magento\Quote\Api\CartRepositoryInterface::class); |
| 56 | +$quoteRepository->save($quote); |
| 57 | + |
| 58 | +/** @var \Magento\Quote\Api\Data\CartItemInterfaceFactory $cartItemFactory */ |
| 59 | +$cartItemFactory = $objectManager->get(\Magento\Quote\Api\Data\CartItemInterfaceFactory::class); |
| 60 | + |
| 61 | +/** @var \Magento\Quote\Api\Data\CartItemInterface $cartItem */ |
| 62 | +$cartItem = $cartItemFactory->create(); |
| 63 | +$cartItem->setQty(10); |
| 64 | +$cartItem->setQuoteId($quote->getId()); |
| 65 | +$cartItem->setSku($product->getSku()); |
| 66 | +$cartItem->setProductType(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE); |
| 67 | + |
| 68 | +/** @var \Magento\Quote\Api\CartItemRepositoryInterface $cartItemRepository */ |
| 69 | +$cartItemRepository = $objectManager->get(\Magento\Quote\Api\CartItemRepositoryInterface::class); |
| 70 | +$cartItemRepository->save($cartItem); |
| 71 | + |
| 72 | +/** @var \Magento\Quote\Api\CartManagementInterface $quoteManagement */ |
| 73 | +$quoteManagement = $objectManager->create(\Magento\Quote\Api\CartManagementInterface::class); |
68 | 74 |
|
| 75 | +$quote = $quoteRepository->get($quote->getId()); |
69 | 76 | $order = $quoteManagement->submit($quote, ['increment_id' => '100000001']);
|
70 | 77 |
|
71 | 78 | /** @var $item \Magento\Sales\Model\Order\Item */
|
72 | 79 | $item = $order->getAllItems()[0];
|
73 | 80 |
|
74 | 81 | /** @var \Magento\Sales\Model\Order\InvoiceFactory $invoiceFactory */
|
75 |
| -$invoiceFactory = $objectManager->get('Magento\Sales\Api\InvoiceManagementInterface'); |
| 82 | +$invoiceFactory = $objectManager->get(\Magento\Sales\Api\InvoiceManagementInterface::class); |
76 | 83 |
|
77 | 84 | /** @var $invoice \Magento\Sales\Model\Order\Invoice */
|
78 | 85 | $invoice = $invoiceFactory->prepareInvoice($order, [$item->getId() => 10]);
|
79 | 86 | $invoice->register();
|
80 | 87 | $invoice->save();
|
81 | 88 |
|
82 | 89 | /** @var \Magento\Sales\Model\Order\CreditmemoFactory $creditmemoFactory */
|
83 |
| -$creditmemoFactory = $objectManager->get('Magento\Sales\Model\Order\CreditmemoFactory'); |
| 90 | +$creditmemoFactory = $objectManager->get(\Magento\Sales\Model\Order\CreditmemoFactory::class); |
84 | 91 | $creditmemo = $creditmemoFactory->createByInvoice($invoice, ['qtys' => [$item->getId() => 5]]);
|
85 | 92 |
|
86 | 93 | foreach ($creditmemo->getAllItems() as $creditmemoItem) {
|
87 | 94 | //Workaround to return items to stock
|
88 | 95 | $creditmemoItem->setBackToStock(true);
|
89 | 96 | }
|
90 | 97 |
|
91 |
| -$creditmemoManagement = $objectManager->create('Magento\Sales\Api\CreditmemoManagementInterface'); |
| 98 | +$creditmemoManagement = $objectManager->create(\Magento\Sales\Api\CreditmemoManagementInterface::class); |
92 | 99 | $creditmemoManagement->refund($creditmemo);
|
0 commit comments