Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
quote_with_product_and_custom_options.php
Go to the documentation of this file.
1 <?php
6 require __DIR__ . '/product_simple.php';
7 require __DIR__ . '/../../../Magento/Checkout/_files/active_quote.php';
8 
10  'field' => 'Test value',
11  'date_time' => [
12  'year' => '2015',
13  'month' => '9',
14  'day' => '9',
15  'hour' => '2',
16  'minute' => '2',
17  'day_part' => 'am',
18  'date_internal' => '',
19  ],
20  'drop_down' => '3-1-select',
21  'radio' => '4-1-radio',
22 ];
23 
25 
26 $productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
28 $product = $productRepository->get('simple');
29 
31 $quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
33 $quoteItemRepository = $objectManager->create(\Magento\Quote\Api\CartItemRepositoryInterface::class);
35 $cartItem = $objectManager->create(\Magento\Quote\Api\Data\CartItemInterface::class);
37 $productOption = $objectManager->create(\Magento\Quote\Model\Quote\ProductOptionFactory::class)->create();
39 $extensionAttributes = $objectManager->create(\Magento\Quote\Api\Data\ProductOptionExtensionFactory::class)->create();
40 $customOptionFactory = $objectManager->create(\Magento\Catalog\Model\CustomOptions\CustomOptionFactory::class);
41 $options = [];
43 foreach ($product->getOptions() as $option) {
46  $customOption->setOptionId($option->getId());
47  $customOption->setOptionValue($optionValue[$option->getType()]);
49 }
50 
51 $quote->load('test_order_1', 'reserved_order_id');
52 $cartItem->setQty(1);
53 $cartItem->setSku('simple');
54 $cartItem->setQuoteId($quote->getId());
55 
56 $extensionAttributes->setCustomOptions($options);
57 $productOption->setExtensionAttributes($extensionAttributes);
58 $cartItem->setProductOption($productOption);
59 
$customOption
Definition: products.php:73
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60