diff --git a/CHANGELOG.md b/CHANGELOG.md index 73cf177..5526a95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## [1.5.3] - 2020-03-21 +## [1.5.4] - 2020-03-21 +### Changed +- fixed issue of non-empty/non-false "request_path" of product entity. +- modified logic of Url Rewrite db table updates + +## [1.5.3] - 2020-03-20 ### Changed - updated Url Rewrite preparing function - updated logic of Url Rewrite regeneration via category entity diff --git a/Model/AbstractRegenerateRewrites.php b/Model/AbstractRegenerateRewrites.php index 42e3cc1..3794f16 100644 --- a/Model/AbstractRegenerateRewrites.php +++ b/Model/AbstractRegenerateRewrites.php @@ -285,18 +285,23 @@ protected function _updateSecondaryTable() $data = $this->_getResourceConnection()->getConnection()->fetchAll($select); if (!empty($data)) { - $this->_getResourceConnection()->getConnection()->beginTransaction(); - try { - $this->_getResourceConnection()->getConnection()->insertOnDuplicate( - $this->_getSecondaryTableName(), - $data, - ['product_id'] - ); - $this->_getResourceConnection()->getConnection()->commit(); - - } catch (\Exception $e) { - $this->_getResourceConnection()->getConnection()->rollBack(); - throw $e; + // I'm using row-by-row inserts because some products/categories not exists in entity tables but Url Rewrites + // for this entities still exists in url_rewrite DB table. + // This is the issue of Magento EE (Data integrity/assurance of the accuracy and consistency of data) + // and this extension was made to not fix this, I just avoid this issue + foreach ($data as $row) { + $this->_getResourceConnection()->getConnection()->beginTransaction(); + try { + $this->_getResourceConnection()->getConnection()->insertOnDuplicate( + $this->_getSecondaryTableName(), + $row, + ['product_id'] + ); + $this->_getResourceConnection()->getConnection()->commit(); + + } catch (\Exception $e) { + $this->_getResourceConnection()->getConnection()->rollBack(); + } } } diff --git a/Model/RegenerateProductRewrites.php b/Model/RegenerateProductRewrites.php index ec1232a..a6310cd 100644 --- a/Model/RegenerateProductRewrites.php +++ b/Model/RegenerateProductRewrites.php @@ -183,15 +183,21 @@ public function processProduct($entity, $storeId = 0) $entity->setData('save_rewrites_history', true); } + // reset url_path to null, we need this to set a flag to use a Url Rewrites: + // see logic in core Product Url model: \Magento\Catalog\Model\Product\Url::getUrl() + // if "request_path" is not null or equal to "false" then Magento do not serach and do not use Url Rewrites + $updateAttributes = ['url_path' => null]; if (!$this->regenerateOptions['noRegenUrlKey']) { $generatedKey = $this->_getProductUrlPathGenerator()->getUrlKey($entity->setUrlKey(null)); - $this->_getProductAction()->updateAttributes( - [$entity->getId()], - ['url_path' => null, 'url_key' => $generatedKey], - $storeId - ); + $updateAttributes['url_key'] = $generatedKey; } + $this->_getProductAction()->updateAttributes( + [$entity->getId()], + $updateAttributes, + $storeId + ); + $urlRewrites = $this->_getProductUrlRewriteGenerator()->generate($entity); $urlRewrites = $this->helper->sanitizeProductUrlRewrites($urlRewrites); diff --git a/composer.json b/composer.json index b5160e2..3587951 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Add into Magento 2 a CLI feature which allow to regenerate a Url Rewrites of products and categories", "keywords": ["magento", "magento2 extension", "magento 2 extension", "extension", "module", "magento2 module", "magento 2 module"], "type": "magento2-module", - "version": "1.5.3", + "version": "1.5.4", "homepage": "https://github.com/olegkoval/magento2-regenerate_url_rewrites", "authors": [ { diff --git a/etc/module.xml b/etc/module.xml index d399103..b497d7c 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -10,7 +10,7 @@ */ --> - +