public static ProductImportRequestItem ToQixolPromosImport(this Product sourceProduct, List<ProductAttributeConfigItem> productAttributeConfigItems, List<Vendor> vendors, List<TaxCategory> taxCategories) { //IProductService _productService = DependencyResolver.Current.GetService<IProductService>(); //IPictureService _pictureService = DependencyResolver.Current.GetService<IPictureService>(); //ICategoryService categoryService = DependencyResolver.Current.GetService<ICategoryService>(); IProductService _productService = EngineContext.Current.Resolve<IProductService>(); IPictureService _pictureService = EngineContext.Current.Resolve<IPictureService>(); ICategoryService categoryService = EngineContext.Current.Resolve<ICategoryService>(); List<Product> insertedProducts = new List<Product>(); ProductImportRequestItem importProduct = new ProductImportRequestItem() { // Hotfix - 2016-10-17 - START //Barcode = string.IsNullOrEmpty(sourceProduct.Gtin) ? string.Empty : sourceProduct.Gtin, // Hotfix - 2016-10-17 - END Deleted = sourceProduct.Deleted, Description = sourceProduct.Name, Price = sourceProduct.Price, ProductCode = sourceProduct.Id.ToString() }; if (!sourceProduct.Deleted) { var productAttributes = GetAttributesForProduct(sourceProduct, productAttributeConfigItems, vendors, taxCategories, categoryService); var defaultProductPicture = _pictureService.GetPicturesByProductId(sourceProduct.Id, 1).FirstOrDefault(); importProduct.ImageUrl = _pictureService.GetPictureUrl(defaultProductPicture); if (productAttributes != null && productAttributes.Count > 0) importProduct.Attributes.AddRange(productAttributes); } return importProduct; }
/// <summary> /// Build the products to be synchronized for the Checkout attribute. Based on the configuration of the attribute, this could result in multiple products, /// one variant for each checkout attribute value. /// </summary> /// <param name="checkoutAttribute"></param> /// <param name="attribMappingItem"></param> /// <param name="isFirst"></param> /// <returns></returns> public static List<ProductImportRequestItem> ToQixolPromosImport(this CheckoutAttribute checkoutAttribute, AttributeValueMappingItem attribMappingItem) { IPictureService _pictureService = EngineContext.Current.Resolve<IPictureService>(); //IPictureService _pictureService = DependencyResolver.Current.GetService<IPictureService>(); var returnItems = new List<ProductImportRequestItem>(); var baseProduct = new ProductImportRequestItem() { Description = checkoutAttribute.Name, ProductCode = attribMappingItem.Code, ImageUrl = _pictureService.GetDefaultPictureUrl() }; baseProduct.Attributes.Add(new ProductImportRequestAttributeItem() { Name = "ischeckoutattribute", Value = "true" }); baseProduct.Attributes.Add(new ProductImportRequestAttributeItem() { Name = "checkoutattributename", Value = checkoutAttribute.Name }); switch (checkoutAttribute.AttributeControlType) { case global::Nop.Core.Domain.Catalog.AttributeControlType.ColorSquares: case global::Nop.Core.Domain.Catalog.AttributeControlType.DropdownList: case global::Nop.Core.Domain.Catalog.AttributeControlType.RadioList: // All of the control types allow the user to select a value (potentially with a price associated) - so we'll need to create a variant for each. // NOTE: Not coping with 'Checkboxes' where we would potentially have to generate all permutations of those checkboxes. Roadmap item (to be confirmed). if (checkoutAttribute.CheckoutAttributeValues != null && checkoutAttribute.CheckoutAttributeValues.Count > 0) { // The checkout attribute values do not have to be unique... List<string> usedVariantCodes = new List<string>(); checkoutAttribute.CheckoutAttributeValues.ToList() .ForEach(cav => { var productVariant = baseProduct.Clone(); productVariant.VariantCode = cav.Id.ToString(); productVariant.Description += string.Concat(" - ", cav.Name); productVariant.Price = cav.PriceAdjustment > 0 ? cav.PriceAdjustment : 0; productVariant.Attributes.Add(new ProductImportRequestAttributeItem() { Name = "checkoutattributevalue", Value = cav.Name }); returnItems.Add(productVariant); }); } else { // The control type indicates there should be values - but there aren't! so just create the base product. returnItems.Add(baseProduct); } break; default: // We're not using variants - so just return the basic product. returnItems.Add(baseProduct); break; } return returnItems; }