Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
quote_with_simple_product_and_custom_option.php
Go to the documentation of this file.
1 <?php
7 require __DIR__ . '/../../../Magento/Catalog/_files/product_simple.php';
8 
11  ->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
12 $product = $productRepository->get('simple');
13 
14 $options = [];
16 foreach ($product->getOptions() as $option) {
17  switch ($option->getGroupByType()) {
18  case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_DATE:
19  $value = ['year' => 2013, 'month' => 8, 'day' => 9, 'hour' => 13, 'minute' => 35];
20  break;
21  case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_SELECT:
22  $value = key($option->getValues());
23  break;
24  default:
25  $value = 'test';
26  break;
27  }
28  $options[$option->getId()] = $value;
29 }
30 
31 $requestInfo = new \Magento\Framework\DataObject(['qty' => 1, 'options' => $options]);
32 
35 $cart->addProduct($product, $requestInfo);
36 $cart->save();
37 
40 $objectManager->removeSharedInstance(\Magento\Checkout\Model\Session::class);
foreach($product->getOptions() as $option) $requestInfo
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$value
Definition: gender.phtml:16