|
20 | 20 |
|
21 | 21 | Bootstrap::getInstance()->loadArea('frontend');
|
22 | 22 | $objectManager = Bootstrap::getObjectManager();
|
23 |
| -$productRepository = $objectManager |
24 |
| - ->create(ProductRepositoryInterface::class); |
25 |
| -$firstProduct = $objectManager->create(Product::class); |
26 |
| -$firstProduct->setTypeId(Type::TYPE_SIMPLE) |
27 |
| - ->setCategoryIds([3]) |
28 |
| - ->setId(123) |
| 23 | + |
| 24 | +$simpleProduct = $objectManager->create(Product::class) |
| 25 | + ->setTypeId(Type::TYPE_SIMPLE) |
29 | 26 | ->setAttributeSetId(4)
|
30 |
| - ->setName('First Test Product For TableRate') |
31 |
| - ->setSku('tableRate-1') |
32 |
| - ->setPrice(40) |
33 |
| - ->setTaxClassId(0) |
34 |
| - ->setMetaTitle('meta title') |
35 |
| - ->setMetaKeyword('meta keyword') |
36 |
| - ->setMetaDescription('meta description') |
| 27 | + ->setWebsiteIds([1]) |
| 28 | + ->setName('Simple Product') |
| 29 | + ->setSku('simple-1') |
| 30 | + ->setPrice(10) |
37 | 31 | ->setVisibility(Visibility::VISIBILITY_BOTH)
|
38 | 32 | ->setStatus(Status::STATUS_ENABLED)
|
39 |
| - ->setStockData( |
40 |
| - [ |
41 |
| - 'qty' => 100, |
42 |
| - 'is_in_stock' => 1, |
43 |
| - 'manage_stock' => 1, |
44 |
| - ] |
45 |
| - ) |
| 33 | + ->setCategoryIds([2]) |
| 34 | + ->setStockData([ |
| 35 | + 'use_config_manage_stock' => 1, |
| 36 | + 'qty' => 100, |
| 37 | + 'is_qty_decimal' => 0, |
| 38 | + 'is_in_stock' => 1, |
| 39 | + ]) |
46 | 40 | ->save();
|
47 | 41 |
|
48 |
| -/** @var ProductRepositoryInterface $productRepository */ |
49 |
| -$firstProduct = $productRepository->save($firstProduct); |
| 42 | +$productRepository = $objectManager->get(ProductRepositoryInterface::class); |
| 43 | +$productRepository->save($simpleProduct); |
50 | 44 |
|
51 |
| -$secondProduct = $objectManager->create(Product::class); |
52 |
| -$secondProduct->setTypeId(Type::TYPE_VIRTUAL) |
53 |
| - ->setCategoryIds([6]) |
54 |
| - ->setId(124) |
| 45 | +$virtualProduct = $objectManager->create(Product::class) |
| 46 | + ->setTypeId(Type::TYPE_VIRTUAL) |
55 | 47 | ->setAttributeSetId(4)
|
56 |
| - ->setName('Second Test Product For TableRate') |
57 |
| - ->setSku('tableRate-2') |
58 |
| - ->setPrice(20) |
59 |
| - ->setTaxClassId(0) |
60 |
| - ->setMetaTitle('meta title') |
61 |
| - ->setMetaKeyword('meta keyword') |
62 |
| - ->setMetaDescription('meta description') |
| 48 | + ->setWebsiteIds([1]) |
| 49 | + ->setName('Virtual Product') |
| 50 | + ->setSku('virtual-1') |
| 51 | + ->setPrice(10) |
63 | 52 | ->setVisibility(Visibility::VISIBILITY_BOTH)
|
64 | 53 | ->setStatus(Status::STATUS_ENABLED)
|
65 |
| - ->setStockData( |
66 |
| - [ |
67 |
| - 'qty' => 100, |
68 |
| - 'is_in_stock' => 1, |
69 |
| - 'manage_stock' => 1, |
70 |
| - ] |
71 |
| - ) |
| 54 | + ->setCategoryIds([2]) |
| 55 | + ->setStockData([ |
| 56 | + 'use_config_manage_stock' => 1, |
| 57 | + 'qty' => 100, |
| 58 | + 'is_qty_decimal' => 0, |
| 59 | + 'is_in_stock' => 1, |
| 60 | + ]) |
72 | 61 | ->save();
|
73 | 62 |
|
74 |
| -/** @var ProductRepositoryInterface $productRepository */ |
75 |
| -$secondProduct = $productRepository->save($secondProduct); |
| 63 | +$productRepository->save($virtualProduct); |
76 | 64 |
|
77 | 65 | $addressData = include __DIR__ . '/address_data.php';
|
78 |
| -$billingAddress = $objectManager->create( |
79 |
| - Address::class, |
80 |
| - ['data' => $addressData] |
81 |
| -); |
| 66 | +$billingAddress = $objectManager->create(Address::class, ['data' => $addressData]); |
82 | 67 | $billingAddress->setAddressType('billing');
|
83 | 68 |
|
84 |
| -$shippingAddress = $objectManager->create( |
85 |
| - Address::class, |
86 |
| - ['data' => $addressData] |
87 |
| -); |
88 |
| -$shippingAddress->setAddressType('shipping'); |
89 |
| - |
90 |
| -$store = $objectManager |
91 |
| - ->get(StoreManagerInterface::class) |
92 |
| - ->getStore(); |
| 69 | +/** @var Address $shippingAddress */ |
| 70 | +$shippingAddress = clone $billingAddress; |
| 71 | +$shippingAddress->setId(null)->setAddressType('shipping'); |
93 | 72 |
|
94 | 73 | /** @var Quote $quote */
|
95 | 74 | $quote = $objectManager->create(Quote::class);
|
96 |
| -$quote->setCustomerIsGuest(true) |
97 |
| - ->setStoreId($store->getId()) |
| 75 | +$quote |
| 76 | + ->setCustomerIsGuest(true) |
| 77 | + ->setStoreId($objectManager->get(StoreManagerInterface::class)->getStore()->getId()) |
98 | 78 | ->setReservedOrderId('quoteWithVirtualProduct')
|
99 | 79 | ->setBillingAddress($billingAddress)
|
100 |
| - ->setShippingAddress($shippingAddress); |
| 80 | + ->setShippingAddress($shippingAddress) |
| 81 | + ->setCustomerEmail('test@test.magento.com'); |
| 82 | +$quote->addProduct($simpleProduct); |
| 83 | +$quote->addProduct($virtualProduct); |
| 84 | + |
| 85 | +$quote->getShippingAddress()->setShippingMethod('tablerate_bestway'); |
101 | 86 | $quote->getPayment()->setMethod('checkmo');
|
102 |
| -$quote->addProduct($firstProduct); |
103 |
| -$quote->addProduct($secondProduct); |
104 |
| -$quote->setIsMultiShipping(0); |
| 87 | +$quote->collectTotals(); |
105 | 88 |
|
106 | 89 | $quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
107 | 90 | $quoteRepository->save($quote);
|
108 | 91 |
|
109 | 92 | /** @var QuoteIdMask $quoteIdMask */
|
110 |
| -$quoteIdMask = $objectManager |
111 |
| - ->create(QuoteIdMaskFactory::class) |
112 |
| - ->create(); |
113 |
| -$quoteIdMask->setQuoteId($quote->getId()) |
| 93 | +$quoteIdMask = $objectManager->create(QuoteIdMaskFactory::class)->create(); |
| 94 | +$quoteIdMask |
| 95 | + ->setQuoteId($quote->getId()) |
114 | 96 | ->setDataChanges(true)
|
115 | 97 | ->save();
|
0 commit comments