• Not Answered

Sitecore commerce - speed up requests into engine possible to send batches with updated cart as result

Hi all, 


Have one question if its possible to use expand during proxy call where you can send batch of cart lines and as a result return a cart via proxy - so make it faster ? 

Simple example : 

I have created one action to update cart lines request but instead of sending request one by one and recalculating cart total again and again i just simply wrapped it into one simple object: 

[{CartlineID: 123456 Quantity:123456}, {....}]. 

Everything is working fine even when returning cart via proxy, but when want to add expand it does not working. In postman i am getting json with expand but not when calling it in code. 

[Route("api/Carts"), Microsoft.AspNetCore.OData.EnableQuery]
public class CartsController : CommerceController
public CartsController(IServiceProvider serviceProvider, CommerceEnvironment globalEnvironment)
: base(serviceProvider, globalEnvironment)

public async Task<IActionResult> UpdateCartLinesWithResult([FromBody] ODataActionParameters value)
IActionResult result;

if (!ModelState.IsValid || value == null)
result = new BadRequestObjectResult(ModelState);
var cartLinesUpdateRequest = JsonConvert.DeserializeObject<CartLinesUpdateRequest>(JsonConvert.SerializeObject(value["cartLinesUpdateRequest"]));

if (!string.IsNullOrEmpty(cartLinesUpdateRequest.CartId))
Cart cart = null;
//to return also error messages / status in one request as a cart custom component
var cartMessages = new CartCustomMessages() { ResponseCode = "Ok" };

foreach (var cartLine in cartLinesUpdateRequest.CartLines)
//update cart lines as result i get the cart object

result = new ObjectResult(cart); //returning cart as a object
return result;

result = new BadRequestObjectResult(value);

return result;


Then in service configuration to register the action : 

var updateCartLinesAction = modelBuilder.Action("UpdateCartLinesWithResult");

Then in code : 


GetContainer(shopName, userId, customerId).UpdateCartLinesWithResult(new CartLinesUpdateRequest() { CartId = "cartId", CartLines = new System.Collections.ObjectModel.ObservableCollection<CartLineUpdateRequest>() {

new CartLineUpdateRequest()
CartLineId = "12345",
Quantity = 12345
} }, "Lines($expand=CartLineComponents),Components"); // will throw an exception, but when put only components this is working fine, but i want to return also lines

Any idea if this is even possible ? I want to find way if its possible to speed it up - so i tried second option which is working fine but instead of using proxy i am calling it in same way as pure rest and then deserialize it with custom type binder.

I am using commerce for Sitecore 8.5 but using MS.Odata will be the same for any of versions of commerce i guess.