Page 1 of 1

Basket.Recalculate() overwrites shipment's province

Posted: Tue Jul 14, 2009 8:45 am
by adamh
We are running Ablecommerce 7.0.3

When calling Recalculate() on a basket, the basket's shipment province and postal codes are replaced with the warehouse's province and postal code for some reason. The following is a code snippet from our checkout process.

Code: Select all

Address address = new Address();
address.Company = CompanyName.Text;
address.FullName = ContactName.Text;
address.Address1 = ShipToAddress.Text;
address.Address2 = ShipToAddress2.Text;
address.Phone = Phone.Text;
address.Fax = Fax.Text;
address.City = ShipToCity.Text;
address.Province = ShipToState.SelectedValue;
address.PostalCode = ShipToZip.Text;
address.Email = Email.Text;

Token.Instance.User.Basket.Save();
Token.Instance.User.Basket.Package();

foreach (BasketShipment shipment in Token.Instance.User.Basket.Shipments)
{
    shipment.SetAddress(address);
    shipment.ShipMessage = ShippingMessage.Text;
    shipment.Save();
}

Token.Instance.User.Basket.Recalculate();
Obviously this shouldn't happen and we can not figure out why it does. If we call Recalculate() before setting the shipment addresses or if we set addresses and then repackage, all addresses are set to the billing address.

This is an urgent matter and any help would be appreciated.

Thanks,
Adam

Re: Basket.Recalculate() overwrites shipment's province

Posted: Tue Jul 14, 2009 9:41 am
by mazhar
Try by associating address with user, try following code

Code: Select all

Address address = new Address();
        address.Company = CompanyName.Text;
        address.FullName = ContactName.Text;
        address.Address1 = ShipToAddress.Text;
        address.Address2 = ShipToAddress2.Text;
        address.Phone = Phone.Text;
        address.Fax = Fax.Text;
        address.City = ShipToCity.Text;
        address.Province = ShipToState.SelectedValue;
        address.PostalCode = ShipToZip.Text;
        address.Email = Email.Text;
        
        Token.Instance.User.Addresses.Add(address);
        Token.Instance.User.Save();
        
        Token.Instance.User.Basket.Save();
        Token.Instance.User.Basket.Package();

        foreach (BasketShipment shipment in Token.Instance.User.Basket.Shipments)
        {
            shipment.SetAddress(address);
            shipment.ShipMessage = ShippingMessage.Text;
            shipment.Save();
        }

        Token.Instance.User.Basket.Recalculate();