8. Shop service - SphereMall/Android-MS-Client GitHub Wiki
Get basket by id
// Get basket by id
basket = client.basket(basketId);
//Get basket by id and userId
basket = client.basket(basketId, userId);
//Get basket order:
Order order = basket.getOrder();
//Get basket items
List<OrderItem> items = basket.getItems()
//Get basket id:
int basketId = basket.getId();
Add products to empty basket
Basket basket = client.basket()
basket.add(
new BasketPredicate(productId, amount),
new BasketPredicate(productId, amount)
)
Add products to existing basket
// Get basket by id
Basket basket = client.basket(basketId)
// OR client.basket(basketId, userId)
basket.add(
new BasketPredicate(productId, amount),
new BasketPredicate(productId, amount)
)
Remove product from basket
// Get basket by id
Basket basket = client.basket(basketId);
//Remove product from basket
basket.remove(new BasketPredicate(product.getId()));
Update product amount in the basket
// Get basket by id
Basket basket = client.basket(basketId);
//Set amount 3
basket.update(new BasketPredicate(productId, 3));
Set basket delivery method
// Get basket by id
Basket basket = client.basket(basketId);
DeliveryProvider deliveryProvider = client.deliveryProviders()
.first()
.data()
//Set delivery to the basket
basket.setDelivery(new Delivery(deliveryProvider))
.update();
Set basket shipping and billing addresses
// Get basket by id
Basket basket = client.basket(basketId);
//Get address
Address address = client.addresses().first().data();
//Update shipping and billing addresses
basket.setShippingAddress(address)
.setBillingAddress(address)
.update();
Set basket payment method
// Get basket by id
Basket basket = client.basket(basketId);
//Get payment method
PaymentMethod paymentMethod = client.paymentMethods().first().data();
//Update payment method
basket.setPaymentMethod(paymentMethod.getId())
.update();