3

addAttributeToSelect is not working in magento 2. i tried below but it is loading all item.

$groupCollection = $this->_productloader->create();
$groupCollection->addAttributeToFilter('sku','24-MB02');
$groupCollection->addAttributeToSelect('name,sku');

below is result

{"entity_id":"6","attribute_set_id":"15","type_id":"simple","sku":"24-MB02","has_options":"0","required_options"
:"0","created_at":"2016-04-26 06:40:51","updated_at":"2016-04-26 06:40:51","is_salable":"1"}
10

You should use an array:

addAttributeToSelect(['name','sku'])

Alternative:

addAttributeToSelect('name')->addAttributeToSelect('sku')
1

if you want to get all the attribute simple add below code it will load all the attributes.

$groupCollection->addAttributeToSelect(array('*'));

Your Answer

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

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