我的问题是,当我尝试将产品添加到购物车时使用Sitecore SES然后它找不到产品:
IShoppingCartManager shoppingCartManager = Context.Entity.Resolve<IShoppingCartManager>();
shoppingCartManager.AddProduct(productCode, q);
我确信我做了以下事情: 我已经将索引“product”添加到Lucene。 我还在商业目录中配置了“产品链接”。 我还添加了ordersDatabase =“orders”actionLogDatabase =“logging”来配置每个网站。 我没有安装«电子商务示例»。 你可以帮我解决这个问题吗? 如果你需要更多澄清,我准备好了。
答案 0 :(得分:0)
我可以给你一些我知道我曾经工作过的代码。希望这会帮助您朝着正确的方向前进。希望这有帮助!
利兹
using Microsoft.Practices.Unity;
using Sitecore.Analytics;
using Sitecore.Diagnostics;
using Sitecore.Ecommerce;
using Sitecore.Ecommerce.Analytics.Components;
using Sitecore.Ecommerce.DomainModel.Carts;
using System;
using System.Collections.Generic;
using System.Linq;
namespace sharedsource_verndale._Classes.Helpers
{
public class ShoppingCartWebHelper
{
public static void AddToShoppingCart(string productCode, string quantity)
{
Assert.ArgumentNotNullOrEmpty(productCode, "productCode");
Assert.ArgumentNotNullOrEmpty(quantity, "quantity");
IShoppingCartManager shoppingCartManager = IoCContainerExtensions.Resolve<IShoppingCartManager>(Context.Entity, new ResolverOverride[0]);
uint result;
if (string.IsNullOrEmpty(quantity) || !uint.TryParse(quantity, out result))
shoppingCartManager.AddProduct(productCode, 1U);
else
shoppingCartManager.AddProduct(productCode, result);
ShoppingCartLine shoppingCartLine = Enumerable.FirstOrDefault<ShoppingCartLine>((IEnumerable<ShoppingCartLine>)Context.Entity.GetInstance<ShoppingCart>().ShoppingCartLines, (Func<ShoppingCartLine, bool>)(p => p.Product.Code.Equals(productCode)));
try
{
Tracker.StartTracking();
AnalyticsUtil.AddToShoppingCart(shoppingCartLine.Product.Code, shoppingCartLine.Product.Title, 1U, shoppingCartLine.Totals.PriceExVat);
}
catch (Exception ex)
{
ShoppingCartWebHelper.LogException(ex);
}
}
public static void UpdateInShoppingCart(string productCode, string quantity)
{
Assert.ArgumentNotNullOrEmpty(productCode, "productCode");
Assert.ArgumentNotNullOrEmpty(quantity, "quantity");
IShoppingCartManager shoppingCartManager = IoCContainerExtensions.Resolve<IShoppingCartManager>(Context.Entity, new ResolverOverride[0]);
uint result;
if (string.IsNullOrEmpty(quantity) || !uint.TryParse(quantity, out result))
shoppingCartManager.UpdateProductQuantity(productCode, 1U);
else
shoppingCartManager.UpdateProductQuantity(productCode, result);
ShoppingCartLine shoppingCartLine = Enumerable.FirstOrDefault<ShoppingCartLine>((IEnumerable<ShoppingCartLine>)Context.Entity.GetInstance<ShoppingCart>().ShoppingCartLines, (Func<ShoppingCartLine, bool>)(p => p.Product.Code.Equals(productCode)));
try
{
Tracker.StartTracking();
AnalyticsUtil.ShoppingCartItemUpdated(shoppingCartLine.Product.Code, shoppingCartLine.Product.Title, 1U);
}
catch (Exception ex)
{
ShoppingCartWebHelper.LogException(ex);
}
}
public static void DeleteFromShoppingCart(string productCode)
{
Assert.ArgumentNotNullOrEmpty(productCode, "productCode");
ShoppingCartLine shoppingCartLine = Enumerable.FirstOrDefault<ShoppingCartLine>((IEnumerable<ShoppingCartLine>)Context.Entity.GetInstance<ShoppingCart>().ShoppingCartLines, (Func<ShoppingCartLine, bool>)(p => p.Product.Code.Equals(productCode)));
try
{
if (shoppingCartLine != null)
{
Tracker.StartTracking();
AnalyticsUtil.ShoppingCartProductRemoved(shoppingCartLine.Product.Code, shoppingCartLine.Product.Title, shoppingCartLine.Quantity);
}
}
catch (Exception ex)
{
ShoppingCartWebHelper.LogException(ex);
}
IoCContainerExtensions.Resolve<IShoppingCartManager>(Context.Entity, new ResolverOverride[0]).RemoveProduct(productCode);
}
public static void DeleteProductLineFromShoppingCart(string productCode)
{
Assert.ArgumentNotNullOrEmpty(productCode, "productCode");
ShoppingCartLine shoppingCartLine = Enumerable.FirstOrDefault<ShoppingCartLine>((IEnumerable<ShoppingCartLine>)Context.Entity.GetInstance<ShoppingCart>().ShoppingCartLines, (Func<ShoppingCartLine, bool>)(p => p.Product.Code.Equals(productCode)));
if (shoppingCartLine != null)
{
try
{
Tracker.StartTracking();
AnalyticsUtil.ShoppingCartItemRemoved(shoppingCartLine.Product.Code, shoppingCartLine.Product.Title, shoppingCartLine.Quantity);
}
catch (Exception ex)
{
ShoppingCartWebHelper.LogException(ex);
}
}
IoCContainerExtensions.Resolve<IShoppingCartManager>(Context.Entity, new ResolverOverride[0]).RemoveProductLine(productCode);
}
private static void LogException(Exception ex)
{
Log.Error("Analytics error:", (object)ex);
}
}
}