5

I installed a plugin to add an extra check-out step to present more cross-sell products from here:

How to add a custom page with cross-sell products

And it works great - the page comes up and loads the cross-sells but now I need to pull the products from a category instead of the actual cross-sell products because I intend to change the cross-sells every once in a while and it would be nearly impossible to change cross-sells in 1300 products manually...

Any idea how I can do that?

Magento 1.9.1.0

Here is the actual code I used to add the extra check-out step:

https://github.com/tmhub/suggestpage


Edited on January 19th, 2017:

Let me just clarify from the very beginning...

There are a few things I did:

  1. I installed the SuggestPage plugin from here: https://github.com/tmhub/suggestpage

that gave me the extra page in the check-out.

Then 2. I modified the IndexController.php file in:

/home/myAccount/public_html/app/code/community/TM/SuggestPage/controllers/backupINDEXCONTROLLER/IndexController.php

In order to:

  1. Display cross-sell products on the extra check-out page

and

  1. Give the option for customers to enter a coupon.

The original IndexController.php looked liked this:

<?php
class TM_SuggestPage_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        $this->loadLayout()
            ->_initLayoutMessages('checkout/session')
            ->_initLayoutMessages('catalog/session');
        $this->renderLayout();
    }
}

My modified IndexController.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('checkout/cart_crosssell')->setProduct($_product)->setTemplate('checkout/cart/crosssell.phtml'); $this->getLayout()->getBlock('content')->append($block);

    $this->renderLayout();
    }
}

This works and it works great displaying the cross-sell products!

Now what I am trying to do is display the products from a category (category ID=190) instead of actually displaying the cross-sell products. There are 2 gentlemen who have been trying to help me with this and I appreciate that very much - Murtuza Zabuawala and Piyush. They both have different approaches on how to do this:

Murtuza Zabuawala (in his answer below) says to add the following code to the IndexController.php file in:

/home/myAccount/public_html/app/code/community/TM/SuggestPage/controllers/backupINDEXCONTROLLER/IndexController.php

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

 $category = Mage::getModel('catalog/category')->load(11); //here 11 is category id
 $block    = $this->getLayout()->createBlock('catalog/product_list')->setCategory($category)->setTemplate('catalog/product/list.phtml');
 $this->getLayout()->getBlock('content')->append($block);
 $this->renderLayout();

But when I do that - my IndexController.php file looks like this (it's possible I am doing it wrong):

<?php

class TM_SuggestPage_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()

{

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

 $category = Mage::getModel('catalog/category')->load(190); //here 11 is category id
 $block    = $this->getLayout()->createBlock('catalog/product_list')->setCategory($category)->setTemplate('catalog/product/list.phtml');
 $this->getLayout()->getBlock('content')->append($block);

    $this->renderLayout();
    }
}

And it gives the following Error:

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/myACCOUNT/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#1 /home/myACCOUNT/public_html/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#2 /home/myACCOUNT/public_html/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array)
.......

Error log record number: 366748739907

If I try to make my IndexController.php 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('checkout/cart_crosssell')->setProduct($_product)->setTemplate('checkout/cart/crosssell.phtml'); $this->getLayout()->getBlock('content')->append($block);


    $this->renderLayout();

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


 $category = Mage::getModel('catalog/category')->load(190); //here 11 is category id
 $block    = $this->getLayout()->createBlock('catalog/product_list')->setCategory($category)->setTemplate('catalog/product/list.phtml');
 $this->getLayout()->getBlock('content')->append($block);


 $this->renderLayout();


    }
}

It gives this Error:

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/myACCOUNT/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#1 /home/myACCOUNT/public_html/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#2 /home/myACCOUNT/public_html/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array)
#3 /home/myACCOUNT/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('SELECT `mg_cata...', Array)
....

Error log record number: 988885499570

The truth is - I don't know how to modify the IndexController.php file and it's entirely possible I am doing it wrong and therefore getting these Errors.

