Copied to clipboard

Flag this post as spam?

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


  • iiii 15 posts 154 karma points
    Sep 13, 2017 @ 09:01
    iiii
    0

    PackageBasket null shipment

    Hello,

    I'm using packageBasket method to get shipment and to get the shipment rates. But for some reason the returning shipment is always null (ie the returning ienumerable is empty).

    What are the conditions so it returns a not null shipment?

    What I've done:

    • have defined a shipping address
    • have items in the cart/basket
    • user is logged in
    • have Shipping Countries defined
    • have shipping providers defined

    my code:

    var shipAddress = _checkoutManager.Customer.GetShipToAddress();
    var shipment = _basket.PackageBasket(shipAddress).FirstOrDefault();
    var shipmentRateQuotes = shipment.ShipmentRateQuotes();
    

    THANK YOU! :)

  • Tolu Jemilua 36 posts 160 karma points
    Sep 13, 2017 @ 15:54
    Tolu Jemilua
    0

    did you do:

      _checkoutManager.Customer.SaveShipToAddress(someaddress);
    
  • iiii 15 posts 154 karma points
    Sep 14, 2017 @ 13:10
    iiii
    0

    yes I did

    public void SetDummyShippingAddress()
        {
            var shippingAddress = new AddressModel();
            shippingAddress.Address1 = ...
            ....
            _checkoutManager.Customer.SaveShipToAddress(CreateAddress(shippingAddress));
        }
    
  • Tolu Jemilua 36 posts 160 karma points
    Sep 14, 2017 @ 15:10
    Tolu Jemilua
    0

    What does Create Address look like?

  • iiii 15 posts 154 karma points
    Sep 14, 2017 @ 15:29
    iiii
    0

    It just converts my AddressModel to one Merchello.Core.Models.IAddress address.

    private IAddress CreateAddress(AddressModel model)
    {
                var address = new Address();
                address.Address1 = model.Address1;
                ...
                return address;
    }
    

    (in fact this is kinda useless and i changed it to create directly an IAddress instead of an AddressModel)

  • iiii 15 posts 154 karma points
    Sep 22, 2017 @ 09:10
    iiii
    100

    The error was when I add items to the basket, I wasnt including the extendedData.

    I had:

    public void AddItem(string prodSku, int quantity)
    {
       if (!prodSku.IsNullOrWhiteSpace())
        {
            var product = MerchelloHelper.Query.Product.GetBySku(prodSku);
    
            if (!_basket.Items.Any(i => i.Key.Equals(product.Key)))
            {
                _basket.AddItem(product.Name,product.Sku, quantity, product.Price);
                _basket.Save();
            }
        }
    }
    

    Had to change to

    public void AddItem(string prodSku, int quantity)
    {
        if (!prodSku.IsNullOrWhiteSpace())
        {
            var product = MerchelloHelper.Query.Product.GetProductVariantBySku(prodSku);
    
            if (!_basket.Items.Any(i => i.Key.Equals(product.Key)))
            {
                var extendedData = new ExtendedDataCollection();
                extendedData.SetValue(Merchello.Core.Constants.ExtendedDataKeys.CurrencyCode, "USD");
                extendedData.SetValue(Merchello.Core.Constants.ExtendedDataKeys.Taxable, product.Taxable.ToString());
                extendedData.SetValue(Merchello.Core.Constants.ExtendedDataKeys.Shippable, product.Shippable.ToString());
                extendedData.SetValue(Merchello.Core.Constants.ExtendedDataKeys.ProductVariantKey, product.Key.ToString());
    
                _basket.AddItem(product.Name,product.Sku, quantity, product.Price, extendedData);
                _basket.Save();
            }
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft