How to add a custom page with cross-sell products
Install below extension that will help you to create extra page after cart
https://github.com/tmhub/suggestpage
above extension add extra page after cart and that page you will add these code and you will get cross-sell product data
change your indexController indexAction as below
public function indexAction()
{
$this->loadLayout()
->_initLayoutMessages('checkout/session')
->_initLayoutMessages('catalog/session');
$_product = Mage::getModel('catalog/product')->load(1); //here 1 is product Id
$block = $this->getLayout()->createBlock('checkout/cart_crosssell')->setProduct($_product)->setTemplate('checkout/cart/crosssell.phtml');
$this->getLayout()->getBlock('content')->append($block);
$this->renderLayout();
}
and for your 4 product issue please check in your app/design/frontend/YourPackge/YourTheme/checkout/cart/crosssell.phtml
file any condition who breaks for loop after four product then change it.
to increase limit for cross-sell product follow this quick step
1) copy app/code/core/Mage/Checkout/Block/Cart/Crosssell.php
file to app/code/local/Mage/Checkout/Block/Cart/Crosssell.php
2) find this line and increase limit as per your need protected $_maxItemCount = 4;
We've implemented something on a client website where you click on proceed to checkout you land on a page before it asking you to add free samples, these are pulled in from a category but would be just as easy to pull in some cross-sell/related products.
Essentially code wise what would have to happen is, a module would have to listen for the event controller_action_predispatch_checkout_onepage_index
and redirect the user to a page built by that module with the products you require, then after that set a session flag to say this user has already seen this up-sell page and allow them through to the checkout.
I'm not sure if there are any modules out there that currently do this.
As a brief example we have this as our xml:
<controller_action_predispatch_checkout_onepage_index>
<observers>
<namespace_module>
<class>namespace_module/observer</class>
<method>redirectToUpsellOnCheckout</method>
</namespace_module>
</observers>
</controller_action_predispatch_checkout_onepage_index>
Edit 15/11/16 Here's what i have so far, still needs some amends:
app/etc/modules/
<?xml version="1.0"?>
<config>
<modules>
<Dc_Crosssells>
<active>true</active>
<codePool>community</codePool>
</Dc_Crosssells>
</modules>
</config>
app/code/community/Dc/Crosssells/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Dc_Crosssells>
<version>0.0.1</version>
</Dc_Crosssells>
</modules>
<global>
<blocks>
<dc_crosssells>
<class>Dc_Crosssells_Block</class>
</dc_crosssells>
</blocks>
<events>
<controller_action_predispatch_checkout_onepage_index>
<observers>
<dc_crosssells>
<class>Dc_Crosssells_Model_Observer</class>
<method>controllerActionPredispatchCheckoutOnepageIndex</method>
</dc_crosssells>
</observers>
</controller_action_predispatch_checkout_onepage_index>
</events>
</global>
<frontend>
<routers>
<beforeyoucheckout>
<use>standard</use>
<args>
<module>Dc_Crosssells</module>
<frontName>before-you-checkout</frontName>
</args>
</beforeyoucheckout>
</routers>
<layout>
<updates>
<dc_crosssells>
<file>dc/dc_crosssells.xml</file>
</dc_crosssells>
</updates>
</layout>
</frontend>
</config>
app/code/community/Dc/Crosssells/Model/Observer.php
<?php
class Dc_Crosssells_Model_Observer
{
public function controllerActionPredispatchCheckoutOnepageIndex(Varien_Event_Observer $observer)
{
if(Mage::getSingleton('core/session')->getCrossSellFlag()) {
Mage::app()->getResponse()->setRedirect(Mage::getBaseUrl() . 'before-you-checkout');
Mage::getSingleton('core/session')->setCrossSellFlag('true');
}
}
}
That above is enough to redirect the user to another page after hitting going to checkout. Would need to set a flag within this observer to the session and then check if that flag exists, if it does, do the redirect.
Then we can create a controller this will be our "before-you-checkout" page, it creates/renders the layout using a block from the template. app/code/community/Dc/Crosssells/controllers/IndexController.php
<?php
class Dc_Crosssells_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout(array('default'));
$block = $this->getLayout()->getBlock('before.you.buy')->getBlockHtml('before.you.buy');
$this->getLayout()->getBlock('content')->append($block);
$this->_initLayoutMessages('core/session');
$this->renderLayout();
}
}
We have a block class to house the functions needed by the frontend block, I haven't fully tested this, it is supposed to return a product collection filtered by the category you should have created in the backend, in my case it's category 292. app/code/community/Dc/Crosssells/Block/BeforeYouBuy.php
<?php
class Dc_Crosssells_Block_BeforeYouBuy extends Mage_Core_Block_Template
{
public function getCrossSellProductsFromCategory()
{
$category = Mage::getModel('catalog/category')->load(292);
$products = Mage::getModel('catalog/product')->getCollection()
->addCategoryFilter($category)
->addAttributeToSelect('*');
return $products;
}
}
app/design/frontend/base/default/layout/dc/dc_crosssell.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<beforeyoucheckout_index_index>
<reference name="content">
<block type="dc_crosssells/beforeYouBuy" name="before.you.buy" template="dc/crosssell.phtml"/>
</reference>
</beforeyoucheckout_index_index>
</layout>
app/design/frontend/base/default/template/dc/crosssell.phtml
<?php $products = $this->getCrossSellProductsFromCategory();
foreach($products as $item) {
echo $item->getName(). '<br />';
}
I haven't fully tested this code properly yet and still needs some work to actually display the products properly with add to cart buttons etc. I've put it in a github repo here: https://github.com/DanCarlyon/MagentoCrossSellPage
Feel free to download and have a play with it.