Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function update($productSku, $optionId, \Magento\Bundle\Service\V1\Data\Product\Option $option)
 {
     $product = $this->getProduct($productSku);
     $optionCollection = $this->type->getOptionsCollection($product);
     $optionCollection->setIdFilter($optionId);
     /** @var \Magento\Bundle\Model\Option $optionModel */
     $optionModel = $optionCollection->getFirstItem();
     $updateOption = $this->optionConverter->getModelFromData($option, $optionModel);
     if (!$updateOption->getId()) {
         throw new NoSuchEntityException('Requested option doesn\'t exist');
     }
     $updateOption->setStoreId($this->storeManager->getStore()->getId());
     /**
      * @var Link[] $existingProductLinks
      */
     $existingProductLinks = $optionModel->getProductLinks();
     if (!is_array($existingProductLinks)) {
         $existingProductLinks = array();
     }
     /**
      * @var Link[] $newProductLinks
      */
     $newProductLinks = $option->getProductLinks();
     if (is_null($newProductLinks)) {
         $newProductLinks = array();
     }
     /**
      * @var Link[] $linksToDelete
      */
     $linksToDelete = array_udiff($existingProductLinks, $newProductLinks, array($this, 'compareLinks'));
     foreach ($linksToDelete as $link) {
         $this->linkWriteService->removeChild($productSku, $option->getId(), $link->getSku());
     }
     /**
      * @var Link[] $linksToAdd
      */
     $linksToAdd = array_udiff($newProductLinks, $existingProductLinks, array($this, 'compareLinks'));
     foreach ($linksToAdd as $link) {
         $this->linkWriteService->addChild($productSku, $option->getId(), $link);
     }
     try {
         $updateOption->save();
     } catch (\Exception $e) {
         throw new CouldNotSaveException('Could not save option', [], $e);
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function update($productSku, $optionId, \Magento\Bundle\Service\V1\Data\Product\Option $option)
 {
     $product = $this->getProduct($productSku);
     $optionCollection = $this->type->getOptionsCollection($product);
     $optionCollection->setIdFilter($optionId);
     /** @var \Magento\Bundle\Model\Option $optionModel */
     $optionModel = $optionCollection->getFirstItem();
     $updateOption = $this->optionConverter->getModelFromData($option, $optionModel);
     if (!$updateOption->getId()) {
         throw new NoSuchEntityException('Requested option doesn\'t exist');
     }
     $updateOption->setStoreId($this->storeManager->getStore()->getId());
     try {
         $updateOption->save();
     } catch (\Exception $e) {
         throw new CouldNotSaveException('Could not save option', [], $e);
     }
     return true;
 }