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

Url rewrites are all removed when mass updating visibility on store view when set to not visible indivudually. #34937

Closed
1 of 5 tasks
leonhelmus opened this issue Jan 5, 2022 · 21 comments
Assignees
Labels
Area: Search Area: SEO Component: DB Component: UrlRewrite Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: done Reported on 2.4.2 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch

Comments

@leonhelmus
Copy link

leonhelmus commented Jan 5, 2022

Preconditions (*)

  1. php 7.4
  2. composer 1
  3. Magento version 2.4.2 enterprise
  4. RabbitMQ

Steps to reproduce (*)

  1. Have a multi store website (2-5 store views)
  2. Create a product that's connected to all stores make sure attribute code: visibility is on catalog,search
  3. Now go to backend Catalog -> Product. Select the created product and use the action update attributes.
  4. Now select a specific store view after change the attribute code: visibility to Not Visible Individually
  5. Now click on Save.

Expected result (*)

  1. Only the urls of the specific store for the specific product should be deleted in the url_rewrite table.

Actual result (*)

  1. ALL urls are removed of the specific product in the url_rewrite table and Admin UI - Marketing - URL Rewrites page

What my two cents tells me what it is.
I have debugged the issue and found out that the following observer does not take into account that the mass action can be done on store level (see

'global' => ScopedAttributeInterface::SCOPE_STORE,
). If you look in these two classes you see that it does not take into account that the user could change the visibility on store view. See these two classes:

While it does take account for the global way it does not take account that it can be set on store view. When you look at the dispatch of the event:

It does pass a store id. I think the store level should be taken into account to resolve this issue.

I believe this is a S1 problem there are workarounds by changing it in the database or changing everything manual but it's a lot of work to fix. And this could give merchant problems with their SEO while they are not aware of it.


Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
@m2-assistant
Copy link

m2-assistant bot commented Jan 5, 2022

Hi @leonhelmus. Thank you for your report.
To speed up processing of this issue, make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


⚠️ According to the Magento Contribution requirements, all issues 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 issues happens in the queue order. If you want to speed up the delivery of your contribution, 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 this to Ready for Confirmation in Issue Confirmation and Triage Board Jan 5, 2022
@leonhelmus leonhelmus changed the title Url rewrites are all removed when mass updating visibility on store view when set to 0. Url rewrites are all removed when mass updating visibility on store view when set to not visible indivudually. Jan 5, 2022
@engcom-Hotel engcom-Hotel self-assigned this Jan 6, 2022
@m2-assistant
Copy link

m2-assistant bot commented Jan 6, 2022

Hi @engcom-Hotel. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Hotel
Copy link
Contributor

@magento give me 2.4-develop instance

@magento-deployment-service
Copy link

Hi @engcom-Hotel. Thank you for your request. I'm working on Magento instance for you.

@magento-deployment-service
Copy link

Hi @engcom-Hotel, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.

@leonhelmus
Copy link
Author

It seems it did not work @engcom-Hotel

@igorwulff
Copy link
Contributor

@magento give me 2.4-develop instance

@magento-deployment-service
Copy link

Hi @igorwulff. Thank you for your request. I'm working on Magento instance for you.

@magento-deployment-service
Copy link

Hi @igorwulff, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.

@Aquarvin
Copy link
Contributor

This is a proposition to solve the issue. The idea is to pass store ID to appropriate methods:

--- a/vendor/magento/module-catalog-url-rewrite/Observer/ProcessUrlRewriteOnChangeProductVisibilityObserver.php	
+++ b/vendor/magento/module-catalog-url-rewrite/Observer/ProcessUrlRewriteOnChangeProductVisibilityObserver.php	(date 1642437502101)
@@ -43,12 +43,13 @@
         $event = $observer->getEvent();
         $attrData = $event->getAttributesData();
         $productIds = $event->getProductIds();
