I am using this code in the Magento_Catalog (items.phtml.
switch ($type = $block->getType()) {
case 'related-rule':
if ($exist = $block->hasItems()) {
$type = 'related';
$class = $type;
$image = 'related_products_list';
$title = __('YOU MAY ALSO LIKE');
$items = $block->getAllItems();
$limit = $block->getPositionLimit();
$shuffle = (int) $block->isShuffled();
$canItemsAddToCart = $block->canItemsAddToCart();
$showAddTo = true;
$showCart = false;
$templateType = MagentoCatalogBlockProductReviewRendererInterface::SHORT_VIEW;
$description = false;
}
break;
case 'related':
/** @var MagentoCatalogBlockProductProductListRelated $block */
if ($exist = $block->getItems()->getSize()) {
$type = 'related';
$class = $type;
$image = 'related_products_list';
$title = __('YOU MAY ALSO LIKE');
$items = $block->getItems();
$limit = 0;
$shuffle = 0;
$canItemsAddToCart = $block->canItemsAddToCart();
$showAddTo = true;
$showCart = false;
$templateType = MagentoCatalogBlockProductReviewRendererInterface::SHORT_VIEW;
$description = false;
}
break;
case 'upsell-rule':
if ($exist = $block->hasItems()) {
$type = 'upsell';
$class = $type;
$image = 'upsell_products_list';
$title = __('We found other products you might like!');
$items = $block->getAllItems();
$limit = $block->getPositionLimit();
$shuffle = (int) $block->isShuffled();
$showAddTo = false;
$showCart = false;
$templateType = null;
$description = false;
$canItemsAddToCart = false;
}
break;
case 'upsell':
/** @var MagentoCatalogBlockProductProductListUpsell $block */
if ($exist = count($block->getItemCollection()->getItems())) {
$type = 'upsell';
$class = $type;
$image = 'upsell_products_list';
$title = __('We found other products you might like!');
$items = $block->getItemCollection()->getItems();
$limit = $block->getItemLimit('upsell');
$shuffle = 0;
$showAddTo = false;
$showCart = false;
$templateType = null;
$description = false;
$canItemsAddToCart = false;
}
break;
case 'crosssell-rule':
/** @var MagentoCatalogBlockProductProductListCrosssell $block */
if ($exist = $block->hasItems()) {
$type = 'crosssell';
$class = $type;
$image = 'cart_cross_sell_products';
$title = __('Add a gift bag');
$items = $block->getItemCollection();
$showAddTo = true;
$showCart = true;
$templateType = MagentoCatalogBlockProductReviewRendererInterface::SHORT_VIEW;
$description = false;
$canItemsAddToCart = true;
}
break;
case 'crosssell':
/** @var MagentoCatalogBlockProductProductListCrosssell $block */
if ($exist = count($block->getItems())) {
$type = 'crosssell';
$class = $type;
$image = 'cart_cross_sell_products';
$title = __('Add a gift bag');
$items = $block->getItems();
$showAddTo = true;
$showCart = true;
$templateType = MagentoCatalogBlockProductReviewRendererInterface::SHORT_VIEW;
$description = false;
$canItemsAddToCart = true;
}
break;
It is working fine.
I call my same template in the checkout_cart_index, but not getting any data.
The same data is coming correct on the PDP, but help me to achieve this in the cart page.
And also I want to get the get the collection of the products of the
specific product related rule