/// <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;
        }
        public ActionResult IntegrationCodeUpdate(IntegrationCodeItemModel model)
        {
            if (!string.IsNullOrEmpty(model.IntegrationCode))
            {
                // Check for existing uses of this code!  - but only if we're NOT clearing it out.
                IQueryable<AttributeValueMappingItem> allAttributeValues = _attributeValueService.RetrieveAllForAttribute(model.EntityAttributeSystemName);
                if (allAttributeValues != null && allAttributeValues.Count() > 0
                    && allAttributeValues.Any(av => string.Compare(av.Code, model.IntegrationCode, true) == 0 && av.AttributeValueId != model.EntityId))
                {
                    ModelState.AddModelError(string.Empty, _localizationService.GetResource("Plugins.Misc.QixolPromo.IntegrationCode.ValidationMsg"));
                    return Json(new DataSourceResult { Errors = ModelState.SerializeErrors() });
                }
            }

            if (model.AttributeId == 0)
            {
                // It's a new code.
                var newAttribItem = new AttributeValueMappingItem()
                {
                    AttributeName = model.EntityAttributeSystemName,
                    AttributeValueId = model.EntityId,
                    Code = model.IntegrationCode
                };
                if (model.Priority.HasValue)
                    newAttribItem.Priority = model.Priority.Value;

                _attributeValueService.Insert(newAttribItem);
            }
            else
            {
                var existingAttribItem = _attributeValueService.Retrieve(model.EntityId, model.EntityAttributeSystemName);
                if (existingAttribItem != null)
                {
                    existingAttribItem.Code = model.IntegrationCode;
                    if (model.Priority.HasValue)
                        existingAttribItem.Priority = model.Priority.Value;
                    _attributeValueService.Update(existingAttribItem);
                }
            }

            return new NullJsonResult();
        }
 public void Delete(AttributeValueMappingItem itemToDelete)
 {
     this._repository.Delete(itemToDelete);
     this._eventPublisher.EntityDeleted<AttributeValueMappingItem>(itemToDelete);
 }
 public void Update(AttributeValueMappingItem itemToUpdate, bool publishEvents = true)
 {
     this._repository.Update(itemToUpdate);
     if (publishEvents)
         this._eventPublisher.EntityUpdated<AttributeValueMappingItem>(itemToUpdate);
 }
 public void Insert(AttributeValueMappingItem itemToInsert)
 {
     itemToInsert.CreatedOnUtc = DateTime.UtcNow;
     this._repository.Insert(itemToInsert);
     this._eventPublisher.EntityInserted<AttributeValueMappingItem>(itemToInsert);
 }