I tried to search in other templates for the crosssell.phtml file, but could not find it. Does anybody know what code I should put in the crosssell file to make it show the crosssell products in cart?
I'm using Magento 2.1.5
Best Answer
What are you trying to achieve?
FYI, the file which creates the cross sell section is module-catalog/view/frontend/templates/product/list/items.phtml
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;
If you want to call a block in html file, AJAX loading the content is the way to it. Magento 2's export functionality does the same thing. When you change export entity magento has to change filter html that is rendered. so magento calls this Controller
Notice that parent node is and not
That's it. You will have your cross sell html as response to your ajax request. Just insert the html wherever you want.
To an ajax call you can write jquery inside your html. somthing like this
<script>
require(['jquery'],function($){
$.get('url/of/controller',function(response){
//do stuff with your html
})
})
<script>
If you knockout do with knockout. Or doing it with x-magento-init is even better.
Just start with a simple echo "Hello world" in your controller and it will become clear. If your controller action is route/controller/action then your layout name should be route_controller_action.xml . That's why result factory knows which layout.xml to use from your module
Best Answer
What are you trying to achieve?
FYI, the file which creates the cross sell section is
module-catalog/view/frontend/templates/product/list/items.phtml