If I try to do what Piyush is suggesting (in his answer also below) which is to replace the following code in app/code/community/TM/SuggestPage/Block/Cart.php

getLastAddedQuoteItems() function in app/code/community/TM/SuggestPage/Block/Cart.php

with this code:

public function getLastAddedQuoteItems()
{
    $items = Mage::getModel('catalog/category')->load('your_category_id')
             ->getProductCollection()
             ->addAttributeToSelect('*')
             ->addAttributeToFilter('status', 1)
             ->addAttributeToFilter('visibility', 4)
             ;
    $this->_lastAddedQuoteItems = $items;

    return $this->_lastAddedQuoteItems;
}

then my Cart.php file looks like this (again - I'm not sure if I'm doing this right):

<?php
class TM_SuggestPage_Block_Cart extends Mage_Checkout_Block_Cart_Sidebar
{
    protected $_lastAddedQuoteItems = null;
    protected function _prepareLayout()
    {
        if (!Mage::registry('product')) {
            $productId = Mage::getSingleton('checkout/session')->getSuggestpageProductId();
            if (!$productId) {
                return false;
            }
            $product = Mage::getModel('catalog/product')
                ->setStoreId(Mage::app()->getStore()->getId())
                ->load($productId);
            if (!$product->getId()) {
                return false;
            }
            Mage::register('product', $product);
        }
    }
   public function getLastAddedQuoteItems()
{
    $items = Mage::getModel('catalog/category')->load('190')
             ->getProductCollection()
             ->addAttributeToSelect('*')
             ->addAttributeToFilter('status', 1)
             ->addAttributeToFilter('visibility', 4)
             ;
    $this->_lastAddedQuoteItems = $items;

    return $this->_lastAddedQuoteItems;
}
}

and I get the following Error message:

--- Hand Made light was added to your shopping cart.

Fatal error: Call to a member function isVisibleInSiteVisibility() on a non-object in /home/myACCOUNT/public_html/app/design/frontend/base/default/template/checkout/cart/sidebar/default.phtml on line 29

It is also possible that I am modifying this file wrong...

If I make my Cart.php file look like this:

<?php
class TM_SuggestPage_Block_Cart extends Mage_Checkout_Block_Cart_Sidebar
{
    protected $_lastAddedQuoteItems = null;
    protected function _prepareLayout()
    {
        if (!Mage::registry('product')) {
            $productId = Mage::getSingleton('checkout/session')->getSuggestpageProductId();
            if (!$productId) {
                return false;
            }
            $product = Mage::getModel('catalog/product')
                ->setStoreId(Mage::app()->getStore()->getId())
                ->load($productId);
            if (!$product->getId()) {
                return false;
            }
            Mage::register('product', $product);
        }
    }
    public function getLastAddedQuoteItems()
    {
        if (null === $this->_lastAddedQuoteItems) {
           $items = Mage::getModel('catalog/category')->load('190')
             ->getProductCollection()
             ->addAttributeToSelect('*')
             ->addAttributeToFilter('status', 1)
             ->addAttributeToFilter('visibility', 4)
             ;
    $this->_lastAddedQuoteItems = $items;

    return $this->_lastAddedQuoteItems;
}
}

It gives the following Error:

Parse error: syntax error, unexpected end of file, expecting function (T_FUNCTION) in /home/myACCOUNT/public_html/app/code/community/TM/SuggestPage/Block/Cart.php on line 34

Edited later on January 19th, 2017:

Murtuza Zabuawala (thank you for trying) suggested to try a different code and so I made my IndexController.php in /home/myACCOUNT/public_html/app/code/community/TM/SuggestPage/controllers/

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');


     $block = $this->getLayout()->createBlock('catalog/product_list')->setCategoryId(190)->setTemplate('catalog/product/list.phtml'); 
     $this->getLayout()->getBlock('content')->append($block);


        $this->renderLayout();
        }
    }

