Score:0

Export product image with Commerce Cart API module

gb flag

I'm usng the "Commerce Cart API" module on my website to build a custom cart js layer. The problem i am facing is the purchased entity has a field_image field and I would like get the url of that images instead of the file id.

The json response of cart?_format=json looks like the following:

    [
  {
    "order_id": 9,
    "uuid": "a4604a10-f956-41e7-87f6-0d745b9345a4",
    "order_number": null,
    "store_id": 2,
    "order_items": [
      {
        "order_item_id": 12,
        "uuid": "33bca307-2ee1-4be4-9599-9ecf3604f83c",
        "order_id": 9,
        "purchased_entity": {
          "variation_id": 1181,
          "uuid": "8112b394-5008-4209-85dc-a9deaf5dfea1",
          "type": "default",
          "product_id": 470,
          "sku": "345",
          "title": "Glade Aerosol 330",
          "list_price": {
            "number": "1.000000",
            "currency_code": "ARS",
            "formatted": "ARS 1,00"
          },
          "price": {
            "number": "2.000000",
            "currency_code": "ARS",
            "formatted": "ARS 2,00"
          },
          "resolved_price": {
            "number": "4.000000",
            "currency_code": "ARS",
            "formatted": "ARS 4,00"
          },
          "field_imagenes": [
            122
          ]

In brief what i'm tring to get is field_imagenes as an array of image urls. Is there a way to do it?

Thank you in advance!

Score:0
br flag

It's reasonable for you to move to Commerce API?

That module is based on JSONA:API, therefore you should be able to get the data of relationship entities quite easily, look at include\relationship example on docs.

Plus, the headless system on Drupal mostly prefer json:api, including commerce itself

Mariano Banchio avatar
gb flag
That could be an option. Thanks!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.