5

I am not sure if this is a bug or something with my configuration.

I have one database on one magento install running two stores.

Some products are only enabled in (store 1) and these do only show up under (store 1). However through analytics I found some 404 pages that come from /review/product/list/id/nnn pages which brought to my attention, that products not in (store 2) are showing the product name, price and image. (the product did once exist and was in the sitemap so this would be why and how it was brought to my attention).

When you click the link back from the product review form page, you get as expected a 404 not found page so my question is why and how does this much of the product show up at all ? The product review templates all seem to come from the same templates that already do not allow the product to show up, so I am wondering is this more the routing url controlling what shows or within the code itself ?

Even if i output the value for $_product = $this->getProduct(); I get info on the product, and the info does show it is store2 which this product should by all accounts not exist in.

  • By default another store review not showing to other store...Please check you codes – Amit Bera Mar 7 '14 at 8:20
  • I should point out, the reviews themselves do not show up on the wrong store, so the review itself is not on the wrong store. It is just the review page has the ability to show: Product Name, Price, Image of a product that is NOT in it's store. – vbird Mar 7 '14 at 16:52
  • Another clue that has me thinking is the url controlling the output: /review/product/list/id/3583/category/138/#review-form changing the category say from 138 to 120 changes the breadcrumb category. It will NOT show a category that does not belong in the store which is as it should be, but the review/product/list/id is showing the product that does NOT belong :( – vbird Mar 7 '14 at 17:32
  • Did you built the functionality with the shown products yourself or is this magento default? – Fabian Blechschmidt Mar 12 '14 at 9:07
  • I have not built any custom function to getProduct() so this is where I am stuck as to how it can load any info at all on a product that is not in the store being viewed. What on the review form makes the getProduct() function pass ? Does anyone have a multistore with products that are to only show under one store ?? If so could they try to load the product by going to (their_url)/review/product/list/id/(the_product_id) ?? I would love to know if this is a magento bug or something within our setup here. – vbird Mar 13 '14 at 21:19
2

Oh this is an odd one, it does appear that there is a "bug" or maybe just a "difference" in opinions as to when a product should show in the review.

Product View

So currently the catalog product view page uses Mage_Catalog_Helper_Product to help init and render the product. Sounds good and it does a couple of good checks.

$product = Mage::getModel('catalog/product')
    ->setStoreId(Mage::app()->getStore()->getId())
    ->load($productId);
if (!$this->canShow($product)) {
    return false;
}
if (!in_array(Mage::app()->getStore()->getWebsiteId(), $product->getWebsiteIds())) {
    return false;
}

The canShow function when looked into deeper simply returns the results of $product->isVisibleInCatalog() && $product->isVisibleInSiteVisibility() the the product has loaded correctly.

Now this all seems to work well, good job Magento.

Review List

So let's see how the review list does it.

Well firstly it does not use the same helper, which is a bit odd as I would assume that this to limit a lot of duplicate code such as checking if a product can be displayed, which seems to be the issue we are looking at here :(

So we know what it does not do so let's check what it does do.

Well it classifies a product as allowed with the following check:

if (!$product->getId() || !$product->isVisibleInCatalog() || !$product->isVisibleInSiteVisibility()) {

Which we have seen before in the helper's canShow function, but sadly that is all it checks and so does not do a further check for websites. Now I am not sure if this is actually a bug or the desired results, but but it should be fairly simply to sort out.

Fix

To fix this it appears to be fairly simple, luckily there are two events that can be hooked onto. They are both fired in the Mage_Review_ProductController::_initProduct.

Mage::dispatchEvent('review_controller_product_init', array('product'=>$product));
Mage::dispatchEvent('review_controller_product_init_after', array(
    'product'           => $product,
    'controller_action' => $this
));

So I would suggest creating an observer that works with one of these events and checks the websites attached to a product and if it is not allowed to be shown on the current website simply call clearInstance

  • in my observer I keep getting true for isVisibleInSiteVisibility() which basically has me back where I began as well the review has already checked and passed this, so I am a bit confused how to approach this. I am somewhat new to magento coding, but it really seems I am not passing the store to the product in this case, so I am not sure how to get back a false response ?? – vbird Jun 5 '14 at 20:21
  • sorry I totally missed the part of your answer about if (!in_array(Mage::app()->getStore()->getWebsiteId(), $product->getWebsiteIds()))... (Thanks to alan s for pointing me to that part of your answer). I was stuck assuming the first check was supposed to do something and looking as to why it was different on the review, when you clearly explained the difference :-/ Thanks!! if (!in_array(Mage::app()->getStore()->getWebsiteId(), $product->getWebsiteIds())) { Mage::throwException('Product Not Found'); } works perfect! – vbird Jun 6 '14 at 19:45
0

go to admin catalog->manage product . now find that product seen in store 2 .. check product enable in both website enter image description here here in this screen see in website column only diamond store display so product see only in diamond store. in other store can't see this product

if you find multi sites in single product remove it . goto edit product ->website tab -> remove click to disable from other store . (select only store where you want to display).

  • thanks for the pointers, but my question is not: 'how to make a product show up in one store'. My question is: 'when a product is set to show up in one store only, here is a case it shows up in both on the review page, why?' It surprises me no-one has tried this to at least tell me it must be my setup only as none of anyone elses setup does this? – vbird Apr 10 '14 at 17:23
  • check your product collection get at review page have filtered with store .. e.q. $storeId = Mage::app()->getStore()->getId(); $products = Mage::getModel('catalog/product')->getCollection()->addStoreFilter($storeId); filter your product collection with store .. at review page put above code for product collection – ankit Apr 11 '14 at 5:54
  • I just tried your suggestion filtering and $product returns the product collection object, but the product object shows when it should not. The object in my case is: All4coding_Core_Model_Resource_Product_Collection Object as we have the all4coding sort order plugin installed. But it does not seem to do much past: class All4coding_Core_Model_Resource_Product_Collection extends Mage_Catalog_Model_Resource_Product_Collection { public function getAttributeFieldName($attributeCode) { return $this->_getAttributeFieldName($attributeCode); } } – vbird Apr 15 '14 at 20:14

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.