Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 22 of 22

Thread: Shipping options based on customer level

  1. #1
    biggunn is offline Member
    Join Date
    Jun 2011
    Posts
    48

    Default Shipping options based on customer level

    Is it possible to show different shipping options based on a customers level. For instance my client wants wholesale customers to see UPS options only (ground, 3day, etc), but regular retail customers should see USPS options only (standard, priority, etc).

    I don't see anyway to set this up in the backend, but it is entirely possible I am just not seeing it.

  2. #2
    cjbarth is offline Senior Member
    Join Date
    Oct 2008
    Posts
    392

    Default

    You would likely have to change the cart object to make decisions based on customer level.
    ML9.3.1.1
    SQL 2012 Express
    VS 2010
    Azure VM

  3. #3
    biggunn is offline Member
    Join Date
    Jun 2011
    Posts
    48

    Default

    thanks cjbarth for the reply. Can you give me any more details on how possibly to do this. What pages and maybe a code example.

    Thank you.

  4. #4
    biggunn is offline Member
    Join Date
    Jun 2011
    Posts
    48

    Default

    Ok, So i think i have it figured out where I need to make the change, on checkoutshipping.aspx and I believe this is the existing code that would need to be modified:

    Code:
                <asp:Panel ID="pnlCartAllowsShippingMethodSelection" runat="server">
                    <asp:Label ID="ShipSelectionMsg" runat="server"></asp:Label>
                <aspdnsfc:ShippingMethodControl ID="ctrlShippingMethods" runat="server"/>
            <br />
                </asp:Panel>
    So my question is how do you determine the customer level in an .aspx page. I think in an xmlpackage you would do something like this:

    Code:
    <xsl:when test="/root/Runtime/CustomerLevelID=1">
    but I don't know how you would do it on a .aspx page.

  5. #5
    chrismartz is offline Senior Member
    Join Date
    Apr 2010
    Posts
    339

    Default

    The InitializeShippingMethodDisplayFormat void, you can use the following to get the current customer's customer level.

    Code:
    int CustomerLevel = ThisCustomer.CustomerLevelID;
    Then you can loop through your shipping methods and only show the ones you want if CustomerLevel = your level.

  6. #6
    biggunn is offline Member
    Join Date
    Jun 2011
    Posts
    48

    Default

    Thanks chrismartz,

    So would I need to add a new column to the DB to set which shipping methods are assigned to which customer levels or is there some other way to make that determination?

  7. #7
    cjbarth is offline Senior Member
    Join Date
    Oct 2008
    Posts
    392

    Default

    I would just modify the control directly in ShippingMethodControl.vb. There is a method that binds the data source of shipping options to the radio button list (BindData()). If you filter that data source before binding then you'll be good to go and nothing else in the shipping process will break.

    In fact, if you modify the property DataSource you can intercept the call to BindData with a call to your own custom function that pares down the shipping options. This way you don't have to modify any ASPDNSF code at all except for one line. That makes maintenance of the code much easier.
    ML9.3.1.1
    SQL 2012 Express
    VS 2010
    Azure VM

  8. #8
    biggunn is offline Member
    Join Date
    Jun 2011
    Posts
    48

    Default

    Thank you cjbarth, but I do not have access to ShippingMethodControl.vb since I do not have source code. I only have access to checkoutshipping.aspx.cs.

  9. #9
    cjbarth is offline Senior Member
    Join Date
    Oct 2008
    Posts
    392

    Default

    I would not add columns to ASPDNSF tables. Just create a new table in the database that contains the information you need. Then in your custom routine, perform a look-up on that table, and filter the data set.

    Of course, you could also just modify the GetShippingMehtods(Address, Decimal) function in ShoppingCart.vb. There you could just include a simple If...Then statement to check if such a shipping method is allowed before adding it to the data set instead of going through the effort to remove the ones you don't want later on.
    ML9.3.1.1
    SQL 2012 Express
    VS 2010
    Azure VM

  10. #10
    cjbarth is offline Senior Member
    Join Date
    Oct 2008
    Posts
    392

    Default

    Sorry. IMO the source code it worth every cent when modifying certain aspects of ASPDNSF. The savings in labor more than makes up for the cost of the source code. Not to mention that patching becomes much easier because I've found that non-source changes break very easily upon upgrade (at least the type of changes I've tried).
    ML9.3.1.1
    SQL 2012 Express
    VS 2010
    Azure VM

  11. #11
    biggunn is offline Member
    Join Date
    Jun 2011
    Posts
    48

    Default

    unfortunately it is not my choice to not have source code. I just have to do what I am told and figure out ways to make it work.

  12. #12
    biggunn is offline Member
    Join Date
    Jun 2011
    Posts
    48

    Default

    OK, here is where I am. I figured out the code to change, and I have a general idea how to do it, but I need a little help figuring out the details. Here is what I have so far.
    Code:
            private void InitializeShippingMethodDisplayFormat(ShippingMethodCollection shippingMethods)
            {
    
    			if (ThisCustomer.CustomerLevelID == 1)
    			{
    				using (SqlConnection con = new SqlConnection(DB.GetDBConn()))
    					{
    						con.Open();
    						using (IDataReader rs = DB.GetRS("SELECT * FROM ShippingMethod WHERE ShippingMethodID IN (SELECT ShippingMethodID FROM CustomerLevelShippingOption WHERE CustomerLevelID = 1) order by DisplayOrder,Name", con))
    						{
    							foreach (ShippingMethod shipMethod in shippingMethods)
    							{
    								shipMethod.DisplayFormat = string.Format("{0} {1}", shipMethod.Name, "");
    							}
    						}
    					}
    			}
    			else
    			{
    				using (SqlConnection con = new SqlConnection(DB.GetDBConn()))
    					{
    						con.Open();
    						using (IDataReader rs = DB.GetRS("SELECT * FROM ShippingMethod WHERE ShippingMethodID IN (SELECT ShippingMethodID FROM CustomerLevelShippingOption WHERE CustomerLevelID = 0) order by DisplayOrder,Name", con))
    						{
    							foreach (ShippingMethod shipMethod in shippingMethods)
    							{
    								shipMethod.DisplayFormat = string.Format("{0} {1}", shipMethod.Name, "");
    							}
    						}
    					}				
    			}
    		}
    If the concept is right, what I need to know is:
    1. how should the foreach statements be written
    2. how should the shipMethod.DisplayFormat line be rewritten

    .NET is not my strongest which is why I am struggling with this part. Your help is greatly appreciated.

  13. #13
    cjbarth is offline Senior Member
    Join Date
    Oct 2008
    Posts
    392

    Default

    So you now have the source code?
    ML9.3.1.1
    SQL 2012 Express
    VS 2010
    Azure VM

  14. #14
    biggunn is offline Member
    Join Date
    Jun 2011
    Posts
    48

    Default

    I don't think so. this is the code from the aspx.cs page. This is code, but I don't think it is the full source code. Am I wrong?

  15. #15
    cjbarth is offline Senior Member
    Join Date
    Oct 2008
    Posts
    392

    Default

    What errors are you seeing?

    It seems here that you are just hiding the text of the shipping methods that you don't want to make available instead of actually setting them to not display.
    ML9.3.1.1
    SQL 2012 Express
    VS 2010
    Azure VM

  16. #16
    biggunn is offline Member
    Join Date
    Jun 2011
    Posts
    48

    Default

    You are probably correct. I don't know how to have the the actual radio buttons not display. If you could give any guidance on what bit of code I should be looking for to get them to not display I would appreciate it.

    I am actually having a similar issue trying to hide the "I'm over 13" checkbox on the registration page. I can remove the text, but can't figure out what i need to remove to hide the box. There is obviously something I am missing, or a piece of the puzzle I don't have.

  17. #17
    cjbarth is offline Senior Member
    Join Date
    Oct 2008
    Posts
    392

    Default

    Sadly the piece that you don't have is the source code. Since all the items are drawn as part of components this can get very difficult without the source code.

    I would try changing the Visible or Display property in the look instead of hiding the text.
    ML9.3.1.1
    SQL 2012 Express
    VS 2010
    Azure VM

  18. #18
    biggunn is offline Member
    Join Date
    Jun 2011
    Posts
    48

    Default

    thank you for the quick response. I was afraid that might be the case. I will see what I can do with some CSS or maybe some js.

  19. #19
    cjbarth is offline Senior Member
    Join Date
    Oct 2008
    Posts
    392

    Default

    Is there a property on shipMethod for Visibility or Display?
    ML9.3.1.1
    SQL 2012 Express
    VS 2010
    Azure VM

  20. #20
    biggunn is offline Member
    Join Date
    Jun 2011
    Posts
    48

    Default

    not that I know of,but they have ID's, so using either CSS or JS I should be able to hide elements with specific ID's.

  21. #21
    cjbarth is offline Senior Member
    Join Date
    Oct 2008
    Posts
    392

    Default

    That's the fun part about ASP.Net, the IDs after the code is rendered in the browser are different than what you'll see in your code. Let me know how things go.
    ML9.3.1.1
    SQL 2012 Express
    VS 2010
    Azure VM

  22. #22
    biggunn is offline Member
    Join Date
    Jun 2011
    Posts
    48

    Default

    I figured I would use the ID's that I see when I view source on the page in my CSS or JS. we will see how it goes. thanks again for your help