Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
OptionManagement.php
Go to the documentation of this file.
1 <?php
8 namespace Magento\Bundle\Model;
9 
11 
13 {
17  protected $optionRepository;
18 
22  protected $productRepository;
23 
28  public function __construct(
29  \Magento\Bundle\Api\ProductOptionRepositoryInterface $optionRepository,
31  ) {
32  $this->optionRepository = $optionRepository;
33  $this->productRepository = $productRepository;
34  }
35 
39  public function save(\Magento\Bundle\Api\Data\OptionInterface $option)
40  {
41  $product = $this->productRepository->get($option->getSku(), true);
42  if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
43  throw new InputException(__('This is implemented for bundle products only.'));
44  }
45  return $this->optionRepository->save($product, $option);
46  }
47 }
__()
Definition: __.php:13
__construct(\Magento\Bundle\Api\ProductOptionRepositoryInterface $optionRepository, \Magento\Catalog\Api\ProductRepositoryInterface $productRepository)
save(\Magento\Bundle\Api\Data\OptionInterface $option)