1

There are a number of conditions that determine if a product can be displayed in a certain store view. From the top of my head, I know 3:

  • Is the product associated with the website?
  • Is the product configured as enabled/active for that website?
  • Does the product have a non-empty price field for that store view?

Background is that I have an external search function using a Solr server in the backend. That search function has been altered so that when a product number is entered into the search function and enter is pressed and there is a product matching that product number close to 100% (capitalization is ignored, but otherwise it needs to be a match), then it jumps directly to the product detail page, otherwise a normal search is performed.

Now, it dawned on me that I could in that way find a product that is not visible to the store view (see the conditions above). The result is that the URL is called correctly, but results in a 404.

Is there a transparent way of testing if a product could theoretically be viewed for a certain store view without finding and spelling out the exhaustive list as it currently is? I imagine something like

Mage::Helper('something')->canViewInStoreview($productId, $storeviewId)

would be right on the spot. If spelled out, the conditions in the next version could change, and I would not want to re-check with every update if the list is still complete.

1

I think you got it all covered.

  • The product needs to be assigned to the current website
  • The product needs to be enabled.
  • The product needs to have the visibility catalog or catalog & search in order to appear when browsing the catalog. And search or catalog & search when using the search functionality.

I don't know about the 0 price. I think products with 0 price can be displayed.

But to make sure, you can follow the trace starting from the product controller view action.

Mage_Catalog_ProductController::viewAction.
This one calls $viewHelper->prepareAndRender($productId, $this, $params); which means Mage_Catalog_Helper_Product_View::prepareAndRender().
This one calls Mage_Catalog_Helper_Product::initProduct.

and this one contains:

    if (!$this->canShow($product)) {
        return false;
    }
    if (!in_array(Mage::app()->getStore()->getWebsiteId(), $product->getWebsiteIds())) {
        return false;
    }

Which basically means (canShow) if the product exists, is enabled and has the proper visibility it's OK. The next if checks if the product is assigned to the current website.

But you should also be careful at the custom code you have that hook onto some events dispatched in prepareAndRender method and the ones that are called from it.

| improve this answer | |
  • The price field condition was referring to an empty field, not a "0.00" value. You can get empty price fields using importers. I'll implement your version and accept, if it works. Thanks so far. – 0xCAFEBABE Oct 18 '16 at 9:34
  • It works very well, although I wasn't able to instantiate the respective helper class in my module. I'm doing the checks manually, and the customers are happy. Thank you. – 0xCAFEBABE Oct 19 '16 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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