Skip to content

Crosssells are never shown when using product/list/items.phtml template #7353

Closed
@koenner01

Description

@koenner01

If you try to add the crosssells block anywhere in the layout and use the product/list/items.phtml template, you will never see any output.

Preconditions

  1. PHP7.0
  2. Magento 2.1.2

Steps to reproduce

  1. Add crosssells block to product detail
<block class="Magento\Catalog\Block\Product\ProductList\Crosssell" name="product.info.crosssell" template="Magento_Catalog::product/list/items.phtml">
    <arguments>
        <argument name="type" xsi:type="string">crosssell</argument>
    </arguments>
    <block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="crosssell.product.addto" as="addto" />
</block>
  1. output the childHtml on the frontend

Expected result

  1. Show crosssells on product detail

Actual result

  1. No crosssells are shown

I traced this back to the product/list/items.phtml template where $block->getItemCount() is called. This function will always return null

case 'crosssell':
    /** @var \Magento\Catalog\Block\Product\ProductList\Crosssell $block */
    if ($exist = $block->getItemCount()) {
        $type = 'crosssell';
        $class = $type;

        $image = 'cart_cross_sell_products';
        $title = __('More Choices:');
        $items = $block->getItems();

        $showAddTo = true;
        $showCart = true;
        $templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
        $description = false;
        $canItemsAddToCart = false;
    }
break;

The line should be changed to similiar functionality as the upsells

if ($exist = count($block->getItems())) {

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions