1

I pass to catalogs list.phtml a custom product collection as

    public function getCurrentProduct()
    {
        return $this->_coreRegistry->registry('current_product');
    }

    public function _getProductCollection()
    {
        $product = $this->getCurrentProduct();
        if ($product->getTypeId() == \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE) {
            $variants = $this->getProduct()->getTypeInstance()->getUsedProductIds($product);

            $collection = $this->_productsFactory->create();
            $collection->addIdFilter($variants);

            return $collection;
        }

        return null;
    }

but on output I do not have price and product name. Can somebody help with this issue?

2 Answers 2

2

Try add following code before return $collection:

$collection->addAttributeToSelect('*');
0
1

I reckon you need to add those attributes to select in your collection:

$collection = $this->_productsFactory->create();
$collection->addAttributeToSelect(['name','price']);
$collection->addIdFilter($variants);
3
  • 'price' is just one field, to get all data connected with special prices etc. '*' would be better in my opinion :) Commented Apr 22, 2016 at 8:08
  • @BartłomiejSzubert I reckon the addAttributeToSelect method is additive, so both price and name will be added to the attributes that are added to select by default, I don't think you need the * selector Commented Apr 22, 2016 at 8:13
  • Maybe you're right, I just assumed that he would like to get data about promotions, and so on. For simply including those attributes to default selected yours answer better. Commented Apr 22, 2016 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.