Page 1 of 1

Warehouse based on state

Posted: Tue May 11, 2010 3:58 pm
by mfreeze
I have set up a Zone that contains all the states west of the Mississippi River.

What I need to do now is on one page checkout set a different warehouse (for shipping charge purposes) based upon whether the province in the shipping address matches any province in this zone.

I have done this for countries but never for provinces. Following is how I did the change based on country. How could I do the same thing based on province?

Code: Select all

 protected ICollection<ShipRateQuote> CanadianQuoteForShipment(CommerceBuilder.Orders.BasketShipment shipment)
    {
        ICollection<ShipRateQuote> rateQuotes = new System.Collections.ObjectModel.Collection<ShipRateQuote>();
        //GET ALL OF THE POSSIBLE SHIPMETHODS for CANADIAN ORIGIN
        WarehouseCollection warehouses = WarehouseDataSource.LoadForCountry(shipment.Address.CountryCode);
        if (warehouses.Count > 0 && shipment.Address.CountryCode == "CA")
        {
            shipment.WarehouseId = warehouses[0].WarehouseId;
            shipment.Save();
        }

Re: Warehouse based on state

Posted: Wed May 12, 2010 2:57 am
by s_ismail
Give a try by this, hopefully it will work

Code: Select all

protected ICollection<ShipRateQuote> CanadianQuoteForShipment(CommerceBuilder.Orders.BasketShipment shipment)
    {
        ICollection<ShipRateQuote> rateQuotes = new System.Collections.ObjectModel.Collection<ShipRateQuote>();
        //GET ALL OF THE POSSIBLE SHIPMETHODS for CANADIAN ORIGIN
        WarehouseCollection warehouses = WarehouseDataSource.LoadForCountry(shipment.Address.CountryCode);
        
       ProvinceCollection provinces = ProvinceDataSource.LoadForCountry("CA");
        foreach (Province province in provinces)
        {
            if (shipment.Address.Province == province.Name)
            {
                shipment.WarehouseId = warehouses[0].WarehouseId;
                shipment.Save();
                break;
            }
        }
}

Re: Warehouse based on state

Posted: Wed May 12, 2010 6:08 am
by mazhar
Well what about making certain shipping method available only to some certain warehouse through merchant admin. Then when products belonging to that warehouse will be purchased, shipping method for warehouse will be available for order.

Re: Warehouse based on state

Posted: Wed May 12, 2010 10:46 am
by mfreeze
That won't work for how the client wants to handle shipping. Here's the story and what she wants to do.

There are 2 partners in the business; one will handle shipping for all products sold East of the Mississippi, the other products sold West of the Mississippi.

They both sell all products and they don't want to duplicate them on the site.

They want 2 warehouses one for West and one for East. If the shipping address is West then it will ship from the West warehouse, if it is East it will ship from the East warehouse.

I know I can do this somewhat similar to the way I checked the shipping country by comparing the shipping address to the provinces in the zone I set up. Looking at commercebuilder.shipping, I see that there is a commercebuilder.shipping.province.shipzoneprovince but am not 100% sure how to pull in the provinces in the zone I set up and do the compare to the shipping address province.

My coding skills are enough to come up with the idea but not the entire functionality. I think this would also solve some of the issues with multiple warehouses that have been posted on the forums but, like I said, my coding skills aren't strong enough to pull it off.

If you could point me in a direction, I could probably figure the rest of it out.

Re: Warehouse based on state

Posted: Thu May 13, 2010 10:33 am
by mfreeze
Had to use one of my programmers but it's working. Here's the code.

Code: Select all

    protected ICollection<ShipRateQuote> WestOfMSQuoteForShipment(CommerceBuilder.Orders.BasketShipment shipment)
    {
        ICollection<ShipRateQuote> rateQuotes = new System.Collections.ObjectModel.Collection<ShipRateQuote>();
        //GET ALL OF THE POSSIBLE SHIPMETHODS for COLORADO ORIGIN
        WarehouseCollection warehouses = WarehouseDataSource.LoadForCriteria("name='colorado'");
        if (warehouses.Count > 0 && shipment.Address.ShipZones.FindAll(delegate(ShipZone oZone) { return oZone.Name.ToLowerInvariant == "west of mississippi"; }).Count > 0)
        {
            shipment.WarehouseId = warehouses[0].WarehouseId;
            shipment.Save();
        }