public void Add(CatalogSku sku, int quantity, Action<KnetikResult<CartItem>> cb) { Client.CartAdd(sku.CatalogID, sku.ID, quantity, (res) => { var result = new KnetikResult<CartItem> { Response = res }; if (!res.IsSuccess) { cb(result); return; } var item = new CartItem(Client, this); item.FromSku(sku, quantity); Items.Add(item); result.Value = item; cb(result); }); }
public void FromSku(CatalogSku sku, int quantity = 1) { ID = -1; TypeHint = sku.Item.TypeHint; SystemPrice = sku.Price; UnitPrice = sku.Price; TotalPrice = sku.Price * quantity; SkuID = sku.ID; Sku = sku.Sku; SkuDescription = sku.Description; Inventory = sku.Inventory; CatalogID = sku.CatalogID; ItemID = sku.Item.ID; Name = sku.Item.Name; Thumbnail = null; ErrorMessage = null; ErrorCode = 0; }
public override void Deserialize(KnetikJSONNode json) { if(json == null || json.ToString() == "\"null\"") { return; } if (json ["id"] != null && json ["id"] != "null") { ID = json ["id"].AsInt; } UniqueKey = json ["unique_key"].Value; TypeHint = json ["type_hint"].Value; Name = json ["name"].Value; ShortDescription = json ["short_description"].Value; LongDescription = json ["long_description"].Value; Assets.Clear (); if (json ["assets"] != null) { foreach (KnetikJSONNode node in json["assets"].Children) { ItemAsset asset = new ItemAsset (Client); asset.Deserialize (node); if (json ["behaviors"] != null) { asset.setSlug(json ["behaviors"]); } Assets.Add (asset); } } Skus.Clear (); if (json ["skus"] != null) { foreach (KnetikJSONNode node in json["skus"].Children) { CatalogSku sku = new CatalogSku (Client, this); sku.Deserialize (node); Skus.Add (sku); } } Behaviors.Clear(); if (json ["behaviors"] != null) { foreach (KnetikJSONNode node in json["behaviors"].Children) { Behavior behavior = Behavior.Parse (Client, node); Behaviors.Add (behavior.TypeHint, behavior); } } if (json ["deleted_at"] != null && json ["deleted_at"] != "null") { DeletedAt = new DateTime (json ["deleted_at"].AsInt); } if (json ["date_created"] != null && json ["date_created"] != "null") { DateCreated = new DateTime (json ["date_created"].AsInt); } if (json ["date_updated"] != null && json ["date_updated"] != "null") { DateUpdated = new DateTime (json ["date_updated"].AsInt); } }
public void QuickPurchase(CatalogSku sku, Action<KnetikResult<Cart>> cb) { Client.CartGet((res) => { if (res.IsSuccess) { KnetikJSONNode existingItems = res.Body["result"]["items"]; foreach (KnetikJSONNode json in existingItems.Children) { Client.CartModify(json["catalog_id"].AsInt, json["sku_id"].AsInt, 0); } } Client.CartAdd(sku.CatalogID, sku.ID, 1, (addResponse) => { var result = new KnetikResult<Cart> { Response = addResponse }; if (!addResponse.IsSuccess) { cb(result); return; } Client.CartCheckout((checkoutResponse) => { result.Response = checkoutResponse; if (!checkoutResponse.IsSuccess) { cb(result); return; } result.Value = this; cb(result); }); }); }); }
public KnetikApiResponse CartCreateWithVirtualCurrency(KnetikJSONArray currencies,CatalogSku catlog,Action<KnetikApiResponse> cb = null) { StringBuilder createCartBuilder = new StringBuilder(); createCartBuilder.Append(CartCreateEndpoint); JSONObject j = new JSONObject (JSONObject.Type.OBJECT); if (catlog.Item != null) { if(catlog.Item.TypeHint == "virtual_item" || catlog.CurrencyId != 0) { foreach(KnetikJSONNode element in currencies) { if(element["id"].AsInt == catlog.CurrencyId) { createCartBuilder.Append("?currency_code="+element["code"].Value); } } } } String body = j.Print (); KnetikRequest req = CreateRequest(createCartBuilder.ToString(), body); KnetikApiResponse response = new KnetikApiResponse(this, req, cb); return response; }