Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
quote_with_bundle_and_options.php
Go to the documentation of this file.
1 <?php
7 require __DIR__ . '/../../../Magento/Bundle/_files/product_with_multiple_options.php';
8 
10 
12 $product = $objectManager->create(\Magento\Catalog\Model\Product::class);
13 $product->load(3);
14 
16 //Load options
17 $typeInstance = $product->getTypeInstance();
18 $typeInstance->setStoreFilter($product->getStoreId(), $product);
19 $optionCollection = $typeInstance->getOptionsCollection($product);
20 
24 foreach ($optionCollection as $option) {
25  $selectionsCollection = $typeInstance->getSelectionsCollection([$option->getId()], $product);
26  if ($option->isMultiSelection()) {
27  $bundleOptions[$option->getId()] = array_column($selectionsCollection->toArray(), 'selection_id');
28  } else {
29  $bundleOptions[$option->getId()] = $selectionsCollection->getFirstItem()->getSelectionId();
30  }
31  $bundleOptionsQty[$option->getId()] = 1;
32 }
33 
34 $requestInfo = new \Magento\Framework\DataObject(
35  ['qty' => 1, 'bundle_option' => $bundleOptions, 'bundle_option_qty' => $bundleOptionsQty]
36 );
37 
39 $quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
40 $quote->setStoreId(1)->setReservedOrderId('test_order_bundle')->save();
41 $quote->addProduct($product, $requestInfo);
42 $quote->save();
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
foreach($optionCollection as $option) $requestInfo