27 private $dataDifferenceCalculator;
34 private $processFactory;
41 private $storeManager;
55 private $cacheManager;
71 $this->dataDifferenceCalculator = $dataDifferenceCalculator;
72 $this->processFactory = $processFactory;
74 $this->cacheManager = $cacheManager;
84 public function import(array
$data)
91 $messages = [
'Stores were processed'];
94 $newGroups = $this->getGroupsToCreate(
$data);
97 $messages[] = sprintf(
98 $this->getStoreGroupAssignMessage(),
99 implode(
', ', array_column($newGroups,
'name'))
104 $this->reinitStores();
106 $this->resource->beginTransaction();
108 foreach ($actions as $action) {
109 $this->processFactory->create($action)->run(
$data);
111 }
catch (\Exception $exception) {
112 $this->resource->rollBack();
113 $this->reinitStores();
118 $this->resource->commit();
119 $this->reinitStores();
129 private function reinitStores()
131 $this->storeManager->reinitStores();
132 $this->cacheManager->clean();
140 private function getStoreGroupAssignMessage()
142 return 'The following new store groups must be associated with a root category: %s. ' 144 .
'Associate a store group with a root category in the Admin Panel: Stores > Settings > All Stores.';
153 private function getGroupsToCreate(array
$data)
159 $groups = $this->dataDifferenceCalculator->getItemsToCreate(
176 foreach (
$data as $scope => $scopeData) {
178 'These %s will be deleted: %s' => $this->dataDifferenceCalculator->getItemsToDelete($scope, $scopeData),
179 'These %s will be updated: %s' => $this->dataDifferenceCalculator->getItemsToUpdate($scope, $scopeData),
180 'These %s will be created: %s' => $this->dataDifferenceCalculator->getItemsToCreate($scope, $scopeData),
208 implode(
', ', array_column(
$items,
'name'))
__construct(DataDifferenceCalculator $dataDifferenceCalculator, ProcessorFactory $processFactory, StoreManagerInterface $storeManager, CacheInterface $cacheManager, Website $resource)
getWarningMessages(array $data)