Skip to content

MC-40031: [UX] Configurations are not preserved on form reload when new configurable product creation fails #32194

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

Merged
merged 4 commits into from
Apr 6, 2021

Conversation

namlier
Copy link
Contributor

@namlier namlier commented Feb 16, 2021

Description (*)

This is a usability issue.

Fixed Issues (if relevant)

  1. Fixes [UX] Configurations are not preserved on form reload when new configurable product creation fails #32102

Manual testing scenarios (*)

  1. Open backend
  2. Go to products grid
  3. Create configurable product with 1 attribute named "Configurable One"
  4. Save product
  5. Create new configurable product configuration basing on 5 attributes with only 2 variations each
  6. Enter "Configurable One" as name
  7. Configure variations qty and prices (enter different price and qty for each vatiation)
  8. CLick Save

Actual: Form is reloaded. Error is displayed:
The value specified in the URL Key field would generate a URL that already exists.
The variations you configured have disappeared. Information that has to be entered manually and requires significant time is lost.

Expected: To be identified by UX team.

  • Form is reloaded, configurations are preserved.
    OR
  • Form is not reloaded, AJAX validation includes URL Key check.

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 are green)

@m2-assistant
Copy link

m2-assistant bot commented Feb 16, 2021

Hi @mastiuhin-olexandr. Thank you for your contribution
Here are some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@m2-community-project m2-community-project bot added Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Severity: S2 Major restrictions or short-term circumventions are required until a fix is available. labels Feb 16, 2021
@namlier
Copy link
Contributor Author

namlier commented Feb 16, 2021

@magento run all tests

@namlier
Copy link
Contributor Author

namlier commented Feb 16, 2021

@magento run Functional Tests B2B

1 similar comment
@namlier
Copy link
Contributor Author

namlier commented Feb 17, 2021

@magento run Functional Tests B2B

@@ -130,11 +158,18 @@ public function execute()
$resource->getAttribute('news_from_date')->setMaxValue($product->getNewsToDate());
$resource->getAttribute('custom_design_from')->setMaxValue($product->getCustomDesignTo());

$this->validateUrlKeyUniqueness($product);
Copy link
Contributor

Choose a reason for hiding this comment

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

You should not perform validation in controller
It is better to do it inside
\Magento\Catalog\Model\ResourceModel\Product::validate

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 think it should stay in controller, because other requests also has this validation.

@namlier
Copy link
Contributor Author

namlier commented Feb 18, 2021

@magento run all tests

@namlier
Copy link
Contributor Author

namlier commented Feb 18, 2021

@magento run Functional Tests EE

@namlier
Copy link
Contributor Author

namlier commented Feb 18, 2021

@Magneto run Functional Tests B2B

@namlier
Copy link
Contributor Author

namlier commented Feb 18, 2021

@magento run Functional Tests B2B

7 similar comments
@namlier
Copy link
Contributor Author

namlier commented Feb 18, 2021

@magento run Functional Tests B2B

@namlier
Copy link
Contributor Author

namlier commented Feb 18, 2021

@magento run Functional Tests B2B

@namlier
Copy link
Contributor Author

namlier commented Feb 18, 2021

@magento run Functional Tests B2B

@namlier
Copy link
Contributor Author

namlier commented Feb 19, 2021

@magento run Functional Tests B2B

@namlier
Copy link
Contributor Author

namlier commented Feb 19, 2021

@magento run Functional Tests B2B

@namlier
Copy link
Contributor Author

namlier commented Feb 19, 2021

@magento run Functional Tests B2B

@namlier
Copy link
Contributor Author

namlier commented Feb 19, 2021

@magento run Functional Tests B2B

\Magento\Catalog\Model\ProductFactory $productFactory,
ProductUrlPathGenerator $productUrlPathGenerator,
UrlFinderInterface $urlFinder,
GetStoresListByWebsiteIds $getStoresListByWebsiteIds
Copy link
Contributor

Choose a reason for hiding this comment

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

added constructor parameters should be nullable and should be initialized inside constructor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, fixed.

@namlier
Copy link
Contributor Author

namlier commented Feb 22, 2021

@magento run all tests

