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