Skip to content

Commit 89e0481

Browse files
authored
Merge pull request #49 from xcom-magento/magento2
Add possibility to restore use default values for product or category
2 parents efce35c + cc64c97 commit 89e0481

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Console/Command/RestoreUseDefaultValueCommand.php

100644100755
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Magento\Framework\App\ProductMetadataInterface;
55
use Symfony\Component\Console\Command\Command;
66
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Input\InputOption;
78
use Symfony\Component\Console\Output\OutputInterface;
89
use Symfony\Component\Console\Question\ConfirmationQuestion;
910

@@ -35,7 +36,14 @@ protected function configure()
3536
->setDescription("
3637
Restore product's 'Use Default Value' if the non-global value is the same as the global value
3738
")
38-
->addOption('dry-run');
39+
->addOption('dry-run')
40+
->addOption(
41+
'entity',
42+
null,
43+
InputOption::VALUE_OPTIONAL,
44+
'Set entity to cleanup (product or category)',
45+
'product'
46+
);
3947
}
4048

4149
/**
@@ -49,6 +57,12 @@ protected function configure()
4957
public function execute(InputInterface $input, OutputInterface $output)
5058
{
5159
$isDryRun = $input->getOption('dry-run');
60+
$entity = $input->getOption('entity');
61+
62+
if (!in_array($entity, ['product', 'category'])) {
63+
$output->writeln('Please specify the entity with --entity. Possible options are product or category');
64+
return;
65+
}
5266

5367
if (!$isDryRun && $input->isInteractive()) {
5468
$output->writeln('WARNING: this is not a dry run. If you want to do a dry-run, add --dry-run.');
@@ -72,7 +86,7 @@ public function execute(InputInterface $input, OutputInterface $output)
7286

7387
foreach ($tables as $table) {
7488
// Select all non-global values
75-
$fullTableName = $db->getTableName('catalog_product_entity_' . $table);
89+
$fullTableName = $db->getTableName('catalog_' . $entity . '_entity_' . $table);
7690
$rows = $db->fetchAll('SELECT * FROM ' . $fullTableName . ' WHERE store_id != 0');
7791

7892
foreach ($rows as $row) {

composer.json

100644100755
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"magento/magento-composer-installer": "*"
88
},
99
"type": "magento2-module",
10-
"version": "1.1.0",
1110
"autoload": {
1211
"files": [
1312
"registration.php"

0 commit comments

Comments
 (0)