Magento Forum

   
Upsell Block
 
steve91386
Jr. Member
 
Total Posts:  26
Joined:  2008-11-27
 

Somehow my upsell block is stuck on showing 4 products.

Despite modifying the catalog.xml & upsell.php files I am unable to increase or decrease the quantity of displayed upsells.

Any hints?

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
magestore
Mentor
 
Avatar
Total Posts:  1013
Joined:  2009-08-07
Viet Nam
 

Hello,
To increase or decrease the quantity of products to display in the upsell block, you can follow these steps:
1. Open the file app/code/core/Mage/Catalog/Block/Product/List/Upsell.php
2. Add this code to the top of function _prepareData()

protected function _prepareData()
    
{
        
/*Add this code to change the quantity of product to show in the upsell block*/
        
$quantity 20;
        
$this->setItemLimit('upsell'$quantity);
        
/*End code*/
        
...
}

Hope you will succeed.

Image Attachments
upsell.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
 
steve91386
Jr. Member
 
Total Posts:  26
Joined:  2008-11-27
 

Didn’t work for me. The Upsell block still is displaying 4 products. Here is my code for Upsell.php as you advised:

class Mage_Catalog_Block_Product_List_Upsell extends Mage_Catalog_Block_Product_Abstract
{
    
protected $_columnCount 3;

    protected 
$_items;

    protected 
$_itemCollection;

    protected 
$_itemLimits = array();

    protected function 
_prepareData()
    
{

/*Add this code to change the quantity of product to show in the upsell block*/
        
$quantity 3;
        
$this->setItemLimit('upsell'$quantity);
        
/*End code*/

        
$product Mage::registry('product');
        
/* @var $product Mage_Catalog_Model_Product */
        
$this->_itemCollection $product->getUpSellProductCollection()
            ->
addAttributeToSort('position''asc')
            ->
addStoreFilter()
        ;
        
Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_itemCollection,
            
Mage::getSingleton('checkout/session')->getQuoteId()
        );
        
$this->_addProductAttributesAndPrices($this->_itemCollection);

//        Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->_itemCollection);
        
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_itemCollection);

        if (
$this->getItemLimit('upsell') > 0{
            $this
->_itemCollection->setPageSize($this->getItemLimit('upsell'));
        
}

        $this
->_itemCollection->load();

        
/**
         * Updating collection with desired items
         */
        
Mage::dispatchEvent('catalog_product_upsell', array(
            
'product'       => $product,
            
'collection'    => $this->_itemCollection,
            
'limit'         => $this->getItemLimit()
        ));

        foreach (
$this->_itemCollection as $product{
            $product
->setDoNotUseCategoryId(true);
        
}

        
return $this;
    
}

    
protected function _beforeToHtml()
    
{
        $this
->_prepareData();
        return 
parent::_beforeToHtml();
    
}

    
public function getItemCollection()
    
{
        
return $this->_itemCollection;
    
}

    
public function getItems()
    
{
        
if (is_null($this->_items)) {
            $this
->_items $this->getItemCollection()->getItems();
        
}
        
return $this->_items;
    
}

    
public function getRowCount()
    
{
        
return ceil(count($this->getItemCollection()->getItems())/$this->getColumnCount());
    
}

    
public function setColumnCount($columns)
    
{
        
if (intval($columns) > 0{
            $this
->_columnCount intval($columns);
        
}
        
return $this;
    
}

    
public function getColumnCount()
    
{
        
return $this->_columnCount;
    
}

    
public function resetItemsIterator()
    
{
        $this
->getItems();
        
reset($this->_items);
    
}

    
public function getIterableItem()
    
{
        $item 
current($this->_items);
        
next($this->_items);
        return 
$item;
    
}

    
/**
     * Set how many items we need to show in upsell block
     * Notice: this parametr will be also applied
     *
     * @param string $type
     * @param int $limit
     * @return Mage_Catalog_Block_Product_List_Upsell
     */
    
public function setItemLimit($type$limit)
    
{
        
if (intval($limit) > 0{
            $this
->_itemLimits[$type] intval($limit);
        
}
        
return $this;
    
}

    
public function getItemLimit($type '')
    
{
        
if ($type == ''{
            
return $this->_itemLimits;
        
}
        
if (isset($this->_itemLimits[$type])) {
            
return $this->_itemLimits[$type];
        
}
        
else {
            
return 0;
        
}
    }
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
Piyush Dankhra
Jr. Member
 
Avatar
Total Posts:  2
Joined:  2011-01-27
 

In layout catalog.xml

<block type="catalog/product_list_upsell" name="product.info.upsell" as="upsell_products" template="catalog/product/list/upsell.phtml">
       <
action method="setColumnCount"><columns>4</columns></action>
       <
action method="setItemLimit"><type>upsell</type><limit>4</limit></action> <!-- set product limit here -->
</
block>

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