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

Thread: New ASPX page adding items to shopping cart.

  1. #1
    GoodFella is offline Member
    Join Date
    Mar 2009
    Posts
    99

    Default New ASPX page adding items to shopping cart.

    Is it possible to use the existing APSDNSF Functionality to add items to the shopping cart from a brand new page?

    I created a new ASPX page running AJAX to pick a part number and price from a new table based on the users input of vehicle Make, Model, and Year.

    Once the correct product is found based on these inputs, I would like to be able to add the item to the shopping cart like it already does.

    Thanks,
    Marc

  2. #2
    George the Great is offline Senior Member
    Join Date
    Nov 2006
    Location
    Cleveland, OH
    Posts
    1,792

    Default

    Just create a button/image/link that posts to the addtocart.aspx with the following query string parameters:

    • productid
    • variantid
    • quantity
    • price (if applicable...eg. a customer enters price product)


    For example, the URL to add 2 of a product with a productid of 23 and a variantid of 27 to the cart would be addtocart.aspx?productid=23&variantid=27&quantity= 2
    <a href="http://www.aspdotnetstorefront.com">Shopping Cart Software</a>

  3. #3
    GoodFella is offline Member
    Join Date
    Mar 2009
    Posts
    99

    Default

    Thank you for the reply.

    What can I do if these products are not in the existing product or productVariant tables?

    I plan to make a new table for this manufacturer because there are hundreds of thousands of combinations.

    Or, should I just append this data to the existing product table using some creating SQL work?

    Thanks again.

  4. #4
    George the Great is offline Senior Member
    Join Date
    Nov 2006
    Location
    Cleveland, OH
    Posts
    1,792

    Default

    Because of the nature of the AspDotNetStorefront cart, there really isn't anything you can do for products that don't already exist; the feature-set is very heavily intertwined and our shopping cart items depend entirely on the fact that the items in it exist within the storefront. If this is the route that you want to go, your best bet is probably going to be to create a reference to our WSI service that can be called from within your page, and then simply pass in a product node with the data you have from your custom tables (and the required fields of course) to create the product on the site (we have an ERPS specification pdf in our manual that shows examples of building WSI-ready xml fragments). With a little creativity and the correct fields filled in, over time your customer base would actually add the products to the site for you just by adding them to the cart through your custom page
    <a href="http://www.aspdotnetstorefront.com">Shopping Cart Software</a>

  5. #5
    GoodFella is offline Member
    Join Date
    Mar 2009
    Posts
    99

    Default

    Can you explain what you mean by "there really isn't anything you can do for products that don't already exist"?

    Do you mean I have to add them through the ADMIN page?

  6. #6
    George the Great is offline Senior Member
    Join Date
    Nov 2006
    Location
    Cleveland, OH
    Posts
    1,792

    Default

    Can you explain what you mean by "there really isn't anything you can do for products that don't already exist"?
    Sure...what I mean is that out-of-box there is no way for you to add an item to the shopping cart that doesn't already exist in AspDotNetStorefront through normal means. If you want the item in the shopping cart, you can do one of two things.

    1. You can modify the shopping cart architecture so that a product can be added to the cart that does not exist in the AspDotNetStorefront database as a product. You'll need to be careful if you go this route, as we depend on product id, variant id, sename, and multiple other data values from the existing data in order to perform pricing calculations, get shipping information, and for other calculation logic throughout the checkout process.

    2. You can implement the WSI feature on your custom page (briefly mentioned in the posts above) or develop some other creative way (maybe based on SKU), of querying the database to determine if the combination of items that have been selected on your custom page is already a product in the database. If it's not, add it (you don't even have to specify a mapping...that way the product stays hidden from other customers on normal entity/product pages). If it is, then use the addtocart.aspx post outlined above.

    For example, on your custom page you could query the product table in the database to see if a particular SKU existed (I assume you would get the final SKU from the combination of the user input):
    Code:
    select p.ProductID, pv.VariantID, pv.Price from dbo.Product p with(NOLOCK) join dbo.ProductVariant pv on pv.ProductID = p.ProductID where p.SKU='yourSKU' and pv.IsDefault=1
    If the result set has a count of 1, you know the product already exists, so get the productID and variantID and use those to build your addtocart.aspx query string parameters. If the count is 0, you know the product doesn't already exist so insert it into the database, then use the productID and variantID to build the query string for addtocart.aspx. eg.
    Code:
    String postURL = "addtocart.aspx?productid={0}&variantid={1}&quantity={2}";
    
    using (IDataReader rs = DB.GetRS("select p.ProductID, pv.VariantID, pv.Price from dbo.Product p with(NOLOCK) join dbo.ProductVariant pv on pv.ProductID = p.ProductID where p.SKU='yourSKU' and pv.IsDefault=1"))
    {
        if (rs.Read())
        {
            // we were able to read so a result set was returned...go ahead and build the post URL
            int pID = DB.RSFieldInt(rs, "ProductID");
            int vID = DB.RSFieldInt(rs, "VariantID");
            int q = 1;
    
            postURL = String.Format(postURL, pID.ToString(), vID.ToString(), q.ToString());
        }
        else
        {
            // we weren't able to read, so the product doesn't exist...let's add it
    
            XElement xe = new XElement("AspDotNetStorefrontImport",
                new XElement("Product",
                    new XAttribute("Action", "Add"),
                    new XElement("SKU", "your SKU"),                                            // this is the SKU that you've assembled from the user input
                    new XElement("Name", "the name of the product"),
                    new XElement("Description", "the description of the product should you choose to give it one"),
                    new XElement("Variants",
                        new XElement("Variant",
                            new XAttribute("Action", "Add"),
                            new XElement("IsDefault", true),
                            new XElement("Price", 94.99))),                                     // this is the price as determined by your custom page/table lookup for your items
                    new XElement("Mappings",                                                    // every product must have a manufacturer...so add one
                        new XElement("Entity",
                            new XAttribute("EntityType", "Manufacturer"),
                            new XAttribute("Name", "Name of existing manufacturer")))));        // if you don't want the product to show on the site, then make this the name of an unpublished manufacturer
    
            // then here create a reference to WSI and pass the xml to the service
    
            // once the service has consumed the xml, check the result to make sure it was successful, then
            // you can get the productid and variantid from the result xml and build your add to cart query string
            postURL = String.Format(postURL, productID_from_result, variantid_from_result, "1");
            // if the result failed, maybe redirect back to the same page with some sort of intuitive error message
            // asking them to call to order that specific part
        }
    }
    or something similar
    <a href="http://www.aspdotnetstorefront.com">Shopping Cart Software</a>

  7. #7
    GoodFella is offline Member
    Join Date
    Mar 2009
    Posts
    99

    Default

    Ahh. I think I understand #2.

    Lets see if I can recap.

    1. Create a master 'lookup' table of all combinations of Make, Model, Year to Part Number/Price.

    2. Create new ASPX page and hit up on the master look up table.

    3. Select the right product number and details

    4. Check to see if this item is already a 'Product' in ASPDNSF
    4.1 If NOT a 'Product', -- >INSERT INTO ASPDNSF as an actual product

    5. Call addtocart.aspx?


    I still have to look into the whole WSI thing. But let me know if I'm on the right track.

    Thank You,
    Marc

  8. #8
    George the Great is offline Senior Member
    Join Date
    Nov 2006
    Location
    Cleveland, OH
    Posts
    1,792

    Default

    Yep...exactly along what I was thinking in this particular instance
    <a href="http://www.aspdotnetstorefront.com">Shopping Cart Software</a>

  9. #9
    GoodFella is offline Member
    Join Date
    Mar 2009
    Posts
    99

    Default

    Are there any particular functions or Stored Procedure calls that the ADMIN page uses when adding a product? Am I able to simply run an INSERT statement in SQL to add a product from my look up table to the ASPDNSF (product and ProductVariant tables)?

  10. #10
    George the Great is offline Senior Member
    Join Date
    Nov 2006
    Location
    Cleveland, OH
    Posts
    1,792

    Default

    Have a look within the Admin/entityEditProducts.aspx.cs and Admin/entityEditProductVariant.aspx.cs pages of the site. All of the insert and update statements for adding and updating products and variants can be found within those two files and should give you a really good starting point.
    <a href="http://www.aspdotnetstorefront.com">Shopping Cart Software</a>

  11. #11
    GoodFella is offline Member
    Join Date
    Mar 2009
    Posts
    99

    Default

    Thanks George!

    I think I have enough info to get started.

    I really appreciate your help.

  12. #12
    GoodFella is offline Member
    Join Date
    Mar 2009
    Posts
    99

    Default

    George,

    I have been doing some more work and analysis on my situation. It turns out the pricing structure is a lot more simple than originally thought.

    There are 10 products and each product has 6 variants (V1 - V6). These variants are the same across the board in regards to the selected Make, Model, Year combination. All Year, Make, Model combinations will correspond to only 1 variant. Once the correct variant (pricing level) has been determined, this is able to be applied to the products.

    Example.

    2008 Nissan Altima --> Variant = G3

    If this customer wants Product 1 with Variant G3, his price will be $100.00
    If this customer wants Product 2 with Variant G3, his price will be $150.00


    2009 Porsche Boxter --> Variant = G4

    If this customer wants Product 1 with Variant G4, his price will be $200.00
    If this customer wants Product 2 with Variant G4, his price will be $250.00

    Plan of attack:
    • Create page that lists all 10 products with out any variants. Customer can not add to cart. (Not sure how to do this)

    • On this same page, create an AJAX Cascading Drop Down. When customer selects his vehicle, all the products will be adjusted with the corresponding variant added. The price will be added and will be able to AddToCart. (Most of this has been coded)

    • When product is added to cart, the Make, Model and Year will be added describing the product as well as a derived unique product number from the master data. (Not sure how to do this)


    Do you have any suggestions on how to make this all happen?

    Thank you,
    Marc
    Last edited by GoodFella; 07-25-2009 at 04:15 PM.