How to set property on shipping info in the cart

How do i set for example:

cartContext.Cart.Order.ShippingInfo.FirstOrDefault().ExpectedDeliveryDate = deliveryTime

I get this error NotSupportedException: Collection is read-only. But I can’t figure out how to make it writeable, and save it after.

Litium version: 8.3

If you look at the SalesOrderFixture in the IntegrationTest project, they set it when the Shipment is created.
Could you do that instead? Set that date when you create the shipment?

From Litiums Integration Test project

public Sales.Shipment CreateShipment()
            var shipment = new Sales.Shipment()
                Id = this.UniqueString(),
                TrackingReference = this.UniqueString(),
                TrackingUrl = this.UniqueString(),
                DeliveryInstructions = this.UniqueString(),
                ShipmentDocuments = new Dictionary<string, string> { { "key", "value" } },
                ExpectedDeliveryDate = DateTimeOffset.Now,
                ReceiverAddress = new Litium.Sales.Address()
                    FirstName = this.UniqueString(),
                    LastName = this.UniqueString(),
                    Address1 = "Receiver Address"
                DeliveryCarrierId = this.UniqueString(),
                CurrencyCode = this.UniqueString(),
                AdditionalInfo = new Dictionary<string, object> { { "key", "value" } },
                ContentDescription = this.UniqueString(),
                DeliveryCarrierServiceCode = this.UniqueString(),
                ReceiverReference = this.UniqueString(),
                SenderReference = this.UniqueString(),
                ShippingMethod = ShippingMethod.RegisteredPost,
                TmsShippingOptionReferenceId = this.UniqueString(),
                VatSummary = new Dictionary<decimal, decimal> { { 1, 1 } }

            return shipment;

Thanks, but the shipment is never created in any code I can access in a standard project and I need to update the value on a refresh of the checkout.

If you instead use additionalInfo to store the date you have the option to use cartContext.SelectShippingOptionAsync(selectShippingOptionArgs);

Could work :+1:, but would like to know how to work with the existing properties.

Here is some code sample on how to update the property.

await _cartContextSessionService.UpdateAsync(cartContext.Cart.SystemId, (cartContextSession) =>
    var shippingInfo = cartContextSession.Cart.Order.ShippingInfo.FirstOrDefault();
    if(shippingInfo is null)
        cartContextSession.Cart.Order.ShippingInfo.Add(new ShippingInfo { ExpectedDeliveryDate = DateTimeOffset.Now });
        shippingInfo.ExpectedDeliveryDate = DateTimeOffset.Now;
    return Task.FromResult(true);
1 Like

Just a note: Keep in mind that this code does not use our public API but internal classes that may change without notice in newer releases.

So there is no offical way to set these properties released yet?

Not for the moment but put a comment on your code in case something changes in future so it would be easier to find the issue.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.