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

Improved check when CategoryProcessor attempts to create a new category #8930

Merged
merged 5 commits into from
Mar 31, 2017

Conversation

ccasciotti
Copy link
Contributor

@ccasciotti ccasciotti commented Mar 17, 2017

Improved check perfomed by CategoryProcessor when it checks if it has to create a new category or not.

Description

The original check didn't consider that a category must be supplied with uppercase or lowecase characters. In this case, if you're trying to import a category named Foo, and a category named FOO, the system will create both categories but fails when attempts to create URL keys because the first url already exists causing an exception. Checking path existence by lowercase-ing it will avoid duplicate url keys creation attempts. I've also added a method to clear failed categories between bunches import, and updated related unit test file. Lastly, i've fixed a typo in CategoryProcessor's PHPDoc.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

…keys due to both uppercase and lowercase categories' name
* @param string $string
* @return string
*/
protected function standardizeString(string $string)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the "string" scalar type hint, please? :)
This is only possible with PHP 7+ and Magento's minimum supported PHP version is 5.6.*.

@ccasciotti
Copy link
Contributor Author

@tinogo i've removed type hint :)

*/
protected function standardizeString(string $string)
{
if (function_exists('mb_strtolower')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe composer.json for Magento already requires ext-mbstring so you may remove this check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've removed the check

* @param string $string
* @return string
*/
protected function standardizeString(string $string)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the function_exists check would eliminate the need in the additional method.

@ishakhsuvarov ishakhsuvarov self-assigned this Mar 20, 2017
@ishakhsuvarov ishakhsuvarov added this to the March 2017 milestone Mar 20, 2017
@@ -1529,6 +1529,9 @@ protected function _saveProducts()
$existingImages = $this->getExistingImages($bunch);

foreach ($bunch as $rowNum => $rowData) {
// reset category processor's failed categories array
$this->categoryProcessor->clearFailedCategories();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change clears failed categories' array for every bunch, avoiding to log the same failed categories every time a bunch is imported. See app/code/Magento/CatalogImportExport/Model/Import/Product.php::processRowCategories that is called for every bunch's import called in the same file at line 1603

*/
protected function standardizeString($string)
{
if (function_exists('mb_strtolower')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe composer.json for Magento already requires ext-mbstring so you may remove this check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, i've removed the check

* @param string $string
* @return string
*/
protected function standardizeString($string)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still need a method which just calls strtolower? I guess it is redundant now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but if in the future we have to change it with more complex checks, we just have to change the function's code instead of changing all the pieces of code where appears mb_strtolower. It's more efficient i think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, at least make it private and provide a reason behind this method in docblock. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, done.

@magento-team magento-team merged commit 5bbc908 into magento:develop Mar 31, 2017
magento-team pushed a commit that referenced this pull request Mar 31, 2017
@okorshenko
Copy link
Contributor

@ccasciotti thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants