How does the shopping cart work?
  • 01 Sep 2022
  • 2 Minutes to read
  • Contributors
  • Dark
    Light

How does the shopping cart work?

  • Dark
    Light

Article Summary

Get the current shopping cart and add and remove products from the shopping cart.

The BookingGate can be reached via: https://bg.promaterial.com/api

upsertProduct

upsertProduct adds a product to the shopping cart and returns the new shopping cart.
Example:

mutation m1 {
  upsertProduct(product:{
    proMaterialId: "<proMaterialId>"
    productGateCode: "<productGateCode>"
    distributionGateCode: "<distributionGateCode>"
    distributionChannel: "<distributionChannel>"
    productPrice: {
      amount: 7.76
      currency: "EUR"
      taxDetails: {
        taxType: VAT
        taxAmount: 19
      }
    }
    productOrderDetails:{
      orderUnit: {
        code: "QM-PIECE"
      }
      quantity: 1
    }
    email: "<email>",
    clientNumber: "801754"
  }){
    shoppingCartId
    creationDate
    orderTotals {
      totalOrderProducts
      totalAmountNet
      orderCurrency
    }
    products {
      productOrderDetails {
        orderUnit {
          code
        }
      }
    }
  }
}

If no shopping cart yet exists, leave the field shoppingCartId empty; a new shopping cart is created. Use the ID of this shopping cart to add more products.

You specify the product you want to add via the proMaterialId. If the product is already in the shopping cart, the old quantity is replaced by the new quantity. The proMaterialId will be replaced by the productId in the future.

You need to provide productPrice; use the price you obtained via the pricesearch. We use the productPrice to check if the price the user saw in the frontend changed in the meantime.

productGateCode is an information that can be retrieved via productsearch.

distributionGateCode is the first part of the DistributionGate URL and can also be retrieved with the connectedDistributionGates query.

Add the ID of your distributionChannel as returned by the connectedDistributionGate query. The ID is different for each DistributionGate.

productOrderDetails is optional.

clientNumber und email are obligatory fields that can be retrieved via the getUser query.

deleteProduct

Delete a product by providing the shoppingCartId and the proMaterialId of the product. The new shoppingCart is returned.

Example:

mutation m2 {
deleteProduct(
    shoppingCartId: "<shoppingCartId>" 
    proMaterialId: "<proMaterialId>"
    ){
    shoppingCartId
    creationDate
    orderTotals {
      totalOrderProducts
      totalAmountNet
      orderCurrency
    }
    products {
      productOrderDetails {
        orderUnit {
          code
        }
      }
    }
  }
}

shoppingCart

You can get shopping carts for a user using this query:

query q1 {
  shoppingCart(id:"<shoppingCartId>"){
    content {
      shoppingCartId
      creationDate
      orderTotals {
        totalOrderProducts
        totalAmountNet
        orderCurrency
      }
      products {
        shoppingCartId
        proMaterialId
        distributionChannel
        productPrice {
          amount
          currency
          taxDetails {taxType taxAmount}
        }
        productOrderDetails {
          orderUnit{
            code
            value
            unit
          }
          quantity
        }
        category
      }
    }
    
  }
}

The shoppingCartId is optional here. When you do not send it, you will get the latest shoppingCart that belongs to the user who is identified by the token you send. By default it always returns one.
By using the page parameter, you can get other, older carts. For example this: page:{page:0 size: 5} would return the last five carts of the logged in user.


Was this article helpful?