but that gives the following Error:

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/myACCOUNT/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#1 /home/myACCOUNT/public_html/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#2 /home/myACCOUNT/public_html/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array)
#3 /home/myACCOUNT/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('SELECT `mg_cata...', Array)

...

Error log record number: 559785389974

Where these are the contents of the 559785389974 log record:

**a:5:{i:0;s:307:"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 =)";i:1;s:3928:"#0 /home/myACCOUNT/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#1 /home/myACCOUNT/public_html/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)

...

------Edited on January 18th:

I am really open to ANY solution that allows me to up-sell (I'm using this as a business term not Magento jargon here = Would you like some fries with that? kind of a thing...) on a separate page of the checkout (preferably after the customer adds the product and before they login to check out....


Edited on January 16th in response to an answer given by Piyush bellow:

Here is the ORIGINAL Cart.php file:

    <?php
class TM_SuggestPage_Block_Cart extends Mage_Checkout_Block_Cart_Sidebar
{
    protected $_lastAddedQuoteItems = null;
    protected function _prepareLayout()
    {
        if (!Mage::registry('product')) {
            $productId = Mage::getSingleton('checkout/session')->getSuggestpageProductId();
            if (!$productId) {
                return false;
            }
            $product = Mage::getModel('catalog/product')
                ->setStoreId(Mage::app()->getStore()->getId())
                ->load($productId);
            if (!$product->getId()) {
                return false;
            }
            Mage::register('product', $product);
        }
    }
    public function getLastAddedQuoteItems()
    {
        if (null === $this->_lastAddedQuoteItems) {
            $itemIds = Mage::getSingleton('checkout/session')->getSuggestpageQuoteItemIds();
            if (!$itemIds) {
                return false;
            }
            $items = array();
            $cartItems = $this->getItems();
            foreach ($cartItems as $cartItem) {
                if (in_array($cartItem->getId(), $itemIds)) {
                    $items[] = $cartItem;
                }
            }
            if (!$items) {
                return false;
            }
            $this->_lastAddedQuoteItems = $items;
        }
        return $this->_lastAddedQuoteItems;
    }
}

I changed it to this (as indicated in Piyush's answer):

<?php
class TM_SuggestPage_Block_Cart extends Mage_Checkout_Block_Cart_Sidebar
{
    protected $_lastAddedQuoteItems = null;
    protected function _prepareLayout()
    {
        if (!Mage::registry('product')) {
            $productId = Mage::getSingleton('checkout/session')->getSuggestpageProductId();
            if (!$productId) {
                return false;
            }
            $product = Mage::getModel('catalog/product')
                ->setStoreId(Mage::app()->getStore()->getId())
                ->load($productId);
            if (!$product->getId()) {
                return false;
            }
            Mage::register('product', $product);
        }
    }
    public function getLastAddedQuoteItems()
{
    $items = Mage::getModel('catalog/category')->load('190')
             ->getProductCollection()
             ->addAttributeToSelect('*')
             ->addAttributeToFilter('status', 1)
             ->addAttributeToFilter('visibility', 4)
             ;
    $this->_lastAddedQuoteItems = $items;

    return $this->_lastAddedQuoteItems;
}
}

But I get the following Error on the website:

Product blah blah was added to your shopping cart.

**

Fatal error: Call to a member function isVisibleInSiteVisibility() on a non-object in /home/myAccount/public_html/app/design/frontend/base/default/template/checkout/cart/sidebar/default.phtml on line 29

**

What am I doing wrong? Please help!

This is line 29 that the Error message is talking about:

$this->_lastAddedQuoteItems = $items;

I tried to mess with the closing tags -

**}**

add or remove some but it does not seem to help!

My default.‌​phtml in /home/myAccount/public_html/app/design/frontend/base/default‌​/template/checkout/c‌​art/sidebar/

looks like this (the entire file):

     <?php
        /**
         * Magento
         *
         * NOTICE OF LICENSE
         *
         * This source file is subject to the Academic Free License (AFL 3.0)
         * that is bundled with this package in the file LICENSE_AFL.txt.
         * It is also available through the world-wide-web at this URL:
         * http://opensource.org/licenses/afl-3.0.php
         * If you did not receive a copy of the license and are unable to
         * obtain it through the world-wide-web, please send an email
         * to license@magento.com so we can send you a copy immediately.
         *
         * DISCLAIMER
         *
         * Do not edit or add to this file if you wish to upgrade Magento to newer
         * versions in the future. If you wish to customize Magento for your
         * needs please refer to http://www.magento.com for more information.
         *
         * @category    design
         * @package     base_default
         * @copyright   Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
         * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
         */
        ?>
        <?php
            $_item = $this->getItem();
            $isVisibleProduct = $_item->getProduct()->isVisibleInSiteVisibility();
            $canApplyMsrp = Mage::helper('catalog')->canApplyMsrp($_item->getProduct(), Mage_Catalog_Model_Product_Attribute_Source_Msrp_Type::TYPE_BEFORE_ORDER_CONFIRM);
        ?>
        <li class="item">
            <?php if ($this->hasProductUrl()): ?>
                <a href="<?php echo $this->getProductUrl()?>" title="<?php echo $this->escapeHtml($this->getProductName()) ?>" class="product-image"><img src="<?php echo $this->getProductThumbnail()->resize(50, 50)->setWatermarkSize('30x10'); ?>" width="50" height="50" alt="<?php echo $this->escapeHtml($this->getProductName()) ?>" /></a>
            <?php else: ?>
                <span class="product-image"><img src="<?php echo $this->getProductThumbnail()->resize(50, 50)->setWatermarkSize('30x10'); ?>" width="50" height="50" alt="<?php echo $this->escapeHtml($this->getProductName()) ?>" /></span>
            <?php endif; ?>
            <div class="product-details">
                <a href="<?php echo $this->getDeleteUrl() ?>" title="<?php echo $this->__('Remove This Item') ?>" onclick="return confirm('<?php echo $this->__('Are you sure you would like to remove this item from the shopping cart?') ?>');" class="btn-remove"><?php echo $this->__('Remove This Item') ?></a>
                <?php if ($isVisibleProduct): ?>
                <a href="<?php echo $this->getConfigureUrl() ?>" title="<?php echo $this->__('Edit item') ?>" class="btn-edit"><?php echo $this->__('Edit item')?></a>
                <?php endif ?>
                <p class="product-name"><?php if ($this->hasProductUrl()): ?><a href="<?php echo $this->getProductUrl() ?>"><?php endif; ?><?php echo $this->escapeHtml($this->getProductName()) ?><?php if ($this->hasProductUrl()): ?></a><?php endif; ?></p>
                <strong><?php echo $this->getQty() ?></strong> x

    <?php if ($canApplyMsrp): ?>

            <span class="map-cart-sidebar-item"><?php echo $this->__('See price before order confirmation.'); ?></span>

        <?php else: ?>

        <?php if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
            <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
                <?php echo $this->__('Excl. Tax'); ?>:
            <?php endif; ?>
            <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales')): ?>
                <?php echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()); ?>
            <?php else: ?>
                <?php echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()) ?>
            <?php endif; ?>
            <?php if (Mage::helper('weee')->getApplied($_item)): ?>
                <br />
                <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales')): ?>
                    <small>
                    <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                        <span class="nobr"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount'],true,true); ?></span><br />
                    <?php endforeach; ?>
                    </small>
                <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
                    <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                        <span class="nobr"><small><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount_incl_tax'],true,true); ?></small></span><br />
                    <?php endforeach; ?>
                <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales')): ?>
                    <small>
                    <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                        <span class="nobr"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount_incl_tax'],true,true); ?></span><br />
                    <?php endforeach; ?>
                    </small>
                <?php endif; ?>
                <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
                    <span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>:<br /> <?php echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()); ?></span>
                <?php endif; ?>
            <?php endif; ?>
        <?php endif; ?>

 <?php if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
        <?php $_incl = $this->helper('checkout')->getPriceInclTax($_item); ?>
        <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
            <br /><?php echo $this->__('Incl. Tax'); ?>:
        <?php endif; ?>
        <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales')): ?>
            <?php echo $this->helper('checkout')->formatPrice($_incl + Mage::helper('weee')->getWeeeTaxInclTax($_item)); ?>
        <?php else: ?>
            <?php echo $this->helper('checkout')->formatPrice($_incl-$_item->getWeeeTaxDisposition()) ?>
        <?php endif; ?>
        <?php if (Mage::helper('weee')->getApplied($_item)): ?>
            <br />
            <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales')): ?>
                <small>
                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                    <span class="nobr"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount'],true,true); ?></span><br />
                <?php endforeach; ?>
                </small>
            <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                    <span class="nobr"><small><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount_incl_tax'],true,true); ?></small></span><br />
                <?php endforeach; ?>
            <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales')): ?>
                <small>
                <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
                    <span class="nobr"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount_incl_tax'],true,true); ?></span><br />
                <?php endforeach; ?>
                </small>
            <?php endif; ?>
            <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales')): ?>
                <span class="nobr"><?php echo Mage::helper('weee')->__('Total incl. tax'); ?>:<br /> <?php echo $this->helper('checkout')->formatPrice($_incl + Mage::helper('weee')->getWeeeTaxInclTax($_item)); ?></span>
            <?php endif; ?>
        <?php endif; ?>
    <?php endif; ?>

    <?php endif; //Can apply MSRP ?>

        <?php if ($_options = $this->getOptionList()):?>
        <div class="truncated">
          <div class="truncated_full_value">
            <dl class="item-options">
                <?php foreach ($_options as $_option) : ?>
                <dt><?php echo $this->escapeHtml($_option['label']) ?></dt>
                <dd>
                    <?php if (is_array($_option['value'])): ?>
                    <?php echo nl2br(implode("\n", $_option['value'])) ?>
                    <?php else: ?>
                    <?php echo $_option['value'] ?>
                    <?php endif; ?>
                </dd>
                <?php endforeach; ?>
            </dl>
          </div>
        <a href="#" onclick="return false;" class="details"><?php echo $this->__('Details') ?></a>
        </div>
        <?php endif; ?>
    </div>

