89 $this->optionSave = $optionSave;
103 __(
"The option that was requested doesn't exist. Verify the entity and try again.")
107 $productLinks = $this->linkManagement->getChildren(
$product->getSku(),
$optionId);
110 $optionDataObject = $this->optionFactory->create();
111 $this->dataObjectHelper->populateWithArray(
114 \Magento\Bundle\Api\Data\OptionInterface::class
116 $optionDataObject->setOptionId(
$option->getId())
119 ->setProductLinks($productLinks);
121 return $optionDataObject;
139 return $this->productOptionList->getItems(
$product);
148 $this->optionResource->delete(
$option);
150 throw new \Magento\Framework\Exception\StateException(
151 __(
'The option with "%1" ID can\'t be deleted.',
$option->getOptionId()),
168 return $hasBeenDeleted;
180 $productToSave = $this->productRepository->get(
$product->getSku());
181 $this->productRepository->save($productToSave);
183 return $savedOption->getOptionId();
193 protected function updateOptionSelection(
198 $existingLinks = $this->linkManagement->getChildren(
$product->getSku(),
$optionId);
202 if (is_array(
$option->getProductLinks())) {
203 $productLinks =
$option->getProductLinks();
212 $linksToDelete = $this->compareLinks($existingLinks, $linksToUpdate);
218 $this->linkManagement->removeChild(
235 private function getProduct($sku)
237 $product = $this->productRepository->get($sku,
true,
null,
true);
238 if (
$product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
239 throw new InputException(
__(
'This is implemented for bundle products only.'));
252 private function compareLinks(array $firstArray, array $secondArray)
259 $secondArrayIds = [];
261 foreach ($firstArray as
$item) {
262 $firstArrayIds[] =
$item->getId();
267 foreach ($secondArray as
$item) {
268 $secondArrayIds[] =
$item->getId();
271 foreach (array_diff($firstArrayIds, $secondArrayIds) as
$id) {
__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)
getListByProduct(ProductInterface $product)
deleteById($sku, $optionId)
save(\Magento\Catalog\Api\Data\ProductInterface $product, \Magento\Bundle\Api\Data\OptionInterface $option)