From 1aefe283a8faab2cd5d38be81d84be7b8bd10318 Mon Sep 17 00:00:00 2001 From: itnavad <93799095+itnavad@users.noreply.github.com> Date: Tue, 13 Sep 2022 16:15:55 +0200 Subject: [PATCH 1/3] Update RegenerateUrlRewritesAbstract.php Added INPUT_KEY_PRODUCTS_TYPE constant --- Console/Command/RegenerateUrlRewritesAbstract.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Console/Command/RegenerateUrlRewritesAbstract.php b/Console/Command/RegenerateUrlRewritesAbstract.php index dc32675..7ad6986 100644 --- a/Console/Command/RegenerateUrlRewritesAbstract.php +++ b/Console/Command/RegenerateUrlRewritesAbstract.php @@ -34,6 +34,7 @@ abstract class RegenerateUrlRewritesAbstract extends Command const INPUT_KEY_NO_CACHE_CLEAN = 'no-cache-clean'; const INPUT_KEY_CATEGORIES_RANGE = 'categories-range'; const INPUT_KEY_PRODUCTS_RANGE = 'products-range'; + const INPUT_KEY_PRODUCTS_TYPE = 'products-type'; const INPUT_KEY_CATEGORY_ID = 'category-id'; const INPUT_KEY_PRODUCT_ID = 'product-id'; const INPUT_KEY_REGENERATE_ENTITY_TYPE_PRODUCT = 'product'; From bdce3f6858dfed197761d740a73d03aab4e6bc29 Mon Sep 17 00:00:00 2001 From: itnavad <93799095+itnavad@users.noreply.github.com> Date: Tue, 13 Sep 2022 16:19:28 +0200 Subject: [PATCH 2/3] Update RegenerateUrlRewrites.php Added INPUT_KEY_PRODUCTS_TYPE option --- Console/Command/RegenerateUrlRewrites.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Console/Command/RegenerateUrlRewrites.php b/Console/Command/RegenerateUrlRewrites.php index d006f84..c9ffa9c 100644 --- a/Console/Command/RegenerateUrlRewrites.php +++ b/Console/Command/RegenerateUrlRewrites.php @@ -90,6 +90,12 @@ protected function configure() InputArgument::OPTIONAL, 'Products ID range, e.g.: 101-152 (Pro version only)' ), + new InputOption( + self::INPUT_KEY_PRODUCTS_TYPE, + null, + InputArgument::OPTIONAL, + 'Products Type, e.g.: grouped, simple (Pro version only)' + ), new InputOption( self::INPUT_KEY_CATEGORY_ID, null, @@ -219,6 +225,14 @@ public function getCommandOptions() ); $distinctOptionsUsed++; } + + if (isset($options[self::INPUT_KEY_PRODUCTS_TYPE])) { + $this->_commandOptions['productsFilter'] = $this->_generateIdsTypeArray( + $options[self::INPUT_KEY_PRODUCTS_TYPE], + 'product' + ); + $distinctOptionsUsed++; + } if (isset($options[self::INPUT_KEY_PRODUCT_ID])) { $this->_commandOptions['productId'] = (int)$options[self::INPUT_KEY_PRODUCT_ID]; @@ -278,6 +292,7 @@ public function getCommandOptions() $this->_errors[] = $this->_getLogicalConflictError( self::INPUT_KEY_REGENERATE_ENTITY_TYPE_CATEGORY, self::INPUT_KEY_PRODUCTS_RANGE, + self::INPUT_KEY_PRODUCTS_TYPE, self::INPUT_KEY_PRODUCT_ID ); } @@ -289,7 +304,8 @@ public function getCommandOptions() 'o1' => self::INPUT_KEY_CATEGORIES_RANGE, 'o2' => self::INPUT_KEY_PRODUCTS_RANGE, 'o3' => self::INPUT_KEY_CATEGORY_ID, - 'o4' => self::INPUT_KEY_PRODUCT_ID + 'o4' => self::INPUT_KEY_PRODUCT_ID, + 'o5' => self::INPUT_KEY_PRODUCTS_TYPE ] ); } From 5ffb7e5bbd8438229d8095c5ea717279ee2d60cb Mon Sep 17 00:00:00 2001 From: itnavad <93799095+itnavad@users.noreply.github.com> Date: Tue, 13 Sep 2022 16:20:43 +0200 Subject: [PATCH 3/3] Update RegenerateUrlRewritesAbstract.php added _generateIdsTypeArray function --- .../Command/RegenerateUrlRewritesAbstract.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Console/Command/RegenerateUrlRewritesAbstract.php b/Console/Command/RegenerateUrlRewritesAbstract.php index 7ad6986..0f87c30 100644 --- a/Console/Command/RegenerateUrlRewritesAbstract.php +++ b/Console/Command/RegenerateUrlRewritesAbstract.php @@ -200,6 +200,35 @@ protected function _generateIdsRangeArray($idsRange, $type = 'product') return $result; } + + /** + * Generate from product's type + * @param string $productType + * @param string $type + * @return array + */ + protected function _generateIdsTypeArray($productType, $type = 'product') + { + + $type = 'product'; + + $tableName = $this->_resource->getTableName('catalog_product_entity'); + + $sql = "SELECT entity_id FROM {$tableName} WHERE type_id = '{$productType}' ORDER BY entity_id"; + + $queryResult = $this->_resource->getConnection()->fetchAll($sql); + + foreach ($queryResult as $row) { + $result[] = (int)$row['entity_id']; + } + + // if not entity_id in this range - show error + if (count($result) == 0) { + $this->_errors[] = __("ERROR: %type ID's in this product type not exists", ['type' => ucfirst($type)]); + } + + return $result; + } /** * Collect console messages