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

How Do I Limit the Number of Crosssell Items in Cart? 
 
kframe
Jr. Member
 
Total Posts:  21
Joined:  2008-09-13
 

Happy Wednesday Fellow Magento-ers! wink

I have a question that I’m hoping someone can help me out with. I’m trying to limit the number of crosssell items that show up in the cart.  I have three crosssell items set for each product.  In cart, I only want to show two at all times.  It works fine when I only have one product in the cart.  When I add a second product, the crosssells area pulls an additional cross sell product from the last product placed in the cart making it now three crosssell items visible.

Is there some place in Magento that I can set it so that only 2 crosssell items show in the cart?

Thanks in advance for all your help!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Appmerce
Guru
 
Avatar
Total Posts:  376
Joined:  2008-05-13
Amsterdam, The Netherlands
 

Have you found a way?

I actually want to increase the limit to 8…

 
Magento Community Magento Community
Magento Community
Magento Community
 
Appmerce
Guru
 
Avatar
Total Posts:  376
Joined:  2008-05-13
Amsterdam, The Netherlands
 

Allright, I figured it out!

The limit is hardcoded in app/code/core/Mage/Checkout/Block/Cart/Crossell.php

class Mage_Checkout_Block_Cart_Crosssell extends Mage_Catalog_Block_Product_Abstract
{
    
protected $_maxItemCount 4;

    public function 
getItems()
    
{

!!!!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ingo
Member
 
Total Posts:  73
Joined:  2008-08-31
Bremen, Germany
 

Is there a way to overwrite it with a template? I don´t want to change the core (update-problems).

 
Magento Community Magento Community
Magento Community
Magento Community
 
lotusseedsD
Mentor
 
Avatar
Total Posts:  1144
Joined:  2007-08-31
 

Didn’t test it so you have to find out if it works:

In checkout.xml, look for <!-- Mage_Checkout --> section and add action method with set item limit.
<block type="checkout/cart_crosssell" name="checkout.cart.crosssell" as="crosssell" template="checkout/cart/crosssell.phtml">
<action method="setItemLimit"><type>crosssell</type><limit>4</limit></action>
</block>

 
Magento Community Magento Community
Magento Community
Magento Community
 
Giannis-M-
Jr. Member
 
Avatar
Total Posts:  24
Joined:  2010-06-24
Greece
 

Thanks Morningtime smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
mptorr
Member
 
Avatar
Total Posts:  62
Joined:  2010-04-06
 

Yeah, Morningtime’s solution works fine—@chinesedream’s solution did not work for me—maybe because the action needs to effect crosssell.PHP and not crosssell.PHTML?

 
Magento Community Magento Community
Magento Community
Magento Community
 
ptjedi
Sr. Member
 
Avatar
Total Posts:  250
Joined:  2008-03-12
Porto, Portugal
 

You can create your own override in the template by using a counter. Here’s the content of my crosssell.phtml file:

<?php if($this->getItemCount()): ?>
<div class="crosssell">
    <
h2><?php echo $this->__('Based on your selection, you may be interested in the following items:'?></h2>
    <
ul id="crosssell-products-list">
    
<?php $i 3// NUMBER OF ITEMS HERE ?>
    
<?php foreach ($this->getItems() as $_item): ?>
        <?php 
if($i>0): ?>
        
<li class="item">
            <
class="product-image" href="<?php echo $_item->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_item->getName()) ?>"><img src="<?php echo $this->helper('catalog/image')->init($_item, 'thumbnail')->resize(75); ?>" width="75" height="75" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" /></a>
            <
div class="product-details">
                <
h3 class="product-name"><a href="<?php echo $_item->getProductUrl() ?>"><?php echo $this->htmlEscape($_item->getName()) ?></a></h3>
                
<?php echo $this->getPriceHtml($_itemtrue?>
                
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_item) ?>')"><span><span><?php echo $this->__('Add to Cart'?></span></span></button>
            </
div>
        </
li>
        
<?php $i=$i-1?>
        <?php 
endif; ?>
    <?php 
endforeach; ?>
    
</ul>
    <
script type="text/javascript">decorateList('crosssell-products-list''none-recursive')</script>
</div>
<?php endif; ?>

Hope it helps someone.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ravi Goswami
Jr. Member
 
Avatar
Total Posts:  20
Joined:  2010-03-11
 

Hey Morning Time.

I changed the $_maxItemCount variable manually in crosssell.php but it didn’t work on my live test website. Ironically it worked perfectly on my localhost website. I don’t understand what am I doing wrong.

Magento Version: 1.5.0.1

Any reply would be really appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Pinpoint
Member
 
Total Posts:  56
Joined:  2010-01-19
 
Morningtime - 18 October 2008 04:03 AM

Allright, I figured it out!

The limit is hardcoded in app/code/core/Mage/Checkout/Block/Cart/Crossell.php

class Mage_Checkout_Block_Cart_Crosssell extends Mage_Catalog_Block_Product_Abstract
{
    
protected $_maxItemCount 4;

    public function 
getItems()
    
{

!!!!!

Thank you for this solution. It works perfect!

I use 1.5.0.1

 
Magento Community Magento Community
Magento Community
Magento Community
 
elvar
Member
 
Total Posts:  59
Joined:  2009-01-30
 
Morningtime - 18 October 2008 04:03 AM

Allright, I figured it out!
The limit is hardcoded in app/code/core/Mage/Checkout/Block/Cart/Crossell.php

class Mage_Checkout_Block_Cart_Crosssell extends Mage_Catalog_Block_Product_Abstract
{
    
protected $_maxItemCount 4;

    public function 
getItems()
    
{

!!!!!

Yes this is working. But why they in Magento hardcoded this anyway?

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