Skip to content

Adding updated readme instructions on how to use product ID range and… #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions Model/UrlRewrite/Entity/Product.php
Original file line number Diff line number Diff line change
@@ -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();
}

}
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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