Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SynchronizeWebsiteAttributesOnStoreChange.php
Go to the documentation of this file.
1 <?php
8 
13 
19 {
23  private $synchronizer;
24 
29  public function __construct(WebsiteAttributesSynchronizer $synchronizer)
30  {
31  $this->synchronizer = $synchronizer;
32  }
33 
37  public function execute(Observer $observer)
38  {
39  $store = $observer->getData('data_object');
40  if (!$store instanceof Store) {
41  return;
42  }
43 
44  if (!$store->hasDataChanges()) {
45  return;
46  }
47 
48  $isWebsiteIdChanged = $store->getOrigData('website_id') != $store->getWebsiteId();
49  $isStoreNew = $store->isObjectNew();
50 
51  if ($isWebsiteIdChanged || $isStoreNew) {
52  $this->synchronizer->scheduleSynchronization();
53  }
54  }
55 }