I have a magento 2 site version 2.2.4 . When I enter URL of disabled products it throws an error and for SEO purpose I need to create a 302 redirect to category page. Currently I use ProductProcessUrlRewriteSavingObserver

 if ($product->dataHasChangedFor('status')
    ) {

            $this->urlPersist->deleteByData([
            UrlRewrite::ENTITY_ID => $product->getId(),
            UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE,
            UrlRewrite::REDIRECT_TYPE => 0,
            UrlRewrite::STORE_ID => $product->getStoreId()
        ]);

    }

Instead of deleting I need to create a 302 redirect to category page and revert it when the product status is enabled.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.