コード例 #1
0
        public static bool UnAssignAllProducts(ProductFilter filter, int groupId)
        {
            int totalCount   = ProductDataSource.FindProductsCount(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly);
            int currentIndex = 0;
            IDatabaseSessionManager database = AbleContext.Current.Database;

            database.BeginTransaction();
            while (currentIndex < totalCount)
            {
                IList <Product> currentBatch = ProductDataSource.FindProducts(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly, 100, currentIndex);
                foreach (Product p in currentBatch)
                {
                    ProductGroup pg = ProductGroupDataSource.Load(p.Id, groupId);
                    if (pg != null)
                    {
                        p.ProductGroups.Remove(pg);
                        p.Save();
                        pg.Delete();
                    }
                }
                currentIndex += 100;
            }

            database.CommitTransaction();
            return(true);
        }
コード例 #2
0
        public static bool AssignAllProducts(ProductFilter filter, int[] groupIds, string groupRestrictions)
        {
            int totalCount   = ProductDataSource.FindProductsCount(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly);
            int currentIndex = 0;
            IDatabaseSessionManager database = AbleContext.Current.Database;

            database.BeginTransaction();
            List <Group> groups = new List <Group>();

            foreach (int gid in groupIds)
            {
                Group group = GroupDataSource.Load(gid);
                if (group != null)
                {
                    groups.Add(group);
                }
            }
            while (currentIndex < totalCount)
            {
                IList <Product> currentBatch = ProductDataSource.FindProducts(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly, 100, currentIndex);
                foreach (Product p in currentBatch)
                {
                    foreach (Group group in groups)
                    {
                        ProductGroup pg = ProductGroupDataSource.Load(p.Id, group.Id);
                        if (pg == null)
                        {
                            pg = new ProductGroup(p, group);
                            p.ProductGroups.Add(pg);
                        }
                    }

                    switch (groupRestrictions)
                    {
                    case "YES":
                        p.EnableGroups = true;
                        break;

                    case "NO":
                        p.EnableGroups = false;
                        break;

                    default:
                        break;
                    }

                    p.Save();
                }
                currentIndex += 100;
            }

            database.CommitTransaction();
            return(true);
        }
コード例 #3
0
        public static bool DeleteAllProducts(ProductFilter filter)
        {
            int totalCount   = ProductDataSource.FindProductsCount(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly);
            int currentIndex = 0;

            while (currentIndex < totalCount)
            {
                IList <Product> currentBatch = ProductDataSource.FindProducts(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly, 100, currentIndex);
                foreach (Product p in currentBatch)
                {
                    p.Delete();
                }
                currentIndex += 100;
            }
            return(true);
        }