protected List <string> HandleLabels(InventoryItem product, KCBulkProductMaint graph) { List <string> bulkLabels = new List <string>(); KNSIKCInventoryItem kcProduct = graph.KCInventoryItem.SelectSingle(product.InventoryID); IEnumerable <string> aLabels = graph.ItemLabels.Select(product.InventoryID).RowCast <KNSIKCLabel>().Select(y => y.LabelName); IEnumerable <string> caLabels = ApiHelper.GetProductLabels(kcProduct.UsrKCCAID).Select(x => x.Name); if (!aLabels.OrderBy(x => x).SequenceEqual(caLabels.OrderBy(x => x))) { IEnumerable <string> obsoleteLabels = caLabels.Where(x => aLabels.All(y => y != x)); IEnumerable <string> newLabels = aLabels.Where(x => caLabels.All(y => y != x)); foreach (string oldLabel in obsoleteLabels) { // 04/22/19 AT: When deleting label through FTP, ChannelAdvisor requires '-' before label to determine that it should be deleted bulkLabels.Add("-" + oldLabel); } foreach (string newLabel in newLabels) { bulkLabels.Add(newLabel); } } return(bulkLabels); }
public void RetrieveChannelAdvisorIds(KCStore store) { KCDataExchangeMaint graph = PXGraph.CreateInstance <KCDataExchangeMaint>(); KCSiteMaster connection = graph.Connection.Select().RowCast <KCSiteMaster>().First(x => x.SiteMasterCD.Equals(store.SiteMasterCD)); KCARestClient client = new KCARestClient(connection); KCInventoryItemAPIHelper helper = new KCInventoryItemAPIHelper(client); foreach (KCAPIIdSkuJuxtaposion juxtaposion in helper.GetAllIdSkuJuxtaposions()) { InventoryItem item = graph.ItemByCd.SelectSingle(juxtaposion.Sku); if (item == null) { continue; } KNSIKCInventoryItem cItem = graph.KCInventoryItem.SelectSingle(item.InventoryID); if (cItem != null && cItem.UsrKCActiveOnCa.GetValueOrDefault()) { cItem.UsrKCCAID = juxtaposion.ID; cItem.UsrKCCAParentID = juxtaposion.ParentProductID.ToString(); graph.KCInventoryItem.Update(cItem); } } graph.Actions.PressSave(); if (logger != null) { logger.ClearLoggingIds(); logger.Information(KCMessages.ProductIdsRetrievalSuccess); } }
private bool IsKitUpdated(InventoryItem product, KNSIKCInventoryItem kcProduct) { if (product.KitItem.GetValueOrDefault()) { if (kcProduct == null) { return(true); } var kitProduct = KitProduct.SelectSingle(product.InventoryID); if (kitProduct == null) { return(false); } if (kitProduct.LastModifiedDateTime.GetValueOrDefault().BiggerThan(kcProduct.UsrKCCASyncDate.GetValueOrDefault())) { return(true); } if (StockKitComponents.SelectSingle(product.InventoryID, kitProduct.RevisionID, kcProduct.UsrKCCASyncDate) != null) { return(true); } if (NonStockKitComponents.SelectSingle(product.InventoryID, kitProduct.RevisionID, kcProduct.UsrKCCASyncDate) != null) { return(true); } } return(false); }
private void UpdateSiteQuantity(KCDataExchangeMaint masterGraph, KCMSMQInventoryQuantity quantityProduct, KCInventoryItemAPIHelper helper) { InventoryItem inventoryItem = masterGraph.ProductByInvCd.Select(quantityProduct.InventoryID.Trim()); if (inventoryItem != null) { KNSIKCInventoryItem kcProduct = masterGraph.KCInventoryItem.SelectSingle(inventoryItem.InventoryID); if (kcProduct.UsrKCCAID != null) { logger.SetParentAndEntityIds(null, inventoryItem.InventoryCD); try { APIQuantityValue apiQuantity = new APIQuantityValue { Value = new APIUpdates() { UpdateType = "InStock", Updates = quantityProduct.Updates } }; helper.UpdateQuantity(apiQuantity, kcProduct.UsrKCCAID); logger.Information(KCMessages.MSMQSyncAPI); } catch (Exception e) { logger.Information(e.Message); } } } }
private void UpdatePrice(KCDataExchangeMaint masterGraph, KCMSMQInventoryPrice priceProduct, KCInventoryItemAPIHelper helper) { InventoryItem inventoryItem = masterGraph.ProductByInvCd.Select(priceProduct.InventoryID.Trim()); if (inventoryItem != null) { KNSIKCInventoryItem kcProduct = masterGraph.KCInventoryItem.SelectSingle(inventoryItem.InventoryID); InventoryItemPCExt inventoryItemPCExt = inventoryItem.GetExtension <InventoryItemPCExt>(); InventoryItem parent = KCGeneralDataHelper.GetInventoryItemByInventoryId(PXGraph.CreateInstance <KCDataExchangeMaint>(), inventoryItemPCExt.UsrKNCompositeID); logger.SetParentAndEntityIds(parent?.InventoryCD, inventoryItem.InventoryCD); try { if (kcProduct.UsrKCCAID != null) { helper.EditProduct(KCMapInventoryItem.GetAPIMSMQInventoryPrice(priceProduct), kcProduct.UsrKCCAID); } logger.Information(KCMessages.MSMQSyncAPI); } catch (Exception e) { logger.Information(e.Message); } } }
private bool IsVariationRelationshipUpdated(InventoryItem product, KNSIKCInventoryItem kcProduct) { InventoryItemPCExt productPcExt = product.GetExtension <InventoryItemPCExt>(); if (productPcExt?.UsrKNCompositeType != KCConstants.ConfigurableProduct) { return(false); } return(RequiredRelation.SelectSingle(product.ItemClassID, kcProduct.UsrKCCASyncDate) != null); }
protected List <KCAPIAttribute> HandleAttributes(InventoryItem product) { List <KCAPIAttribute> attributes = new List <KCAPIAttribute>(); KNSIKCInventoryItem kcProduct = Graph.KCInventoryItem.SelectSingle(product.InventoryID); HandleProductAttributes(product, ref attributes); HandleCrossReferences(product, ref attributes); KCODataWrapper <KCAPIAttribute> CAAttributes = ApiHelper.GetAttributes(kcProduct.UsrKCCAID); if (CAAttributes?.Value != null) { foreach (KCAPIAttribute attribute in CAAttributes.Value) { if (!attributes.Select(x => x.Name.Trim().ToUpper()).Contains(attribute.Name.Trim().ToUpper())) { // 04/22/19 AT: When deleting attribute's value through FTP, ChannelAdvisor requires to pass DeleteMarker (currently "_Delete_") // to indicate that its value should be deleted attributes.Add(new KCAPIAttribute { Name = attribute.Name, Value = KCConstants.DeleteMarker }); } } } bool existProductType = Graph.RequiredChannelAdvisorAttribute.Select(KCConstants.ProductTypeAttributeName).Count > 0; if (existProductType && attributes.All(x => x.Name != KCConstants.ProductTypeAttributeName)) { attributes.Add(new KCAPIAttribute { Name = KCConstants.ProductTypeAttributeName, Value = GetProductType(product) }); } return(attributes); }
private bool IsClassificationUpdated(KNSIKCInventoryItem productKcExt) { return(ClassificationMappings.SelectSingle(productKcExt.UsrKCCASyncDate) != null); }
private bool IsSiteMasterUpdated(KNSIKCInventoryItem kcProduct) { return(SiteMaster.LastModifiedDateTime > kcProduct.UsrKCCASyncDate.GetValueOrDefault()); }
private bool IsAttributesMappingUpdated(KNSIKCInventoryItem kcProduct) { return(AttributesMappings.SelectSingle(kcProduct.UsrKCCASyncDate) != null); }
private bool IsQuantityUpdated(KNSIKCInventoryItem kcProduct) { return(QuantityUpdate.SelectSingle(kcProduct.UsrKCCASyncDate) != null); }
private bool IsImagePlacementUpdated(KNSIKCInventoryItem kcProduct) { return(ImagePlacements.SelectSingle(kcProduct.UsrKCCASyncDate) != null); }
private bool IsKcProductUpdated(KNSIKCInventoryItem kcProduct) { return(kcProduct.LastModifiedDateTime.GetValueOrDefault().BiggerThan(kcProduct.UsrKCCASyncDateTicks)); }
public void ProcessMessageFTP(List <KCPriceAndInventoryMessage> messages, CancellationToken cancellationToken) { KCDataExchangeMaint masterGraph = PXGraph.CreateInstance <KCDataExchangeMaint>(); KCPriceAndInventoryMaint graph = PXGraph.CreateInstance <KCPriceAndInventoryMaint>(); var MSMQQuantityUpdates = new Dictionary <string, List <KCAPIQuantity> >(); var MSMQPrices = new Dictionary <string, KCAPIInventoryItem>(); var productsForExportPrice = new List <KeyValuePair <string, InventoryItem> >(); var productsForExportQuantity = new Dictionary <string, KeyValuePair <string, InventoryItem> >(); PushNotificationsHook pricePN = graph.PushNotification.SelectSingle(KCMSMQQueueHelper.GetSyncName(SyncType.InventoryPrice)); PushNotificationsHook quantityPN = graph.PushNotification.SelectSingle(KCMSMQQueueHelper.GetSyncName(SyncType.InventoryQuantity)); PushNotificationsHook vendorPN = graph.PushNotification.SelectSingle(KCMSMQQueueHelper.GetSyncName(SyncType.VendorQuantity)); KCMSMQueueReader price = null; KCMSMQueueReader quantity = null; KCMSMQueueReader vendor = null; try { price = new KCMSMQueueReader(pricePN.Address); quantity = new KCMSMQueueReader(quantityPN.Address); vendor = new KCMSMQueueReader(vendorPN.Address); foreach (KCPriceAndInventoryMessage msg in messages) { var syncType = KCMSMQQueueHelper.ParseSyncQueueName(msg.Address); if (syncType == SyncType.InventoryQuantity || syncType == SyncType.VendorQuantity) { List <object> insertedMessages = null; if (syncType == SyncType.InventoryQuantity && quantity.TryReceiveMessage(msg.MessageID, out var invMessage)) { insertedMessages = invMessage.Inserted; } if (syncType == SyncType.VendorQuantity && vendor.TryReceiveMessage(msg.MessageID, out var vendorMessage)) { insertedMessages = vendorMessage.Inserted; } if (insertedMessages != null) { foreach (object item in insertedMessages) { KCMSMQInventoryQuantity quantityProduct = JsonConvert.DeserializeObject <KCMSMQInventoryQuantity>(item.ToString()); InventoryItem inventoryItem = masterGraph.ProductByInvCd.Select(quantityProduct.InventoryID.Trim()); KNSIKCInventoryItem kcProduct = masterGraph.KCInventoryItem.SelectSingle(inventoryItem.InventoryID); if (kcProduct.UsrKCCAID != null) { var key = inventoryItem.InventoryCD; if (!MSMQQuantityUpdates.ContainsKey(key)) { MSMQQuantityUpdates.Add(key, quantityProduct.Updates); } if (!productsForExportQuantity.ContainsKey(key)) { InventoryItemPCExt inventoryItemPCExt = inventoryItem.GetExtension <InventoryItemPCExt>(); productsForExportQuantity.Add(inventoryItem.InventoryCD, new KeyValuePair <string, InventoryItem>(inventoryItemPCExt.UsrKNCompositeType, inventoryItem)); } } } } } else if (syncType == SyncType.InventoryPrice) { if (price.TryReceiveMessage(msg.MessageID, out var message)) { foreach (object item in message.Inserted) { KCMSMQInventoryPrice priceProduct = JsonConvert.DeserializeObject <KCMSMQInventoryPrice>(item.ToString()); InventoryItem inventoryItem = masterGraph.ProductByInvCd.Select(priceProduct.InventoryID.Trim()); InventoryItemPCExt inventoryItemPCExt = inventoryItem.GetExtension <InventoryItemPCExt>(); productsForExportPrice.Add(new KeyValuePair <string, InventoryItem>(inventoryItemPCExt.UsrKNCompositeType, inventoryItem)); MSMQPrices.Add(inventoryItem.InventoryCD, KCMapInventoryItem.GetAPIMSMQInventoryPrice(priceProduct)); } } } } } finally { price?.Dispose(); quantity?.Dispose(); vendor?.Dispose(); } Export(masterGraph, productsForExportPrice, cancellationToken, MSMQPrices); Export(masterGraph, productsForExportQuantity.Values.ToList(), cancellationToken, null, MSMQQuantityUpdates); }
private bool IsKcProductUpdated(KNSIKCInventoryItem kcProduct) { return(kcProduct.LastModifiedDateTime.GetValueOrDefault().BiggerThan(DateFrom) && kcProduct.LastModifiedDateTime.GetValueOrDefault().LessThan(DateTo)); }