/** * {@inheritdoc} */ public function getProductOptions(ProductInterface $product, $requiredOnly = false) { return $this->getCollectionFactory()->create()->getProductOptions($product->getEntityId(), $product->getStoreId(), $requiredOnly); }
/** * {@inheritdoc} */ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, \Magento\Bundle\Api\Data\OptionInterface $option) { $metadata = $this->getMetadataPool()->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class); $option->setStoreId($product->getStoreId()); $option->setParentId($product->getData($metadata->getLinkField())); $linksToAdd = []; $option->setDefaultTitle($option->getDefaultTitle() ?: $option->getTitle()); if (is_array($option->getProductLinks())) { $linksToAdd = $option->getProductLinks(); } try { $this->optionResource->save($option); } catch (\Exception $e) { throw new CouldNotSaveException(__('Could not save option'), $e); } /** @var \Magento\Bundle\Api\Data\LinkInterface $linkedProduct */ foreach ($linksToAdd as $linkedProduct) { $this->linkManagement->addChild($product, $option->getOptionId(), $linkedProduct); } $product->setIsRelationsChanged(true); return $option->getOptionId(); }