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 4 of 4

Thread: Category Shipping Restriction

  1. #1
    gmaniac is offline Member
    Join Date
    Jul 2010
    Location
    Missouri
    Posts
    59

    Default Category Shipping Restriction

    I am looking for a way to select one category as having shipping restrictions. So for example I have ammunition and I can not ship to all 50 states. How do I setup a way to restrict the category so it can only ship to states I designate.

    Any help will be much appreciated, again if I find the answer before I hear back I will post a reply of what I did. Thank you all again

  2. #2
    AspDotNetStorefront Staff - Scott's Avatar
    AspDotNetStorefront Staff - Scott is offline Administrator
    Join Date
    Mar 2007
    Location
    Ashland, OR
    Posts
    2,390

    Default

    That's going to take some custom dev, there's no way to restrict shipping method per product/entity 'out of the box'. You'll need the source code, and a dev to do the work on the site. If you don't have one on staff, any of the firms at http://www.aspdotnetstorefront.com/devnet.aspx can help.

  3. #3
    gmaniac is offline Member
    Join Date
    Jul 2010
    Location
    Missouri
    Posts
    59

    Default thank you

    I figured that was what I was going to have to do. We thought of all the options after doing some research. Here is what we thinking we will do:

    1. List all the states we can not ship to and allow them all, but when we are manually shipping check the address. If it is one we can't ship to just refund, this always leaves room for manual errors.

    2. To view this restricted product make customers login and only show the buy button if their shipping address is not a restricted one.

    3. During checkout check the address entered for the ship to and block the restricted.

    These were all ideas, I believe the best option would either be 2 or 3, I feel 3 would be most difficult one for me. I don't like messing with the checkout section of the site, but I can if need be. Scott would you be able to tell me which docs I would need to edit. If not I will figure it out, it would just speed up the process.

    Also I will post what I do when I am done in case someone else has this same question.

  4. #4
    gmaniac is offline Member
    Join Date
    Jul 2010
    Location
    Missouri
    Posts
    59

    Default Shipping Restriction Answer

    Here is what I have come up with and yes it could be written a little differently. I am a novice C# programmer, so this code could be simplified. Here is the doc I edited:

    wwwroot>checkoutshipping.aspx.cs

    I don't know if it matters where you place it, but I will give you where I placed it and I know it works.

    Look for this line:
    Code:
                ErrorMsgLabel.Text = "";
                pnlErrorMsg.Visible = false;
    
                CartItem FirstCartItem = (CartItem)cart.CartItems[0];
                Address FirstItemShippingAddress = new Address();
                FirstItemShippingAddress.LoadByCustomer(ThisCustomer.CustomerID, FirstCartItem.m_ShippingAddressID, AddressTypes.Shipping);
    Here it is:
    Code:
     //
    			//						********************************************************
    			string myMsg = "shoppingcart.aspx?errormsg=" + "We are currently unable to ship ammunition to your state.";
    			int cntr = 0;
    			bool noShip = false;
    			if ( ( FirstItemShippingAddress.State == "MO" ) || ( FirstItemShippingAddress.State == "CA" ) || ( FirstItemShippingAddress.State == "MA" ) || ( FirstItemShippingAddress.State == "IL" ) )
    			{
    				//  Loop through items in the cart
    				for(int i = 0; i < 1000; i++)
    				{
    					try
    					{
                			CartItem cartItem = (CartItem)cart.CartItems[i];
    						using (SqlConnection con = new SqlConnection(DB.GetDBConn()))
    						{
    							con.Open();
    							using (IDataReader rs1 = DB.GetRS("select CategoryID from ProductCategory with (NOLOCK) where ProductID=" + cartItem.m_ProductID.ToString(), con))
    								{
    									if (rs1.Read())
    									{
    										int firstCat = DB.RSFieldInt(rs1, "CategoryID");
    										int lastCat = firstCat;
    										using (SqlConnection myCon = new SqlConnection(DB.GetDBConn()))
    											{
    												myCon.Open();
    												//CategoryID,ParentCategoryID
    												using (IDataReader rs2 = DB.GetRS("select * from Category with (NOLOCK) where CategoryID=" + firstCat.ToString(), myCon))
    													{
    														if (rs2.Read())
    														{
    															int parentCat = DB.RSFieldInt(rs2, "ParentCategoryID");
    															lastCat = DB.RSFieldInt(rs2, "CategoryID");
    															while ( true )
    															{
    																if ( parentCat != 0 )
    																{
    																	using (SqlConnection myCon2 = new SqlConnection(DB.GetDBConn()))
    																		{
    																			myCon2.Open();
    																			using (IDataReader rs3 = DB.GetRS("select * from Category with (NOLOCK) where CategoryID=" + parentCat.ToString(), myCon2))
    																			{
    																				if ( rs3.Read() )
    																				{
    																					parentCat = DB.RSFieldInt(rs3, "ParentCategoryID");
    																					lastCat = DB.RSFieldInt(rs3, "CategoryID");
    																				}
    																			}
    																		}
    																}
    																else
    																{
    																	if ( lastCat == 138 )
    																	{
    																		noShip = true;
    																	}
    																	break;
    																}
    															}
    														}
    													}
    											}
    									 }
    								}
    						}
    					}
    					catch { break; }
    				}
    				if ( noShip )
    				{
    					Response.Redirect( myMsg );
    				}
    			}
    If anyone would like some explaining I would be more than happy. If you would like to know how to customize this code or integrate your database into it just ask.