/// <summary>
        ///     The select cross sell from previous display or crss sell list.
        /// </summary>
        /// <param name="crossSellList">
        ///     The cross sell list.
        /// </param>
        /// <param name="lastSeenCrossSell">
        ///     The last seen cross sell.
        /// </param>
        /// <returns>
        /// </returns>
        public static CrossSellInfo SelectCrossSellFromPreviousDisplayOrCrssSellList(MyHLShoppingCart shoppingCart,
                                                                                     List <CrossSellInfo> crossSellList,
                                                                                     CrossSellInfo lastSeenCrossSell,
                                                                                     Dictionary <string, SKU_V01> allSKUs)
        {
            CrossSellInfo candidate = null;

            if (lastSeenCrossSell != null && lastSeenCrossSell.Product != null)
            {
                if (!ifInShoppingCart(shoppingCart, lastSeenCrossSell.Product) &&
                    !IfOutOfStock(lastSeenCrossSell.Product, allSKUs))
                {
                    return(candidate = lastSeenCrossSell);
                }
            }

            if (crossSellList != null && crossSellList.Count > 0)
            {
                //return candidate = crossSellList.First();
                foreach (CrossSellInfo cs in crossSellList)
                {
                    if (!ifInShoppingCart(shoppingCart, cs.Product) && !IfOutOfStock(cs.Product, allSKUs))
                    {
                        return(candidate = cs);
                    }
                }
            }

            return(candidate);
        }
        /// <summary>
        ///     The should select this cross sell.
        /// </summary>
        /// <param name="cs">
        ///     The cs.
        /// </param>
        /// <param name="shoppingCart">
        ///     The shopping cart.
        /// </param>
        /// <param name="lastSeenProd">
        ///     The last seen prod.
        /// </param>
        /// <param name="lastSeenCrossSell">
        ///     The last seen cross sell.
        /// </param>
        /// <returns>
        ///     The should select this cross sell.
        /// </returns>
        public static bool ShouldSelectThisCrossSell(
            ProductInfo_V02 cs,
            MyHLShoppingCart shoppingCart,
            CrossSellInfo lastSeenProd,
            CrossSellInfo lastSeenCrossSell
            )
        {
            // if it is in shopping cart, do not pick
            if (ifInShoppingCart(shoppingCart, cs))
            {
                return(false);
            }

            if (lastSeenProd != null && cs.ID == lastSeenProd.Product.ID)
            {
                return(false);
            }

            if (lastSeenCrossSell != null && cs.ID == lastSeenCrossSell.Product.ID)
            {
                return(false);
            }

            return(true);
        }
Пример #3
0
        private void findCrossSell(int id)
        {
            if (ProductInfoCatalog != null)
            {
                var crossSellList = new List <CrossSellInfo>();
                ProductDetail.CollectAllCrossSellProducts(CatalogHelper.FindCategory(ProductInfoCatalog, id),
                                                          crossSellList);

                if (crossSellList.Count > 0)
                {
                    CrossSellInfo candidate = null;
                    foreach (CrossSellInfo c in crossSellList)
                    {
                        if (ProductDetail.ShouldSelectThisCrossSell(c.Product, ShoppingCart,
                                                                    Session[ProductDetail.LAST_SEEN_PRODUCT_SESSION_EKY]
                                                                    as CrossSellInfo,
                                                                    Session[
                                                                        ProductDetail
                                                                        .LAST_SEEN_CROSS_SELL_PRODUCT_SESSION_EKY]
                                                                    as CrossSellInfo))
                        {
                            if (!ProductDetail.IfOutOfStock(c.Product, AllSKUS))
                            {
                                candidate = c;
                                break;
                            }
                        }
                    }
                    // if nothing found
                    if (candidate == null)
                    {
                        candidate = ProductDetail.SelectCrossSellFromPreviousDisplayOrCrssSellList(ShoppingCart,
                                                                                                   crossSellList,
                                                                                                   Session[
                                                                                                       ProductDetail
                                                                                                       .LAST_SEEN_CROSS_SELL_PRODUCT_SESSION_EKY
                                                                                                   ] as
                                                                                                   CrossSellInfo,
                                                                                                   AllSKUS);
                    }
                    if (candidate != null)
                    {
                        Session[ProductDetail.LAST_SEEN_CROSS_SELL_PRODUCT_SESSION_EKY] = candidate;

                        // fire event
                        CrossSellFound(this, new CrossSellEventArgs(candidate));
                        return;
                    }
                }
            }
            else
            {
                LoggerHelper.Error(string.Format("ProductInfoCatalog is null in finding cross-sell : {0}", this.Locale));
            }
            NoCrossSellFound(this, null);
        }
        public void findCrossSell(List <ShoppingCartItem_V01> products)
        {
            if (products.Count == 0)
            {
                NoCrossSellFound(this, null);
                return;
            }
            List <CrossSellInfo> crossSellList = new List <CrossSellInfo>();

            foreach (ShoppingCartItem_V01 cartItem in products)
            {
                var item = ShoppingCart.ShoppingCartItems.Find(s => s.SKU == cartItem.SKU);
                if (item != null)
                {
                    if (item.ProdInfo == null || item.ParentCat == null || item.ProdInfo.CrossSellProducts == null)
                    {
                        continue;
                    }

                    foreach (int cat in item.ProdInfo.CrossSellProducts.Keys)
                    {
                        crossSellList.AddRange(from a in item.ProdInfo.CrossSellProducts[cat]
                                               select new CrossSellInfo(cat, a));
                    }
                }
            }
            if (crossSellList.Count > 0)
            {
                CrossSellInfo candidate = null;
                foreach (CrossSellInfo c in crossSellList)
                {
                    if (ProductDetail.ShouldSelectThisCrossSell(c.Product, ShoppingCart,
                                                                Session[ProductDetail.LAST_SEEN_PRODUCT_SESSION_EKY]
                                                                as CrossSellInfo,
                                                                Session[
                                                                    ProductDetail.
                                                                    LAST_SEEN_CROSS_SELL_PRODUCT_SESSION_EKY] as
                                                                CrossSellInfo))
                    {
                        if (!ProductDetail.IfOutOfStock(c.Product, AllSKUS))
                        {
                            candidate = c;
                            break;
                        }
                    }
                }

                // if nothing found
                if (candidate == null)
                {
                    candidate = ProductDetail.SelectCrossSellFromPreviousDisplayOrCrssSellList(ShoppingCart, crossSellList,
                                                                                               Session[
                                                                                                   ProductDetail.
                                                                                                   LAST_SEEN_CROSS_SELL_PRODUCT_SESSION_EKY
                                                                                               ] as
                                                                                               CrossSellInfo, AllSKUS);
                }

                if (candidate != null)
                {
                    Session[ProductDetail.LAST_SEEN_CROSS_SELL_PRODUCT_SESSION_EKY] = candidate;

                    // fire event
                    CrossSellFound(this, new CrossSellEventArgs(candidate));
                    return;
                }
            }
            NoCrossSellFound(this, null);
            //findCrossSell();
        }
 public CrossSellEventArgs(CrossSellInfo crossSellInfo)
 {
     CrossSellInfo = crossSellInfo;
 }