Manipulate Cart in App

Shopify Partner
3 0 0

Hi Everyone,

i am trying to develop an app which will use a kind of external inventory.
I created an app-theme-extension and created a block to check if a unit of the product exists in my inventory and if yes, i will add it to the cart and proceed to the purchase. See the code of my block below. 

My code is not working and i got the error : Uncaught (in promise) ReferenceError: cart is not defined
isn't it possible to use cart as an object ? 

Do you think this is the best approach ? 

// This script will check if the product is in stock in the external inventory system.
// If it is, it will add the product to the Shopify basket.
async function checkInventory() {
// Get the product ID from the Shopify product.
console.log("Product id:",{{}});
const productId = {{}};

// Make a request to the external inventory system to check the inventory for the product.
const response = await fetch('' + productId);

// Check the response status code.
if (response.status === 200) {
// The product is in stock. Add the product to the Shopify basket.
product_id: {{ }},
quantity: 1
} else {
// The product is not in stock. Show an alert message to the customer.
alert('The product is not in stock.');
style="background-color:{{ block.settings.background-color }};color:{{ block.settings.color }}"
{{ 'myapp.addToBasketButton.label' | t }}

{% schema %}
"name": "My app Product",
"target": "section",
"settings": [
{ "type": "product", "id": "product", "label": "product", "autofill": true },
{ "type": "color", "id": "color", "label": "Button Color", "default": "#FFFFFF" },
{ "type": "color", "id": "background-color", "label": "Button background Color", "default": "#168F30" }
{% endschema %}
Replies 0 (0)