private void ExtractPrice(AssortmentStockPriceProduct product, ref decimal?price, ref decimal?specialPrice, ref string commercialStatus) { var priceElement = product.Prices.FirstOrDefault(); if (priceElement != null) { commercialStatus = priceElement.CommercialStatus.Trim(); if (bool.Parse(Connector.ConnectorSettings.GetValueByKey("PriceInTax", "True"))) { price = priceElement.UnitPrice * ((priceElement.TaxRate / 100) + 1); } else { price = priceElement.UnitPrice; } if (priceElement.SpecialPrice.HasValue) { if (bool.Parse(Connector.ConnectorSettings.GetValueByKey("PriceInTax", "True"))) { specialPrice = priceElement.SpecialPrice.Value * ((priceElement.SpecialPrice.Value / 100) + 1); } else { specialPrice = priceElement.SpecialPrice.Value; } } } }
private void ProcessProduct(AssortmentHelper helper, AssortmentStockPriceProduct product, SortedDictionary <string, catalog_product_entity> skuList, SortedDictionary <string, eav_attribute> attributeList, Dictionary <string, int> stockStoreList, IEnumerable <AssortmentRetailStock> productRetailStock ) { string sku = product.ManufacturerID; int productID = product.ProductID; string customProductId = product.CustomProductID; bool isNonAssortmentItem = (product.IsNonAssortmentItem); bool isConfigurable = (product.IsConfigurable); bool childrenOnStock = false; string type = isConfigurable ? "configurable" : "simple"; catalog_product_entity entity = null; skuList.TryGetValue(sku, out entity); if (entity == null) { return; } if (isConfigurable && ConfigurableProducts.ContainsKey(productID)) { var children = ConfigurableProducts[productID]; childrenOnStock = (children.Any(x => x.Stock != null && x.Stock.InStock > 0)); } int storeid = 0; if (MultiLanguage && !IsPrimaryLanguage) { storeid = StoreList[CurrentStoreCode].store_id; } int productStatus = (int)PRODUCT_STATUS.ENABLED; #region Stock if (IsPrimaryLanguage) { int? quantityOnHand = null; int? quantityToReceive = null; string stockStatus = "S"; DateTime?promisedDeliveryDate = null; var stockElement = product.Stock; if (stockElement != null) { int tmp; quantityOnHand = stockElement.InStock; quantityToReceive = stockElement.QuantityToReceive; stockStatus = stockElement.StockStatus.Trim(); DateTime dt; if (stockElement.PromisedDeliveryDate.HasValue) { promisedDeliveryDate = stockElement.PromisedDeliveryDate.Value; } } if (productRetailStock != null) { if (productRetailStock.Count() > 0) { foreach (var s in stockStoreList) { var store_record = productRetailStock.FirstOrDefault(x => x.VendorCode == s.Key); int qty = (store_record != null) ? store_record.InStock : 0; helper.SyncStoreStock(sku, s.Value, qty); } } else { helper.ClearStoreStock(sku); //no stores left with stock, clear all } } if (RequiresStockUpdate) { helper.SyncAttributeValue(attributeList["quantity_to_receive"].attribute_id, PRODUCT_ENTITY_TYPE_ID, 0, entity.entity_id, quantityToReceive ?? 0, "int"); helper.SyncAttributeValue(attributeList["promised_delivery_date"].attribute_id, PRODUCT_ENTITY_TYPE_ID, 0, entity.entity_id, promisedDeliveryDate, "datetime"); helper.SyncAttributeValue(attributeList["stock_status"].attribute_id, PRODUCT_ENTITY_TYPE_ID, 0, entity.entity_id, stockStatus, "varchar"); helper.SyncWebsiteProduct(StoreList[CurrentStoreCode].website_id, entity.entity_id); bool is_in_stock = quantityOnHand > 0 || (promisedDeliveryDate.HasValue && quantityToReceive > 0) || (productRetailStock != null && productRetailStock.Count() > 0) || (!String.IsNullOrEmpty(stockStatus) && stockStatus != "O"); if (isConfigurable) { if (childrenOnStock) { is_in_stock = true; } else { is_in_stock = false; } } helper.SyncStock(new cataloginventory_stock_item() { product_id = entity.entity_id, qty = quantityOnHand ?? 0, is_in_stock = is_in_stock }); if (!is_in_stock) { productStatus = (int)PRODUCT_STATUS.DISABLED; } SetProductStatus(entity.entity_id, productStatus, helper, attributeList, 0); } } SetProductStatus(entity.entity_id, productStatus, helper, attributeList, StoreList[CurrentStoreCode].store_id); #endregion #region Price decimal?price = null; decimal?specialPrice = null; string commercialStatus = "O"; int visibility = 4; //catalog, search if (isNonAssortmentItem || (UsesConfigurableProducts && SimpleProducts.Contains(productID)) || !product.Visible) { visibility = 1; // not visible individually } ExtractPrice(product, ref price, ref specialPrice, ref commercialStatus); helper.SyncAttributeValue(attributeList["visibility"].attribute_id, PRODUCT_ENTITY_TYPE_ID, StoreList[CurrentStoreCode].store_id, entity.entity_id, visibility, "int"); helper.SyncAttributeValue(attributeList["price"].attribute_id, PRODUCT_ENTITY_TYPE_ID, StoreList[CurrentStoreCode].store_id, entity.entity_id, price, "decimal"); if (IsPrimaryLanguage) { helper.SyncAttributeValue(attributeList["visibility"].attribute_id, PRODUCT_ENTITY_TYPE_ID, 0, entity.entity_id, visibility, "int"); helper.SyncAttributeValue(attributeList["price"].attribute_id, PRODUCT_ENTITY_TYPE_ID, 0, entity.entity_id, price, "decimal"); } helper.SyncAttributeValue(attributeList["special_price"].attribute_id, PRODUCT_ENTITY_TYPE_ID, 0, entity.entity_id, null, "decimal"); if ((specialPrice ?? 0) > 0) { helper.SyncAttributeValue(attributeList["special_price"].attribute_id, PRODUCT_ENTITY_TYPE_ID, StoreList[CurrentStoreCode].store_id, entity.entity_id, specialPrice, "decimal"); if (Connector.ConnectorID == 11) { helper.SyncAttributeValue(attributeList["special_price"].attribute_id, PRODUCT_ENTITY_TYPE_ID, 0, entity.entity_id, specialPrice, "decimal"); } } else { helper.DeleteAttributeValue(attributeList["special_price"].attribute_id, PRODUCT_ENTITY_TYPE_ID, StoreList[CurrentStoreCode].store_id, entity.entity_id, "decimal"); } #endregion }