Edited on January 20th, 2017: My IndexController.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(100); 
$block = $this->getLayout()->createBlock('checkout/cart_crosssell')->setProduct($_product)->setTemplate('checkout/cart/crosssell.phtml'); $this->getLayout()->getBlock('content')->append($block);


$this->renderLayout();
    }
}
  • just check your code you will get the error, you have not closed braces { properly – Piyush Jan 12 '17 at 18:50
  • @Piyush I tried to mess with the closing tags - } add or remove some but it does not seem to help! Any other ideas? The Error message is talking about line number 29 and that has this: $this->_lastAddedQuoteItems = $items; Please help me with this. I am going to start another bounty on this as soon as the system lets me (I have enough reputation but it's not letting me to start a bounty for some reason) – Allysin Jan 16 '17 at 13:44
  • Pretty sure you have the wrong line, your error message says Fatal error: Call to a member function isVisibleInSiteVisibility() on a non-object in /home/myAccount/public_html/app/design/frontend/base/default/template/checkout/cart/sidebar/default.phtml on line 29 and you're showing cart code, please provide template code. – Summer Developer Jan 18 '17 at 22:05
  • @Summer Developer I have put all the info in much detail into the original post just now - can you please look at it? I think I may just be modifying the file wrong...Thank you! – Allysin Jan 19 '17 at 8:54
  • @Summer Developer I'm sorry - where do I get the template code? – Allysin Jan 19 '17 at 16:33
3

As per github url Module provided by you.

You can simply change the product collection of your getLastAddedQuoteItems() function of block.

For category product you can use this code in your Modules Block file Cart.php-

public function getLastAddedQuoteItems()
{
    $items = Mage::getModel('catalog/category')->load('your_category_id')
             ->getProductCollection()
             ->addAttributeToSelect('*')
             ->addAttributeToFilter('status', 1)
             ->addAttributeToFilter('visibility', 4)
             ;
    $this->_lastAddedQuoteItems = $items;

    return $this->_lastAddedQuoteItems;
}
  • Thank you so much for your answer! Let me jusk ask this - which file and path should I put this code into? And which code will it replace? Thank you again! :-* – Allysin Jan 12 '17 at 15:49
  • replace the getLastAddedQuoteItems() function in app/code/community/TM/SuggestPage/Block/Cart.php File – Piyush Jan 12 '17 at 16:54
  • I did and it gave me the following Error: Parse error: syntax error, unexpected 'public' (T_PUBLIC) in /home/myaccount/public_html/app/code/community/TM/SuggestPage/Block/Cart.php on line 27 – Allysin Jan 12 '17 at 18:18
  • you have missed something in cart.php , check for { } and ; – Piyush Jan 12 '17 at 18:21
  • I think you may be right. I posted my cart.php file up above in the original question. Would you look at it please? – Allysin Jan 12 '17 at 18:55
3
+100

as far as I know add below code in your indexAction That I have given previously

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

 $category = Mage::getModel('catalog/category')->load(11); //here 11 is category id
 $block    = $this->getLayout()->createBlock('catalog/product_list')->setCategory($category)->setTemplate('catalog/product/list.phtml');
 $this->getLayout()->getBlock('content')->append($block);
 $this->renderLayout(); 

I am not sure but you can try below code to

 $block    = $this->getLayout()->createBlock('catalog/product_list')->setCategoryId(199)->setTemplate('catalog/product/list.phtml'); //here 199 is category Id
 $this->getLayout()->getBlock('content')->append($block);
 $this->renderLayout(); 

EDIT

In your indexController indexAction put below code and remove all other code and here 1 is your product Id so you have to update only 1 product ids cross sell product , that way you can solve your problem and close this question

$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(100); //here 100 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();

Edit 2

$block    = $this->getLayout()->createBlock('catalog/product_list')->setData('category_id',199)->setTemplate('catalog/product/list.phtml'); //here 199 is category Id
 $this->getLayout()->getBlock('content')->append($block);
 $this->renderLayout(); 
  • I am going to start a bounty on this question and I have enough reputation but it's not letting me write now....The code you gave me - which code in the Cart.php does it suppose to replace? I am really desperate now ;-( – Allysin Jan 16 '17 at 13:40
  • @Allysin this code is for IndexController.php file – Murtuza Zabuawala Jan 16 '17 at 14:36
  • When you say "add" - you mean I really just add it or replace some code with this new one? I tried it both ways but it always gives me Errors...Which part of the file would you say I should replace with your code above? I ended up with this but it didn't work either: – Allysin Jan 18 '17 at 7:26
  • <?php class TM_SuggestPage_IndexController extends Mage_Core_Controller_Front_Action { public function indexAction() { $this->loadLayout() ->_initLayoutMessages('checkout/session') ->_initLayoutMessages('catalog/session'); $category = Mage::getModel('catalog/category')->load(190); //here 11 is category id $block = $this->getLayout()->createBlock('catalog/product_list')->setCategory($category)->setTemplate('catalog/product/list.phtml'); $this->getLayout()->getBlock('content')->append($block); $this->renderLayout(); } } – Allysin Jan 18 '17 at 7:27
  • 2
    I awarded the 100 bounty points to Murtuza Zabuawala because he really tried to help me and even though we did not get it to work I appreciate your efforts my friend! ;-) All the best! :o) PS: I may start another bounty as soon as I get enough points for it - I will find a solution eventually! :-) – Allysin Jan 25 '17 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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