Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
quote_with_items_and_custom_options_saved.php
Go to the documentation of this file.
1 <?php
8 
9 require __DIR__ . '/../../Checkout/_files/quote_with_address.php';
10 require __DIR__ . '/../../Catalog/_files/product_with_options.php';
11 require __DIR__ . '/../../Checkout/_files/ValidatorFileMock.php';
12 
15 $productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
16 $product = $productRepository->get('simple');
17 
18 $options = [];
20 foreach ($product->getOptions() as $option) {
21  switch ($option->getGroupByType()) {
22  case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_DATE:
23  $value = ['year' => 2013, 'month' => 8, 'day' => 9, 'hour' => 13, 'minute' => 35];
24  break;
25  case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_SELECT:
26  $value = key($option->getValues());
27  break;
28  case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_FILE:
29  $value = 'test.jpg';
30  break;
31  default:
32  $value = 'test';
33  break;
34  }
35  $options[$option->getId()] = $value;
36 }
37 
38 $requestInfo = new \Magento\Framework\DataObject(['qty' => 1, 'options' => $options]);
39 $validatorFile = (new ValidatorFileMock())->getInstance();
40 $objectManager->addSharedInstance($validatorFile, \Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile::class);
41 
42 
43 $quote->setReservedOrderId('test_order_item_with_items_and_custom_options');
44 $quote->addProduct($product, $requestInfo);
45 $quote->collectTotals();
46 $objectManager->get(\Magento\Quote\Model\QuoteRepository::class)->save($quote);
47 
50  ->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
51  ->create();
52 $quoteIdMask->setQuoteId($quote->getId());
53 $quoteIdMask->setDataChanges(true);
54 $quoteIdMask->save();
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$quote
$value
Definition: gender.phtml:16
foreach($product->getOptions() as $option) $requestInfo