How to Increase the Number of Crosssell Items in Cart?
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!
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>
<checkout>
<rewrite>
<cart_crosssell>Website_Crossell_Block_Checkout_Crossell</cart_crosssell>
</rewrite>
</checkout>
</blocks>
</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.crosssell">
<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.crosssell" as="crosssell" template="checkout/cart/crosssell.phtml">
<action method="setLimit"><limit>6</limit></action>
</block>