Skip to content

Commit 0245cd2

Browse files
committed
Updated logic of Url Rewrite regeneration via category entity. Fixed compilation issue in helper.
1 parent fb037a1 commit 0245cd2

7 files changed

+23
-15
lines changed

.github/FUNDING.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
patreon: olegkoval
2+
custom: ["https://api.fondy.eu/s/aeOD4YCieqKE7U", Fondy]

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [1.5.5] - 2020-04-02
8+
### Changed
9+
- updated logic of Url Rewrite regeneration via category entity
10+
- fixed compilation issue in helper
11+
712
## [1.5.4] - 2020-03-21
813
### Changed
914
- fixed issue of non-empty/non-false "request_path" of product entity.

Helper/Regenerate.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ class Regenerate extends \Magento\Framework\App\Helper\AbstractHelper
3333
*/
3434
public function __construct(
3535
Context $context,
36-
StoreManagerInterface $storeManager,
37-
ScopeConfigInterface $scopeConfig
36+
StoreManagerInterface $storeManager
3837
)
3938
{
4039
parent::__construct($context);
4140
$this->storeManager = $storeManager;
42-
$this->scopeConfig = $scopeConfig;
41+
$this->scopeConfig = $context->getScopeConfig();
4342
}
4443

4544
/**
@@ -51,8 +50,7 @@ public function getSupportMeText()
5150
return [
5251
'Please, support me on:',
5352
'https://www.patreon.com/olegkoval',
54-
'You can hire me via Upwork:',
55-
'https://www.upwork.com/o/profiles/users/~01a40656da65c38d3a/'
53+
'https://api.fondy.eu/s/aeOD4YCieqKE7U'
5654
];
5755
}
5856

Model/RegenerateCategoryRewrites.php

+11-7
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,14 @@ protected function categoryProcess($category, $storeId = 0)
223223
$this->saveUrlRewrites($categoryUrlRewriteResult);
224224
}
225225

226-
$productsIds = $this->_getCategoriesProductsIds($category->getAllChildren());
227-
if (!empty($productsIds)) {
228-
$this->regenerateProductRewrites->regenerateOptions = $this->regenerateOptions;
229-
$this->regenerateProductRewrites->regenerateOptions['showProgress'] = false;
230-
$this->regenerateProductRewrites->regenerateProductsRangeUrlRewrites($productsIds, $storeId);
226+
// if config option "Use Categories Path for Product URLs" is "Yes" then regenerate product urls
227+
if ($this->helper->useCategoriesPathForProductUrls($storeId)) {
228+
$productsIds = $this->_getCategoriesProductsIds($category->getAllChildren());
229+
if (!empty($productsIds)) {
230+
$this->regenerateProductRewrites->regenerateOptions = $this->regenerateOptions;
231+
$this->regenerateProductRewrites->regenerateOptions['showProgress'] = false;
232+
$this->regenerateProductRewrites->regenerateProductsRangeUrlRewrites($productsIds, $storeId);
233+
}
231234
}
232235

233236
//frees memory for maps that are self-initialized in multiple classes that were called by the generators
@@ -247,11 +250,12 @@ protected function categoryProcess($category, $storeId = 0)
247250
protected function _getCategoriesCollection($categoriesFilter = [], $storeId = 0)
248251
{
249252
$categoriesCollection = $this->categoryCollectionFactory->create();
250-
251253
$categoriesCollection->addAttributeToSelect('name')
252254
->addAttributeToSelect('url_key')
253255
->addAttributeToSelect('url_path')
254-
->addFieldToFilter('level', array('gt' => '1'))
256+
// if we need to regenerate Url Rewrites for all categories then we select only top level
257+
// and all sub-categories (and products) will be regenerated as child's
258+
->addFieldToFilter('level', (count($categoriesFilter) > 0 ? ['gt' => '1'] : 2))
255259
->setOrder('level', 'ASC')
256260
// use limit to avoid a "eating" of a memory
257261
->setPageSize($this->categoriesCollectionPageSize);

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Extension homepage: https://github.com/olegkoval/magento2-regenerate_url_rewrite
99

1010
## DONATIONS / SUPPORT ME ON
1111
* [Patreon](https://www.patreon.com/olegkoval)
12-
* You can hire me via [Upwork](https://www.upwork.com/o/profiles/users/~01a40656da65c38d3a/)
12+
* [Fondy](https://api.fondy.eu/s/aeOD4YCieqKE7U)
1313

1414
## INSTALLATION
1515

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Add into Magento 2 a CLI feature which allow to regenerate a Url Rewrites of products and categories",
44
"keywords": ["magento", "magento2 extension", "magento 2 extension", "extension", "module", "magento2 module", "magento 2 module"],
55
"type": "magento2-module",
6-
"version": "1.5.4",
6+
"version": "1.5.5",
77
"homepage": "https://github.com/olegkoval/magento2-regenerate_url_rewrites",
88
"authors": [
99
{

etc/module.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
-->
1212
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
13-
<module name="OlegKoval_RegenerateUrlRewrites" setup_version="1.5.4">
13+
<module name="OlegKoval_RegenerateUrlRewrites" setup_version="1.5.5">
1414
<sequence>
1515
<module name="Magento_Store"/>
1616
<module name="Magento_Catalog"/>

0 commit comments

Comments
 (0)