Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
OptionRepository Class Reference
Inheritance diagram for OptionRepository:
ProductOptionRepositoryInterface

Public Member Functions

 __construct (\Magento\Catalog\Api\ProductRepositoryInterface $productRepository, \Magento\Bundle\Model\Product\Type $type, \Magento\Bundle\Api\Data\OptionInterfaceFactory $optionFactory, \Magento\Bundle\Model\ResourceModel\Option $optionResource, \Magento\Bundle\Api\ProductLinkManagementInterface $linkManagement, \Magento\Bundle\Model\Product\OptionList $productOptionList, \Magento\Framework\Api\DataObjectHelper $dataObjectHelper, SaveAction $optionSave)
 
 getList ($sku)
 
 getListByProduct (ProductInterface $product)
 
 delete (\Magento\Bundle\Api\Data\OptionInterface $option)
 
 deleteById ($sku, $optionId)
 
 save (\Magento\Catalog\Api\Data\ProductInterface $product, \Magento\Bundle\Api\Data\OptionInterface $option)
 
- Public Member Functions inherited from ProductOptionRepositoryInterface
 get ($sku, $optionId)
 
 delete (\Magento\Bundle\Api\Data\OptionInterface $option)
 
 save (\Magento\Catalog\Api\Data\ProductInterface $product, \Magento\Bundle\Api\Data\OptionInterface $option)
 

Protected Attributes

 $productRepository
 
 $type
 
 $optionFactory
 
 $optionResource
 
 $linkManagement
 
 $productOptionList
 
 $dataObjectHelper
 

Detailed Description

Repository for performing CRUD operations for a bundle product's options.

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 20 of file OptionRepository.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Catalog\Api\ProductRepositoryInterface  $productRepository,
\Magento\Bundle\Model\Product\Type  $type,
\Magento\Bundle\Api\Data\OptionInterfaceFactory  $optionFactory,
\Magento\Bundle\Model\ResourceModel\Option  $optionResource,
\Magento\Bundle\Api\ProductLinkManagementInterface  $linkManagement,
\Magento\Bundle\Model\Product\OptionList  $productOptionList,
\Magento\Framework\Api\DataObjectHelper  $dataObjectHelper,
SaveAction  $optionSave 
)
Parameters
\Magento\Catalog\Api\ProductRepositoryInterface$productRepository
Product\Type$type
\Magento\Bundle\Api\Data\OptionInterfaceFactory$optionFactory
\Magento\Bundle\Model\ResourceModel\Option$optionResource
\Magento\Bundle\Api\ProductLinkManagementInterface$linkManagement
Product\OptionList$productOptionList
\Magento\Framework\Api\DataObjectHelper$dataObjectHelper
SaveAction$optionSave

Definition at line 72 of file OptionRepository.php.

81  {
82  $this->productRepository = $productRepository;
83  $this->type = $type;
84  $this->optionFactory = $optionFactory;
85  $this->optionResource = $optionResource;
86  $this->linkManagement = $linkManagement;
87  $this->productOptionList = $productOptionList;
88  $this->dataObjectHelper = $dataObjectHelper;
89  $this->optionSave = $optionSave;
90  }

Member Function Documentation

◆ delete()

{}

Definition at line 145 of file OptionRepository.php.

146  {
147  try {
148  $this->optionResource->delete($option);
149  } catch (\Exception $exception) {
150  throw new \Magento\Framework\Exception\StateException(
151  __('The option with "%1" ID can\'t be deleted.', $option->getOptionId()),
152  $exception
153  );
154  }
155  return true;
156  }
__()
Definition: __.php:13

◆ deleteById()

deleteById (   $sku,
  $id 
)

{Remove bundle option

Parameters
string$sku
int$optionId
Returns
bool
Exceptions
}

Implements ProductOptionRepositoryInterface.

Definition at line 161 of file OptionRepository.php.

162  {
163  $product = $this->getProduct($sku);
164  $optionCollection = $this->type->getOptionsCollection($product);
165  $optionCollection->setIdFilter($optionId);
166  $hasBeenDeleted = $this->delete($optionCollection->getFirstItem());
167 
168  return $hasBeenDeleted;
169  }

◆ getList()

getList (   $sku)

{Get all options for bundle product

Parameters
string$sku
Returns
\Magento\Bundle\Api\Data\OptionInterface[]
Exceptions
}

Implements ProductOptionRepositoryInterface.

Definition at line 127 of file OptionRepository.php.

128  {
129  $product = $this->getProduct($sku);
130  return $this->getListByProduct($product);
131  }
getListByProduct(ProductInterface $product)

◆ getListByProduct()

getListByProduct ( ProductInterface  $product)
Parameters
ProductInterface$product
Returns
\Magento\Bundle\Api\Data\OptionInterface[]

Definition at line 137 of file OptionRepository.php.

138  {
139  return $this->productOptionList->getItems($product);
140  }

◆ save()

{}

{} @SuppressWarnings(PHPMD.CyclomaticComplexity)

Definition at line 174 of file OptionRepository.php.

177  {
178  $savedOption = $this->optionSave->save($product, $option);
179 
180  $productToSave = $this->productRepository->get($product->getSku());
181  $this->productRepository->save($productToSave);
182 
183  return $savedOption->getOptionId();
184  }

Field Documentation

◆ $dataObjectHelper

$dataObjectHelper
protected

Definition at line 55 of file OptionRepository.php.

◆ $linkManagement

$linkManagement
protected

Definition at line 45 of file OptionRepository.php.

◆ $optionFactory

$optionFactory
protected

Definition at line 35 of file OptionRepository.php.

◆ $optionResource

$optionResource
protected

Definition at line 40 of file OptionRepository.php.

◆ $productOptionList

$productOptionList
protected

Definition at line 50 of file OptionRepository.php.

◆ $productRepository

$productRepository
protected

Definition at line 25 of file OptionRepository.php.

◆ $type

$type
protected

Definition at line 30 of file OptionRepository.php.


The documentation for this class was generated from the following file: