Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpdateHandler.php
Go to the documentation of this file.
1 <?php
7 
11 
16 {
20  protected $linkRepository;
21 
26  {
27  $this->linkRepository = $linkRepository;
28  }
29 
36  public function execute($entity, $arguments = [])
37  {
39  if ($entity->getTypeId() != Type::TYPE_DOWNLOADABLE) {
40  return $entity;
41  }
42 
44  $links = $entity->getExtensionAttributes()->getDownloadableProductLinks() ?: [];
45  $updatedLinks = [];
46  $oldLinks = $this->linkRepository->getList($entity->getSku());
47  foreach ($links as $link) {
48  if ($link->getId()) {
49  $updatedLinks[$link->getId()] = true;
50  }
51  $this->linkRepository->save($entity->getSku(), $link, !(bool)$entity->getStoreId());
52  }
54  foreach ($oldLinks as $link) {
55  if (!isset($updatedLinks[$link->getId()])) {
56  $this->linkRepository->delete($link->getId());
57  }
58  }
59 
60  return $entity;
61  }
62 }
$entity
Definition: element.phtml:22
$arguments