ShoppingCartManager.AddToCart v 1.20

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
14 anos atrás
Hi

When im calling ShoppingCartManager.AddToCart and providing the SelectedAttributeIDs,  im assuming these are the id's of the ProductVariantAttributesValues? is that correct?

I keep getting a Attribute Error on AddToCart but they are valid ProductVariantAttributesValue ids for this product variant in IsShoppingCartItemAllowed

the error is happening cause my variant id is 21 but its comparing that with a variant id of 1

So since im importing all my product data externally I think I might be loading it wrong.   When I load attributes for example color,  should I be loading a new variant attribute color for each product variant or should I just load one for color first then use that same id when I create each attribute value for each product variant I load?  could this by why im getting the Attribute error?

Just want to make sure im thinking in the right direction before I start trying to track this down.

My attributes are loaded like this

Attribute     value
Color         white
interface    serial
hardware   takeup assy

Thanks
-Keith
14 anos atrás
After reviewing my import code I think im doing it right.
in my import

I create the Product attributes,  color, interface and hardware,  id 1,2 and 3

then foreach variant I call InsertProductVariantAttribute

Then i call InsertProductVariantAttributeValue for that ProductVariantAttribute

Display wise it looks fine
14 anos atrás
Here is my code for add to cart,  What im actually doing is using product variants to hold different configurations for my products.  I add a static set of attributes for display only.  so when I add the variant product to the cart I want to add all of the attributes also so they show up for the customer

int productVariantID = Convert.ToInt32(e.CommandArgument);

            List<int> SelectedAttributeIDs = new List<int>();

            // Need to fill this list with all of the attributes for this product
             ProductVariantAttributeCollection theAttributes = NopSolutions.NopCommerce.Common.Products.Attributes.ProductAttributeManager.GetProductVariantAttributesByProductVariantID(productVariantID);

            // loop through all of the attributes to add them to the list
            // This is because im using the attributes like specs but at the
            // product variant level and I want them to show in the cart.
            // So I want to add all of them
            foreach (var theAttributesItem in theAttributes)
            {
                // now get the value for this attribute
                ProductVariantAttributeValue theAttributeValue = ProductAttributeManager.GetProductVariantAttributeValueByID(theAttributesItem.ProductAttributeID);
                SelectedAttributeIDs.Add(theAttributeValue.ProductVariantAttributeValueID);
            }

            // Add this variant to the cart
            string addToCartWarning = string.Empty;
            ShoppingCartManager.AddToCart(ShoppingCartTypeEnum.ShoppingCart,
                productVariantID,
                SelectedAttributeIDs,
                string.Empty,
                1, // QTY
                ref addToCartWarning
                );
            if (string.IsNullOrEmpty(addToCartWarning))
            {
                Response.Redirect("~/ShoppingCart.aspx");
            }
            else
            {
                string theError = addToCartWarning;
            }
14 anos atrás
opps I was using the ProductAttributeID instead of the ProductVariantAttributeValueID now with the correct id all the attributes are being added to the cart.  Works wonderfully!

-Keith
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.