Copied to clipboard

Flag this post as spam?

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


  • Frans Lammers 34 posts 297 karma points c-trib
    Jun 01, 2017 @ 13:20
    Frans Lammers
    0

    Merchello - shipment in custom checkout

    Hi,

    I have been working on a custom-controller for checkout and I got it working except for one problem. When I deselect the "this variant is shippable" option and I run my controller without shipping-code it works fine: I can see the invoices as fulfilled in the paid invoices.

    Now I'm trying to add shipping. So I select the "this variant is shippable" option for my products. I have the default warehouse and catalog selected at shipping information of the products. I have a fixed rate shipping provider with a range defined.

    In my controller I add next snippet:

        var wareHouse = MerchelloContext.Current.Services.WarehouseService.GetDefaultWarehouse();
        var shipmentService = MerchelloContext.Current.Services.ShipmentService;
        var shipmentStatus = shipmentService.GetShipmentStatusByKey(Constants.ShipmentStatus.Quoted); 
        var shipment = shipmentService.CreateShipment(shipmentStatus, wareHouse.AsAddress(), shippmentAddress, basket.Items);
        var quote = MerchelloContext.Current.Gateways.Shipping.GetShipRateQuotesForShipment(shipment, false);
    

    But when I run it and check the value of quote, the enumerable within is always empty.

    I also tried the next one:

    var quotes = shipment.ShipmentRateQuotes();
    

    but this also is empty. What am I doing wrong?

  • Frans Lammers 34 posts 297 karma points c-trib
    Jun 12, 2017 @ 12:39
    Frans Lammers
    0

    Hi,

    I have found this code, which gives me my shipmentRateQuote:

      var shipment = basket.PackageBasket(shippmentAddress).FirstOrDefault();
                if (shipment != null)
                {
                    var shipmentRateQuotes = shipment.ShipmentRateQuotes().ToList();
                    if (shipmentRateQuotes.Any())
                    {
                        checkoutManager.Shipping.SaveShipmentRateQuote(shipmentRateQuotes.First());
                    }
                }
    

    So I am one step further. But I still have to fulfill my order in the backoffice, however in my project shppings are taken care of externally. I only need them as reference, so I would like to create the shippment during checkout. Again it is hard to find the necessary steps. How do I create a shipment and connect it to the order?

  • Frans Lammers 34 posts 297 karma points c-trib
    Jun 26, 2017 @ 13:34
    Frans Lammers
    100

    OK, I solved it by using the ShipmentApiController like in this example

    And to fullfil the order manually, I added:

            foreach (OrderLineItem orderItem in order.Items)
            {
                orderItem.ShipmentKey = shipmentDisplay.Key;
            }
            order.OrderStatus = orderService.GetOrderStatusByKey(Constants.OrderStatus.Fulfilled);
            orderService.Save(order);
    

    For now this seems to work...

Please Sign in or register to post replies

Write your reply to:

Draft