Add custom image to insert into ShoppingCartItem table

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
Ok, I have added the field in the shoppingcartitem table called customProductImageURL.  I have also been able to add this to the basket page where the image pulls from that location.  
I now am having trouble getting the custom image to add from the product page.  How would I add this feature.  I have attempted to add it to the addtocart model in productDetailsmodel.cs and the catalogcontroller.cs.  It is simply a string URL where I can pull a custom image of the product created depending on the options chosen.  
public AddToCartModel()
                {
                    this.AllowedQuantities = new List<SelectListItem>();
                }
                public int ProductVariantId { get; set; }
                public string customProductImageURL { get; set; }

-------------------------------------------------------------------------------------------
-in controller
------------------------------------------------------------------------------------------
productVariantModel.AddToCart.customProductImageURL = "http://s7d4.scene7.com/is/image/CN1?$125$&$fabric=SmartFurniture/CN1_fabric_3005&$NA_frame=SmartFurniture/CN1_NA_frame_91&$frame=SmartFurniture/CN1_frame_91&$arms=SmartFurniture/CN1_arms_frame_91&$no_arms=0&$messagehide=0&$message=SmartFurniture/fsnt_2000x2000&$base=SmartFurniture/CN1_base_g1&$casters=SmartFurniture/CN1_casters_c7&$hidebg=0&$bg=SmartFurniture/CN1_bg_c7";
11 years ago
Still no progress here.  I seem to have everything setup.  The project will compile, but I can't add anything to cart.  And there is no stack error, it is simply the ajax message return.  And the message is actually the data that I am trying to insert into my new field.  Again, what I am trying to do, is add a new string field to the addtocart so I can insert some string data into the shoppingCartItem table.  Any help would be appreciated.  thanks
11 years ago
spockets14 wrote:
It is simply a string URL where I can pull a custom image of the product created depending on the options chosen.  


If, given the options selected ,you can create the URL to insert into the cartItem, why not just use the options to create the URL on the fly when you read the cartItem to display in the basket?
11 years ago
daveb, thanks for your response.  Sorry for the confusion, that is what I have done.  I create the URL with the options selected.  Then I want to insert it into the [ShoppingCartItem] table with the cart item.  The issue I am having is I can't seem to add the URL to the addtocart insert process.  I have added a field to the [ShoppingCartItem] table called customProductImageURL.  I have added the customProductImageURL string var to the product form.  I have added this into the warnings model and the addtocart model and what I think is all of the areas in the shoppingcartcontroller.cs and the IShoppingCartService.cs.  But when I attempt to add the item to cart, it fails and simply returns in the AJAX call a fail and in place of an error message it displays the customProductImageURL.  

Below is where I am getting the error.  And I can't figure out how to debug 2.8 inside of VS2012, so I am sort of guessing on what the issue is.  I really have no idea.  So below the addToCartWarnings.count must be greater than 0 and it drops into the catch and returns the Json message.  Any help on where and what I need to add my new customProductImageURL to would be very helpful.

//save item
            var cartType = (ShoppingCartType)shoppingCartTypeId;
            
            addToCartWarnings.AddRange(_shoppingCartService.AddToCart(_workContext.CurrentCustomer,
                productVariant, cartType, attributes, customerEnteredPriceConverted, quantity,customProductImageURL, true));

            #region Return result

            if (addToCartWarnings.Count > 0)
            {
                //cannot be added to the cart/wishlist
                //let's display warnings
                return Json(new
                {
                    success = false,
                    message = addToCartWarnings.ToArray()
                });
            }
11 years ago
OK maybe I'm not being clear enough.

Instead of trying to store the URL in the DB.

When Nop is reading the cart items to create the basket you can create the URL at this point and display it in the view.

This conforms with standard DB best practice. ie you only store information once.

The information to create the URL is contained within the options of the cartItem. Therefore storing the URL is redundant.

This has the advantage that if the options for the cartItem are changed the generated URL will be correct. If you use your method you would have to re-store the URL if the cartItem options were changed.

Hope that is clearer.
11 years ago
Thanks for your help...I figured out my issue.  I was adding the customProductImageURL to the warnings.  Got happy with trying to make sure I added it everywhere.  Thanks again.
warnings.Add(customProductImageURL);
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.