Closed
Description
Using Magento version 0.74.0-beta12, I'm trying to load a list of products, some of which belong to the Bag attribute set of the sample data.
Roughly this is the code I'm playing with:
$this->searchCriteriaBuilder->addFilter($filters);
$searchCriteria = $this->searchCriteriaBuilder->create();
$productList = $this->productRepository->getList($searchCriteria);
As far as I can tell the ProductRepository::getList()
method only adds the default attribute set attributes to the underlying collection.
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
{
$collection = $this->collectionFactory->create();
$defaultAttributeSetId = $this->eavConfig
->getEntityType(\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE)
->getDefaultAttributeSetId();
$extendedSearchCriteria = $this->searchCriteriaBuilder->addFilter(
[
$this->filterBuilder
->setField('attribute_set_id')
->setValue($defaultAttributeSetId)
->create(),
]
);
foreach ($this->metadataService->getList($extendedSearchCriteria->create())->getItems() as $metadata) {
$collection->addAttributeToSelect($metadata->getAttributeCode());
}
How can I add additional attributes to the loaded products? As far as I can tell it is only possible to specify attribute filters using the SearchCriteria
.
Or is it right to use \Magento\Catalog\Model\Resource\Product\Collection
directly?
Thanks for clarifying.
Activity