Copied to clipboard

Flag this post as spam?

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


  • Marco Teodoro 72 posts 147 karma points c-trib
    Sep 23, 2016 @ 20:09
    Marco Teodoro
    0

    Shipment null when i use a different shipping country address

    Hi Rusty,

    We have an merchello setup on version 2.1 and it's working fine if we use the country PT as shipping address. When we change the country code to es or uk the following line of code returns null.

    var shipment = Basket.PackageBasket(shippingAddress).FirstOrDefault();

    We have the providers configured for each of this countries the same way, off course different prices. I've looked into bazar code to check the differences and don't see many diferences in there.

    if (!ModelState.IsValid)
                    return CurrentUmbracoPage();
    
            var checkoutManager = Basket.GetCheckoutManager();
            var customerManager = checkoutManager.Customer;
            var paymentManager = checkoutManager.Payment;
            var shippingManager = checkoutManager.Shipping;
    
            // Clear Shipment Rate Quotes
            shippingManager.ClearShipmentRateQuotes();
    
            // Get the shipping address
            var shippingAddress = customerManager.GetShipToAddress();
    
            if (shippingAddress == null)
            {
                var customer = ((ICustomer)CurrentCustomer);
                shippingAddress = customer.Addresses.First().AsAddress("Shipping Address");
                shippingAddress.Email = customer.Email;
                shippingAddress.Name = customer.FullName;
                checkoutManager.Customer.SaveBillToAddress(shippingAddress);
                checkoutManager.Customer.SaveShipToAddress(shippingAddress);
            }
    
            var shipment = Basket.PackageBasket(shippingAddress).FirstOrDefault();
    
            // get the quote using the "approved shipping method"
            var quote = shipment.ShipmentRateQuoteByShipMethod(model.ShipMethodKey);
    
            // save the quote
            shippingManager.SaveShipmentRateQuote(quote);
    

    before this step, cause we have a view to define the shipping address we are saving it to basket this way.

    if (!ModelState.IsValid) return CurrentUmbracoPage();

            CheckoutManager.Shipping.ClearShipmentRateQuotes();
            CheckoutManager.Payment.Reset();
    
            var customer = ((ICustomer)CurrentCustomer);
            customer.FirstName = model.Name.Split(' ').First();
            customer.LastName = model.Name.Split(' ').Last();
            MerchelloServices.CustomerService.Save(customer);
    
            var address = customer.Addresses.Any(s => s.AddressType == AddressType.Shipping) ? customer.Addresses.First(s => s.AddressType == AddressType.Shipping) : new CustomerAddress(customer.Key);
            //customer.FirstName = model.Name;
            address.Address1 = model.Address1;
            address.Address2 = model.VatNumber;
            address.AddressType = AddressType.Shipping;
            address.CountryCode = model.CountryCode;
            address.FullName = model.Name;
            address.Phone = model.Phone;
            address.Company = model.Organization;
            address.Region = model.Region;
            address.Locality = model.Locality;
            address.PostalCode = model.PostalCode;
    
            //save address
            customer.SaveCustomerAddress(address);
    
            var sha = address.AsAddress("shipping address");
            var bla = address.AsAddress("billing address");
            sha.Email = model.Email;
            bla.Email = model.Email;
            bla.Name = customer.FullName;
            sha.Name = customer.FullName;
    
            //save checkout addresses
            CheckoutManager.Customer.SaveBillToAddress(bla);
            CheckoutManager.Customer.SaveShipToAddress(sha);
    

    i know the information is not much, but maybe you have a clue of what's missing here.

    Thanks, Marco

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Sep 23, 2016 @ 21:35
    Rusty Swayne
    101

    I think you may be running into a bug that was fixed in 2.2 -

    In your line:

      // get the quote using the "approved shipping method"
      var quote = shipment.ShipmentRateQuoteByShipMethod(model.ShipMethodKey);
    

    Try changing it to

          // get the quote using the "approved shipping method"
        var quote = shipment.ShipmentRateQuoteByShipMethod(model.ShipMethodKey, false);
    
  • Marco Teodoro 72 posts 147 karma points c-trib
    Sep 23, 2016 @ 22:10
    Marco Teodoro
    0

    Thks a lot Rusty it was that!

Please Sign in or register to post replies

Write your reply to:

Draft