Example #1
0
        public KCAPIInventoryItem GetAPIInventoryItem(InventoryItem product)
        {
            DAC.KNSIKCInventoryItem kcProduct = BulkGraph.KCInventoryItem.SelectSingle(product.InventoryID);

            InventoryItemPCExt productPcExt       = product.GetExtension <InventoryItemPCExt>();
            string             classificationName = KCGeneralDataHelper.GetClassificationByInventoryId(ClassificationsGraph, product);

            KCAPIInventoryItem apiProduct = new KCAPIInventoryItem()
            {
                Classification = classificationName
            };

            if (IsConfigurableParentOrChild(product, productPcExt))
            {
                PropagateConfigurable(product, apiProduct, productPcExt.UsrKNCompositeType == null);
            }
            if (productPcExt.UsrKNCompositeType == KCConstants.GroupedProduct)
            {
                PropagateBundle(product, apiProduct);
            }
            if (product.KitItem.GetValueOrDefault())
            {
                PropagateKit(product, apiProduct);
            }

            KCDynamicProductMapper mapper = new KCDynamicProductMapper(KCMappingEntitiesConstants.Product);

            mapper.Mapping.MappingValues = ConversionGraph.GetEntity(product.InventoryCD);
            apiProduct = mapper.MapApiInventoryItem(apiProduct, product, kcProduct);
            apiProduct = KCGeneralDataHelper.FillReservedAttributes(product, apiProduct);

            return(apiProduct);
        }
Example #2
0
        public void PropagateConfigurable(InventoryItem product, KCAPIInventoryItem apiProduct, bool isChild)
        {
            apiProduct.VariationParentSku = isChild ? BulkGraph.ItemById.SelectSingle(product.GetExtension <InventoryItemPCExt>().UsrKNCompositeID).InventoryCD
                                                    : KCConstants.Parent;
            string relationshipName = KCGeneralDataHelper.GetRelationshipName(RelationshipGraph, product.ItemClassID);

            apiProduct.RelationshipName = relationshipName;
        }
Example #3
0
        public IRestRequest EditProductRequest(KCAPIInventoryItem product, int?productId)
        {
            IRestRequest request = CreateRestRequest("/v1/Products({id})");

            request.AddUrlSegment("id", productId.ToString());
            AddBody(request, product);

            return(request);
        }
        protected KCAPIInventoryItem SetPrices(KCAPIInventoryItem product, KCAPIInventoryItem MSMQPrices)
        {
            foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(MSMQPrices))
            {
                if (property.Name.EndsWith("Price") || property.Name.EndsWith("Margin"))
                {
                    property.SetValue(product, property.GetValue(MSMQPrices));
                }
            }

            return(product);
        }
Example #5
0
        public void PropagateBundle(InventoryItem product, KCAPIInventoryItem apiProduct)
        {
            List <KCAPIBundleComponent> bundleComponents = new List <KCAPIBundleComponent>();

            foreach (KNSIGroupedItems component in BulkGraph.GroupedItemChilds.Select(product.InventoryID))
            {
                bundleComponents.Add(new KCAPIBundleComponent()
                {
                    ComponentSku = BulkGraph.ItemById.SelectSingle(component.MappedInventoryID).InventoryCD.Trim(),
                    Quantity     = Convert.ToInt32(component.Quantity)
                });
            }

            DeleteObsoleteBundleComponents(bundleComponents, product);

            apiProduct.BundleType       = "BundleItem";
            apiProduct.BundleComponents = bundleComponents;
        }