+        $storeId = $event->getStoreId();
         $visibility = $attrData[ProductInterface::VISIBILITY] ?? 0;
 
         if (!$visibility || !$productIds) {
             return;
         }
 
-        $this->adaptUrlRewritesToVisibility->execute($productIds, (int)$visibility);
+        $this->adaptUrlRewritesToVisibility->execute($productIds, (int)$visibility, $storeId);
     }
 }

diff --git a/vendor/magento/module-catalog-url-rewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php b/vendor/magento/module-catalog-url-rewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php
--- a/vendor/magento/module-catalog-url-rewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php	
+++ b/vendor/magento/module-catalog-url-rewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.php	(date 1642437629598)
@@ -65,9 +65,10 @@
      *
      * @param array $productIds
      * @param int $visibility
+     * @param int $storeId
      * @throws UrlAlreadyExistsException
      */
-    public function execute(array $productIds, int $visibility): void
+    public function execute(array $productIds, int $visibility, int $storeId): void
     {
         $products = $this->getProductsByIds($productIds);
 
@@ -78,6 +79,7 @@
                     [
                         UrlRewrite::ENTITY_ID => $product->getId(),
                         UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE,
+                        UrlRewrite::STORE_ID => $storeId,
                     ]
                 );
             } elseif ($visibility !== Visibility::VISIBILITY_NOT_VISIBLE) {```

@engcom-Hotel engcom-Hotel removed their assignment Jan 21, 2022
@leonhelmus
Copy link
Author

@magento give me 2.4-develop instance

@leonhelmus
Copy link
Author

@Aquarvin
Copy link
Contributor

Aquarvin commented Feb 1, 2022

The solution given above solve this issue. But it is not complete, problem still occurs when we change visibility back to "Catalog, Search", take a look at #35036
I propose this solution #35036 (comment) as a full fix for both tickets.

@engcom-November engcom-November self-assigned this Feb 22, 2022
@m2-assistant
Copy link

m2-assistant bot commented Feb 22, 2022

Hi @engcom-November. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-November
Copy link

engcom-November commented Feb 23, 2022

Verified the issue on Magento 2.4-develop branch and the issue is reproducible.
Issue: After setting the product visibility to "Not visible individually" for only one specific store view using "Update Attributes", all entries of product are deleted from url_rewrite table and also from UI - Marketing - URL Rewrites

@engcom-November engcom-November added Component: DB Component: UrlRewrite Reported on 2.4.2 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Area: Content Area: Search Area: SEO and removed Area: Content labels Feb 23, 2022
@engcom-Hotel engcom-Hotel added the Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch label Mar 1, 2022
@m2-community-project m2-community-project bot moved this from Ready for Confirmation to Confirmed in Issue Confirmation and Triage Board Mar 1, 2022
@engcom-Hotel engcom-Hotel added the Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. label Mar 1, 2022
@m2-community-project m2-community-project bot added this to Dev In Progress in High Priority Backlog Mar 1, 2022
@github-jira-sync-bot
Copy link

✅ Jira issue https://jira.corp.magento.com/browse/AC-2535 is successfully created for this GitHub issue.

@m2-assistant
Copy link

m2-assistant bot commented Mar 1, 2022

✅ Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@leonhelmus
Copy link
Author

We also have a fix when doing this with the api will share it tomorrow

@m2-community-project m2-community-project bot moved this from Dev In Progress to Ready for Development in High Priority Backlog Mar 9, 2022
@m2-community-project m2-community-project bot moved this from Ready for Development to Dev In Progress in High Priority Backlog Apr 4, 2022
@m2-community-project m2-community-project bot moved this from Dev In Progress to Ready for Development in High Priority Backlog Apr 4, 2022
@m2-community-project m2-community-project bot moved this from Dev In Progress to Ready for Development in High Priority Backlog Apr 4, 2022
@m2-community-project m2-community-project bot moved this from Ready for Development to Pull Request In Progress in High Priority Backlog Apr 5, 2022
@m2-community-project m2-community-project bot moved this from Ready for Development to Pull Request In Progress in High Priority Backlog Apr 5, 2022
@leonhelmus
Copy link
Author

This patch i applied for apis, sorry for the delay.


diff --git a/Observer/ProductProcessUrlRewriteSavingObserver.php b/Observer/ProductProcessUrlRewriteSavingObserver.php
--- a/Observer/ProductProcessUrlRewriteSavingObserver.php
+++ b/Observer/ProductProcessUrlRewriteSavingObserver.php
@@ -18,6 +18,8 @@
 use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException;
 use Magento\UrlRewrite\Model\UrlPersistInterface;
 use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
+use Magento\Catalog\Api\Data\ProductInterface;
+use Magento\Catalog\Model\Attribute\ScopeOverriddenValue;

 /**
  * Class ProductProcessUrlRewriteSavingObserver
@@ -46,6 +48,11 @@
      */
     private $getStoresList;

+    /**
+     * @var ScopeOverriddenValue|null
+     */
+    private ?ScopeOverriddenValue $scopeOverriddenValue;
+
     /**
      * @param UrlPersistInterface $urlPersist
      * @param AppendUrlRewritesToProducts|null $appendRewrites
@@ -56,12 +63,15 @@
         UrlPersistInterface $urlPersist,
         AppendUrlRewritesToProducts $appendRewrites,
         ScopeConfigInterface $scopeConfig,
-        GetStoresListByWebsiteIds $getStoresList
+        GetStoresListByWebsiteIds $getStoresList,
+        ?ScopeOverriddenValue $scopeOverriddenValue = null
     ) {
         $this->urlPersist = $urlPersist;
         $this->appendRewrites = $appendRewrites;
         $this->scopeConfig = $scopeConfig;
         $this->getStoresList = $getStoresList;
+        $this->scopeOverriddenValue = $scopeOverriddenValue ?: \Magento\Framework\App\ObjectManager::getInstance()
+            ->create(ScopeOverriddenValue::class);
     }

     /**
@@ -103,7 +113,22 @@
         );
         if ((int)$product->getVisibility() === Visibility::VISIBILITY_NOT_VISIBLE) {
             $isGlobalScope = $product->getStoreId() == Store::DEFAULT_STORE_ID;
-            $storesToRemove[] = $isGlobalScope ? $product->getStoreIds() : $product->getStoreId();
+            $storesToRemove = [];
+            if ($isGlobalScope) {
+                foreach ($product->getStoreIds() as $storeId) {
+                    if (!$this->scopeOverriddenValue->containsValue(
+                        ProductInterface::class,
+                        $product,
+                        \Magento\Catalog\Api\Data\ProductInterface::VISIBILITY,
+                        $storeId
+                    )
+                    ) {
+                        $storesToRemove[] = $storeId;
+                    }
+                }
+            } else {
+                $storesToRemove[] = $product->getStoreId();
+            }
         }
         if ($storesToRemove) {
             $this->urlPersist->deleteByData(

@engcom-Alfa
Copy link
Contributor

Hi @reporter ,
Thanks for your reported bug, the internal team has fixed and delivered this issue successfully.
Please find related commits HERE.

Kindly upgrade to the latest Magento version 2.4-develop to retest the case.

In case of any Magento related issues found in 2.4-develop, you may report a new bug with all the information like Preconditions, detailed steps to reproduce, expected and actual Results along with screenshots/ screen recordings.

For any Magento related references, you may refer to the Magento user guide.

Thanks!

@m2-community-project m2-community-project bot moved this from Pull Request In Progress to Done in High Priority Backlog Apr 22, 2022
@leonhelmus
Copy link
Author

@engcom-Alfa thanks for solving it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Search Area: SEO Component: DB Component: UrlRewrite Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: done Reported on 2.4.2 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch
Projects
Development

No branches or pull requests

7 participants