Skip to content

Sites

This article contains all actions for retrieving and managing sites.

Get site by ID#

query {
  getLocaleSite(id: "1") {
    id
    parentid
    code
    level
    label
    config
    status
    icon
    logo
    theme
    refid
    rating
    ratings
    mtime
    ctime
    editor
  }
}
const body = JSON.stringify({'query':
`query {
  getLocaleSite(id: "1") {
    id
    parentid
    code
    level
    label
    config
    status
    icon
    logo
    theme
    refid
    rating
    ratings
    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": {
    "getLocaleSite": {
      "id": "1",
      "parentid": "0",
      "code": "default",
      "level": 0,
      "label": "Aimeos",
      "config": "{}",
      "status": 1,
      "icon": "logo.png",
      "logo": "{200: \"logo.svg\"}",
      "theme": "default",
      "refid": "",
      "rating": "5.0",
      "ratings": 1,
      "mtime": "2022-05-28 06:26:33",
      "ctime": "2022-05-28 06:26:33",
      "editor": "setup"
    }
  }
}

Search sites#

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

query {
  searchLocaleSites(filter: "{\"==\": {\"locale.site.status\":1}}") {
    id
    parentid
    code
    level
    label
    config
    status
    icon
    logo
    theme
    refid
    rating
    ratings
    mtime
    ctime
    editor
  }
}
let filter = {
    "==": {"locale.site.status":1}
};
const fstr = JSON.stringify(JSON.stringify(filter));
const body = JSON.stringify({'query':
`query {
  searchLocaleSites(filter: ` + fstr + `) {
    id
    parentid
    code
    level
    label
    config
    status
    icon
    logo
    theme
    refid
    rating
    ratings
    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": {
    "searchLocaleSites": [
      {
        "id": "1",
        "parentid": "0",
        "code": "default",
        "level": 0,
        "label": "Aimeos",
        "config": "{}",
        "status": 1,
        "icon": "logo.png",
        "logo": "{200: \"logo.svg\"}",
        "theme": "default",
        "refid": "",
        "rating": "5.0",
        "ratings": 1,
        "mtime": "2022-05-28 06:26:33",
        "ctime": "2022-05-28 06:26:33",
        "editor": "setup"
      },
      {
        "id": "1",
        "parentid": "0",
        "code": "asite",
        "level": 0,
        "label": "Another site",
        "config": "{}",
        "status": 1,
        "icon": "logo.png",
        "logo": "{200: \"logo.svg\"}",
        "theme": "default",
        "refid": "",
        "rating": "0.0",
        "ratings": 0,
        "mtime": "2022-05-28 06:26:33",
        "ctime": "2022-05-28 06:26:33",
        "editor": "setup"
      }
    ]
  }
}

Save single site#

mutation {
  saveLocaleSite(input: {
    id: "1"
    label: "My site"
  }) {
    id
  }
}
const body = JSON.stringify({'query':
`mutation {
  saveLocaleSite(input: {
    id: "1"
    label: "My site"
  }) {
    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": {
    "saveLocaleSite": {
      "id": "1"
    }
  }
}

Save multiple sites#

mutation {
  saveLocaleSites(input: [{
    id: "1"
    label: "My site"
  },{
    id: "2"
    label: "Your site"
  }]) {
    id
  }
}
const body = JSON.stringify({'query':
`mutation {
  saveLocaleSites(input: [{
    id: 1
    label: "My site"
  },{
    id: 2
    label: "Your site"
  }]) {
    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": {
    "saveLocaleSites": [
      {
        "id": "1"
      },
      {
        "id": "2"
      }
    ]
  }
}

Delete single site#

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

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": {
    "deleteLocaleSite": "1"
  }
}

Delete multiple sites#

mutation {
  deleteLocaleSites(id: ["1", "2"])
}
const body = JSON.stringify({'query':
`mutation {
  deleteLocaleSites(id: ["1", "2"])
}`});

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": {
    "deleteLocaleSites": [
      "1",
      "2"
    ]
  }
}

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.