AddToCartWidget error after 5.3 upgrade
Hi there!
I have an Ecommerce site where I have used the AddToCart widget in Product listing views. After upgrading to 5.3 all these pages produces an error:
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Telerik.Sitefinity.Modules.Ecommerce.Orders.Web.UI.AddToCartWidget.InitializeControls(GenericContainer container) +19
Telerik.Sitefinity.Web.UI.SimpleView.CreateChildControls() +81
System.Web.UI.Control.EnsureChildControls() +181
System.Web.UI.Control.PreRenderRecursiveInternal() +59
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Control.PreRenderRecursiveInternal() +221
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4200
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
When I comment out the AddToCartWidget the page renders just fine.
I just can't see what's changed since 5.2 to create this error.
Anyone with any insights into this?
Thanks,
OC
Hmm....
This looks like a bug.
I've now tried to use the default product Thumbnails temlpate and the default out-of-the-box AddToCartWidget, just in case this was related to my own templates. But the result is the same error.
Any one else upgraded an eCommerce site to 5.3?
OC
Hey Ole,
Have done a client 5.2 upgrade without any problems (no BuyNow widgets, standard shippable products) and after reading your post also took a 5.2.3700 test site with BuyNow widgets and upgraded it and it seems to function without any problem.
The test-site I played with uses the BuyNow widget with a normal generic product, perhaps you're using variations? Localized? Or some special form of Attributes that may cause issues?
I'd be more than happy to re-upgrade the test-site to verify the bug...
Jochem
Hello,
We have tested upgrades regarding the Ecommerce module and haven't got an issue like that. I think it is specific problem for your project but to find the bug more information is needed as Jochem said. Could you provide us with the upgrade log in order to get the upgrade error if any. Can you share more details about your project? Is it Multilingual? Have you done any custom development? Any information would be helpful.
If you can send us you project and database in support ticket we will be able to easily locate the issue.
Hi there,
The site is multi-lingual and localized. It worked just fine in 5.2. I'm using my own templates both for the Product list widget and the Buy now widget.
But I also tried to use a template called "Thumbnails", that I beleive to be a default out-of-the-box one, along with the default Add to cart Widget. The error is produces also with the default widgets.
OC
Hello Ole,
We will continue helping you with this service request in the support ticket you have submitted.
Kind regards,Hello,
was there a solution? Because I have the same problem...
Kind regards,
Bob,
I've just run on 5.2 so far. But I picked up this again two days ago, and the support team have now my projects and databases for investigation. They have not replyed yet, but I'll update the thred with their findings.
It is very strange, but I think it must have something to do with the inventory. That's the only new thing in 5.3. I'm not using it, I have my own inventory from my backend system.
OC
Hello OC,
thank you for your reply. Here the same situation, don't use the inventory... simple scenario.
Also an upgrade to 5.4 doesn't fix the issue.
Is it possible to keep us informed through the forum? Thanks in advance...
bob
Bob / Ole,
Call me an idiot, but I'd love to try and find out what's causing it - any change either of you is willing to toss a broken project my way ?
Jochem
not at all... :)
but I'm afraid I can't give you the project... I'll see if I can reproduce the problem...
thanks
Jochem,
I'll PM you on LinkedIn with download and login credentials.
OC
@Ole,
Thanks, I've got it up and running - send you an email with the details so far.
Jochem
Hello,
I found a (hopefully temporary) workaround...
I inherited the AddToCartWidget and removed some checks:
public
class
CustomAddToCartWidget : AddToCartWidget
protected
override
void
InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
this
.SwitchVisibilityBasedOnInventory(
this
.GetProductVariations());
this
.QuantityControl.Text =
"1"
;
this
.CssClass =
"sfAddToCartWrp"
;
this
.AddToCartButton.Command +=
new
CommandEventHandler(CustomAddToCartButton_Command);
private
void
CustomAddToCartButton_Command(
object
sender, CommandEventArgs e)
int
quantity =
int
.Parse(
this
.QuantityControl.Text);
IShoppingCartAdder shoppingCartAdder = (IShoppingCartAdder)
new
ShoppingCartAdder();
string
defaultCurrency = Config.Get<EcommerceConfig>().DefaultCurrency;
OptionsDetails optionDetails = GetOptionDetails();
try
shoppingCartAdder.AddItemToShoppingCart((IOrdersControl)
this
, (ICartOrderManager)
this
.OrdersManager,
this
.Product, optionDetails, quantity, defaultCurrency,
new
Guid?());
this
.AddedToCartMessage.ShowPositiveMessage(Res.Get<OrdersResources>(
"AddedToCart"
));
this
.SwitchVisibilityBasedOnInventory(GetProductVariations());
catch
(ArgumentException ex)
//EcommerceLogger.LogException((Exception)ex);
this
.AddedToCartMessage.ShowNegativeMessage(ex.Message);
catch
(Exception ex)
//EcommerceLogger.LogException(ex);
this
.AddedToCartMessage.ShowNegativeMessage(Res.Get<OrdersResources>(
"NotAddedToCart"
));
if
(!
this
.AddToCartRedirectPageId.HasValue)
return
;
this
.Page.Response.Redirect(EcommerceControlExtensions.GetPageNodeUrl((IEcommerceControl)
this
,
this
.AddToCartRedirectPageId.Value,
false
));
private
List<ProductVariation> GetProductVariations()
List<ProductVariationDetail> variationDetails =
this
.GetOptionDetails().ProductVariationDetails;
if
(variationDetails !=
null
)
return
Enumerable.ToList<ProductVariation>(Enumerable.Select<ProductVariationDetail, ProductVariation>((IEnumerable<ProductVariationDetail>)variationDetails, (Func<ProductVariationDetail, ProductVariation>)(pvd => pvd.ProductVariationParent)));
else
return
(List<ProductVariation>)
null
;
private
OptionsDetails GetOptionDetails()
Control parent =
this
.Parent;
OptionsDetails optionsDetails =
new
OptionsDetails();
foreach
(Control control
in
parent.Controls)
if
(control.GetType().Name ==
"ProductOptionsControl"
)
return
((ProductOptionsControl)control).SelectedOptions;
return
optionsDetails;
And used this control in my template.
For the moment this seems to work, but I'll have to map this to a new template to modify some markup. Some issues with the validators.
bye
The error is due to the fact that the AddToCart widget needs a ProductOptionsControl. This is not in product lists templates made prior to 5.3. That's whats causing the error.
Just add this to the template, and everything works just fine (thanks to Telerik Support):
<
div
class
=
"sfproductOptions"
>
<
sf:ProductOptionsControl
id
=
"productOptionsControl"
ProductItem='<%# Page.GetDataItem() %>'
runat="server" />
</
div
>
Hi,
We are running in a similar issue, I have upgraded a project from 5.2 -> 6.0 -> 7.0,
Now getting error
Argument 'productId' cannot be empty GUID
related to addToCartWidget,
I have custom Product Detail template and it seems that
<sfOrders:AddToCartWidget ID="addToCartWidget" ProductId='<%# Eval("Id") %>' runat="server" />
<%#Eval("Id") %> is returning nothing, however when I debug the code I am able to retrieve product.
I also tried to
addToCartWidget.ProductId = product.Id;
in .cs though still getting error.
[ArgumentException: Argument 'productId' cannot be empty GUID.]
DynamicModule.ns.Wrapped_OpenAccessCatalogDataProvider_80a7082b5b4c45cd80ea849fb2fcce2e.GetProduct(Guid productId) +413
Telerik.Sitefinity.Modules.Ecommerce.Orders.Web.UI.AddToCartWidget.get_Product() +177
Telerik.Sitefinity.Modules.Ecommerce.Orders.Web.UI.AddToCartWidget.SwitchVisibilityBasedOnInventory(ProductVariation selectedProductVariation) +284
Telerik.Sitefinity.Modules.Ecommerce.Orders.Web.UI.AddToCartWidget.InitializeControls(GenericContainer container) +43
Telerik.Sitefinity.Web.UI.SimpleView.CreateChildControls() +88
System.Web.UI.Control.EnsureChildControls() +189
Thanks
OC work around by adding ProductOptionsControl worked for me.
I had similar situation where AddToCart was working on product list in version 5.2 although after upgrading it up to 7.0.5100 it wasn't working, i added "productOptionsControl" and it worked.