Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
virtual_quote_with_empty_billing_address.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
21 
22 require __DIR__ . '/../../Customer/_files/customer.php';
23 
24 Bootstrap::getInstance()->loadArea('adminhtml');
25 $objectManager = Bootstrap::getObjectManager();
26 
28 $customerRepository = $objectManager->create(CustomerRepositoryInterface::class);
30 
32 $product = $objectManager->create(Product::class);
33 $product->isObjectNew(true);
34 $product->setTypeId(Type::TYPE_VIRTUAL)
35  ->setAttributeSetId(4)
36  ->setWebsiteIds([1])
37  ->setName('Virtual Product')
38  ->setSku('virtual-product-express')
39  ->setPrice(10)
40  ->setWeight(1)
41  ->setVisibility(Visibility::VISIBILITY_BOTH)
42  ->setStatus(Status::STATUS_ENABLED);
43 
45 $stockItem = $objectManager->create(StockItemInterface::class);
46 $stockItem->setQty(100)
47  ->setIsInStock(true);
48 $extensionAttributes = $product->getExtensionAttributes();
49 $extensionAttributes->setStockItem($stockItem);
50 
52 $productRepository = $objectManager->create(ProductRepositoryInterface::class);
54 
55 $billingAddress = $objectManager->create(Address::class);
56 $billingAddress->setAddressType('billing');
57 
59 $quote = $objectManager->create(Quote::class);
60 $quote->setCustomerIsGuest(false)
61  ->setCustomerId($customer->getId())
62  ->setCustomer($customer)
63  ->setStoreId($objectManager->get(StoreManagerInterface::class)->getStore()->getId())
64  ->setReservedOrderId('test02')
65  ->setBillingAddress($billingAddress);
66 $item = $objectManager->create(Item::class);
67 $item->setProduct($product)
68  ->setPrice($product->getPrice())
69  ->setQty(1);
70 $quote->addItem($item);
71 $quote->getPayment()->setMethod(\Magento\Paypal\Model\Config::METHOD_EXPRESS);
72 
74 $quoteRepository = $objectManager->create(CartRepositoryInterface::class);
76 $quote = $quoteRepository->get($quote->getId());
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60