Example #6
0
        public void PropagateKit(InventoryItem product, KCAPIInventoryItem apiProduct)
        {
            List <KCAPIBundleComponent> bundleComponents = new List <KCAPIBundleComponent>();

            INKitSpecHdr kit = BulkGraph.KitProduct.SelectSingle(product.InventoryID);

            foreach (INKitSpecStkDet component in BulkGraph.StockKitComponents.Select(product.InventoryID, kit.RevisionID))
            {
                if (!ComponentIsActive(component.CompInventoryID))
                {
                    continue;
                }

                bundleComponents.Add(new KCAPIBundleComponent()
                {
                    ComponentSku = BulkGraph.ItemById.SelectSingle(component.CompInventoryID).InventoryCD.Trim(),
                    Quantity     = Convert.ToInt32(component.DfltCompQty)
                });
            }

            foreach (INKitSpecNonStkDet component in BulkGraph.NonStockKitComponents.Select(product.InventoryID, kit.RevisionID))
            {
                if (!ComponentIsActive(component.CompInventoryID))
                {
                    continue;
                }

                bundleComponents.Add(new KCAPIBundleComponent()
                {
                    ComponentSku = BulkGraph.ItemById.SelectSingle(component.CompInventoryID).InventoryCD.Trim(),
                    Quantity     = Convert.ToInt32(component.DfltCompQty)
                });
            }

            DeleteObsoleteBundleComponents(bundleComponents, product);

            apiProduct.BundleType       = "BundleItem";
            apiProduct.BundleComponents = bundleComponents;
        }
        public List <KCBulkProduct> HandleItems(List <KeyValuePair <string, InventoryItem> > productsForExport,
                                                Dictionary <string, KCAPIInventoryItem> MSMQPrices             = null,
                                                Dictionary <string, List <KCAPIQuantity> > MSMQQuantityUpdates = null)
        {
            if (productsForExport.Count == 0)
            {
                return(new List <KCBulkProduct>(0));
            }

            var dtos           = new List <Tuple <string, InventoryItem, KCBulkProduct> >(productsForExport.Count);
            var availableTasks = Environment.ProcessorCount - 1;
            var itemsToProcess = productsForExport.SplitList((productsForExport.Count / availableTasks) + 1).ToArray();

            Task[] tasks  = new Task[itemsToProcess.Length];
            object locker = new object();

            //force load extensions to slot (GetSlot<PXCacheExtensionCollection>)
            productsForExport[0].Value.GetExtension <InventoryItemPCExt>();

            //get slot data with extensions (slots are located in CallContext)
            var cacheExtensions = CallContext.GetData("PX.Data.PXCacheExtensionCollection");


            for (int x = 0; x < itemsToProcess.Length; x++)
            {
                int index = x;
                var items = itemsToProcess[index];
                tasks[index] = new Task(() =>
                {
                    //Set slot with extensions to other thread
                    CallContext.SetData("PX.Data.PXCacheExtensionCollection", cacheExtensions);
                    var graph = PXGraph.CreateInstance <KCBulkProductMaint>();
                    KCRelationshipSetupMaint relationshipGraph         = PXGraph.CreateInstance <KCRelationshipSetupMaint>();
                    KCClassificationsMappingMaint classificationsGraph = PXGraph.CreateInstance <KCClassificationsMappingMaint>();
                    KCIItemConversionDataMaint conversionGraph         = PXGraph.CreateInstance <KCIItemConversionDataMaint>();
                    KCMapInventoryItem itemMapper = new KCMapInventoryItem(relationshipGraph, classificationsGraph, graph, conversionGraph, _store, logger.LoggerProperties);

                    foreach (KeyValuePair <string, InventoryItem> product in items)
                    {
                        InventoryItem inventoryItem = product.Value;
                        var key = inventoryItem.InventoryCD;

                        KCAPIInventoryItem apiProduct = itemMapper.GetAPIInventoryItem(inventoryItem);
                        if (MSMQPrices != null)
                        {
                            apiProduct = SetPrices(apiProduct, MSMQPrices[key]);
                        }

                        List <string> labels = HandleLabels(inventoryItem, graph);
                        List <(string imagePlacement, string imageUrl)> images = HandleImages(inventoryItem, graph);

                        APIUpdates quantityUpdates;
                        if (MSMQQuantityUpdates?.ContainsKey(key) == true)
                        {
                            quantityUpdates = new APIUpdates()
                            {
                                UpdateType = "InStock",
                                Updates    = MSMQQuantityUpdates[key]
                            };
                        }
                        else
                        {
                            quantityUpdates = HandleQuantities(graph, inventoryItem);
                        }

                        string formattedLabels           = FormatLabels(labels);
                        string formattedImages           = FormatPictureUrls(images);
                        string formattedBundleComponents = FormatBundleComponents(apiProduct?.BundleComponents);
                        string formattedQuantities       = FormatQuantities(quantityUpdates, graph);

                        apiProduct.Labels              = formattedLabels;
                        apiProduct.PictureUrls         = formattedImages;
                        apiProduct.FtpBundleComponents = formattedBundleComponents;
                        apiProduct.DCQuantity          = formattedQuantities;
                        apiProduct.QuantityUpdateType  = "InStock";

                        lock (locker)
                        {
                            dtos.Add(new Tuple <string, InventoryItem, KCBulkProduct>(product.Key, inventoryItem, new KCBulkProduct(apiProduct, HandleAttributes(inventoryItem))));
                        }

                        SetSyncDateTime(inventoryItem, graph);
                        graph.Actions.PressSave();
                    }
                }, cancellationToken);
            }

            tasks.StartAndWaitAll(cancellationToken);
            Thread.Sleep((int)KCConstants.SYNC_DELAY_SECONDS * 1000);

            dtos.Sort(new KCProductTypeComparer());

            List <KCBulkProduct> list = dtos.Select(x => x.Item3).ToList();


            return(list);
        }
Example #8
0
 public KCBulkProduct(KCAPIInventoryItem product, IEnumerable <KCAPIAttribute> attributes)
 {
     Product    = product;
     Attributes = attributes;
 }
Example #9
0
 public void EditProduct(KCAPIInventoryItem apiProduct, int?productId, string parentCd = null)
 {
     client.Patch <KCAPIResponse>(request.EditProductRequest(apiProduct, productId));
 }