├── .gitignore
├── Iazel
└── RegenProductUrl
│ ├── Console
│ └── Command
│ │ └── RegenerateProductUrlCommand.php
│ ├── etc
│ ├── di.xml
│ └── module.xml
│ └── registration.php
├── LICENSE
├── README.md
└── composer.json
/.gitignore:
--------------------------------------------------------------------------------
1 | /.idea/
2 | /atlassian-ide-plugin.xml
3 | /composer.lock
4 | /vendor/
5 |
6 |
--------------------------------------------------------------------------------
/Iazel/RegenProductUrl/Console/Command/RegenerateProductUrlCommand.php:
--------------------------------------------------------------------------------
1 | state = $state;
45 | $this->collection = $collection;
46 | $this->productUrlRewriteGenerator = $productUrlRewriteGenerator;
47 | $this->urlPersist = $urlPersist;
48 | parent::__construct();
49 | }
50 |
51 | protected function configure()
52 | {
53 | $this->setName('iazel:regenurl')
54 | ->setDescription('Regenerate url for given products')
55 | ->addArgument(
56 | 'pids',
57 | InputArgument::IS_ARRAY,
58 | 'Products to regenerate'
59 | )
60 | ->addOption(
61 | 'store', 's',
62 | InputOption::VALUE_REQUIRED,
63 | 'Use the specific Store View',
64 | Store::DEFAULT_STORE_ID
65 | )
66 | ;
67 | return parent::configure();
68 | }
69 |
70 | public function execute(InputInterface $inp, OutputInterface $out)
71 | {
72 | if (!$this->state->getAreaCode()) {
73 | $this->state->setAreaCode('adminhtml');
74 | }
75 |
76 | $store_id = $inp->getOption('store');
77 | $this->collection->addStoreFilter($store_id)->setStoreId($store_id);
78 |
79 | $pids = $inp->getArgument('pids');
80 | if( !empty($pids) )
81 | $this->collection->addIdFilter($pids);
82 |
83 | $this->collection->addAttributeToSelect(['url_path', 'url_key']);
84 | $list = $this->collection->load();
85 | foreach($list as $product)
86 | {
87 | if($store_id === Store::DEFAULT_STORE_ID)
88 | $product->setStoreId($store_id);
89 |
90 | $this->urlPersist->deleteByData([
91 | UrlRewrite::ENTITY_ID => $product->getId(),
92 | UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE,
93 | UrlRewrite::REDIRECT_TYPE => 0,
94 | UrlRewrite::STORE_ID => $store_id
95 | ]);
96 | try {
97 | $this->urlPersist->replace(
98 | $this->productUrlRewriteGenerator->generate($product)
99 | );
100 | }
101 | catch(\Exception $e) {
102 | $out->writeln('Duplicated url for '. $product->getId() .'');
103 | }
104 | }
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/Iazel/RegenProductUrl/etc/di.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 | - Iazel\RegenProductUrl\Console\Command\RegenerateProductUrlCommand
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Iazel/RegenProductUrl/etc/module.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Iazel/RegenProductUrl/registration.php:
--------------------------------------------------------------------------------
1 | =100.1",
7 | "magento/module-catalog-url-rewrite": ">=100.1",
8 | "magento/magento-composer-installer": "*"
9 | },
10 | "type": "magento2-module",
11 | "version": "1.0.0.1",
12 | "license": [
13 | "OSL-3.0",
14 | "AFL-3.0"
15 | ],
16 | "autoload": {
17 | "files": [
18 | "Iazel/RegenProductUrl/registration.php"
19 | ],
20 | "psr-4": {
21 | "Iazel\\RegenProductUrl\\": "Iazel/RegenProductUrl"
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------