diff --git a/Model/UrlRewrite/Entity/Product.php b/Model/UrlRewrite/Entity/Product.php index 67b8a6e..4ff01a2 100644 --- a/Model/UrlRewrite/Entity/Product.php +++ b/Model/UrlRewrite/Entity/Product.php @@ -42,9 +42,21 @@ public function rebuild(int $storeId, array $arguments = []) $this->productCollection->clear(); $this->productCollection->setStoreId($storeId); $this->productCollection->addAttributeToSelect(['url_path', 'url_key']); - + // do we have any arguments for this if ($arguments) { - $this->productCollection->addFieldToFilter('entity_id', ['in' => $arguments]); + // Are we trying to do a range from x to y? + if(strstr((string)$arguments[0], '-')) + { + $range = (string)$arguments[0]; + $parts = explode("-", $range); + $from_id = (int)$parts[0]; + $to_id = (int)$parts[1]; + // make sure we have two valid IDs + if($from_id && $to_id) + { + $this->productCollection->addFieldToFilter('entity_id', ['from' => $from_id, 'to' => $to_id]); + } + } } $this->urlRewrite @@ -54,4 +66,5 @@ public function rebuild(int $storeId, array $arguments = []) ->setCollection($this->productCollection) ->rebuild(); } + } diff --git a/README.md b/README.md index e9fea7b..a31ce6a 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,12 @@ Rebuild only products ```php bin/magento urlrewrite:rebuild products +``` + + or products by IDs as an ID range this example is IDs from 16 to 69 + +```php +bin/magento urlrewrite:rebuild products -p=16-69 ``` Rebuild only cms-pages