Developer forum

Forum » Ecommerce - Standard features » Add to favorites broken

Add to favorites broken

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi guys,

We run into an issue with adding favorites to the cart. It seems it's caused by a recent change introduced in Dynamicweb 9.3.13. Here's what we've witnessed:

1. Add to cart ultimately calls: CustomerProductList.AddToFavorites(string productId, string variantId, string languageId, string listName, string listType, string listDescription, int favoriteListId, int userId)

2. That method tries to check if the item already exists by calling GetProductByIdAndList

  if (CustomerProductListProduct.GetProductByIdAndList(listId, productId, languageId, variantId) != null)
  
3. GetProductByIdAndList then checks if the item exists in the cache. if not, it tries to get the products. If there are products, it caches them,. But if there aren't any products (which is when the list is new, or a new product is added),  it tries to cache null:

  IEnumerable<CustomerProductListProduct> productsBySql = CustomerProductListProduct.GetProductsBySql(CommandBuilder.Create("SELECT TOP 1 * FROM EcomCustomerFavoriteProducts WHERE ProductId = {0} AND ProductLanguageId = {1} AND ProductVariantId = {2} AND FavoriteListId = {3}", new object[] { productId, productLanguageId, productVariantId, listId }));
  if (!productsBySql.Any<CustomerProductListProduct>())
  {
      Cache.Current.Set(str, null);
  }
  else
  {
      item = productsBySql.First<CustomerProductListProduct>();
      Cache.Current.Set(str, item);
  }
  
4. Caching null doesn't make sense, and the underlying Cache provider thinks the same. The Set method on MemoryCacheManager calls  MemoryCacheManager.InternalCache.Set which eventually calls the following code to create a MemoryCacheEntry:

   MemoryCacheEntry memoryCacheEntry = new MemoryCacheEntry(key, value, ObjectCache.InfiniteAbsoluteExpiration, ObjectCache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null, null, this);
   
5. The constructor of MemoryCacheEntry looks like this:

  if (value == null)
  {
    throw new ArgumentNullException("value");
  }
  
  and this is where the computer says No ;-(
  
So, ultimately,  because the code tries to cache a null for something that doesn't exist, the check fails, and the item never gets added.

Can you look into this please? We're going live with this tomorrow, and favorites play an important part, so I would love to see this fixed soon.

Thanks!

Imar


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Imar,
it is already fixed in 9.4 branch, tfs# 46678.
Regards, Dmitrij

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Great. Can this be merged down to 9.3 as well? WIth the breaking changes in 9,4, now is not a good time for us to upgrade to 9.4.

Thanks!

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Bump Any chance we can get this in 9.3?

 

You must be logged in to post in the forum