0

I have the following code to get a product collection but how do I also return back the stock levels too

$products = $this->productCollectionFactory->create()
            ->addAttributeToSelect('*')
            ->addAttributeToFilter('type_id', Type::TYPE_SIMPLE);
1
  • stock levels? .
    – Sohel Rana
    May 30 '19 at 14:18
0

Is this the best way

$products = $this->productCollectionFactory->create()
        ->addAttributeToSelect('*')
        ->joinField(
            'qty',
            'cataloginventory_stock_item',
            'qty',
            'product_id=entity_id',
            '{{table}}.stock_id=1',
            'left'
        )
        ->addAttributeToFilter('type_id', Type::TYPE_SIMPLE);
1
  • This completely ignores the new inventory system, so the reported stock wont include reservations.
    – Dom
    May 21 at 15:33

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.