2

I'm using the following to load a product by SKU:

/* $this->productRepository (populated by DI) \Magento\Catalog\Model\ProductRepository */
$product = $this->productRepository->get($sku);

However, when calling $product->getData() or $product->getId(), there is no ID returned. I have looked at the \Magento\Catalog\Model\ProductRepository::get() method and it does find the ID correctly. Other data is included as expected:

Array
(
    [store_id] => 1
    [website_ids] => Array
        (
            [0] => 1
        )

    [attribute_set_id] => 9
    [type_id] => simple
    [tax_class_id] => 1
    [visibility] => 1
    [created_at] => 1459845988
    [sku] => ABC
    [name] => Some product
    [status] => 1
    [price] => 1.00
    [meta_title] => Some product
    [meta_keyword] => 
    [meta_description] => 
    [description] => Product description here
    [short_description] => Short product description here
    [size] => 4
    [stock_data] => Array
        (
            [use_config_manage_stock] => 0
            [manage_stock] => 1
            [min_sale_qty] => 1
            [max_sale_qty] => 2
            [is_in_stock] => 1
            [qty] => 1000
        )

    [related_products] => Array
        (
        )

    [cross_sell_products] => Array
        (
        )

    [up_sell_products] => Array
        (
        )

    [tier_price] => Array
        (
        )

    [tier_price_changed] => 0
)

Why does the returned Product object not include this key data?

  • What Magento version do you use? I've just checked it on 2.1.0 with demo data and it worked properly for me. – Wojtek Naruniec Oct 31 '16 at 19:48

Your Answer

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

Browse other questions tagged or ask your own question.