In a .phtml
template file I have loaded a productCollection
using objectManager
as follow:
$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
$values = [14];
$conditionType = "in";
$productCollection->addAttributeToSelect('*');
$productCollection->addCategoriesFilter([$conditionType => $values]);
I'd like to print a json with all the products, showing only the following product attributes:
- Name
- Sku
- Link to img
What's the "Magento way" to do this? Thanks