Check available stock in shop
The checkIsAvailable
callback triggers a custom function that is used to check the stock of the desired ski. If stock information is provided to the widget and the ski is out of stock it will display a sold out message. You can then setup an additional custom function for the confirmSizeUnavailable
callback to specify what happens after closing the widget.
If your function to check your stock returns false for the suggested size, the result screen of the widget will show a different button reading Continue shopping.
For this button to work, you need to provide another callback function confirmSizeUnavailable
which decides what should happen in this scenario.
- Code
- Payload
- Example
const myCheckStockFunction = (payload) => {
const { code, displaySize01, type } = payload;
let sizeAvailable = false;
// here goes YOUR code that will check the stock for recommended ski…
// … and return `true` if in stock or `false` if not
// use the payload to identify the recommended ski in your shop that you need to check the stock for
return sizeAvailable;
};
const OZ_CONFIG = {
settings: {
// config options here
},
events: {
checkIsAvailable: {
callback: myCheckStockFunction,
},
},
};
Object {
code: ""7615523592692"", // will be in the same format as you passed it to the widget.
displaySize01: "169",
size: "169", // Deprecated. Use displaySize01 instead.
}
const myCheckStockFunction = (payload) => {
const { code } = payload;
// variantStock is an array of objects with key-value pairs (productcode: stock) for all variants.
// E.g.
// 4712878580879: 0
// 4712878580886: 1
// 4712878580893: 1
if (variantStock[code] > 0) {
return true;
} else {
return false;
}
};
const OZ_CONFIG = {
settings: {
apiKey: "YOUR API-KEY",
// more config options
},
events: {
checkIsAvailable: {
callback: myCheckStockFunction,
},
},
};
We explicitely recommend that you use the product code passed in the payload to your function to query the stock for the desired variant. Passed size information is not consistent and should not be used as an identifier.