I need some direction...
Within Magento 2, I am not finding exactly how to do a getCollection()
that will allow me to see a list of all products. I am developing an Rest API to allow me to get a list of products based on a defined set of attributes. The code I have is the following:
class Inventory implements InventoryInterface {
private $scopeConfig;
private $product;
public function __construct(
Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
Magento\Catalog\Model\ProductFactory $product
) {
$this->scopeConfig = $scopeConfig;
$this->product = $product;
}
public function get($id = null) {
$data = $this->product->create()->getCollection();
$data->addFieldToFilter('status', 1);
$data->addFieldToFilter('type_id', 'simple');
if ($id) {
$data->addFieldToFilter('entity_id', $id);
}
return $data->getData();
}
}
with this, I am getting back the XML, but I am missing how to be able to select additional attributes to display.
Please be gentle in your responses... I am new to this list AND Magento 2, so feeling a little stupid at this point. Thanks in advance.