Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

I want to increase the number of cross sell items appearing in cart. The max item count is 4 in defined at app/code/core/Mage/Checkout/Block/Cart/Crossell.php

class Mage_Checkout_Block_Cart_Crosssell extends Mage_Catalog_Block_Product_Abstract
{
    protected $_maxItemCount = 4;

How can I increase this limit from admin end or set the limit in checkout.xml file.

Please Guide.

Thanks.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

You're going to need to implement your own module to do so

app/code/local/MyCompany/Checkout/Block/Cart in Crosssell.php

 class MyCompany_Checkout_Block_Cart_Crosssell extends Mage_Catalog_Block_Product_Abstract
{

//     /**
//      * Items quantity will be capped to this value
//      *
//      * @var int
//      */
//     protected $_maxItemCount = 100;

//     /**
//      * Get crosssell items
//      *
//      * @return array
//      */

public function getItemCount()
{
         return count($this->getItems());
}

public function getItems()
{
    $items = $this->getData(\'items\');
    if (is_null($items)) {
        $items = array();
        $ninProductIds = $this->_getCartProductIds();
        if ($ninProductIds) {
            $lastAdded = (int) $this->_getLastAddedProductId();
            if ($lastAdded) {
                $collection = $this->_getCollection()
                    ->addProductFilter($lastAdded);
                if (!empty($ninProductIds)) {
                    $collection->addExcludeProductFilter($ninProductIds);
                }
                $collection->setPositionOrder()->load();

                foreach ($collection as $item) {
                    $ninProductIds[] = $item->getId();
                    $items[] = $item;
                }
            }

            if (count($items) < 100) {
                $filterProductIds = array_merge($this->_getCartProductIds(), $this->_getCartProductIdsRel());
                $collection = $this->_getCollection()
                    ->addProductFilter($filterProductIds)
                    ->addExcludeProductFilter($ninProductIds)
                    ->setPageSize(100-count($items))
                    ->setGroupBy()
                    ->setPositionOrder()
                    ->load();
                foreach ($collection as $item) {
                    $items[] = $item;
                }
            }

        }

        $this->setData(\'items\', $items);
    }
    return $items;
}
}

app/code/local/MyCompany/Checkout/etc in config.xml:

 <?xml version="1.0"?>
 <config>
<modules>
    <MyCompany_Checkout>
        <version>1.0</version>
    </MyCompany_Checkout>
</modules>
<global>
    <blocks>
        <checkout>
                <rewrite>
                    <cart_crosssell>
                        MyCompany_Checkout_Block_Cart_Crosssell
                    </cart_crosssell>
                </rewrite>
        </checkout>
        <mycompany_checkout>
            <class>MyCompany_Checkout_Block</class>
        </mycompany_checkout>
    </blocks>
</global>

app/etc/modules in MyCompany_Checkout.xml:

<?xml version="1.0"?>
<config>
<modules>
    <MyCompany_Checkout>
        <active>true</active>
        <codePool>local</codePool>
    </MyCompany_Checkout>
</modules>

app/design/frontend/default/mytheme/layout/ in checkout.xml:

 <?xml version="1.0"?>
<reference name="content">
    <block type="mycompany_checkout/cart_crosssell" name="checkout.cart.crosssell" as="crosssell" template="checkout/cart/crosssell.phtml"/>
</reference> 

EDIT : To make the value selectable in the backend, you'll want to create:

app/code/local/MyCompany/Checkout/etc in system.xml:

<config>
<tabs>
    <mycompany_tab translate="label" module="mycompany">
        <label>MyCompany X-Sell Settings</label>
        <sort_order>100</sort_order>
    </mycompany_tab>
</tabs>
<sections>
    <mycompany_section translate="label" module="mycompany">
        <label>Max QTY For Upsell Block</label>
        <tab>mycompany_tab</tab>
        <frontend_type>How many</frontend_type>
        <sort_order>0</sort_order>
        <show_in_default>1</show_in_default>
        <show_in_website>1</show_in_website>
        <show_in_store>1</show_in_store>      
        <groups>
            <mycompany_group translate="label">
                <label>Settings</label>
                <frontend_type>text</frontend_type>
                <sort_order>1</sort_order>
                <show_in_default>1</show_in_default>
                <show_in_website>1</show_in_website>
                <show_in_store>1</show_in_store>
                <fields>
                    <mycompany_field>
                        <label>Maximum QTY To Display</label>
                        <frontend_type>text</frontend_type>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                        <comment>This is the maximum number of upsell products to display</comment>                    
                    </mycompany_field>
                </fields>                      
            </mycompany_group>
        </groups>              
    </mycompany_section>
</sections>    

Add this to your existing app/code/local/MyCompany/Checkout/etc/ in config.xml:

....
<adminhtml>
    <acl>
        <resources>
            <admin>
                <children>
                    <system>
                        <children>
                            <config>
                                <children>
                                    <mycompany_section>
                                        <title>MyCompany - All</title>
                                    </mycompany_section>
                                </children>
                            </config>
                        </children>
                    </system>
                </children>
            </admin>
        </resources>
    </acl>
</adminhtml>

And finally, you'd want to replace app/code/local/MyCompany/Checkout/Block/Cart in Crossell.php:

protected $_maxItemCount = 100;

With

protected $_maxItemCount = Mage::getStoreConfig('mycompany_section/mycompany_group/mycompany_field');

If you'd like to know why the config section works like it works, the best article for reference in my opinion is:

Alan Storm | Custom Magento System Configuration

Good luck!

share|improve this answer
    
Can we do it using configuration from admin or xml file ? –  Mark Mar 31 at 7:41
    
There's not a setting in the admin side, the changes will need to be made on a code level as described above –  moose Mar 31 at 7:54
    
Yes I know but can not protected $_maxItemCount = 100; be set from admin so that if limit changes from time to time we dont have to change form block file everytime. –  Mark Mar 31 at 9:12
    
Ah, now I understand. I've updated the answer to demonstrate this. –  moose Mar 31 at 11:12
    
Thanks a ton..:) –  Mark Mar 31 at 12:16

I came across this looking for an xml way to do this and since @moose did the admin version I will share the xml way/

You will need to create a module to either extend or rewrite the checkout crossell block.

app/etc/modules/Namespace_Crosssell.xml

<?xml version="1.0" ?>
<config>
    <modules>
        <Namespace_Crosssell>
            <active>true</active>
            <codePool>local</codePool>
        </Namespace_Crosssell>
    </modules>
</config>

app/code/local/Namespace/Crosssell/etc/config.xml

<?xml version="1.0" ?>
<config>
    <modules>
        <Namespace_Crosssell>
            <version>0.1.0</version>
        </Namespace_Crosssell>
    </modules>

    <global>
        <blocks>
            <namespace_crosssell>
                <class>Namespace_Crosssell_Block</class>
            </namespace_crosssell>
        </blocks>

        <checkout>
            <rewrite>
               <cart_crosssell>Webtise_Crossell_Block_Checkout_Crossell</cart_crosssell>
            </rewrite>
        </checkout>
    </global>
</config>

app/code/local/Namespace/Crosssell/Block/Checkout/Crosssell.php

<?php
class Namespace_Crosssell_Block_Checkout_Crosssell extends Mage_Checkout_Block_Cart_Crosssell
{
    public function setLimit($limit){
        $this->_maxItemCount = $limit;
    }
}

You can then simply add a setLimit action to your block <action method="setLimit"><limit>10</limit></action> like below.

Ideally you'd do this in local.xml like below

<reference name="checkout.cart.crossssell">
<action method="setLimit"><limit>6</limit></action>
</reference>

or in a new block you can just add it in like below

 <block type="checkout/cart_crosssell" name="checkout.cart.crossssell" as="crosssell" template="checkout/cart/crosssell.phtml">
                        <action method="setLimit"><limit>6</limit></action>
    </block>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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