Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Category display on product page
 
CrashTest
Member
 
Avatar
Total Posts:  43
Joined:  2007-09-12
Boise, ID
 

Ok, so I have successfully integrated the display of the currently selected items category for display on the bottom of the product view, by simply adding the following to my custom layout xml file:

<catalog_product_view>
        <!-- 
Mage_Catalog -->
        <
reference name="root">
            <
action method="setTemplate"><template>page/1column.phtml</template></action>
        </
reference>
        <
reference name="content">
        
            <
block type="catalog/product_list" name="product_list"></block>
        
        </
reference>
    </
catalog_product_view>

This works great, perfectly in fact, however when I try to pull up a product view from my advanced search (I haven’t tried simple search, don’t have it activated) it of course produces an error, because there is no catalog/product list.

Is there a way to insert some logic along the way (in other words, where would I do this) to test to see if this is a search result or a catalog display, and then display the correct thing?

Thanks,

Pat

 
Magento Community Magento Community
Magento Community
Magento Community
 
CrashTest
Member
 
Avatar
Total Posts:  43
Joined:  2007-09-12
Boise, ID
 

Am I not asking correctly?  I am really just trying to figure out where to start looking so that I can manage to make this work in my own module.  Any clues would be totally awesome smile

Thanks,

Pat

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

overload Mage_Catalog_Block_Product_List, like this:

protected function _getProductCollection()
    
{
        
if (is_null($this->_productCollection)) {
            $collection 
Mage::getSingleton('catalog/layer');
            if (
$this->getShowRootCategory()) {
                $this
->setCategoryId(Mage::getStoreConfig('catalog/category/root_id'));
            
}
// START ADD
// if this is a product view page
            
if (Mage::registry('product')) {
// get collection of categories this product is associated with
                
$categories Mage::registry('product')->getCategoryCollection()
// request only first category
                    
->setPage(11)
// and load the collection data
                    
->load();
// if the product is associated with any category
                
if ($categories->count()) {
// show products from this category
                    
$this->setCategoryId(current($categories->getIterator()));
                
}
            }
// END ADD
            
if ($this->getCategoryId()) {
                $category 
Mage::getModel('catalog/category')->load($this->getCategoryId());
                
$collection->setCurrentCategory($category);
            
}
            $this
->_productCollection $collection->getProductCollection();
        
}
        
return $this->_productCollection;
    
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
CrashTest
Member
 
Avatar
Total Posts:  43
Joined:  2007-09-12
Boise, ID
 

Thanks Moshe, that is an excellent way to display products related to a searched product, however what I am looking to do is to actually display the search results at the bottom of the product page, from a search performed.  So if they searched on Gold, and they get 4 results, I want those exact items displayed (so the search results block) on the bottom of the page of each one of those when clicked from there.

You mentioned that I could show the catalogsearch/result block, which sounds exactly correct.

You also said that I should overload the Mage_Catalog_ProductController to do the following:

you should put in the controller Mage::helper(’catalogSearch’)->setQueryText(’...’)
and transfer this query in the URL with each link of the product on the search

I will give this a try and get back to you!

Pat

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top