November Happy Hour will be moved to Thursday December 5th.

Order Creation Programmatically

Vote:
 

Hi ,

I created an order by using IPurchaseorder API and created the LineItem using LineItem API. I added the LineItem to the order using PurchaseOrder.AddLineItem(LineItem).

On the CMS it displays the order total , order status. After editing Shipping method  order total automatically change to $0.0 and Line Item disappered.

And another issue was after saving my purchase order if I load that order it returns null.

I need to check if it happens is correct or not and also I need some blogs to refer.

Thanks in advance.

//Create purchase order
            var purchaseOrder = orderRepository.Create(contactId, "computer");

//Create Line Item
            LineItem lineitem = new LineItem()
            {
                DisplayName = "PenLine",
                Quantity = 10,
                PlacedPrice = 500,
                Code = "1477707",
                ListPrice = 500,
                ShippingMethodName = "In Store Pick up",
                ParentCatalogEntryId = "cart_1",
                ShippingAddressId = "0077777",
                WarehouseCode = "SAMPLE",
                IsInventoryAllocated = true,
                
            };
////Create Shipment
            Shipment shipment = new Shipment()
            {
                WarehouseCode = "SAMPLE",
                ShipmentTrackingNumber = "0077777",
                ShippingMethodName="Shipping",
                ShippingAddressId="1"

            };
purchaseOrder.AddLineItem(lineitem);
 purchaseOrder.AddShipment(shipment);

//Save
orderRepository.Save(purchaseOrder);

//Load

purchaseOrder = orderRepository.Load(contactId);//It returns null

#187973
Feb 07, 2018 17:01
Vote:
 

https://github.com/episerver/Quicksilver/blob/master/Sources/EPiServer.Reference.Commerce.Site/Features/Cart/Services/CartService.cs

You can follow the examples here. In short we don't work with the concrete Shipment and LineItem class, but use cart.CreateLineItem and cart.CreateShipment extension methods to create the instances of ILineItem and IShipment we need.

#187984
Feb 08, 2018 4:27
Vote:
 

Hi,

Thanks for reply.

I tried to create line item and shipment using cart.CreateLineItem and cart.CreateShipment.But still same issue occured.

#187985
Feb 08, 2018 6:46
Vote:
 

The most common reason for an lineitem to be removed during a validation is that it does not have a valid price, or it does not have a valid inventory. Make sure your "1477707" lineitem has both those information. 

#188004
Feb 08, 2018 9:26
Vote:
 

Hi,

Thanks for the reply.Order Total is not null.I found that Shipping method's base price is reflected in order total.I just get shipping methods using ShippingMethodDto and assign Base price value and save the changes.But it does not reflect in Commerce Manager.My code is like

//Get the list of all shipping methods to be filtered 
            ShippingMethodDto methods = ShippingManager.GetShippingMethods(SiteContext.Current.LanguageName);

//Assigning Base price value
for(int i = 0; i < 4; i++)
            {
                methods.ShippingMethod[i].BasePrice = 500;
                methods.AcceptChanges();
}
methods = ShippingManager.GetShippingMethods(SiteContext.Current.LanguageName);  //-->its returns old Base price value

Help me to override the base price value.

Thanks in advance.

#188017
Feb 08, 2018 14:30
Vote:
 

For future ref!

Updates or add a shippingmethod (COM 13):

var method = ShippingManager.GetShippingMethod(model.ShippingMethodId);
                if (method?.ShippingMethod?.Count > 0)//update
                {
                    method.ShippingMethod[0].DisplayName = model.DisplayName;
                    method.ShippingMethod[0].Currency = model.Currency;
                    method.ShippingMethod[0].IsActive = model.IsActive;
                    method.ShippingMethod[0].IsDefault = model.IsDefault;
                    method.ShippingMethod[0].Name = model.Name;
                    method.ShippingMethod[0].Description = model.Description;
                    method.ShippingMethod[0].Ordering = model.Ordering;
                    method.ShippingMethod[0].LanguageId = model.LanguageId;
                    method.ShippingMethod[0].BasePrice = model.BasePrice;
                    ShippingManager.SaveShipping(method);
                }
                else
                {
                    //add
                    var methods = ShippingManager.GetShippingMethods("");
                    var row = methods.ShippingMethod.NewShippingMethodRow();
                    row.ShippingMethodId = model.ShippingMethodId;
                    row.ShippingOptionId = model.ShippingOptionId;
                    row.Created = row.Modified = DateTime.UtcNow;
                    row.DisplayName = model.DisplayName;
                    row.Currency = model.Currency;
                    row.IsActive = model.IsActive;
                    row.IsDefault = model.IsDefault;
                    row.Name = model.Name;
                    row.Description = model.Description;
                    row.Ordering = model.Ordering;
                    row.LanguageId = model.LanguageId;
                    row.BasePrice = model.BasePrice;
                    methods.ShippingMethod.Rows.Add(row);
                    ShippingManager.SaveShipping(methods);
                }

 

#281488
Jun 07, 2022 18:44
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.