|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +// @codingStandardsIgnoreFile |
| 8 | + |
| 9 | +require __DIR__ . '/configurable_products.php'; |
| 10 | + |
| 11 | +/** @var \Magento\Quote\Model\Quote $quote */ |
| 12 | +$quote = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Quote\Model\Quote::class); |
| 13 | + |
| 14 | +$product = $productRepository->getById(10); |
| 15 | +$product->setStockData(['use_config_manage_stock' => 1, 'qty' => 1, 'is_qty_decimal' => 0, 'is_in_stock' => 1]); |
| 16 | +$productRepository->save($product); |
| 17 | + |
| 18 | +$product = $productRepository->getById(20); |
| 19 | +$product->setStockData(['use_config_manage_stock' => 1, 'qty' => 0, 'is_qty_decimal' => 0, 'is_in_stock' => 0]); |
| 20 | +$productRepository->save($product); |
| 21 | + |
| 22 | +/** @var \Magento\Quote\Model\Quote $quote */ |
| 23 | +$quote = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Quote\Model\Quote::class); |
| 24 | +$request = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Framework\DataObject::class); |
| 25 | + |
| 26 | +/** @var \Magento\Eav\Model\Config $eavConfig */ |
| 27 | +$eavConfig = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Eav\Model\Config::class); |
| 28 | +/** @var $attribute */ |
| 29 | +$attribute = $eavConfig->getAttribute('catalog_product', 'test_configurable'); |
| 30 | + |
| 31 | +$request->setData( |
| 32 | + [ |
| 33 | + 'product_id' => $productRepository->get('configurable')->getId(), |
| 34 | + 'selected_configurable_option' => '1', |
| 35 | + 'super_attribute' => [ |
| 36 | + $attribute->getAttributeId() => $attribute->getOptions()[1]->getValue() |
| 37 | + ], |
| 38 | + 'qty' => '1' |
| 39 | + ] |
| 40 | +); |
| 41 | + |
| 42 | +$quote->setStoreId( |
| 43 | + 1 |
| 44 | + )->setIsActive( |
| 45 | + true |
| 46 | + )->setIsMultiShipping( |
| 47 | + false |
| 48 | + )->setReservedOrderId( |
| 49 | + 'test_order_with_configurable_product' |
| 50 | + )->setEmail( |
| 51 | + 'store@example.com' |
| 52 | + )->addProduct( |
| 53 | + $productRepository->get('configurable'), |
| 54 | + $request |
| 55 | + ); |
| 56 | + |
| 57 | +/** @var \Magento\Quote\Model\QuoteRepository $quoteRepository */ |
| 58 | +$quoteRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( |
| 59 | + \Magento\Quote\Model\QuoteRepository::class |
| 60 | +); |
| 61 | +$quote->collectTotals(); |
| 62 | +$quoteRepository->save($quote); |
| 63 | + |
| 64 | +/** @var \Magento\Checkout\Model\Session $session */ |
| 65 | +$session = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( |
| 66 | + \Magento\Checkout\Model\Session::class |
| 67 | +); |
| 68 | +$session->setQuoteId($quote->getId()); |
0 commit comments