Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
wishlist_shared.php
Go to the documentation of this file.
1 <?php
7 require __DIR__ . '/../../../Magento/Customer/_files/customer.php';
8 require __DIR__ . '/../../../Magento/Catalog/_files/product_simple.php';
9 
11 $simpleProduct = $product->load($product->getId());
12 
13 $options = [];
14 foreach ($simpleProduct->getOptions() as $option) {
15  /* @var $option \Magento\Catalog\Model\Product\Option */
16  switch ($option->getType()) {
17  case 'field':
18  $options[$option->getId()] = '1-text';
19  break;
20  case 'date_time':
21  $options[$option->getId()] = ['month' => 1, 'day' => 1, 'year' => 2001, 'hour' => 1, 'minute' => 1];
22  break;
23  case 'drop_down':
24  $options[$option->getId()] = '1';
25  break;
26  case 'radio':
27  $options[$option->getId()] = '1';
28  break;
29  }
30 }
31 
32 /* @var $wishlist \Magento\Wishlist\Model\Wishlist */
34  \Magento\Wishlist\Model\Wishlist::class
35 );
36 $wishlist->loadByCustomerId($customer->getId(), true);
37 $wishlist->addNewItem($simpleProduct, new \Magento\Framework\DataObject(['options' => $options]));
38 $wishlist->setSharingCode('fixture_unique_code')
39  ->setShared(1)
40  ->save();
$customer
Definition: customers.php:11
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
foreach($simpleProduct->getOptions() as $option) $wishlist
$options
$simpleProduct