1

For my store I want to create the situation where children of Configurable Products that are set to 'Not Visible Individually' are accessable anyway, when the direct URL is provided. Currently it returns a 404-error.

The purpose of this is, so we can only load the direct URLs in Google Shopping using Product Feeds, but not display the products in either Search or Catalog on the site.

I have no idea where to start. Can anyone help me out?

Update:

Using Marius' code from another question I created a module with the following code in /Namespace/Modulename/Model/Observer.php

<?php
     class Namespace_Modulename_Model_Observer {
        public function redirectToUrl($observer) {
            $id = Mage::app()->getRequest()->getParam('id');
            $_product = Mage::getModel('catalog/product')->load($id);

            $urlKey = $_product->getProductUrl($id);

            if (isset($urlKey)) {

            Mage::app()->getResponse()->setRedirect($urlKey, 301);
            Mage::app()->getResponse()->sendResponse();
            exit;
        }
        return $this;
    }
} ?>

This (obviously) sends the server in a loop, as I'm trying to send it to the simple product's page and Magento is trying to send it back to 404.

I think I'm very close to a solution, because all that needs to be done now (I think) is a way to overwrite Magento's default behavior of sending it to 404.

Any ideas?

Update #2

It's starting to seem that what I want is impossible and I can't find anything on the internet that can help me out.

2 Answers 2

3

This is not an answer to your question, but it may be a solution to your problem.
If you want the simple products to be accessible, you can just set their visibility to Catalog and don't assign them to any categories.
This way your simple product will not be found in search or by browsing the catalog.
They will only be accessible via direct URL, as you need it.

This way you can do it via the admin panel without any coding involved.

3
  • I've looked into your solution, but I'm afraid it is not what I'm looking for. Your solution (as far as I understand Magento) will only work for simple products, who are not children of a configurable product. In my case, I have only configurable products, who inherit their categories from their (configurable) parent. In other words, I'm looking for a 'set and forget' solution. Any product that is the child of a configurable product AND has visibility set to 'Not visible individually', should be accessable with the direct URL. Thank you, however, for trying to help. Commented Aug 29, 2016 at 18:50
  • I was looking into one of your previous responses in another topic and I was wondering if I could do something with this: magento.stackexchange.com/questions/104492/… I'm going to try to create a redirect using a similar logic as you stated there. Any help would be appreciated. :) Commented Aug 30, 2016 at 7:49
  • you can try it.
    – Marius
    Commented Aug 30, 2016 at 7:50
1

I am not sure in Magento 1 but in Magento 2 you should check and modify the logic of function \Magento\Catalog\Helper\Product::canShow

The definition of this function as per Magento 2.3.0 is

    public function canShow($product, $where = 'catalog')
    {
        if (is_int($product)) {
            try {
                $product = $this->productRepository->getById($product);
            } catch (NoSuchEntityException $e) {
                return false;
            }
        } else {
            if (!$product->getId()) {
                return false;
            }
        }
        return $product->isVisibleInCatalog() && $product->isVisibleInSiteVisibility();
    }

This function returns false for the product having visibility set to "Not display individually" and parent function calling it will redirect to 404 if this doesn't return a true value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.