|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +use Magento\TestFramework\Helper\Bootstrap; |
| 7 | + |
| 8 | +Bootstrap::getInstance()->loadArea(Magento\Framework\App\Area::AREA_FRONTEND); |
| 9 | + |
| 10 | +$product = Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class); |
| 11 | +$product->setTypeId('simple') |
| 12 | + ->setId(1) |
| 13 | + ->setAttributeSetId(4) |
| 14 | + ->setName('Simple Product') |
| 15 | + ->setSku('simple') |
| 16 | + ->setPrice(10) |
| 17 | + ->setTaxClassId(0) |
| 18 | + ->setMetaTitle('meta title') |
| 19 | + ->setMetaKeyword('meta keyword') |
| 20 | + ->setMetaDescription('meta description') |
| 21 | + ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH) |
| 22 | + ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED) |
| 23 | + ->setStockData( |
| 24 | + [ |
| 25 | + 'qty' => 100, |
| 26 | + 'is_in_stock' => 1, |
| 27 | + ] |
| 28 | + ); |
| 29 | + |
| 30 | +/** @var Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ |
| 31 | +$productRepository = Bootstrap::getObjectManager() |
| 32 | + ->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); |
| 33 | +$product = $productRepository->save($product); |
| 34 | + |
| 35 | +$addressData = include __DIR__ . '/../../Sales/_files/address_data.php'; |
| 36 | +$billingAddress = Bootstrap::getObjectManager()->create( |
| 37 | + \Magento\Quote\Model\Quote\Address::class, |
| 38 | + ['data' => $addressData] |
| 39 | +); |
| 40 | +$billingAddress->setAddressType('billing'); |
| 41 | + |
| 42 | +$shippingAddress = clone $billingAddress; |
| 43 | +$shippingAddress->setId(null)->setAddressType('shipping'); |
| 44 | + |
| 45 | +/** @var \Magento\Store\Api\Data\StoreInterface $store */ |
| 46 | +$store = Magento\TestFramework\Helper\Bootstrap::getObjectManager() |
| 47 | + ->get(\Magento\Store\Model\StoreManagerInterface::class) |
| 48 | + ->getStore(); |
| 49 | + |
| 50 | +/** @var \Magento\Quote\Model\Shipping $shipping */ |
| 51 | +$shipping = Bootstrap::getObjectManager()->create(\Magento\Quote\Model\Shipping::class); |
| 52 | +$shipping->setAddress($shippingAddress); |
| 53 | +/** @var \Magento\Quote\Model\ShippingAssignment $shippingAssignment */ |
| 54 | +$shippingAssignment = Bootstrap::getObjectManager()->create(\Magento\Quote\Model\ShippingAssignment::class); |
| 55 | +$shippingAssignment->setItems([]); |
| 56 | +$shippingAssignment->setShipping($shipping); |
| 57 | +/** @var \Magento\Quote\Api\Data\CartExtension $extensionAttributes */ |
| 58 | +$extensionAttributes = Bootstrap::getObjectManager()->create(\Magento\Quote\Api\Data\CartExtension::class); |
| 59 | +$extensionAttributes->setShippingAssignments([$shippingAssignment]); |
| 60 | + |
| 61 | +/** @var \Magento\Quote\Model\Quote $quote */ |
| 62 | +$quote = Bootstrap::getObjectManager()->create(\Magento\Quote\Model\Quote::class); |
| 63 | +$quote->setCustomerIsGuest(true) |
| 64 | + ->setStoreId($store->getId()) |
| 65 | + ->setReservedOrderId('test01') |
| 66 | + ->setBillingAddress($billingAddress) |
| 67 | + ->setShippingAddress($shippingAddress) |
| 68 | + ->addProduct($product); |
| 69 | +$quote->getPayment()->setMethod('checkmo'); |
| 70 | +$quote->setIsMultiShipping('1'); |
| 71 | +$quote->collectTotals(); |
| 72 | +$quote->setExtensionAttributes($extensionAttributes); |
| 73 | +$quote->save(); |
| 74 | + |
| 75 | +/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ |
| 76 | +$quoteIdMask = Bootstrap::getObjectManager() |
| 77 | + ->create(\Magento\Quote\Model\QuoteIdMaskFactory::class) |
| 78 | + ->create(); |
| 79 | +$quoteIdMask->setQuoteId($quote->getId()); |
| 80 | +$quoteIdMask->setDataChanges(true); |
| 81 | +$quoteIdMask->save(); |
0 commit comments