1
Magento 1.9.1
Porto theme

I have added an extra step in the check-out by installing this:

https://github.com/tmhub/suggestpage

This page comes up after the product details page.

I have spent many (many) hours in an effort to display products on there. The idea is to offer up-sell products there (I'm using the word "up-sell" as business jargon here rather than Magento terminology).

Here are my previous posts regarding this very issue. None of the solutions suggested in them worked:

How to modify an existing custom page with product-specific cross-sell products so that it shows generic cross-sell products instead?

How to add a custom page with cross-sell products

It is so hard for me to believe that it is so very difficult to make products appear on a page within Magento....All I need to do is display a group of products on the extra step of the check-out - I don't really care if these be products from a category, products that have the Featured attribute selected or any other way that will accomplish this.


Here is my IndexController.php file (which dictates what shows up on the extra check-out step page):

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();
    }
}
1

If you want to display the group of product in the same category, you can do this by:

phtml:

$rootId=$block->getRootCategory();
foreach ($block->getCategoryCollection($rootId) as $yourCategory) : 
  $yourCategoryName=$yourCategory->getName();
  $yourCategoryId=$yourCategory->getId();
    if($yourCategoryName== 'upsells'){
      foreach ($block->getCategoryCollection($yourCategoryId) as $category) :
        $catId=$category->getId();
            foreach ($block->getProductCollection($category->getId()) as $product) : 
               $upsellProductId=$check=$product->getId();

      <your html code to display product using product Id>

         endforech;
     endforech;
   }
endforech;

block:

public function getRootCategory()
{


    $rootCategoryID = NULL;
  if($this->getData('parentcat') > 0)
        $rootCategoryID = $this->getData('parentcat'); 
    else
        $rootCategoryID = $this->_storeManager->getStore()->getRootCategoryId();


    return $rootCategoryID ;
}

//get children category by parent category id
public function getCategoryCollection($categoryId)
{
 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
 $category = $objectManager->create('Magento\Catalog\Model\Category')->load($categoryId);
    $childCategories = $category->getChildrenCategories();
    return $childCategories;
}
  public function getProductCollection($categoryId)
{
 return $this->getCategory($categoryId)->getProductCollection()->addAttributeToSelect('*'); 
}

remember to finish the di.xml file.

  • Thank you so much for trying to help. My category name is "upsells" = ID: 216. I have an IndexController.php which is part of the extra step in the checkout (github.com/tmhub/suggestpage) plugin that controls what displays on the extra check-out step --) I will put the contents of that file up in my original post now. Would I be able to put your code for "block" in that file or do I actually have to create a Static block and then reference that in the IndexController.php file? How would I modify your code given my category name and ID? Thank you so much for helping! :o) – Allysin Jan 26 '18 at 12:18
  • You can put it in your block and display your product using product id $upsellProductId in html code. I have add more details already. – Ricky.C Jan 29 '18 at 1:20

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.