Skip to content
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

Added option in order to regenerate products' urlkey from product's type (Eg: simple, grouped) #160

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
18 changes: 17 additions & 1 deletion Console/Command/RegenerateUrlRewrites.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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
);
}
Expand All @@ -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
]
);
}
Expand Down
30 changes: 30 additions & 0 deletions Console/Command/RegenerateUrlRewritesAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -199,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
Expand Down