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 $sampleRepository;
21 
26  {
27  $this->sampleRepository = $sampleRepository;
28  }
29 
36  public function execute($entity, $arguments = [])
37  {
39  if ($entity->getTypeId() != Type::TYPE_DOWNLOADABLE) {
40  return $entity;
41  }
42 
44  $samples = $entity->getExtensionAttributes()->getDownloadableProductSamples() ?: [];
45  $updatedSamples = [];
46  $oldSamples = $this->sampleRepository->getList($entity->getSku());
47  foreach ($samples as $sample) {
48  if ($sample->getId()) {
49  $updatedSamples[$sample->getId()] = true;
50  }
51  $this->sampleRepository->save($entity->getSku(), $sample, !(bool)$entity->getStoreId());
52  }
54  foreach ($oldSamples as $sample) {
55  if (!isset($updatedSamples[$sample->getId()])) {
56  $this->sampleRepository->delete($sample->getId());
57  }
58  }
59 
60  return $entity;
61  }
62 }
__construct(SampleRepository $sampleRepository)
$entity
Definition: element.phtml:22
$arguments