Page 1 of 1

PO Box and UPS

Posted: Wed Feb 10, 2010 2:24 pm
by derekz
I'm trying to restrict my customers from shipping to a PO Box. I've set up a regular expression in a custom validator for my Address1 text box on my checkout page. Unfortunately, AbleCommerce is not validating it correctly. I have the same regular expression in custom C# code and it is working perfectly.

Has anyone had any luck restricting PO Boxes?

If I can't restrict, I would at least like to limit the shipping methods based on the PO Box in the Address1 text box. Can that be done?

Thanks,
Derek

Re: PO Box and UPS

Posted: Thu Feb 11, 2010 7:27 am
by mazhar
I guess you need to setup shipping zones. Create shipping zones for different regions and then mark shipping methods available to their respective zones. After this change customer belonging to one shipping zone will see shipping methods only available to that zone.

Re: PO Box and UPS

Posted: Thu Feb 11, 2010 8:13 am
by jmestep
We have filtered out shipping methods on the checkout page based on the customer having a PO Box in the address. You have to do it in the ShipmentList_ItemDataBound method before the
localQuotes.Add(new LocalShipRateQuote(quote.ShipMethodId, methodName, formattedRate));

Re: PO Box and UPS

Posted: Thu Feb 11, 2010 12:33 pm
by derekz
I managed to get this working with Regular Expressions and the Custom Validator

OnePageCheckout.aspx

Code: Select all

<asp:TextBox ID="BillToAddress1" runat="server" EnableViewState="false" Width="200px" MaxLength="100" ValidationGroup="OPC"></asp:TextBox> 
<asp:RequiredFieldValidator ID="BillToAddress1Required" runat="server"
    ErrorMessage="Billing address is required." Display="None" Text="*" ControlToValidate="BillToAddress1"
    EnableViewState="false" SetFocusOnError="false" ValidationGroup="OPC"></asp:RequiredFieldValidator>
<asp:CustomValidator ID="BillToAddress1CustomValidator" runat="server"
    ControlToValidate="BillToAddress1" EnableViewState="false" Display="None" ValidationGroup="OPC"
    ErrorMessage="PO Boxes are not allowed." OnServerValidate="ValidateAddress" />
OnePageCheckout.aspx.cs

Code: Select all

    public void ValidateAddress(object sender, ServerValidateEventArgs args)
    {
        Regex reg = new Regex(@"[p|P][\s]*[o|O][\s]*[b|B][\s]*[o|O][\s]*[x|X][\s]*[a-zA-Z0-9]*|\b[P|p]+(OST|ost|o|O)?\.?\s*[O|o|0]+(ffice|FFICE)?\.?\s*[B|b][O|o|0]?[X|x]+\.?\s+[#]?(\d+)*(\D+)*\b");
        if (reg.IsMatch(args.Value))
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }
    }