Skip to content

Instantly share code, notes, and snippets.

@nspeet
Last active February 4, 2019 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nspeet/1bf1b42b5468dacaaa43e650ff9b585f to your computer and use it in GitHub Desktop.
Save nspeet/1bf1b42b5468dacaaa43e650ff9b585f to your computer and use it in GitHub Desktop.
AR button action flow with Commercetools
// Step 1. create a menu button to select products
// Then on this menu button click... search for products, you can set a filter as required
ProductProjection.search(sort: ["name.en asc"], limit: 10, lang: Locale(identifier: "en"), { result in
if let response = result.model, let total = response.total as? UInt,
let results = response.results as? Array<ProductProjection>, result.isSuccess {
//handle showing results
}
....
// Step 2. Update the view with the product selected
let couch = SCNScene(named: "art.scnassets/sofa.dae")
self.object3D = couch?.rootNode;
self.object.removeFromParentNode()
self.object = self.object3D;
....
// Step 3. Cart the product as required in your logic flow
Cart.byId(self.cartID, result: { result in
let currentCartVersion = result.model?.version;
let draft = LineItemDraft(productVariantSelection: .productVariant(productId: self.currentProductID, variantId: Int(self.currentProductVariantID)! ))
let updateActions = UpdateActions<CartUpdateAction>(version: currentCartVersion!, actions: [.addLineItem(lineItemDraft: draft)])
Cart.update(self.cartID, actions: updateActions, result:{result in
if let cart = result.model, result.isSuccess {
// Cart successfully updated, response contains updated cart
}else{
print("error: " + (result.errors?.description)!);
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment