@@ -258,6 +258,93 @@ String stockId = client.inventory().saveStockItems(productSku, inventory_for_sku
258
258
259
259
### Guest Shopping Cart
260
260
261
+ The sample code below shows how to create a new guest shopping cart, add/update/delete items in the shopping cart:
262
+
263
+ Note that creating guest shopping cart does not require login
264
+
265
+ ``` java
266
+ MagentoClient client = new MagentoClient (Mediator . url);
267
+ String cartId = client. guestCart(). newCart();
268
+
269
+ CartItem item = new CartItem ();
270
+ item. setQty(1 );
271
+ item. setSku(" product_dynamic_758" );
272
+
273
+ // add new item to shopping cart
274
+ item = client. guestCart(). addItemToCart(cartId, item);
275
+ System . out. println(" cartItem: " + JSON . toJSONString(item, SerializerFeature . PrettyFormat ));
276
+
277
+ // update item in the shopping cart
278
+ item. setQty(3 );
279
+ item = client. guestCart(). updateItemInCart(cartId, item);
280
+ System . out. println(" cartItem: " + JSON . toJSONString(item, SerializerFeature . PrettyFormat ));
281
+
282
+ // delete item in the shopping cart
283
+ boolean deleted = client. guestCart(). deleteItemInCart(cartId, item. getItem_id());
284
+
285
+ Cart cart = client. guestCart(). getCart(cartId);
286
+ CartTotal cartTotal = client. getGuestCart(). getCartTotal(cartId);
287
+
288
+ System . out. println(" cart: " + JSON . toJSONString(cart, SerializerFeature . PrettyFormat ));
289
+ System . out. println(" cartTotal: " + JSON . toJSONString(cartTotal, SerializerFeature . PrettyFormat ));
290
+ ```
291
+
292
+ The sample code belows show how to transfer a guest cart to my cart after user login:
293
+
294
+ ``` bash
295
+ MagentoClient client = new MagentoClient(Mediator.url);
296
+
297
+ String cartId = client.guestCart().newCart ();
298
+
299
+ CartItem item = new CartItem ();
300
+ item.setQty(1);
301
+ item.setSku(" product_dynamic_758" );
302
+
303
+ item = client.guestCart ().addItemToCart(cartId, item);
304
+
305
+ client.loginAsClient(" username" , " password" );
306
+ boolean result = client.myCart ().transferGuestCartToMyCart(cartId);
307
+
308
+ Cart cart = client.myCart().getCart ();
309
+ CartTotal cartTotal = client.myCart().getCartTotal ();
310
+
311
+ ```
312
+
313
+ ### My Shopping Cart
314
+
315
+ The sample code below shows how to create my shopping cart, add/update/delete items in the shopping cart:
316
+
317
+ Note that creating my shopping cart requires login
318
+
319
+ ``` java
320
+ MagentoClient client = new MagentoClient (Mediator . url);
321
+ client. loginAsClient(" username" , " password" );
322
+ String quoteId = client. myCart(). newQuote();
323
+
324
+ CartItem item = new CartItem ();
325
+ item. setQty(1 );
326
+ item. setSku(" product_dynamic_758" );
327
+
328
+ // add new item to shopping cart
329
+ item = client. myCart(). addItemToCart(quoteId, item);
330
+ System . out. println(" cartItem: " + JSON . toJSONString(item, SerializerFeature . PrettyFormat ));
331
+
332
+ // update item in the shopping cart
333
+ item. setQty(3 );
334
+ item = client. myCart(). updateItemInCart(quoteId, item);
335
+ System . out. println(" cartItem: " + JSON . toJSONString(item, SerializerFeature . PrettyFormat ));
336
+
337
+ // delete item in the shopping cart
338
+ boolean deleted = client. myCart(). deleteItemInCart(item. getItem_id());
339
+
340
+ Cart cart = client. myCart(). getCart();
341
+ CartTotal cartTotal = client. myCart(). getCartTotal();
342
+
343
+ System . out. println(" cart: " + JSON . toJSONString(cart, SerializerFeature . PrettyFormat ));
344
+ System . out. println(" cartTotal: " + JSON . toJSONString(cartTotal, SerializerFeature . PrettyFormat ));
345
+ ```
346
+
347
+
261
348
The sample code below shows how to create a new guest shopping cart, add/update/delete items in the shopping cart:
262
349
263
350
Note that creating guest shopping cart does not require login
0 commit comments