smartstore / Smartstore

A modular, scalable and ultra-fast open-source all-in-one eCommerce platform built on ASP.NET Core 7
http://www.smartstore.com/
GNU Affero General Public License v3.0
1.21k stars 449 forks source link

Could a shipment record be created automatically if there is no record and the status is marked as shipped #831

Closed suatsuphi closed 1 year ago

suatsuphi commented 1 year ago

Hi,

Could a shipment record be created automatically if there is no record and the status is marked as shipped ?

I have prepared the relevant section. if there is no record and the status is marked as shipped, record is ok.

case "ship":
case "deliver":
if (o.ShippingStatus != ShippingStatus.ShippingNotRequired && o.ShippingAddressId != 0)
{
    var ship = operation == "ship";
    if (o.Shipments.Count > 0)
    {
        foreach (var shipment in o.Shipments)
        {
            if (ship && shipment.ShippedDateUtc == null)
            {
                await _orderProcessingService.ShipAsync(shipment, true);
            }
            else if (!ship && shipment.ShippedDateUtc != null && shipment.DeliveryDateUtc == null)
            {
                await _orderProcessingService.DeliverAsync(shipment, true);
            }
        }

        ++numSuccess;
        succeededOrderNumbers.Add(o.GetOrderNumber());
    }
    else
    {
        if(ship)
        {
            var order = await _db.Orders.IncludeCustomer(true)
                                        .IncludeOrderItems()
                                        .IncludeShipments()
                                        .FindByIdAsync(o.Id);
            if (order == null)
            {
                ++numSkipped;
            }
            else
            {
                var quantities = new Dictionary<int, int>();
                foreach (var orderItem in order.OrderItems)
                {
                    quantities.Add(orderItem.Id, orderItem.Quantity);
                }

                var shipmentRecord = await _orderProcessingService.AddShipmentAsync(order, "", "", quantities);
                if (shipmentRecord != null)
                {
                    Services.ActivityLogger.LogActivity(KnownActivityLogTypes.EditOrder, T("ActivityLog.EditOrder"), order.GetOrderNumber());
                    foreach (var shipment in o.Shipments)
                    {
                        if (ship && shipment.ShippedDateUtc == null)
                        {
                            await _orderProcessingService.ShipAsync(shipment, true);
                        }
                    }

                    ++numSuccess;
                    succeededOrderNumbers.Add(o.GetOrderNumber());
                }
                else
                {
                    ++numSkipped;
                }
            }
        }
        else
        {
            ++numSkipped;
        }
    }
}
else
{
    ++numSkipped;
}
break;

https://github.com/smartstore/Smartstore/issues/782#issuecomment-1726341115

Michael-Herzog commented 1 year ago

Hi, I've only implemented it for set as shipped because for an item to be delivered it must be shipped first. Of course you can implement the code to execute set as shipped and set as delivered in a row. But the date would be the same for Shipping and Delivery which simply feels wrong, If the the merchant wants to do this be executing both actions in a row he still is able to do so relativly comfortable. Regards, Michael