0

I am trying to understand difference between getCrossSellProductCollection and getCrossSellProducts in layout module for cross sells.

As in my admin panel HTML

vendor/magento/module-catalog/Block/Adminhtml/Product/Edit/Tab/Crosssell.php

 /**
 * Retrieve crosssell products
 *
 * @return array
 */
public function getSelectedCrossSellProducts()
{
    $products = [];
    foreach ($this->_coreRegistry->registry('current_product')->getCrossSellProducts() as $product) {
        $products[$product->getId()] = ['position' => $product->getPosition()];
    }
    return $products;
}

and what I use in frontend in my phtml to show is this

    $collection =  $currentProduct->getCrossSellProductCollection();
    $collection->addAttributeToSelect('*');
    $collection->setPageSize(8);
    $this->_crossSellProducts =  $collection->load();
    return $this->_crossSellProducts;

I am getting somehow less data for getCrossSellProducts.

Your Answer

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

Browse other questions tagged or ask your own question.