Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Joe 30 posts 133 karma points
    Nov 02, 2018 @ 20:08
    Joe
    0

    Merchello Partial shipment on same SKU

    I'm using Merchello 2.6 to build an online shop with shipment that seems having contradiction with Merchello's OrderItem.

    • Background:

      The situation is that when the customer makes an purchase invoice on 10 Qty on 1 Product (1 SKU), creating an order after payment captured, the shop needs to split the shipment of these 10 Qty same-SKU items in the same invoice with different carriers! (due to their business restriction, e.g. ship 1 Qty with Carrier A, ship 3 Qty with Carrier B). However, Merchello by default only let user split the shipment by line-item, while this partial shipment inside 1 line-item seems not supported.

    • Problem - SKU is Key for LineItem

      Then I try to split the order line items into the splits they need in the same order,

      e.g. this code just try to split a SKU with 10 Qty into 10 Line Items.

      [Obsolete("It won't work due to conflict with Merchello Core. Leave Code here as reference only", true)]
      private static void SplitOrderLineItemsByQty(IOrder order)
      {
          List<OrderLineItem> newLineItems = new List<OrderLineItem>();
          var itemsToSplit = order.Items.Where(x
              => x.Quantity > 1
              && x.LineItemType == LineItemType.Product
              && x is OrderLineItem)
          .Cast<OrderLineItem>();
          for (int i = 0; i < itemsToSplit.Count(); i++)
          {
              var itemToSplit = itemsToSplit.ElementAt(i);
              for (int iSplit = 1; iSplit < itemToSplit.Quantity; iSplit++)
              {
                  newLineItems.Add(new OrderLineItem(itemToSplit.LineItemType, itemToSplit.Name, itemToSplit.Sku, 1, itemToSplit.Price,
                      itemToSplit.ExtendedData)
                  {
                      // Don't assign value for new splited items
                      //Key = itemToSplit.Key,
                      //ContainerKey = itemToSplit.ContainerKey,
                      //ShipmentKey = itemToSplit.ShipmentKey,
                      //BackOrder = itemToSplit.BackOrder,
                      //Exported = itemToSplit.Exported,
                      //UpdateDate = itemToSplit.UpdateDate,
                      //CreateDate = itemToSplit.CreateDate
                  });
              }
              itemToSplit.Quantity = 1;
          }
      
      
      
      order.Items.Add(newLineItems);
      
      }

    Since the order.Items is LineItemCollection

    class LineItemCollection : NotifiyCollectionBase<string, ILineItem>
    

    and the key is exactly SKU (See https://github.com/Merchello/Merchello/blob/v2.6.0/src/Merchello.Core/Models/LineItemCollection.cs#L193), my sample code won't work! It only add the Qty for adding same SKU; or throw exception due to attempt on adding same-key-item to the collection.

    Can I have some good directions or hints on how should it be handled, so the line-item can be split into multiple shipments?

Please Sign in or register to post replies

Write your reply to:

Draft