HomeHome Product Discus... Product Discus...RazorCartRazorCartUnitCost field error (maybe) in AddToCart overrideUnitCost field error (maybe) in AddToCart override
Previous
 
Next
New Post
12/26/2018 11:21 AM
 
I have a situation where I need to change the price on an item as it is being added to the cart. I am overriding the AddToCart in a custom DLL. When I try to access the CartRequest[0].UnitCost field either to get the value or set the value (what I need to do) I get an error:

Method Not Found: Void RazorCart.Service.Data.ModelDataContext.CartRequest.set_UnitCost(System.Decimal)'.

UnitCost is defined as a decimal in the metadata for CartRequest but it's a decimal? (null allowed) in the database. I don't think that is relevant here.

I get pretty much the same error when I am trying to read the value. Reading and writing Quantity in the same object works fine.

My code (summarized):
List<CartRequest> cartReq = context.CartRequestList.ToList();
i(I check and if there is not a cartReq[0] I return an error)

// return new ActionEndResult() { Success = false, FailureMessage = cartReq[0].UnitCost.ToString() };
decimal PriceFew = Convert.ToDecimal(cartReq[0].UnitCost);
 cartReq[0].Quantity = 255.0M;

The Quantity set works fine. Nothing having to do with UnitCost works.
Is this a bug or am I doing something wrong? If I am doing something wrong do you have any suggestions on how to fix it?

Thank you,
George
 
New Post
12/31/2018 1:37 PM
 
Hi George,

The CartRequest is the add to cart user request info which is being sent from the client-side, the CartRequest.UnitCost decimal value is used when the user is requesting the product price (see Product > edit > User Entered Amount), so in the case of this type of products a price textbox will be used in the product details page to pass the user's price request.
If the product does not allow user entered amount, CartRequest.ProductInfo.UnitCost will be used, I prefer you edit this value.
BTW you should be able to modify the CartRequest.UnitCost value (it allow both get & set) I think the error is because you passing a null value to Convert.ToDecimal, but cartReq[0].UnitCost = 10M should work.

Regards,
Wael
 
New Post
1/3/2019 12:51 PM
 
Wael:

We've checked further and found that Smith is able to execute the same code without an error. This is a problem on our side and not with RazorCart. Thank you for your help!

G
 
Previous
 
Next
HomeHome Product Discus... Product Discus...RazorCartRazorCartUnitCost field error (maybe) in AddToCart overrideUnitCost field error (maybe) in AddToCart override