* @param Product $product
* @return array Array of conflicting Url Keys.
*/
public function findUrlKeyConflicts(Product $product): array
Copy link
Contributor

Choose a reason for hiding this comment

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

A Validator class with a method findUrlKeyConflicts probably doesn't make much sense, I would recommend actually changing it to validateUrlKeyConflicts and throw the exception here. Make this method a void instead, there is no point to return the URL keys if they won't be used.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, agree with Myroslav, the generation should happen on controller and be a parameter on this function. If the information from product that we need is just ID, probably just use it as parameter instead of whole product object.

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 am not sure that rework this to passing UrlKey parameter is a good idea.

In this case the most of logic will stay in the controller. Because there is a function that is using for UrlPath generation
$this->productUrlPathGenerator->getUrlPathWithSuffix($product, $store->getId());,
that uses a product model. The only what will left in the validator is "findAllByData" and the pieace of program that checks found rewrites are not belong to a product.

The other pieace of program generating urlKey, generating urlPathes of stores, searching storeIds of websites (as workaround for performance) will be in the controller.

Please check the last changes and then confirm or deny that it should be reworked like you said before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, fixed. Validator now throws exception. And method renamed.

foreach ($urlRewrites as $urlRewrite) {
if (in_array($urlRewrite->getRequestPath(), $storeIdsToPathForSave)
&& isset($storeIdsToPathForSave[$urlRewrite->getStoreId()])
&& $storeIdsToPathForSave[$urlRewrite->getStoreId()] == $urlRewrite->getRequestPath()
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use ===

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

if (in_array($urlRewrite->getRequestPath(), $storeIdsToPathForSave)
&& isset($storeIdsToPathForSave[$urlRewrite->getStoreId()])
&& $storeIdsToPathForSave[$urlRewrite->getStoreId()] == $urlRewrite->getRequestPath()
&& $product->getId() != $urlRewrite->getEntityId()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use !==

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

$storeIdsToPathForSave = [];
$searchData = [
UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE,
UrlRewrite::REQUEST_PATH => []
Copy link
Contributor

Choose a reason for hiding this comment

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

add comma

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@namlier
Copy link
Contributor Author

namlier commented Mar 31, 2021

@magento run all tests

@namlier namlier requested review from zakdma and gabrieldagama March 31, 2021 15:25
@namlier
Copy link
Contributor Author

namlier commented Mar 31, 2021

@magento run Functional Tests B2B

@namlier
Copy link
Contributor Author

namlier commented Mar 31, 2021

@magento run Functional Tests B2B, WebAPI Tests

@namlier
Copy link
Contributor Author

namlier commented Apr 1, 2021

@magento run WebAPI Tests

@magento-engcom-team
Copy link
Contributor

Hi @gabrieldagama, thank you for the review.
ENGCOM-8808 has been created to process this Pull Request
✳️ @gabrieldagama, could you please add one of the following labels to the Pull Request?

Label Description
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests

@zakdma
Copy link
Contributor

zakdma commented Apr 1, 2021

@magento-engcom-team
Copy link
Contributor

@zakdma the branch with code successfully imported intomagento-tsg/magento2ce repository. Branch name: imported-magento-magento2-32194.

@zakdma
Copy link
Contributor

zakdma commented Apr 6, 2021

@magento-engcom-team
Copy link
Contributor

@zakdma, an error occurred during the Pull Request import.

1 similar comment
@magento-engcom-team
Copy link
Contributor

@zakdma, an error occurred during the Pull Request import.

@zakdma
Copy link
Contributor

zakdma commented Apr 6, 2021

@magento-engcom-team
Copy link
Contributor

@zakdma the branch with code successfully imported intomagento-tsg/magento2ce repository. Branch name: imported-magento-magento2-32194.

@magento-engcom-team magento-engcom-team merged commit 0b36bd2 into magento:2.4-develop Apr 6, 2021
@m2-assistant
Copy link

m2-assistant bot commented Apr 6, 2021

Hi @mastiuhin-olexandr, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Catalog Component: CatalogUrlRewrite Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: ready for testing Release Line: 2.4 Severity: S2 Major restrictions or short-term circumventions are required until a fix is available.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[UX] Configurations are not preserved on form reload when new configurable product creation fails
5 participants