示例#1
0
        /// <summary>
        /// Inserts a viewed item
        /// </summary>
        /// <param name="CustomerSessionGUID">The customer session identifier</param>
        /// <param name="ProductVariantID">The product variant identifier</param>
        /// <param name="CreatedOn">The date and time of instance creation</param>
        /// <returns>Viewed item</returns>
        public static ViewedItem InsertViewedItem(Guid CustomerSessionGUID,
                                                  int ProductVariantID, DateTime CreatedOn)
        {
            if (CustomerSessionGUID == null || ProductVariantID == null)
            {
                return(null);
            }

            CreatedOn = DateTimeHelper.ConvertToUtcTime(CreatedOn);

            ViewedItem   itemFromBase = GetViewedItemByProductVariantID(ProductVariantID);
            DBViewedItem dbItem       = null;

            if (itemFromBase == null)
            {
                dbItem = DBProviderManager <DBViewedItemProvider> .Provider.InsertViewedItem(CustomerSessionGUID,
                                                                                             ProductVariantID, CreatedOn);
            }
            else
            {
                if (itemFromBase.CreatedOn < CreatedOn)
                {
                    dbItem = DBProviderManager <DBViewedItemProvider> .Provider.UpdateViewedItem(itemFromBase.ViewedItemID,
                                                                                                 itemFromBase.CustomerSessionGUID, ProductVariantID, CreatedOn);
                }
            }
            ViewedItem viewedItem = DBMapping(dbItem);

            return(viewedItem);
        }
示例#2
0
        /// <summary>
        /// Gets viewed item
        /// </summary>
        /// <param name="viewedItemID">The viewed item identifier</param>
        /// <returns>Viewed item</returns>
        public static ViewedItem GetViewedItemByID(int viewedItemID)
        {
            if (viewedItemID == 0)
            {
                return(null);
            }

            DBViewedItem dbItem = DBProviderManager <DBViewedItemProvider> .Provider.GetViewedItemByID(viewedItemID);

            ViewedItem viewedItem = DBMapping(dbItem);

            return(viewedItem);
        }
示例#3
0
        private static ViewedItem DBMapping(DBViewedItem dbItem)
        {
            if (dbItem == null)
            {
                return(null);
            }

            ViewedItem item = new ViewedItem();

            item.ViewedItemID        = dbItem.ViewedItemID;
            item.CustomerSessionGUID = dbItem.CustomerSessionGUID;
            item.ProductVariantID    = dbItem.ProductVariantID;
            item.CreatedOn           = dbItem.CreatedOn;

            return(item);
        }
示例#4
0
        /// <summary>
        /// Deletes a viewed item
        /// </summary>
        /// <param name="viewedItemID">The shopping cart item identifier</param>
        /// <param name="ResetCheckoutData">A value indicating whether to reset checkout data</param>
        public static void DeleteViewedItem(int viewedItemID, bool ResetCheckoutData)
        {
            if (ResetCheckoutData)
            {
                if (NopContext.Current.Session != null)
                {
                    CustomerManager.ResetCheckoutData(NopContext.Current.Session.CustomerID, false);
                }
            }

            ViewedItem viewedItem = GetViewedItemByID(viewedItemID);

            if (viewedItem != null)
            {
                DBProviderManager <DBViewedItemProvider> .Provider.DeleteViewedItem(viewedItemID);
            }
        }
示例#5
0
        /// <summary>
        /// Updates the viewed item
        /// </summary>
        /// <param name="ViewedItemID">The viewed item identifier</param>
        /// <param name="CustomerSessionGUID">The customer session identifier</param>
        /// <param name="ProductVariantID">The product variant identifier</param>
        /// <param name="CreatedOn">The date and time of instance creation</param>
        /// <returns>Shopping cart item</returns>
        internal static ViewedItem UpdateShoppingCartItemint(int ViewedItemID, Guid CustomerSessionGUID,
                                                             int ProductVariantID, DateTime CreatedOn)
        {
            if (ViewedItemID == 0)
            {
                return(null);
            }

            CreatedOn = DateTimeHelper.ConvertToUtcTime(CreatedOn);

            DBViewedItem dbItem = DBProviderManager <DBViewedItemProvider> .Provider.UpdateViewedItem(ViewedItemID, CustomerSessionGUID,
                                                                                                      ProductVariantID, CreatedOn);

            ViewedItem viewedItem = DBMapping(dbItem);

            return(viewedItem);
        }
示例#6
0
        private static ViewedItemsCollection DBMapping(DBViewedItemsCollection dbCollection)
        {
            if (dbCollection == null)
            {
                return(null);
            }

            ViewedItemsCollection collection = new ViewedItemsCollection();

            foreach (DBViewedItem dbItem in dbCollection)
            {
                ViewedItem item = DBMapping(dbItem);
                collection.Add(item);
            }

            return(collection);
        }
示例#7
0
        /// <summary>
        /// Gets viewed item
        /// </summary>
        /// <param name="ProductVariantID">The product variant identifier</param>
        /// <returns>Viewed item</returns>
        public static ViewedItem GetViewedItemByProductVariantID(int ProductVariantID)
        {
            if (ProductVariantID == 0)
            {
                return(null);
            }

            if (NopContext.Current.Session == null)
            {
                return(new ViewedItem());
            }

            Guid CustomerSessionGUID = NopContext.Current.Session.CustomerSessionGUID;

            DBViewedItem dbItem = DBProviderManager <DBViewedItemProvider> .Provider.ViewedItemLoadByProductVariantID(ProductVariantID, CustomerSessionGUID);

            ViewedItem viewedItem = DBMapping(dbItem);

            return(viewedItem);
        }