Skip to content
This repository was archived by the owner on Oct 19, 2022. It is now read-only.

Commit 630deb9

Browse files
authored
Merge pull request #136 from YouweGit/bug/export-command-backward-compatible
Bug/export command backward compatible
2 parents 75c5489 + d6e7aff commit 630deb9

File tree

2 files changed

+54
-26
lines changed

2 files changed

+54
-26
lines changed

Console/Command/ExportCommand.php

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -88,48 +88,70 @@ protected function execute(InputInterface $input, OutputInterface $output)
8888
Profiler::enable();
8989
Profiler::add(new ConsoleDriver($output));
9090
}
91+
9192
$isStoreLevelExportEnabled = $this->config->isStoreLevelExportEnabled();
9293
$storeCode = (string) $input->getOption('store');
93-
$stores = [];
94-
if ($storeCode && $isStoreLevelExportEnabled){
94+
$store = null;
95+
96+
$validate = (string)$input->getOption('validate');
97+
if ($validate !== 'y' && $validate !== 'n' && $validate !== "") {
98+
$output->writeln('Validate option can only contain y or n');
99+
100+
return -1;
101+
}
102+
103+
$validate = $validate === "" ? $this->config->isValidate() : $validate === 'y';
104+
$startTime = microtime(true);
105+
$feedFile = (string)$input->getOption('file');
106+
107+
if ($isStoreLevelExportEnabled) {
108+
if (!$storeCode) {
109+
$output->writeln('<error>Store level export enabled please provide --store <store-code></error>');
110+
111+
return -1;
112+
}
113+
95114
try {
96-
$stores[] = $this->storeManager->getStore($storeCode);
115+
$store = $this->storeManager->getStore($storeCode);
116+
} catch (NoSuchEntityException $exception) {
117+
$output->writeln('<error>Store does not exist</error>');
97118

98-
} catch (NoSuchEntityException $exception){
99-
$output->writeln('Store does not exist');
100119
return -1;
101120
}
102-
} else {
103-
$stores = $this->storeManager->getStores();
104-
}
105121

106-
foreach ($stores as $store) {
107122
if (!$this->config->isEnabled($store)) {
108-
continue;
123+
$output->writeln('<error>Tweakwise export does not enabled in this store</error>');
124+
125+
return -1;
109126
}
110-
$feedFile = (string)$input->getOption('file');
127+
111128
if (!$feedFile) {
112129
$feedFile = $this->config->getDefaultFeedFile($store);
113130
}
114131

115-
$validate = (string)$input->getOption('validate');
116-
if ($validate !== 'y' && $validate !== 'n' && $validate !== "") {
117-
$output->writeln('Validate option can only contain y or n');
118-
119-
return;
132+
$output->writeln("<info>generatig feed for {$store->getCode()}</info>");
133+
$this->export->generateToFile($feedFile, $validate, $store);
134+
$output->writeln("<info>feed file: {$feedFile}</info>");
135+
} else {
136+
if ($storeCode) {
137+
$output->writeln('<error>Store level export disabled, remove --store parameter</error>');
138+
return -1;
120139
}
121140

122-
$validate = $validate === "" ? $this->config->isValidate() : $validate === 'y';
141+
if (!$feedFile) {
142+
$feedFile = $this->config->getDefaultFeedFile();
143+
}
123144

124-
$startTime = microtime(true);
125-
$this->export->generateToFile($feedFile, $validate, $store);
126-
$generateTime = round(microtime(true) - $startTime, 2);
127-
$memoryUsage = round(memory_get_peak_usage(true) / 1024 / 1024,
128-
2);
129-
$output->writeln(sprintf('Feed written to %s in %ss using %sMb memory',
130-
$feedFile, $generateTime, $memoryUsage));
145+
$output->writeln("<info>generating single feed for export enabled stores</info>");
146+
$this->export->generateToFile($feedFile, $validate);
147+
$output->writeln("<info>feed file: {$feedFile}</info>");
131148
}
132-
});
133149

150+
$generateTime = round(microtime(true) - $startTime, 2);
151+
$memoryUsage = round(memory_get_peak_usage(true) / 1024 / 1024,
152+
2);
153+
$output->writeln(sprintf('Feed written to %s in %ss using %sMb memory',
154+
$feedFile, $generateTime, $memoryUsage));
155+
});
134156
}
135-
}
157+
}

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ Install package using zip file
1414
Extract tweakwise-export.zip src folder to app/code/Emico/TweakwiseExport/
1515
```
1616

17+
If 'Store Level Export' enabled single store feed can be generated using the command line.
18+
```sh
19+
php bin/magento tweakwise:export --store '<storecode>'
20+
```
21+
1722
Run installers
1823
```sh
1924
php bin/magento setup:upgrade
@@ -68,6 +73,7 @@ If you find an issue with data retrieval please create an issue on github.
6873
6974
7075
## Export Settings
76+
- Store Level Export: Enables generating seperate feed for each store
7177
- Enabled: If products of that store should be exported to tweakwise, note that if this is false for some store then navigation and search should also be disabled for that store.
7278
- Schedule: Cron schedule for generating the feed. We strongly encourage you to register the export task on the server crontab instead of using the Magento cron.
7379
- Schedule export: Generate the feed on the next cron run.

0 commit comments

Comments
 (0)