Exemple #1
0
 /**
  * @param string $entityType
  * @param object $entity
  * @return object
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entityType, $entity)
 {
     /** @var \Magento\Catalog\Api\Data\ProductInterface $entity */
     foreach ($this->linkRepository->getList($entity->getSku()) as $link) {
         $this->linkRepository->delete($link->getId());
     }
     return $entity;
 }
 /**
  * @param object $entity
  * @param array $arguments
  * @return \Magento\Catalog\Api\Data\ProductInterface|object
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entity, $arguments = [])
 {
     if ($entity->getTypeId() != \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE) {
         return $entity;
     }
     /** @var \Magento\Catalog\Api\Data\ProductInterface $entity */
     foreach ($this->linkRepository->getList($entity->getSku()) as $link) {
         $this->linkRepository->delete($link->getId());
     }
     return $entity;
 }
 /**
  * @param string $entityType
  * @param object $entity
  * @return object
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entityType, $entity)
 {
     if ($entity->getTypeId() !== 'downloadable') {
         return $entity;
     }
     /** @var \Magento\Catalog\Api\Data\ProductInterface $entity */
     foreach ($this->linkRepository->getList($entity->getSku()) as $link) {
         $this->linkRepository->delete($link->getId());
     }
     $links = $entity->getExtensionAttributes()->getDownloadableProductLinks() ?: [];
     foreach ($links as $link) {
         $this->linkRepository->save($entity->getSku(), $link, !(bool) $entity->getStoreId());
     }
     return $entity;
 }
Exemple #4
0
 /**
  * @param string $entityType
  * @param object $entity
  * @param array $arguments
  * @return \Magento\Catalog\Api\Data\ProductInterface|object
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entityType, $entity, $arguments = [])
 {
     if ($entity->getTypeId() !== 'downloadable') {
         return $entity;
     }
     $links = $entity->getExtensionAttributes()->getDownloadableProductLinks() ?: [];
     $updatedLinks = [];
     $oldLinks = $this->linkRepository->getList($entity->getSku());
     foreach ($links as $link) {
         if ($link->getId()) {
             $updatedLinks[$link->getId()] = true;
         }
         $this->linkRepository->save($entity->getSku(), $link, !(bool) $entity->getStoreId());
     }
     /** @var \Magento\Catalog\Api\Data\ProductInterface $entity */
     foreach ($oldLinks as $link) {
         if (!isset($updatedLinks[$link->getId()])) {
             $this->linkRepository->delete($link->getId());
         }
     }
     return $entity;
 }