Multiple Shops
This article is intended for merchants and agencies/developers wishing to query and link multiple shops data for a tool to a website (Prestashop, WooCommerce ...).
Introduction
To understand how multiple shops data are linked together, you need know that nothing is magical, and we can only link products (aka Variants) together at this point.
This guide explains the steps to follow on:
- How to query mutiple shops variants.
- How to query a specific shop variants.
- How to combine stocks from multiple shops variants which are linked.
Prepare the ground
Before starting, we suppose that you have already checked:
- The guide about "Interacting with products".
- The guide about "Creating an online store".
- The guide about "The Playground".
Premises
Let's suppose that you have an account which access to 3 shops data (ShopA
, ShopB
, ShopC
).
How to query mutiple shops variants
When you have an account that access multiple shops then by default you will query over all the data in all the shops combined. so a query as the following will return variants from from ShopA
ShopB
and ShopC
query {
variants(first: 5) {
edges {
node {
id
shop {
id
}
}
}
}
}
{
"variants": {
"edges": [
{
"node": {
"id": "any-uuid",
"shop": {
"id": "shop-a--uuid"
}
}
},
{
"node": {
"id": "any-uuid",
"shop": {
"id": "shop-b--uuid"
}
}
},
{
"node": {
"id": "any-uuid",
"shop": {
"id": "shop-a--uuid"
}
}
},
{
"node": {
"id": "any-uuid",
"shop": {
"id": "shop-c--uuid"
}
}
},
{
"node": {
"id": "any-uuid",
"shop": {
"id": "shop-c--uuid"
}
}
}
]
}
}
How to query a specific shop variants
In order to get a specific shop variants, we need to simply filter the results using the identifier of the chosen shop (or shops)
query {
variants(
first: 3,
filterBy: {
shopIds: { _in: ['shop-a--uuid'] }
}
) {
edges {
node {
id
shop {
id
}
}
}
}
}
{
"variants": {
"edges": [
{
"node": {
"id": "any-uuid",
"shop": {
"id": "shop-a--uuid"
}
}
}
{
"node": {
"id": "any-uuid",
"shop": {
"id": "shop-a--uuid"
}
}
},
{
"node": {
"id": "any-uuid",
"shop": {
"id": "shop-a--uuid"
}
}
}
]
}
}
How to combine stocks from multiple shops variants which are linked
Before we can answer this question you need to understand how variants from different shops can be linked.
We can say that two or more variants from two or more shops are linked together if they have the exact same value of their stock keeping unit
or (SKU
), this concept is used by organised shops to keep track of their products across multiple shops and you can read more about this here.
But how we can use this knowledge to combine stock of linked variants from multiple shops, and to answer this question you need to:
- Get all the variants which have the same stock keeping unit value.
- Combine their stock raw quantity with a simple for loop.
Get all the variants which have the same stock keeping unit value
Make sure to query and paginate through all the variants until you have no more values to query
query {
variants(
filterBy: {
stockKeepingUnit: { _equals: '--stock-keeping-unit-value--' }
}
) {
edges {
node {
id
stockKeepingUnit
stock {
# the stock quantity of each variant
rawQuantity
}
shop {
id
}
}
}
}
}
{
"variants": {
"edges": [
{
"node": {
"id": "any-uuid",
"stockKeepingUnit": "--stock-keeping-unit-value--",
"stock": {
"rawQuantity": 10
},
"shop": {
"id": "shop-a--uuid"
}
}
}
{
"node": {
"id": "any-uuid",
"stockKeepingUnit": "--stock-keeping-unit-value--",
"stock": {
"rawQuantity": 2
},
"shop": {
"id": "shop-b--uuid"
}
}
},
...
]
}
}
Combine their stock raw quantity with a simple for loop
const linkedVariantStock = 0
for (const variant of variants) {
linkedVariantStock += variant.stock.rawQuantity
}
console.log(linkedVariantStock) // the Combine stock value of the linked variants
Support
Wino's technical team is available by chat on the following link: help.wino.fr.