Page 1 of 1

Display Shopping Cart Item Based On IP Address

Posted: Tue Feb 09, 2010 10:31 am
by dave@givemore.com
I want to display a shopping cart shipping estimator based on ip address. Basically, only our in-house team should see this feature, but I don't want to require them to login to see it.

How would I do this? Here is the code that spits out the shipping estimator.

Code: Select all

<%-- <label class="cartlabels">Estimate shipping: </label> --%>
<uc1:BasketShippingEstimate ID="BasketShippingEstimate1" runat="server" />
Or, is there a better way to only display content to our shipping team without them having to login?

Thanks!

Re: Display Shopping Cart Item Based On IP Address

Posted: Tue Feb 09, 2010 11:03 am
by mazhar
I guess you should set the shipping zones for those regions where you can ship your orders. This will not allow shipping to persons who have address not falling within configured zones.

Secondly you could use the IP banning feature to not allow customers from specific IP addresses.

Lastly if you are looking for some show/hide shipping estimator feature based on IP then it could be something like

Code: Select all

    
protected void Page_Load(object sender, EventArgs e)
    {
            string clientIPAddress = Request.ServerVariables["REMOTE_ADDR"];
            this.Visible = IsValidIP(clientIPAddress);
    }

    protected bool IsValidIP(string ipAddress)
    {
        bool isValid = true;

        //YOUR CUSTOM IP VALIDATION CODE HERE FOR EXAMPLE
        isValid = (ipAddress != "---.---.---.---");

        return isValid;
    }
Where these changes will be made to ConLib/BasketShippingEstimate.cs file. But I think that setting shipping zones will be a better option. The reason is that you don't need to make any code change. No need to worry about future upgrades becuase those are configurations and you will make no code change.

Re: Display Shopping Cart Item Based On IP Address

Posted: Mon Feb 15, 2010 11:47 am
by dave@givemore.com
Mazhar, you solution was very helpful! I was able to remove the estimate shipping functionality. Thanks for the quick and helpful response.