private void CheckFullAssortmentAndDeactivateProducts(IEnumerable <AssortmentStockPriceProduct> productsSource)
        {
            using (var helper = new AssortmentHelper(Connector.Connection, Version))
            {
                var skuList      = helper.GetSkuList();
                var skuInXmlList = (from p in productsSource
                                    select p.ManufacturerID).ToList();

                var toDeactivate = skuList.Where(x => !skuInXmlList.Contains(x.Key));

                //exclude shipping costs
                toDeactivate = toDeactivate.Where(x => !x.Key.StartsWith("ShippingCostProductID_"));

                if (toDeactivate.Count() > 0)
                {
                    SortedDictionary <string, eav_attribute> attributeList = helper.GetAttributeList(PRODUCT_ENTITY_TYPE_ID);

                    foreach (var p in toDeactivate)
                    {
                        SetProductStatus(p.Value.entity_id, (int)PRODUCT_STATUS.DISABLED, helper, attributeList, StoreList[CurrentStoreCode].store_id);

                        if (RequiresStockUpdate)
                        {
                            helper.SyncStock(new cataloginventory_stock_item()
                            {
                                product_id  = p.Value.entity_id,
                                qty         = 0,
                                is_in_stock = false
                            });
                        }
                    }
                }
            }
        }
        private void ProcessProductCollection(Dictionary <int, List <AssortmentRetailStock> > retailStockList, Dictionary <string, int> stockStoreList, List <AssortmentStockPriceProduct> products)
        {
            int totalProcessed = 0;
            SortedDictionary <string, eav_attribute> attributeList;
            int totalRecords = products.Count();

            Logger.DebugFormat("Found {0} products", totalRecords);

            using (var helper = new AssortmentHelper(Connector.Connection, Version))
            {
                attributeList = helper.GetAttributeList(PRODUCT_ENTITY_TYPE_ID);
            }

            ParallelOptions options = new ParallelOptions()
            {
                MaxDegreeOfParallelism = 1
            };

            Parallel.ForEach(Partitioner.Create(0, totalRecords), options, (range, loopState) =>
            {
                using (var helper = new AssortmentHelper(Connector.Connection, Version))
                {
                    var skuList = helper.GetSkuList();

                    for (int index = range.Item1; index < range.Item2; index++)
                    {
                        int productID = Convert.ToInt32(products[index].ProductID);

                        IEnumerable <AssortmentRetailStock> productRetailStock = null;

                        ProcessProduct(helper, products[index], skuList, attributeList, stockStoreList, productRetailStock);

                        Interlocked.Increment(ref totalProcessed);
                        if (totalProcessed % 100 == 0)
                        {
                            Logger.DebugFormat(String.Format("Processed {0} of {1} records", totalProcessed, totalRecords));
                        }
                    }
                }
            });
        }
        private void DeactivateAssortmentPartial(IEnumerable <AssortmentStockPriceProduct> productsSource)
        {
            using (var helper = new AssortmentHelper(Connector.Connection, Version))
            {
                var skuList      = helper.GetSkuList();
                var toDeactivate = (from p in productsSource
                                    let entity_id = (skuList.ContainsKey(p.ManufacturerID) ? skuList[p.ManufacturerID].entity_id : 0)
                                                    where !p.IsNonAssortmentItem && entity_id != 0 && //only products that are already present in magento
                                                    !p.ManufacturerID.StartsWith("ShippingCostProductID_")
                                                    select new KeyValuePair <string, int>(
                                        p.ManufacturerID,
                                        entity_id
                                        )).ToList();


                //exclude shipping costs


                if (toDeactivate.Count() > 0)
                {
                    SortedDictionary <string, eav_attribute> attributeList = helper.GetAttributeList(PRODUCT_ENTITY_TYPE_ID);

                    foreach (var p in toDeactivate)
                    {
                        SetProductStatus(p.Value, (int)PRODUCT_STATUS.DISABLED, helper, attributeList, StoreList[CurrentStoreCode].store_id);

                        if (RequiresStockUpdate)
                        {
                            helper.SyncStock(new cataloginventory_stock_item()
                            {
                                product_id  = p.Value,
                                qty         = 0,
                                is_in_stock = false
                            });
                        }
                    }
                }
            }
        }
