Page 1 of 1

Order lookup based on Zones

Posted: Wed Mar 25, 2015 4:14 am
by mbartens
I need to be able to look up orders based on zones. I'd like to add a drop down of the zones to the order manager screen. I've seen the drop down on the Tax Report so I can generate that.

I think what I need to do to start is modify the OrderFilter class and add a ShipZoneId.
Should that be an int like this:

Code: Select all

            this.ShipZoneId = 0;
and

Code: Select all

        public int ShipZoneId { get; set; }

AFter that I'm looking the OrderRepository. That is where I'm stuck. It doesn't look like the ShipZoneId associated with the order/shipments is stored so how could I filter that?

Re: Order lookup based on Zones

Posted: Wed Mar 25, 2015 4:48 am
by rmaweb
Hello May,

What version of Ablecommerce are you using? So that I can come up with some code to help you.

Re: Order lookup based on Zones

Posted: Wed Mar 25, 2015 6:08 am
by mbartens
I'm using GoldR9, thank you.

Re: Order lookup based on Zones

Posted: Wed Mar 25, 2015 12:20 pm
by rmaweb
Hello May

I will try to get something together this weekend for you.

Re: Order lookup based on Zones

Posted: Thu Mar 26, 2015 2:48 am
by mbartens
Thank you I really appreciate it!

Re: Order lookup based on Zones

Posted: Thu Mar 26, 2015 6:24 am
by nadeem
I got a chance to have a look at your requirement. You are already in the right direction. You just need to add following more updates after setting the ShipZoneId from admin order manager page.

Go to the "private ICriteria GetFilteredCriteria(OrderFilter filter, int maximumRows, int startRowIndex, string sortExpression, bool count)" method at CommerceBuilder/Orders/OrderRepository.cs, locate the following code:

Code: Select all

// BUILD THE WHERE CRITERIA
List<string> whereCriteria = new List<string>();
and replace with:

Code: Select all

int zoneId = filter.ShipZoneId;
if (zoneId > 0)
{
    ShipZone shipZone = EntityLoader.Load<ShipZone>(zoneId);
    if (shipZone != null)
    {
        // process country rule
        if (shipZone.Countries.Count > 0)
        {
            string[] countryCodes = new string[shipZone.Countries.Count];
            for (int i = 0; i < shipZone.Countries.Count; i++)
            {
               Country country = shipZone.Countries[i];
               countryCodes[i] = country.Id;
            }
            if (shipZone.CountryRule == FilterRule.IncludeSelected)
            criteria.Add(Restrictions.In("O.BillToCountryCode", countryCodes));
            else if (shipZone.CountryRule == FilterRule.ExcludeSelected)
            criteria.Add(Restrictions.Not(Restrictions.In("O.BillToCountryCode", countryCodes)));
       }

// process province rule
if (shipZone.Provinces.Count > 0)
{
    string[] provinceCodes = new string[shipZone.Provinces.Count];
    for (int i = 0; i < shipZone.Provinces.Count; i++)
    {
        Province objProvince = shipZone.Provinces[i];
        provinceCodes[i] = objProvince.ProvinceCode;
    }

if (shipZone.ProvinceRule == FilterRule.IncludeSelected)
criteria.Add(Restrictions.In("O.BillToProvince", provinceCodes));
else if (shipZone.ProvinceRule == FilterRule.ExcludeSelected)
criteria.Add(Restrictions.Not(Restrictions.In("O.BillToProvince", provinceCodes)));
}

// process the include postal codes filter
if (!string.IsNullOrEmpty(shipZone.PostalCodeFilter))
{
   string[] postalCodes = shipZone.PostalCodeFilter.Split(',');
   criteria.Add(Restrictions.In("O.BillToPostalCode", postalCodes));
}

// process the exclude postal codes filter
if (!string.IsNullOrEmpty(shipZone.ExcludePostalCodeFilter))
{
   string[] postalCodes = shipZone.ExcludePostalCodeFilter.Split(',');
   criteria.Add(Restrictions.Not(Restrictions.In("O.BillToPostalCode", postalCodes)));
}
}
}
            
// BUILD THE WHERE CRITERIA
List<string> whereCriteria = new List<string>();
This should do the trick for you.

Re: Order lookup based on Zones

Posted: Thu Mar 26, 2015 6:33 am
by nadeem
Don't forget to add following using statement at the top of the page.

Code: Select all

using CommerceBuilder.Shipping;
After

Code: Select all

using CommerceBuilder.Services;

Re: Order lookup based on Zones

Posted: Fri Mar 27, 2015 4:35 am
by mbartens
This is working out very well. Thank you so much for your help and quick response! :D