Magento 1.9 – How to Add Custom Page with Cross-Sell Products

cross-sellsmagento-1magento-1.9

You wouldn't believe how much time I've spent researching/trying to make this happen. All I want is to have an extra page come up in the order process after the product page asking the customer which cross-sell product(s) they want to add to their order (I would call them up-sell but I guess the Magento lingo is "cross-sell"). I really find it unbelievable that more businesses don't want this (I think "up-selling" can greatly increase profits and what's built into Magento does not really work so well (I have more than 20 "Cross-sell" products and they don't even fit/show on there).

I'm using Magento ver. 1.9.1.0.

I just installed the Porto Theme #11 if that makes a difference

NEW INFO: I've been trying to implement this but no luck so far. I even have someone helping me now but we can't figure it out. Can someone please give step-by-step instructions on how to do this? (ANY solution would be much appreciated).

I would like it to work similar to what proflowers.com has (see the enclosed screenshot): enter image description here

They have this page come up as the next step AFTER customer adds a product to the cart (clicks on PROCEED TO CHECKOUT)

All the cross-sell products are ALWAYS the SAME for everyone (every product ordered)


Edited on November 15th, 2016:

The solution that got awarded the 100 reputation actually works. Anyone trying to do what I am trying to do should download the files and upload them into your root directory and then add the following code in your app/code/community/TM/SuggestPage/controllers/IndexControlle‌​‌​r.php file:

$block2 =  $this->getLayout()->createBlock('checkout/cart_coupon')->setTemplate('checkout/cart/coupon.phtml');
$this->getLayout()->getBlock('content')->append($block2);

I am still trying to figure out how to display 12 products on the special Cross-sell page instead of just 4. Accoring to @MurtuzaZabuawala – this should be done by modifying the crosssell.phtml file in:

app/design/frontend/YourPackge/YourTheme/checkout/cart/

I found my crossell.phtml here:

/public_html/app/design/frontend/smartwave/porto/template/checkout/cart

(I hope it's the right one – I have the Porto Theme installed)

Here is what it looks like:

<?php
/**
 * Cart cross sell items template
 *
 * @see Mage_Checkout_Block_Cart_Crosssell
 */
$store = Mage::app()->getStore();
$code  = $store->getCode();
$aspect_ratio = Mage::getStoreConfig("porto_settings/category/aspect_ratio",$code);
$ratio = ($aspect_ratio || (!$aspect_ratio && Mage::getStoreConfig("porto_settings/category/ratio_width",$code) == 0))?1:(Mage::getStoreConfig("porto_settings/category/ratio_height",$code)/Mage::getStoreConfig("porto_settings/category/ratio_width",$code));
?>
<?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" class="row">
    <?php foreach ($this->getItems() as $_item): ?>
        <li class="item col-sm-6 col-md-3">
            <a class="product-image" href="<?php echo $_item->getProductUrl() ?>" title="<?php echo $this->escapeHtml($_item->getName()) ?>"><img src="<?php echo $this->helper('catalog/image')->init($_item, 'thumbnail')->resize(84,84*$ratio); ?>" width="84" height="<?php echo 84*$ratio ?>" alt="<?php echo $this->escapeHtml($_item->getName()) ?>" /></a>
            <div class="product-details">
                <h3 class="product-name"><a href="<?php echo $_item->getProductUrl() ?>"><?php echo $this->escapeHtml($_item->getName()) ?></a></h3>
                <?php echo $this->getPriceHtml($_item, true) ?>
                <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>
                <ul class="add-to-links">
                    <?php if ($this->helper('wishlist')->isAllow()) : ?>
                        <li><a href="<?php echo $this->getAddToWishlistUrl($_item) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
                    <?php endif; ?>
                    <?php if($_compareUrl=$this->getAddToCompareUrl($_item)): ?>
                        <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
                    <?php endif; ?>
                </ul>
            </div>
        </li>
    <?php endforeach; ?>
    </ul>
    <script type="text/javascript">decorateList('crosssell-products-list', 'none-recursive')</script>
</div>
<?php endif; ?>

EDITED December 2nd, 2016:

This is a great solution which works perfect especially if you want to assign different cross-sell products to each product individually. In my case – I want all of my products to have the EXACT SAME cross-sell products and I want to be able to change that depending on the season so I decided to have the extra step in the check-out (solution provided by Murtuza Zabuawala below) display products from a special category I created just for this reason. Murtuza Zabuawala did a great job with. I'm just missing the final step here:

When I put in the code which should display the products from a specific category:

$block = $this->getLayout()->createBlock('catalog/product_list')->set‌​CategoryId(157)->set‌​Template('catalog/pr‌​oduct/list.phtml'); $this->getLayout()->getBlock('content')->append($block);

I get the following Error message:

> There has been an error processing your request
> 
> 
> SQLSTATE[42000]: Syntax error or access violation: 1064 You have an
> error in your SQL syntax; check the manual that corresponds to your
> MySQL server version for the right syntax to use near ')' at line 1,
> query was: SELECT `mg_catalog_category_entity`.* FROM
> `mg_catalog_category_entity` WHERE (entity_id =)
> 
> Trace:
> #0 /home/mystore/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110):
> Zend_Db_Statement_Pdo->_execute(Array)
> #1 /home/mystore/public_html/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
> #2 /home/mystore/public_html/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array)
> #3 /home/mystore/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238):
> Zend_Db_Adapter_Abstract->query('SELECT `mg_cata...', Array)
> #4 /home/mystore/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(428): Zend_Db_Adapter_Pdo_Abstract->query('SELECT `mg_cata...', Array)
> #5 /home/mystore/public_html/lib/Zend/Db/Adapter/Abstract.php(756): Varien_Db_Adapter_Pdo_Mysql->query(Object(Varien_Db_Select), Array)
> #6 /home/mystore/public_html/app/code/core/Mage/Eav/Model/Entity/Abstract.php(943):
> Zend_Db_Adapter_Abstract->fetchRow(Object(Varien_Db_Select))
> #7 /home/mystore/public_html/app/code/core/Mage/Catalog/Model/Resource/Abstract.php(698):
> Mage_Eav_Model_Entity_Abstract->load(Object(Mage_Catalog_Model_Category),
> Object(Mage_Catalog_Model_Category), NULL)
> #8 /home/mystore/public_html/app/code/core/Mage/Core/Model/Abstract.php(225):
> Mage_Catalog_Model_Resource_Abstract->load(Object(Mage_Catalog_Model_Category),
> Object(Mage_Catalog_Model_Category), NULL)
> #9 /home/mystore/public_html/app/code/core/Mage/Catalog/Block/Product/List.php(80):
> Mage_Core_Model_Abstract->load(Object(Mage_Catalog_Model_Category))
> #10 /home/mystore/public_html/app/code/core/Mage/Catalog/Block/Product/List.php(142):
> Mage_Catalog_Block_Product_List->_getProductCollection()
> #11 /home/mystore/public_html/app/code/core/Mage/Core/Block/Abstract.php(918):
> Mage_Catalog_Block_Product_List->_beforeToHtml()
> #12 /home/mystore/public_html/app/code/core/Mage/Core/Block/Text/List.php(43):
> Mage_Core_Block_Abstract->toHtml()
> #13 /home/mystore/public_html/app/code/core/Mage/Core/Block/Abstract.php(919):
> Mage_Core_Block_Text_List->_toHtml()
> #14 /home/mystore/public_html/app/code/core/Mage/Core/Block/Abstract.php(637):
> Mage_Core_Block_Abstract->toHtml()
> #15 /home/mystore/public_html/app/code/core/Mage/Core/Block/Abstract.php(581):
> Mage_Core_Block_Abstract->_getChildHtml('content', true)
> #16 /home/mystore/public_html/app/design/frontend/smartwave/porto/template/page/1column.phtml(49):
> Mage_Core_Block_Abstract->getChildHtml('content')
> #17 /home/mystore/public_html/app/code/core/Mage/Core/Block/Template.php(241):
> include('/home/mystore/pu...')
> #18 /home/mystore/public_html/app/code/core/Mage/Core/Block/Template.php(272):
> Mage_Core_Block_Template->fetchView('frontend/smartw...')
> #19 /home/mystore/public_html/app/code/core/Mage/Core/Block/Template.php(286):
> Mage_Core_Block_Template->renderView()
> #20 /home/mystore/public_html/app/code/core/Mage/Core/Block/Abstract.php(919):
> Mage_Core_Block_Template->_toHtml()
> #21 /home/mystore/public_html/app/code/core/Mage/Core/Model/Layout.php(555):
> Mage_Core_Block_Abstract->toHtml()
> #22 /home/mystore/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(390):
> Mage_Core_Model_Layout->getOutput()
> #23 /home/mystore/public_html/app/code/community/TM/SuggestPage/controllers/IndexController.php(32):
> Mage_Core_Controller_Varien_Action->renderLayout()
> #24 /home/mystore/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(418):
> TM_SuggestPage_IndexController->indexAction()
> #25 /home/mystore/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250):
> Mage_Core_Controller_Varien_Action->dispatch('index')
> #26 /home/mystore/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(172):
> Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
> #27 /home/mystore/public_html/app/code/core/Mage/Core/Model/App.php(354):
> Mage_Core_Controller_Varien_Front->dispatch()
> #28 /home/mystore/public_html/app/Mage.php(684): Mage_Core_Model_App->run(Array)
> #29 /home/mystore/public_html/index.php(87): Mage::run('', 'store')
> #30 {main}

my

app/code/community/TM/SuggestPage/controllers/IndexControlle‌​‌​r.php

looks like this:

<?php

class TM_SuggestPage_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()


{

    $this->loadLayout()
        ->_initLayoutMessages('checkout/session')
        ->_initLayoutMessages('catalog/session');



$block2 =  $this->getLayout()->createBlock('checkout/cart_coupon')->setTemplate('checkout/cart/coupon.phtml');
$this->getLayout()->getBlock('content')->append($block2);


    $_product = Mage::getModel('catalog/product')->load(1); //here 1 is product Id
    $block = $this->getLayout()->createBlock('catalog/product_list')->set‌​CategoryId(157)->set‌​Template('catalog/pr‌​oduct/list.phtml'); $this->getLayout()->getBlock('content')->append($block);



    $this->renderLayout();
    }
}

When I tried the following code instead (in: app/code/community/TM/SuggestPage/controllers/IndexControlle‌​‌​r.php ):

**

$category = Mage::getModel('catalog/category')->load(190);  
   $block = $this->getLayout()->createBlock('catalog/product_list')->set‌​Category($category)->set‌​Template('catalog/pr‌​oduct/list.phtml'); $this->getLayout()->getBlock('content')->append($block);

**

  • it gave me this Error:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your

MySQL server version for the right syntax to use near ')' at line 1,
query was: SELECT mg_catalog_category_entity.* FROM
mg_catalog_category_entity WHERE (entity_id =)

Trace:
#0 /home/mystore/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110):

Zend_Db_Statement_Pdo->_execute(Array)
#1 /home/mystore/public_html/app/code/core/Zend/Db/Statement.php(291):
Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#2 /home/mystore/public_html/lib/Zend/Db/Adapter/Abstract.php(480):
Zend_Db_Statement->execute(Array)
#3 /home/mystore/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238):
Zend_Db_Adapter_Abstract->query('SELECT mg_cata...', Array)
#4 /home/mystore/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(428):
Zend_Db_Adapter_Pdo_Abstract->query('SELECT
mg_cata…', Array)
#5 /home/mystore/public_html/lib/Zend/Db/Adapter/Abstract.php(756):
Varien_Db_Adapter_Pdo_Mysql->query(Object(Varien_Db_Select), Array)
#6 /home/mystore/public_html/app/code/core/Mage/Eav/Model/Entity/Abstract.php(943):
Zend_Db_Adapter_Abstract->fetchRow(Object(Varien_Db_Select))
#7 /home/mystore/public_html/app/code/core/Mage/Catalog/Model/Resource/Abstract.php(698):
Mage_Eav_Model_Entity_Abstract->load(Object(Mage_Catalog_Model_Category),
Object(Mage_Catalog_Model_Category), NULL)
#8 /home/mystore/public_html/app/code/core/Mage/Core/Model/Abstract.php(225):
Mage_Catalog_Model_Resource_Abstract->load(Object(Mage_Catalog_Model_Category),
Object(Mage_Catalog_Model_Category), NULL)
#9 /home/mystore/public_html/app/code/core/Mage/Catalog/Block/Product/List.php(80):
Mage_Core_Model_Abstract->load(Object(Mage_Catalog_Model_Category))
#10 /home/mystore/public_html/app/code/core/Mage/Catalog/Block/Product/List.php(142):
Mage_Catalog_Block_Product_List->_getProductCollection()
#11 /home/mystore/public_html/app/code/core/Mage/Core/Block/Abstract.php(918):
Mage_Catalog_Block_Product_List->_beforeToHtml()
#12 /home/mystore/public_html/app/code/core/Mage/Core/Block/Text/List.php(43):
Mage_Core_Block_Abstract->toHtml()
#13 /home/mystore/public_html/app/code/core/Mage/Core/Block/Abstract.php(919):
Mage_Core_Block_Text_List->_toHtml()
#14 /home/mystore/public_html/app/code/core/Mage/Core/Block/Abstract.php(637):
Mage_Core_Block_Abstract->toHtml()
#15 /home/mystore/public_html/app/code/core/Mage/Core/Block/Abstract.php(581):
Mage_Core_Block_Abstract->_getChildHtml('content', true)
#16 /home/mystore/public_html/app/design/frontend/smartwave/porto/template/page/1column.phtml(49):
Mage_Core_Block_Abstract->getChildHtml('content')
#17 /home/mystore/public_html/app/code/core/Mage/Core/Block/Template.php(241):
include('/home/mystore/pu…')
#18 /home/mystore/public_html/app/code/core/Mage/Core/Block/Template.php(272):
Mage_Core_Block_Template->fetchView('frontend/smartw…')
#19 /home/mystore/public_html/app/code/core/Mage/Core/Block/Template.php(286):
Mage_Core_Block_Template->renderView()
#20 /home/mystore/public_html/app/code/core/Mage/Core/Block/Abstract.php(919):
Mage_Core_Block_Template->_toHtml()
#21 /home/mystore/public_html/app/code/core/Mage/Core/Model/Layout.php(555):
Mage_Core_Block_Abstract->toHtml()
#22 /home/mystore/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(390):
Mage_Core_Model_Layout->getOutput()
#23 /home/mystore/public_html/app/code/community/TM/SuggestPage/controllers/IndexController.php(33):
Mage_Core_Controller_Varien_Action->renderLayout()
#24 /home/mystore/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(418):
TM_SuggestPage_IndexController->indexAction()
#25 /home/mystore/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250):
Mage_Core_Controller_Varien_Action->dispatch('index')
#26 /home/mystore/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(172):
Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#27 /home/mystore/public_html/app/code/core/Mage/Core/Model/App.php(354):
Mage_Core_Controller_Varien_Front->dispatch()
#28 /home/mystore/public_html/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#29 /home/mystore/public_html/index.php(87): Mage::run('', 'store')
#30 {main}

Error log record number: 573016373867

Does my Controller.php suppose to look like this?

<?php


class TM_SuggestPage_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()


{

    $this->loadLayout()
        ->_initLayoutMessages('checkout/session')
        ->_initLayoutMessages('catalog/session');


$block2 =  $this->getLayout()->createBlock('checkout/cart_coupon')->setTemplate('checkout/cart/coupon.phtml');
$this->getLayout()->getBlock('content')->append($block2);


    $_product = Mage::getModel('catalog/product')->load(1); //here 1 is product Id
    $category = Mage::getModel('catalog/category')->load(190);  
   $block = $this->getLayout()->createBlock('catalog/product_list')->set‌​Category($category)->set‌​Template('catalog/pr‌​oduct/list.phtml');

$this->getLayout()->getBlock('content')->append($block);

    $this->renderLayout();
    }
}

EDITED December 29th, 2016:

The solution posted by Murtuza Zabuawala is great! The only thing I still need to do is put some code in to call up (display) products from a specific category instead of the actual cross-sell items. Any idea how to do that?

Best Answer

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;

Related Topic