示例#4
0
        protected void SyncRequiredCatalogAttributes()
        {
            using (var helper = new AssortmentHelper(Connector.Connection, Version))
            {
                var attributes = helper.GetAttributeList(CATEGORY_ENTITY_TYPE_ID);

                eav_attribute att = null;
                attributes.TryGetValue("icecat_cat_id", out att);
                if (att == null)
                {
                    att = helper.CreateAttribute("icecat_cat_id", CATEGORY_ENTITY_TYPE_ID, "icecat_cat_id", "int", is_required: true);
                }
                else
                {
                    att.is_required     = false;
                    att.is_user_defined = false;
                }

                helper.SyncAttribute(att, addToDefaultSet: true);

                attributes = helper.GetAttributeList(PRODUCT_ENTITY_TYPE_ID);
                if (!attributes.TryGetValue("concentrator_product_id", out att))
                {
                    att = helper.CreateAttribute("concentrator_product_id", PRODUCT_ENTITY_TYPE_ID, "concentrator_product_id", "int", is_visible: false);
                }
                else
                {
                    att.frontend_label          = "Concentrator ID";
                    att.is_required             = false;
                    att.is_user_defined         = false;
                    att.used_in_product_listing = true;
                }

                helper.SyncAttribute(att, addToDefaultSet: true);

                if (!attributes.TryGetValue("barcode", out att))
                {
                    att = helper.CreateAttribute("barcode", PRODUCT_ENTITY_TYPE_ID, "barcode", "varchar");
                }
                else
                {
                    att.frontend_label  = "Barcode";
                    att.is_required     = false;
                    att.is_user_defined = false;
                    att.is_searchable   = true;
                }
                helper.SyncAttribute(att, addToDefaultSet: true);

                if (!attributes.TryGetValue("stock_status", out att))
                {
                    att = helper.CreateAttribute("stock_status", PRODUCT_ENTITY_TYPE_ID, "stock_status", "varchar", is_visible: false);
                }
                else
                {
                    att.frontend_label  = "Stock Status";
                    att.is_required     = false;
                    att.is_user_defined = false;
                }
                helper.SyncAttribute(att, addToDefaultSet: true);



                if (!attributes.TryGetValue("quantity_to_receive", out att))
                {
                    att = helper.CreateAttribute("quantity_to_receive", PRODUCT_ENTITY_TYPE_ID, "quantity_to_receive", "int", is_visible: false);
                }
                else
                {
                    att.frontend_label  = "Quantity on PO";
                    att.is_required     = false;
                    att.is_user_defined = false;
                }
                helper.SyncAttribute(att, addToDefaultSet: true);

                if (!attributes.TryGetValue("promised_delivery_date", out att))
                {
                    att = helper.CreateAttribute("promised_delivery_date", PRODUCT_ENTITY_TYPE_ID, "promised_delivery_date", "date", is_visible: true, used_in_product_listing: true);
                }
                else
                {
                    att.frontend_label          = "Promised Delivery Date";
                    att.frontend_input          = "date";
                    att.is_required             = false;
                    att.is_user_defined         = false;
                    att.is_visible              = false;
                    att.used_in_product_listing = true;
                }
                helper.SyncAttribute(att, addToDefaultSet: true);

                if (!attributes.TryGetValue("custom_item_number", out att))
                {
                    att = helper.CreateAttribute("custom_item_number", PRODUCT_ENTITY_TYPE_ID, "custom_item_number", "varchar", is_visible: true, used_in_product_listing: true, is_searchable: true);
                }
                else
                {
                    att.frontend_label          = "Custom Item Number";
                    att.is_required             = false;
                    att.is_user_defined         = false;
                    att.is_visible              = false;
                    att.used_in_product_listing = false;
                    att.is_searchable           = true;
                }
                helper.SyncAttribute(att, addToDefaultSet: true);

                if (!attributes.TryGetValue("commercial_status", out att))
                {
                    att = helper.CreateAttribute("commercial_status", PRODUCT_ENTITY_TYPE_ID, "commercial_status", "varchar", is_visible: true, used_in_product_listing: true);
                }
                else
                {
                    att.frontend_label          = "Commercial Status";
                    att.is_required             = false;
                    att.is_user_defined         = false;
                    att.is_visible              = false;
                    att.used_in_product_listing = true;
                }
                helper.SyncAttribute(att, addToDefaultSet: true);
            }
        }
        private void SyncProducts()
        {
            bool doRetailStock = ((ConnectorSystemType)Connector.ConnectorType).Has(ConnectorSystemType.ExportRetailStock);

            XDocument retailStock = null;
            Dictionary <int, List <AssortmentRetailStock> > retailStockList = new Dictionary <int, List <AssortmentRetailStock> >();

            if (IsPrimaryLanguage && doRetailStock)
            {
                retailStockList = (from r in Assortment
                                   select new
                {
                    product_id = r.ProductID,
                    store_records = r.RetailStock
                }).Distinct().ToDictionary(x => x.product_id, y => y.store_records);
            }

            Dictionary <string, int> stockStoreList = new Dictionary <string, int>();

            if (doRetailStock)
            {
                using (var helper = new AssortmentHelper(Connector.Connection, Version))
                {
                    stockStoreList = helper.GetStockStoreList();
                }
            }

            var productsSource = (from p in Assortment
                                  select p);

            List <AssortmentStockPriceProduct> products = productsSource.Where(x => !x.IsConfigurable).ToList();

            ProcessProductCollection(retailStockList, stockStoreList, products);

            using (var helper = new AssortmentHelper(Connector.Connection, Version))
            {
                var skuList      = helper.GetSkuList();
                var skuInXmlList = (from p in productsSource
                                    select p.ManufacturerID).ToList();

                var toDeactivate = skuList.Where(x => !skuInXmlList.Contains(x.Key));

                //exclude shipping costs
                toDeactivate = toDeactivate.Where(x => !x.Key.StartsWith("ShippingCostProductID_"));

                if (toDeactivate.Count() > 0)
                {
                    SortedDictionary <string, eav_attribute> attributeList = helper.GetAttributeList(PRODUCT_ENTITY_TYPE_ID);

                    foreach (var p in toDeactivate)
                    {
                        SetProductStatus(p.Value.entity_id, (int)PRODUCT_STATUS.DISABLED, helper, attributeList, StoreList[CurrentStoreCode].store_id);

                        if (RequiresStockUpdate)
                        {
                            helper.SyncStock(new cataloginventory_stock_item()
                            {
                                product_id  = p.Value.entity_id,
                                qty         = 0,
                                is_in_stock = false
                            });
                        }
                    }
                }
            }
        }