internal static product Create(PriceItem item) { var result = new product { active = Convert.ToInt32(item.Active), ean13 = item.Ean13, reference = item.Reference, supplier_reference = item.SupplierReference, price = Convert.ToDecimal(item.RetailPrice), wholesale_price = Convert.ToDecimal(item.WholesalePrice), show_price = 1, redirect_type = "404", id_shop_default = 1, available_for_order = 1, advanced_stock_management = 0, id_tax_rules_group = 1, minimal_quantity = 1, weight = !string.IsNullOrWhiteSpace(item.Weight) ? Convert.ToDecimal(item.Weight) : 0, associations = new AssociationsProduct(), name = new List<language> { new language(1, item.Name) }, description = new List<language> { new language(1, item.Description) }, description_short = new List<language> { new language(1, item.ShortDescription) } }; return result; }
public static IEnumerable<string> DifferentValueFields(product LeftProduct, product RightProduct) { var properties = new List<string>(); foreach (var propertyInfo in LeftProduct.GetType().GetProperties()) { if (propertyInfo.Name.StartsWith("id") || propertyInfo.Name.StartsWith("associations")) { continue; } var type = propertyInfo.PropertyType; if (type.Name.StartsWith("Nullable")) { type = type.GenericTypeArguments[0]; } object leftNullableValue = propertyInfo.GetValue(LeftProduct); object rightNullableValue = propertyInfo.GetValue(RightProduct); var leftValue = leftNullableValue == null ? null : Convert.ChangeType(leftNullableValue, type); var rightValue = rightNullableValue == null ? null : Convert.ChangeType(rightNullableValue, type); if (type == typeof(List<Bukimedia.PrestaSharp.Entities.AuxEntities.language>)) { leftValue = LanguageHelper.GetString(leftValue as IEnumerable<Bukimedia.PrestaSharp.Entities.AuxEntities.language>); rightValue = LanguageHelper.GetString(rightValue as IEnumerable<Bukimedia.PrestaSharp.Entities.AuxEntities.language>); } if (!Equals(leftValue, rightValue)) { properties.Add(propertyInfo.Name); } } return properties; }
private stock_available GetStockValue(product product, Assort assort) { combination combination = null; if (!string.IsNullOrWhiteSpace(assort.Size) || !string.IsNullOrWhiteSpace(assort.Color) || !string.IsNullOrWhiteSpace(assort.Reference)) { combination = _combinationProcessor.GetOrCreateCombination(product, assort); } var filter = new Dictionary<string, string> { { "id_product", product.id.Value.ToString(CultureInfo.InvariantCulture) } }; var stocks = _apiFactory.StockFactory.GetByFilter(filter, null, null); if (stocks == null || !stocks.Any()) { return CreateStock(product, assort, combination); } var stock = combination != null ? stocks.FirstOrDefault(s => s.id_product_attribute == combination.id) : stocks.FirstOrDefault(s => s.id_product == product.id); return stock ?? CreateStock(product, assort, combination); }
internal void FillOptions(PriceItem priceItem, product product) { foreach (var assort in priceItem.Assort) { GetOrCreateCombination(product, assort); } }
internal static product Create(PriceItem item) { var result = new product { active = Convert.ToInt32(item.Active), ean13 = item.Ean13, reference = item.Reference, supplier_reference = item.SupplierReference, price = Convert.ToDecimal(item.RetailPrice), wholesale_price = Convert.ToDecimal(item.WholesalePrice), show_price = 1, redirect_type = "404", id_shop_default = 1, available_for_order = 1, advanced_stock_management = 0, id_tax_rules_group = 1, minimal_quantity = 1, weight = !string.IsNullOrWhiteSpace(item.Weight) ? Convert.ToDecimal(item.Weight) : 0, associations = new AssociationsProduct(), name = new List <language> { new language(1, item.Name) }, description = new List <language> { new language(1, item.Description) }, description_short = new List <language> { new language(1, item.ShortDescription) } }; return(result); }
public async Task FillOptions(PriceItem priceItem, product product) { foreach (var assort in priceItem.Assort) { await GetOrCreateCombination(product, assort); } }
internal static product MapCategory(product product, category category) { product.id_category_default = category.id; product.associations.categories = new List<Bukimedia.PrestaSharp.Entities.AuxEntities.category> { new Bukimedia.PrestaSharp.Entities.AuxEntities.category(category.id.Value) }; return product; }
internal static product MapCategories(product product, List <category> categories) { product.id_category_default = categories[0].id; product.associations.categories = new List <Bukimedia.PrestaSharp.Entities.AuxEntities.category>(); foreach (var category in categories) { product.associations.categories.Add(new Bukimedia.PrestaSharp.Entities.AuxEntities.category(category.id.Value)); } return(product); }
internal static product MapStock(product product, stock_available stock) { product.associations.stock_availables = new List<Bukimedia.PrestaSharp.Entities.AuxEntities.stock_available> { new Bukimedia.PrestaSharp.Entities.AuxEntities.stock_available { id = stock.id.Value, id_product_attribute = stock.id_product_attribute.Value } }; return product; }
internal static product MapStock(product product, stock_available stock) { product.associations.stock_availables = new List <Bukimedia.PrestaSharp.Entities.AuxEntities.stock_available> { new Bukimedia.PrestaSharp.Entities.AuxEntities.stock_available { id = stock.id.Value, id_product_attribute = stock.id_product_attribute.Value } }; return(product); }
public void Update(product product, PriceItem item, PriceType processingPriceType) { _stockProcessor.UpdateStockValue(item, product); UpdateMetaInfo(item, product); if (processingPriceType == PriceType.Stock) { UpdateProductPriceAndActivity(item, product); } if (processingPriceType == PriceType.Discount) { UpdateDiscountInfo(item, product); } }
internal void UpdateStockValue(PriceItem priceItem, product product) { foreach (var assort in priceItem.Assort) { var stock = GetStockValue(product, assort); if (stock.quantity != assort.Balance) { Log.Info("Balance changed from {0} to {1}. Reference: {2}", stock.quantity, assort.Balance, priceItem.Reference); stock.quantity = assort.Balance; _apiFactory.StockFactory.Update(stock); } } }
private stock_available CreateStock(product product, Assort assort, combination combination) { var stock = new stock_available { id_product = product.id, quantity = assort.Balance }; if (combination != null) { stock.id_product_attribute = combination.id; } return _apiFactory.StockFactory.AddList(new List<stock_available> { stock }).First(); }
internal static product MapCombination(product product, combination combination) { if (combination == null) { return(product); } product.associations.combinations.Add( new combinations { id = combination.id.Value }); return(product); }
private void UpdateProductPriceAndActivity(PriceItem item, product product) { // price of onSale products is updated by special file if (product.on_sale == 0 && (product.active != Convert.ToInt32(item.Active) || product.price != Convert.ToDecimal(item.RetailPrice) || product.wholesale_price != Convert.ToDecimal(item.WholesalePrice))) { product.active = Convert.ToInt32(item.Active); product.price = Convert.ToDecimal(item.RetailPrice); product.wholesale_price = Convert.ToDecimal(item.WholesalePrice); Log.Debug("Updating price. Reference: {0}", item.Reference); _apiFactory.ProductFactory.Update(product); } }
internal static product MapFeature(product product, product_feature_value featureValue) { if (featureValue == null) { return(product); } product.associations.product_features.Add( new product_feature { id = featureValue.id_feature.Value, id_feature_value = featureValue.id.Value }); return(product); }
internal static product MapFeature(product product, product_feature_value featureValue) { if (featureValue == null) { return product; } product.associations.product_features.Add( new product_feature { id = featureValue.id_feature.Value, id_feature_value = featureValue.id.Value }); return product; }
internal manufacturer GetManufacturerValue(PriceItem priceItem, product product) { var filter = new Dictionary<string, string> { { "name", priceItem.Manufacturer } }; var manufacturers = _apiFactory.ManufacturerFactory.GetByFilter(filter, null, null); if (manufacturers == null || !manufacturers.Any()) { var manufacturer = new manufacturer { name = priceItem.Manufacturer, active = 1, }; return _apiFactory.ManufacturerFactory.Add(manufacturer); } return manufacturers.First(); }
private Bukimedia.PrestaSharp.Entities.product SaveOrUpdatePsProduct(Bukimedia.PrestaSharp.Entities.product psProduct, ProductEntity product) { if (psProduct.id.HasValue && psProduct.id.Value > 0) { logger.LogInformation($"Update product id: {product.Id}, name: {product.Name}"); prestaShopClient.ProductFactory.Update(psProduct); } else { logger.LogInformation($"Add new product id: {product.Id}, name: {product.Name}"); psProduct = prestaShopClient.ProductFactory.Add(psProduct); } product.WebId = (int)psProduct.id; return(psProduct); }
internal static product MapImage(product product, image image) { if (image == null) { return(product); } if (product.associations.images == null) { product.associations.images = new List <Bukimedia.PrestaSharp.Entities.AuxEntities.image>(); } product.associations.images.Add(new Bukimedia.PrestaSharp.Entities.AuxEntities.image { id = image.id }); return(product); }
internal static product FillMetaInfo(PriceItem priceItem, product product) { if (string.IsNullOrWhiteSpace(priceItem.Name)) { return(product); } product.meta_title = new List <language> { new language(1, priceItem.Name) }; product.meta_description = new List <language> { new language(1, string.Format("Купить {0} дёшево с доставкой", priceItem.Name)) }; product.meta_keywords = new List <language> { new language(1, string.Format("Купить {0} дёшево с доставкой", priceItem.Name)) }; return(product); }
private void UpdateProductAvailability(ProductEntity product, PsProduct psProduct) { var quantity = product.IsAvailable ? 1_000_000 : 0; var stock = prestaShopClient.GetStockForProduct((int)psProduct.id, 0); if (stock != null) { stock.quantity = quantity; } else { stock = new Bukimedia.PrestaSharp.Entities.stock_available(); stock.id_product = psProduct.id; stock.id_product_attribute = 0; stock.id_shop = prestaShopClient.DefaultShopId; stock.quantity = quantity; } SaveOrUpdateStockAvailable(stock); }
internal image GetImageValue(string url, product product) { if (string.IsNullOrWhiteSpace(url)) { return null; } using (var client = new WebClient()) { try { var bytes = client.DownloadData(url); return _apiFactory.ImageFactory.AddProductImage(product.id.Value, bytes); } catch (Exception) { //Log.Error("Error while loading product image", ex); return null; } } }
private async Task <combination> CreateCombination(product product, Assort assort, product_option_value sizeOptionValue, product_option_value colorOptionValue, bool isDefault) { var combination = new combination { id_product = product.id, reference = assort.Reference, ean13 = assort.Ean13, associations = new AssociationsCombination(), minimal_quantity = 1, default_on = Convert.ToInt32(isDefault), }; combination.associations.product_option_values = new List <Bukimedia.PrestaSharp.Entities.AuxEntities.product_option_value>(); if (colorOptionValue != null) { combination.associations.product_option_values.Add(new Bukimedia.PrestaSharp.Entities.AuxEntities.product_option_value { id = colorOptionValue.id.Value }); } if (sizeOptionValue != null) { combination.associations.product_option_values.Add(new Bukimedia.PrestaSharp.Entities.AuxEntities.product_option_value { id = sizeOptionValue.id.Value }); } combination = await _apiFactory.CombinationFactory.Add(combination); product = ProductsMapper.MapCombination(product, combination); Log.Information("Combitation created. Size: {0}, Color: {1}. Product reference: {2}, Combination Reference: {3}", sizeOptionValue?.name[0].Value, colorOptionValue?.name[0].Value, product.reference, combination.reference); await _apiFactory.ProductFactory.Update(product); return(combination); }
private void UpdateMetaInfo(PriceItem item, product product) { if (!SameMetaInfo(item, product)) { product = ProductsMapper.FillMetaInfo(item, product); if (product.on_sale == 1) { var specialPriceRule = GetSpecialPriceRule(product); if (specialPriceRule != null) { if (specialPriceRule.reduction_type != "percentage") { throw new NotImplementedException(); } product.price = product.price / specialPriceRule.reduction; } } Log.Debug("Updating meta info. Reference: {0}", item.Reference); _apiFactory.ProductFactory.Update(product); } }
private void UpdateProductCategories(ProductEntity product, PsProduct psProduct) { psProduct.associations.categories.Clear(); foreach (var category in product.Categories) { if (category.IsWebPublished) { try { var psCategory = prestaShopClient.CategoryFactory.Get(category.WebId.Value); if (psCategory != null) { psProduct.associations.categories.Add(new Bukimedia.PrestaSharp.Entities.AuxEntities.category(psCategory.id.Value)); } } catch (Exception ex) { logger.LogError(ex.ToString()); } } } }
internal product_supplier GetProductSupplierValue(PriceItem priceItem, product product, supplier supplierFeature) { var filter = new Dictionary<string, string> { { "id_product", product.id.Value.ToString(CultureInfo.InvariantCulture) } }; var supplier = _apiFactory.ProductSupplierFactory.GetByFilter(filter, null, null).FirstOrDefault(); if (supplier == null) { supplier = new product_supplier { id_currency = 1, id_product = product.id, id_product_attribute = 0, id_supplier = supplierFeature.id, product_supplier_reference = priceItem.SupplierReference, product_supplier_price_te = Convert.ToDecimal(priceItem.WholesalePrice) }; supplier = _apiFactory.ProductSupplierFactory.Add(supplier); } return supplier; }
private combination CheckCombination(combination combination, Assort assort, product product) { if (combination != null && combination.reference != assort.Reference) { combination.reference = assort.Reference; _apiFactory.CombinationFactory.Update(combination); } if(!product.associations.combinations.Exists(s => s.id == combination.id)) { product = ProductsMapper.MapCombination(product, combination); _apiFactory.ProductFactory.Update(product); } return combination; }
private async Task <combination> CheckCombination(combination combination, Assort assort, product product) { if (combination != null && combination.reference != assort.Reference) { combination.reference = assort.Reference; await _apiFactory.CombinationFactory.Update(combination); } if (!product.associations.combinations.Exists(s => s.id == combination.id)) { product = ProductsMapper.MapCombination(product, combination); await _apiFactory.ProductFactory.Update(product); } return(combination); }
internal static product FillMetaInfo(PriceItem priceItem, product product) { if (string.IsNullOrWhiteSpace(priceItem.Name)) return product; product.meta_title = new List<language> { new language(1, priceItem.Name) }; product.meta_description = new List<language> { new language(1, string.Format("Купить {0} в Москве", priceItem.Name)) }; product.meta_keywords = new List<language> { new language(1, string.Format("Купить {0} в Москве", priceItem.Name)) }; return product; }
public void Remove(product product) { product.active = 0; _apiFactory.ProductFactory.Update(product); }
internal static product MapManufacturer(product product, manufacturer manufacturerValue) { product.id_manufacturer = manufacturerValue.id; return product; }
private void ProcessProduct(ProductEntity product) { try { using (var uow = unitOfWorkProvider.Create()) { product = productRepository.Get(product.Id); Bukimedia.PrestaSharp.Entities.product psProduct = GetPsProduct(product.WebId); if (psProduct == null && product.WebId.HasValue) { product.WebId = null; } if (product.Synchronize == Framework.SynchronizeType.Deleted || product.NotWebAvailable) { if (psProduct != null) { psProduct.active = 0; } } else { if (psProduct == null && product.Synchronize != Framework.SynchronizeType.Deleted) { psProduct = new Bukimedia.PrestaSharp.Entities.product(); } if (psProduct != null) { psProduct.id_tax_rules_group = GetTaxRuleGroupId(product.Tax); psProduct.price = product.Price; psProduct.show_price = 1; var name = Functions.GetPrestaShopName(product.Name); prestaShopClient.SetLangValue(psProduct, x => x.name, name); prestaShopClient.SetLangValue(psProduct, x => x.link_rewrite, Functions.GetLinkRewrite(name)); prestaShopClient.SetLangValue(psProduct, x => x.description_short, Functions.GetPrestaShopDescriptionShort(product.DescriptionShort)); prestaShopClient.SetLangValue(psProduct, x => x.description, product.Description); UpdateProductCategories(product, psProduct); psProduct.active = (product.Active && !product.IsDeleted) ? 1 : 0; psProduct.state = 1; psProduct.available_for_order = 1; psProduct.position_in_category = 0; psProduct.minimal_quantity = product.MinimumOrderQuantity > 0 ? product.MinimumOrderQuantity : 1; psProduct.id_category_default = product.Categories.Where(x => x.WebId.HasValue && !x.IsDeleted && x.Synchronize != Framework.SynchronizeType.Deleted).Max(x => x.WebId); psProduct = SaveOrUpdatePsProduct(psProduct, product); if (!product.IsArchived) { UpdateProductAvailability(product, psProduct); } } } SynchronizeProductImages(product, psProduct); if (product.Synchronize == Framework.SynchronizeType.Deleted) { product.IsDeleted = true; } product.Synchronize = Framework.SynchronizeType.Synchronized; product.IsReady = false; productRepository.SaveOrUpdate(product); uow.Commit(); } } catch (Exception ex) { logger.LogError($"Synchronize product Id: {product.Id} error.{Environment.NewLine}{ex}"); } }
internal static product MapImage(product product, image image) { if (image == null) { return product; } if (product.associations.images == null) { product.associations.images = new List<Bukimedia.PrestaSharp.Entities.AuxEntities.image>(); } product.associations.images.Add(new Bukimedia.PrestaSharp.Entities.AuxEntities.image { id = image.id } ); return product; }
internal void RemoveDiscountInfo(PriceItem item, product product) { var specialPriceRule = GetSpecialPriceRule(product); if(specialPriceRule != null) { Log.Info("Removing special price. Reference: {0}", item.Reference); _apiFactory.SpecialPriceFactory.Delete(specialPriceRule); } if (product.on_sale == 1) { product.on_sale = 0; product.price = Convert.ToDecimal(item.RetailPrice); Log.Debug("Removing discount. Reference: {0}", item.Reference); _apiFactory.ProductFactory.Update(product); } }
internal static product MapSupplier(product product, supplier supplier) { product.id_supplier = supplier.id; return(product); }
private bool SameMetaInfo(PriceItem priceItem, product product) { if (string.IsNullOrWhiteSpace(priceItem.Name)) return true; if (product.meta_title == null || !product.meta_title.Any() || !product.meta_title[0].Value.Equals(priceItem.Name, StringComparison.OrdinalIgnoreCase)) return false; if (product.meta_description == null || !product.meta_description.Any() || !product.meta_description[0].Value.Equals(string.Format("Купить {0} в Москве", priceItem.Name), StringComparison.OrdinalIgnoreCase)) return false; if (product.meta_keywords == null || !product.meta_keywords.Any()) return false; if (!product.meta_keywords.Exists(s => s.Value.Equals(string.Format("Купить {0} в Москве", priceItem.Name), StringComparison.OrdinalIgnoreCase))) return false; return true; }
private specific_price GetSpecialPriceRule(product product) { var filter = new Dictionary<string, string> { { "id_product", Convert.ToString (product.id) } }; var specialPriceRule = _apiFactory.SpecialPriceFactory.GetByFilter(filter, null, null).FirstOrDefault(); return specialPriceRule; }
internal static product MapManufacturer(product product, manufacturer manufacturerValue) { product.id_manufacturer = manufacturerValue.id; return(product); }
internal combination GetOrCreateCombination(product product, Assort assort) { Dictionary<string, string> filter; List<combination> combinations = null; if (!string.IsNullOrWhiteSpace(assort.Reference)) { filter = new Dictionary<string, string> { { "reference", assort.Reference } }; combinations = _apiFactory.CombinationFactory.GetByFilter(filter, null, null); } if(combinations != null && combinations.Any()) { return combinations.First(); } product_option_value colorOptionValue = null; if (!string.IsNullOrWhiteSpace(assort.Color)) { colorOptionValue = GetOptionValue(assort.Color, assort.ColorCode, _apiFactory.ColorOption.id.Value); } product_option_value sizeOptionValue = null; if (!string.IsNullOrWhiteSpace(assort.Size)) { sizeOptionValue = GetOptionValue(assort.Size, string.Empty, _apiFactory.SizeOption.id.Value); } if (colorOptionValue == null && sizeOptionValue == null) { return null; } filter = new Dictionary<string, string> { { "id_product", product.id.Value.ToString() } }; combinations = _apiFactory.CombinationFactory.GetByFilter(filter, null, null); if (combinations == null || !combinations.Any()) { return CreateCombination(product, assort, sizeOptionValue, colorOptionValue, true); } else { foreach (var combination in combinations) { if (sizeOptionValue != null && colorOptionValue != null) { if (combination.associations.product_option_values.Exists(s => s.id == sizeOptionValue.id.Value) && combination.associations.product_option_values.Exists(s => s.id == colorOptionValue.id.Value)) { return CheckCombination(combination, assort, product); } } else if (colorOptionValue != null) { if (combination.associations.product_option_values.Exists(s => s.id == colorOptionValue.id.Value)) { return CheckCombination(combination, assort, product); } } else if (sizeOptionValue != null) { if (combination.associations.product_option_values.Exists(s => s.id == sizeOptionValue.id.Value)) { return CheckCombination(combination, assort, product); } } } return CreateCombination(product, assort, sizeOptionValue, colorOptionValue, false); } }
public void UpdateDiscountInfo(PriceItem item, product product) { specific_price specialPriceRule = null; if (product.on_sale == 1) specialPriceRule = GetSpecialPriceRule(product); if ((product.on_sale == 1 || item.OnSale) && product.on_sale != Convert.ToInt32(item.OnSale)) { if (specialPriceRule != null) { if (!item.OnSale && product.on_sale == 1) { // remove special price Log.Info("Removing discount info. Reference: {0}", item.Reference); _apiFactory.SpecialPriceFactory.Delete(specialPriceRule); } else { if (specialPriceRule.reduction != Convert.ToDecimal(item.DiscountValue) / 100) { specialPriceRule.reduction = Convert.ToDecimal(item.DiscountValue) / 100; Log.Info("Updating reduction info. Reference: {0}", item.Reference); _apiFactory.SpecialPriceFactory.Update(specialPriceRule); } } } else { specialPriceRule = new specific_price { id_product = product.id, reduction = Convert.ToDecimal(item.DiscountValue) / 100, reduction_type = "percentage", id_shop = 1, id_cart = 0, id_currency = 0, id_country = 0, id_group = 0, id_customer = 0, from_quantity = 1, price = -1, }; Log.Info("Adding discount price info. Reference: {0}", item.Reference); _apiFactory.SpecialPriceFactory.Add(specialPriceRule); } } var productRetailPrice = Convert.ToDecimal(item.RetailPrice); if (specialPriceRule != null) { productRetailPrice = Math.Ceiling(productRetailPrice * specialPriceRule.reduction); } if (product.on_sale != Convert.ToInt32(item.OnSale) || product.price != productRetailPrice || product.wholesale_price != Convert.ToDecimal(item.WholesalePrice)) { product.on_sale = Convert.ToInt32(item.OnSale); product.price = Convert.ToDecimal(item.RetailPrice); product.wholesale_price = Convert.ToDecimal(item.WholesalePrice); Log.Debug("Updating discount info. Reference: {0}", item.Reference); _apiFactory.ProductFactory.Update(product); } }
internal static product MapSupplier(product product, supplier supplier) { product.id_supplier = supplier.id; return product; }
public async Task <combination> GetOrCreateCombination(product product, Assort assort) { Dictionary <string, string> filter; List <combination> combinations = null; if (!string.IsNullOrWhiteSpace(assort.Reference)) { filter = new Dictionary <string, string> { { "reference", assort.Reference } }; combinations = await _apiFactory.CombinationFactory.GetByFilter(filter, null, null); } if (combinations != null && combinations.Any()) { return(combinations.First()); } product_option_value colorOptionValue = null; if (!string.IsNullOrWhiteSpace(assort.Color)) { colorOptionValue = await GetOptionValue(assort.Color, assort.ColorCode, _apiFactory.ColorOption.id.Value); } product_option_value sizeOptionValue = null; if (!string.IsNullOrWhiteSpace(assort.Size)) { sizeOptionValue = await GetOptionValue(assort.Size, string.Empty, _apiFactory.SizeOption.id.Value); } if (colorOptionValue == null && sizeOptionValue == null) { return(null); } filter = new Dictionary <string, string> { { "id_product", product.id.Value.ToString() } }; combinations = await _apiFactory.CombinationFactory.GetByFilter(filter, null, null); if (combinations == null || !combinations.Any()) { return(await CreateCombination(product, assort, sizeOptionValue, colorOptionValue, true)); } foreach (var combination in combinations) { if (sizeOptionValue != null && colorOptionValue != null) { if (combination.associations.product_option_values.Exists(s => s.id == sizeOptionValue.id.Value) && combination.associations.product_option_values.Exists(s => s.id == colorOptionValue.id.Value)) { return(await CheckCombination(combination, assort, product)); } } else if (colorOptionValue != null) { if (combination.associations.product_option_values.Exists(s => s.id == colorOptionValue.id.Value)) { return(await CheckCombination(combination, assort, product)); } } else { if (combination.associations.product_option_values.Exists(s => s.id == sizeOptionValue.id.Value)) { return(await CheckCombination(combination, assort, product)); } } } return(await CreateCombination(product, assort, sizeOptionValue, colorOptionValue, false)); }
private combination CreateCombination(product product, Assort assort, product_option_value sizeOptionValue, product_option_value colorOptionValue, bool isDefault) { var combination = new combination { id_product = product.id, reference = assort.Reference, ean13 = assort.Ean13, associations = new AssociationsCombination(), minimal_quantity = 1, default_on = Convert.ToInt32(isDefault), }; combination.associations.product_option_values = new List<Bukimedia.PrestaSharp.Entities.AuxEntities.product_option_value>(); if (colorOptionValue != null) { combination.associations.product_option_values.Add(new Bukimedia.PrestaSharp.Entities.AuxEntities.product_option_value { id = colorOptionValue.id.Value }); } if(sizeOptionValue != null) { combination.associations.product_option_values.Add(new Bukimedia.PrestaSharp.Entities.AuxEntities.product_option_value { id = sizeOptionValue.id.Value }); } combination = _apiFactory.CombinationFactory.Add(combination); product = ProductsMapper.MapCombination(product, combination); _apiFactory.ProductFactory.Update(product); return combination; }
internal static product MapCombination(product product, combination combination) { if(combination == null) { return product; } product.associations.combinations.Add( new combinations { id = combination.id.Value }); return product; }