0

When we use this API

https://magento.host/index.php/rest/V1/carts/mine/items

to get Cart Items its gives response like

Array
(
[0] => stdClass Object
    (
        [item_id] => 1234
        [sku] => 123456789          
        [qty] => 1
        [name] => Test Product
        [price] => 123
        [product_type] => simple
        [quote_id] => 1234
    )

)

I need to get the product id with that response like .

     Array
  (
  [0] => stdClass Object
    (
        [item_id] => 1234
        [sku] => 123456789
        [product_id] => 1234
        [qty] => 1
        [name] => Test Product
        [price] => 123
        [product_type] => simple
        [quote_id] => 1234
    )

)

I know if we edit this file CartItemInterface.php and add these lines

 const KEY_PRODUCT_ID = 'product_id';
 public function getProductId();
 public function setProductId($productId);

and edit Item.php add these functions

  public function getProductId()
    {
        return $this->getData(self::KEY_PRODUCT_ID);
    }

  public function setProductId($productId)
    {
        return $this->setData(self::KEY_PRODUCT_ID, $productId);
    }

will retun automatically. But I want to implement this in properway. without edit original files.

How to I achieve this.

  • after fetching the collection you can modify the array. – Aditya Shah Sep 26 '18 at 12:45
  • I also faced this. – Aditya Shah Sep 26 '18 at 12:45
  • IN response array. – Aditya Shah Sep 26 '18 at 12:55
  • Yes, In cartItemInterfacer, they does not return product_id But we can get from quote_item, am getting confusion to override click here – Mohamed abdul Sep 26 '18 at 12:56
  • I am not suggesting to edit in CORE files :) – Aditya Shah Sep 26 '18 at 13:13
0

You cannot get the Product id from this API .

As per as, you can get those value which is defined at there respective interfacer CartItemInterface .,

So you have to build own API for archive this task.

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.