Skip to content

Prices

This article contains all actions for retrieving and managing prices.

Tip

The price domain supports fetching related resources.

Get price by ID#

query {
  getPrice(id: "1") {
    id
    siteid
    type
    domain
    label
    currencyid
    quantity
    value
    costs
    rebate
    taxrates
    taxflag
    status
    mtime
    ctime
    editor
  }
}
const body = JSON.stringify({'query':
`query {
  getPrice(id: "1") {
    id
    siteid
    type
    domain
    label
    currencyid
    quantity
    value
    costs
    rebate
    taxrates
    taxflag
    status
    mtime
    ctime
    editor
  }
}`});

fetch($('.aimeos').data('graphql'), {
    method: 'POST',
    credentials: 'same-origin',
    headers: { // Laravel only
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    },
    body: body
}).then(response => {
    return response.json();
}).then(data => {
    console.log(data);
});

Response:

{
  "data": {
    "getPrice": {
      "id": "1",
      "siteid": "1.",
      "type": "default",
      "domain": "attribute",
      "label": "Demo: Large print",
      "currencyid": "EUR",
      "quantity": 1,
      "value": "15.00",
      "costs": "0.00",
      "rebate": "0.00",
      "taxrates": "{\"tax\":\"20.00\"}",
      "taxflag": true,
      "status": 1,
      "mtime": "2022-05-28 06:26:38",
      "ctime": "2022-05-28 06:26:38",
      "editor": "core:setup"
    }
  }
}

Search prices#

The filter parameter is explained in the filter section of the GraphQL basics article.

query {
  searchPrices(filter: "{\"=~\": {\"price.label\":\"Demo\"}}") {
    id
    siteid
    type
    domain
    label
    currencyid
    quantity
    value
    costs
    rebate
    taxrates
    taxflag
    status
    mtime
    ctime
    editor
  }
}
let filter = {
    "=~": {"price.label":"Demo"}
};
const fstr = JSON.stringify(JSON.stringify(filter));
const body = JSON.stringify({'query':
`query {
  searchPrices(filter: ` + fstr + `) {
    id
    siteid
    type
    domain
    label
    currencyid
    quantity
    value
    costs
    rebate
    taxrates
    taxflag
    status
    mtime
    ctime
    editor
  }
}`});

fetch($('.aimeos').data('graphql'), {
    method: 'POST',
    credentials: 'same-origin',
    headers: { // Laravel only
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    },
    body: body
}).then(response => {
    return response.json();
}).then(data => {
    console.log(data);
});

Response:

{
  "data": {
    "searchPrices": [
      {
        "id": "3",
        "siteid": "1.",
        "type": "default",
        "domain": "attribute",
        "label": "Demo: Large print",
        "currencyid": "EUR",
        "quantity": 1,
        "value": "15.00",
        "costs": "0.00",
        "rebate": "0.00",
        "taxrates": "{\"tax\":\"20.00\"}",
        "taxflag": true,
        "status": 1,
        "mtime": "2022-05-28 06:26:38",
        "ctime": "2022-05-28 06:26:38",
        "editor": "core:setup"
      },
      {
        "id": "4",
        "siteid": "1.",
        "type": "default",
        "domain": "attribute",
        "label": "Demo: Large print",
        "currencyid": "USD",
        "quantity": 1,
        "value": "20.00",
        "costs": "0.00",
        "rebate": "0.00",
        "taxrates": "{\"tax\":\"10.00\"}",
        "taxflag": true,
        "status": 1,
        "mtime": "2022-05-28 06:26:38",
        "ctime": "2022-05-28 06:26:38",
        "editor": "core:setup"
      }
    ]
  }
}

Save single price#

mutation {
  savePrice(input: {
    domain: "product"
    label: "Test price"
    currencyid: "EUR"
    value: "100.00"
  }) {
    id
  }
}
const body = JSON.stringify({'query':
`mutation {
  savePrice(input: {
    domain: "product"
    label: "Test price"
    currencyid: "EUR"
    value: "100.00"
  }) {
    id
  }
}`});

fetch($('.aimeos').data('graphql'), {
    method: 'POST',
    credentials: 'same-origin',
    headers: { // Laravel only
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    },
    body: body
}).then(response => {
    return response.json();
}).then(data => {
    console.log(data);
});

Response:

{
  "data": {
    "savePrice": {
      "id": "30"
    }
  }
}

Save multiple prices#

mutation {
  savePrices(input: [{
    domain: "product"
    label: "Test 2 price"
    currencyid: "EUR"
    value: "200.00"
  },{
    domain: "product"
    label: "Test 3 price"
    currencyid: "USD"
    value: "220.00"
  }]) {
    id
  }
}
const body = JSON.stringify({'query':
`mutation {
  savePrices(input: [{
    domain: "product"
    label: "Test 2 price"
    currencyid: "EUR"
    value: "200.00"
  },{
    domain: "product"
    label: "Test 3 price"
    currencyid: "USD"
    value: "220.00"
  }]) {
    id
  }
}`});

fetch($('.aimeos').data('graphql'), {
    method: 'POST',
    credentials: 'same-origin',
    headers: { // Laravel only
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    },
    body: body
}).then(response => {
    return response.json();
}).then(data => {
    console.log(data);
});

Response:

{
  "data": {
    "savePrices": [
      {
        "id": "31"
      },
      {
        "id": "32"
      }
    ]
  }
}

Delete single price#

mutation {
  deletePrice(id: "30")
}
const body = JSON.stringify({'query':
`mutation {
  deletePrice(id: "30")
}`});

fetch($('.aimeos').data('graphql'), {
    method: 'POST',
    credentials: 'same-origin',
    headers: { // Laravel only
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    },
    body: body
}).then(response => {
    return response.json();
}).then(data => {
    console.log(data);
});

Response:

{
  "data": {
    "deletePrice": "30"
  }
}

Delete multiple prices#

mutation {
  deletePrices(id: ["31", "32"])
}
const body = JSON.stringify({'query':
`mutation {
  deletePrices(id: ["31", "32"])
}`});

fetch($('.aimeos').data('graphql'), {
    method: 'POST',
    credentials: 'same-origin',
    headers: { // Laravel only
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    },
    body: body
}).then(response => {
    return response.json();
}).then(data => {
    console.log(data);
});

Response:

{
  "data": {
    "deletePrices": [
      "31",
      "32"
    ]
  }
}

Comments

Become an Aimeos Partner

Aimeos partners are first-class specialists in creating or hosting your Aimeos e-commerce project. They have proven their expertise by building top level e-commerce applications using Aimeos.