//edit
        public ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            var checkoutAttribute = _checkoutAttributeService.GetCheckoutAttributeById(id);

            if (checkoutAttribute == null)
            {
                throw new ArgumentException("No checkout attribute found with the specified id", "id");
            }
            var model = checkoutAttribute.ToModel();

            //locales
            AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.Name       = checkoutAttribute.GetLocalized(x => x.Name, languageId, false, false);
                locale.TextPrompt = checkoutAttribute.GetLocalized(x => x.TextPrompt, languageId, false, false);
            });
            PrepareCheckoutAttributeModel(model, checkoutAttribute, false);

            return(View(model));
        }
        //edit
        public ActionResult Edit(int id)
        {
            if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            var checkoutAttribute = _checkoutAttributeService.GetCheckoutAttributeById(id);

            if (checkoutAttribute == null)
            {
                return(RedirectToAction("List"));
            }

            var model = checkoutAttribute.ToModel();

            //locales
            AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.Name       = checkoutAttribute.GetLocalized(x => x.Name, languageId, false, false);
                locale.TextPrompt = checkoutAttribute.GetLocalized(x => x.TextPrompt, languageId, false, false);
            });
            PrepareCheckoutAttributeModel(model, checkoutAttribute, false);

            return(View(model));
        }
Beispiel #3
0
        //edit
        public ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes))
            {
                return(AccessDeniedView());
            }

            var checkoutAttribute = _checkoutAttributeService.GetCheckoutAttributeById(id);

            if (checkoutAttribute == null)
            {
                //No checkout attribute found with the specified id
                return(RedirectToAction("List"));
            }

            var model = checkoutAttribute.ToModel();

            //locales
            AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.Name       = checkoutAttribute.GetLocalized(x => x.Name, languageId, false, false);
                locale.TextPrompt = checkoutAttribute.GetLocalized(x => x.TextPrompt, languageId, false, false);
            });
            //tax categories
            PrepareTaxCategories(model, checkoutAttribute, false);
            //Stores
            PrepareStoresMappingModel(model, checkoutAttribute, false);

            return(View(model));
        }
        protected virtual void SaveConditionAttributes(CheckoutAttribute checkoutAttribute, CheckoutAttributeModel model)
        {
            string attributesXml = null;

            if (model.ConditionModel.EnableCondition)
            {
                var attribute = _checkoutAttributeService.GetCheckoutAttributeById(model.ConditionModel.SelectedAttributeId);
                if (attribute != null)
                {
                    switch (attribute.AttributeControlType)
                    {
                        case AttributeControlType.DropdownList:
                        case AttributeControlType.RadioList:
                        case AttributeControlType.ColorSquares:
                        case AttributeControlType.ImageSquares:
                            {
                                var selectedAttribute = model.ConditionModel.ConditionAttributes
                                    .FirstOrDefault(x => x.Id == model.ConditionModel.SelectedAttributeId);
                                var selectedValue = selectedAttribute?.SelectedValueId;

                                //for conditions we should empty values save even when nothing is selected
                                //otherwise "attributesXml" will be empty
                                //hence we won't be able to find a selected attribute
                                attributesXml = _checkoutAttributeParser.AddCheckoutAttribute(null, attribute, string.IsNullOrEmpty(selectedValue) ? string.Empty : selectedValue);
                            }
                            break;
                        case AttributeControlType.Checkboxes:
                            {
                                var selectedAttribute = model.ConditionModel.ConditionAttributes
                                    .FirstOrDefault(x => x.Id == model.ConditionModel.SelectedAttributeId);
                                var selectedValues = selectedAttribute?.Values
                                    .Where(x => x.Selected)
                                    .Select(x => x.Value)
                                    .ToList();

                                if (selectedValues?.Any() ?? false)
                                    foreach (var value in selectedValues)
                                        attributesXml = _checkoutAttributeParser.AddCheckoutAttribute(attributesXml, attribute, value);
                                else
                                    attributesXml = _checkoutAttributeParser.AddCheckoutAttribute(null, attribute, string.Empty);
                            }
                            break;
                        case AttributeControlType.ReadonlyCheckboxes:
                        case AttributeControlType.TextBox:
                        case AttributeControlType.MultilineTextbox:
                        case AttributeControlType.Datepicker:
                        case AttributeControlType.FileUpload:
                        default:
                            //these attribute types are not supported as conditions
                            break;
                    }
                }
            }

            checkoutAttribute.ConditionAttributeXml = attributesXml;
        }
Beispiel #5
0
        public async Task <IActionResult> Edit(string id)
        {
            var checkoutAttribute = await _checkoutAttributeService.GetCheckoutAttributeById(id);

            if (checkoutAttribute == null)
            {
                //No checkout attribute found with the specified id
                return(RedirectToAction("List"));
            }

            var model = checkoutAttribute.ToModel();

            //locales
            await AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.Name       = checkoutAttribute.GetTranslation(x => x.Name, languageId, false);
                locale.TextPrompt = checkoutAttribute.GetTranslation(x => x.TextPrompt, languageId, false);
            });

            //tax categories
            await _checkoutAttributeViewModelService.PrepareTaxCategories(model, checkoutAttribute, false);

            //condition
            await _checkoutAttributeViewModelService.PrepareConditionAttributes(model, checkoutAttribute);

            return(View(model));
        }
        //edit
        public IActionResult Edit(string id)
        {
            var checkoutAttribute = _checkoutAttributeService.GetCheckoutAttributeById(id);

            if (checkoutAttribute == null)
            {
                //No checkout attribute found with the specified id
                return(RedirectToAction("List"));
            }

            var model = checkoutAttribute.ToModel();

            //locales
            AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.Name       = checkoutAttribute.GetLocalized(x => x.Name, languageId, false, false);
                locale.TextPrompt = checkoutAttribute.GetLocalized(x => x.TextPrompt, languageId, false, false);
            });

            //tax categories
            _checkoutAttributeViewModelService.PrepareTaxCategories(model, checkoutAttribute, false);
            //Stores
            model.PrepareStoresMappingModel(checkoutAttribute, false, _storeService);

            //condition
            _checkoutAttributeViewModelService.PrepareConditionAttributes(model, checkoutAttribute);
            //ACL
            model.PrepareACLModel(checkoutAttribute, false, _customerService);
            //Stores
            model.PrepareStoresMappingModel(checkoutAttribute, false, _storeService);

            return(View(model));
        }
        public ActionResult Edit(int id)
        {
            var checkoutAttribute = _checkoutAttributeService.GetCheckoutAttributeById(id);

            if (checkoutAttribute == null)
            {
                return(RedirectToAction("List"));
            }

            var model = checkoutAttribute.ToModel();

            //locales
            AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.Name       = checkoutAttribute.GetLocalized(x => x.Name, languageId, false, false);
                locale.TextPrompt = checkoutAttribute.GetLocalized(x => x.TextPrompt, languageId, false, false);
            });
            PrepareCheckoutAttributeModel(model, checkoutAttribute, false);

            return(View(model));
        }
Beispiel #8
0
        /// <summary>
        /// Gets selected checkout attributes
        /// </summary>
        /// <param name="attributes">Attributes</param>
        /// <returns>Selected checkout attributes</returns>
        public virtual IList <CheckoutAttribute> ParseCheckoutAttributes(string attributes)
        {
            var caCollection = new List <CheckoutAttribute>();
            var ids          = ParseCheckoutAttributeIds(attributes);

            foreach (int id in ids)
            {
                var ca = _checkoutAttributeService.GetCheckoutAttributeById(id);
                if (ca != null)
                {
                    caCollection.Add(ca);
                }
            }
            return(caCollection);
        }
        /// <summary>
        /// Gets selected checkout attributes
        /// </summary>
        /// <param name="attributesXml">Attributes in XML format</param>
        /// <returns>Selected checkout attributes</returns>
        public virtual IList <CheckoutAttribute> ParseCheckoutAttributes(string attributesXml)
        {
            var result = new List <CheckoutAttribute>();
            var ids    = ParseCheckoutAttributeIds(attributesXml);

            foreach (int id in ids)
            {
                var attribute = _checkoutAttributeService.GetCheckoutAttributeById(id);
                if (attribute != null)
                {
                    result.Add(attribute);
                }
            }
            return(result);
        }
        /// <summary>
        /// Gets selected checkout attributes
        /// </summary>
        /// <param name="attributes">Attributes</param>
        /// <returns>Selected checkout attributes</returns>
        public virtual async Task <IList <CheckoutAttribute> > ParseCheckoutAttributes(IList <CustomAttribute> customAttributes)
        {
            var result = new List <CheckoutAttribute>();

            if (customAttributes == null || !customAttributes.Any())
            {
                return(result);
            }

            foreach (var customAttribute in customAttributes.GroupBy(x => x.Key))
            {
                var attribute = await _checkoutAttributeService.GetCheckoutAttributeById(customAttribute.Key);

                if (attribute != null)
                {
                    result.Add(attribute);
                }
            }
            return(result);
        }
        /// <summary>
        /// Save entity use code
        /// </summary>
        /// <param name="model">Base Nop entity model</param>
        private void SaveEntityUseCode(BaseNopEntityModel model)
        {
            //ensure that received model is BaseNopEntityModel
            if (model == null)
            {
                return;
            }

            //get entity by received model
            var entity = model is CustomerModel ? (BaseEntity)_customerService.GetCustomerById(model.Id)
                : model is CustomerRoleModel ? (BaseEntity)_customerService.GetCustomerRoleById(model.Id)
                : model is ProductModel ? (BaseEntity)_productService.GetProductById(model.Id)
                : model is CheckoutAttributeModel ? (BaseEntity)_checkoutAttributeService.GetCheckoutAttributeById(model.Id)
                : null;

            if (entity == null)
            {
                return;
            }

            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTaxSettings))
            {
                return;
            }

            //ensure that Avalara tax provider is active
            if (!(_taxService.LoadActiveTaxProvider(_workContext.CurrentCustomer) is AvalaraTaxProvider))
            {
                return;
            }

            //whether there is a form value for the entity use code
            if (_httpContextAccessor.HttpContext.Request.Form.TryGetValue(AvalaraTaxDefaults.EntityUseCodeAttribute, out StringValues entityUseCodeValue) &&
                !StringValues.IsNullOrEmpty(entityUseCodeValue))
            {
                //save attribute
                var entityUseCode = !entityUseCodeValue.ToString().Equals(Guid.Empty.ToString()) ? entityUseCodeValue.ToString() : null;
                _genericAttributeService.SaveAttribute(entity, AvalaraTaxDefaults.EntityUseCodeAttribute, entityUseCode);
            }
        }
        /// <summary>
        /// Gets selected checkout attributes
        /// </summary>
        /// <param name="attributesXml">Attributes in XML format</param>
        /// <returns>Selected checkout attributes</returns>
        public virtual async Task <IList <CheckoutAttribute> > ParseCheckoutAttributes(string attributesXml)
        {
            var result = new List <CheckoutAttribute>();

            if (String.IsNullOrEmpty(attributesXml))
            {
                return(result);
            }

            var ids = ParseCheckoutAttributeIds(attributesXml);

            foreach (string id in ids)
            {
                var attribute = await _checkoutAttributeService.GetCheckoutAttributeById(id);

                if (attribute != null)
                {
                    result.Add(attribute);
                }
            }
            return(result);
        }
        /// <summary>
        /// Handle model received event
        /// </summary>
        /// <param name="eventMessage">Event message</param>
        public void HandleEvent(ModelReceivedEvent <BaseNopModel> eventMessage)
        {
            //get entity by received model
            var entity = eventMessage.Model switch
            {
                CustomerModel customerModel => (BaseEntity)_customerService.GetCustomerById(customerModel.Id),
                CustomerRoleModel customerRoleModel => _customerService.GetCustomerRoleById(customerRoleModel.Id),
                ProductModel productModel => _productService.GetProductById(productModel.Id),
                CheckoutAttributeModel checkoutAttributeModel => _checkoutAttributeService.GetCheckoutAttributeById(checkoutAttributeModel.Id),
                _ => null
            };

            if (entity == null)
            {
                return;
            }

            //ensure that Avalara tax provider is active
            if (!_taxPluginManager.IsPluginActive(AvalaraTaxDefaults.SystemName))
            {
                return;
            }

            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTaxSettings))
            {
                return;
            }

            //whether there is a form value for the entity use code
            if (_httpContextAccessor.HttpContext.Request.Form.TryGetValue(AvalaraTaxDefaults.EntityUseCodeAttribute, out var entityUseCodeValue) &&
                !StringValues.IsNullOrEmpty(entityUseCodeValue))
            {
                //save attribute
                var entityUseCode = !entityUseCodeValue.ToString().Equals(Guid.Empty.ToString()) ? entityUseCodeValue.ToString() : null;
                _genericAttributeService.SaveAttribute(entity, AvalaraTaxDefaults.EntityUseCodeAttribute, entityUseCode);
            }
        }
Beispiel #14
0
        /// <summary>
        /// Invoke the widget view component
        /// </summary>
        /// <param name="widgetZone">Widget zone</param>
        /// <param name="additionalData">Additional parameters</param>
        /// <returns>View component result</returns>
        public IViewComponentResult Invoke(string widgetZone, object additionalData)
        {
            //ensure that model is passed
            if (!(additionalData is BaseNopEntityModel entityModel))
            {
                return(Content(string.Empty));
            }

            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTaxSettings))
            {
                return(Content(string.Empty));
            }

            //ensure that Avalara tax provider is active
            if (!(_taxService.LoadActiveTaxProvider(_workContext.CurrentCustomer) is AvalaraTaxProvider))
            {
                return(Content(string.Empty));
            }

            //ensure that it's a proper widget zone
            if (!widgetZone.Equals(AdminWidgetZones.CustomerDetailsInfoTop) &&
                !widgetZone.Equals(AdminWidgetZones.CustomerRoleDetailsTop) &&
                !widgetZone.Equals(AdminWidgetZones.ProductDetailsInfoColumnLeftTop) &&
                !widgetZone.Equals(AdminWidgetZones.CheckoutAttributeDetailsInfoTop))
            {
                return(Content(string.Empty));
            }

            //get Avalara pre-defined entity use codes
            var cachedEntityUseCodes = _cacheManager.Get(AvalaraTaxDefaults.EntityUseCodesCacheKey, () => _avalaraTaxManager.GetEntityUseCodes());
            var entityUseCodes       = cachedEntityUseCodes?.Select(useCode => new SelectListItem
            {
                Value = useCode.code,
                Text  = $"{useCode.name} ({useCode.validCountries.Aggregate(string.Empty, (list, country) => $"{list}{country},").TrimEnd(',')})"
            }).ToList() ?? new List <SelectListItem>();

            //add the special item for 'undefined' with empty guid value
            var defaultValue = Guid.Empty.ToString();

            entityUseCodes.Insert(0, new SelectListItem
            {
                Value = defaultValue,
                Text  = _localizationService.GetResource("Plugins.Tax.Avalara.Fields.EntityUseCode.None")
            });

            //prepare model
            var model = new EntityUseCodeModel
            {
                Id             = entityModel.Id,
                EntityUseCodes = entityUseCodes
            };

            //get entity by the model identifier
            BaseEntity entity = null;

            if (widgetZone.Equals(AdminWidgetZones.CustomerDetailsInfoTop))
            {
                model.PrecedingElementId = nameof(CustomerModel.IsTaxExempt);
                entity = _customerService.GetCustomerById(entityModel.Id);
            }

            if (widgetZone.Equals(AdminWidgetZones.CustomerRoleDetailsTop))
            {
                model.PrecedingElementId = nameof(CustomerRoleModel.TaxExempt);
                entity = _customerService.GetCustomerRoleById(entityModel.Id);
            }

            if (widgetZone.Equals(AdminWidgetZones.ProductDetailsInfoColumnLeftTop))
            {
                model.PrecedingElementId = nameof(ProductModel.IsTaxExempt);
                entity = _productService.GetProductById(entityModel.Id);
            }

            if (widgetZone.Equals(AdminWidgetZones.CheckoutAttributeDetailsInfoTop))
            {
                model.PrecedingElementId = nameof(CheckoutAttributeModel.IsTaxExempt);
                entity = _checkoutAttributeService.GetCheckoutAttributeById(entityModel.Id);
            }

            //try to get previously saved entity use code
            model.AvalaraEntityUseCode = entity == null ? defaultValue :
                                         _genericAttributeService.GetAttribute <string>(entity, AvalaraTaxDefaults.EntityUseCodeAttribute);

            return(View("~/Plugins/Tax.Avalara/Views/EntityUseCode/EntityUseCode.cshtml", model));
        }
Beispiel #15
0
        public virtual async Task <IActionResult> UploadFileCheckoutAttribute(string attributeId)
        {
            var attribute = await _checkoutAttributeService.GetCheckoutAttributeById(attributeId);

            if (attribute == null || attribute.AttributeControlType != AttributeControlType.FileUpload)
            {
                return(Json(new
                {
                    success = false,
                    downloadGuid = Guid.Empty,
                }));
            }

            var httpPostedFile = Request.Form.Files.FirstOrDefault();

            if (httpPostedFile == null)
            {
                return(Json(new
                {
                    success = false,
                    message = "No file uploaded",
                    downloadGuid = Guid.Empty,
                }));
            }

            var fileBinary = httpPostedFile.GetDownloadBits();

            var qqFileNameParameter = "qqfilename";
            var fileName            = httpPostedFile.FileName;

            if (String.IsNullOrEmpty(fileName) && Request.Form.ContainsKey(qqFileNameParameter))
            {
                fileName = Request.Form[qqFileNameParameter].ToString();
            }
            //remove path (passed in IE)
            fileName = Path.GetFileName(fileName);

            var contentType = httpPostedFile.ContentType;

            var fileExtension = Path.GetExtension(fileName);

            if (!String.IsNullOrEmpty(fileExtension))
            {
                fileExtension = fileExtension.ToLowerInvariant();
            }

            if (attribute.ValidationFileMaximumSize.HasValue)
            {
                //compare in bytes
                var maxFileSizeBytes = attribute.ValidationFileMaximumSize.Value * 1024;
                if (fileBinary.Length > maxFileSizeBytes)
                {
                    //when returning JSON the mime-type must be set to text/plain
                    //otherwise some browsers will pop-up a "Save As" dialog.
                    return(Json(new
                    {
                        success = false,
                        message = string.Format(_localizationService.GetResource("ShoppingCart.MaximumUploadedFileSize"), attribute.ValidationFileMaximumSize.Value),
                        downloadGuid = Guid.Empty,
                    }));
                }
            }

            var download = new Download
            {
                DownloadGuid   = Guid.NewGuid(),
                UseDownloadUrl = false,
                DownloadUrl    = "",
                DownloadBinary = fileBinary,
                ContentType    = contentType,
                //we store filename without extension for downloads
                Filename  = Path.GetFileNameWithoutExtension(fileName),
                Extension = fileExtension,
                IsNew     = true
            };
            await _downloadService.InsertDownload(download);

            //when returning JSON the mime-type must be set to text/plain
            //otherwise some browsers will pop-up a "Save As" dialog.
            return(Json(new
            {
                success = true,
                message = _localizationService.GetResource("ShoppingCart.FileUploaded"),
                downloadUrl = Url.Action("GetFileUpload", "Download", new { downloadId = download.DownloadGuid }),
                downloadGuid = download.DownloadGuid,
            }));
        }
        protected virtual void SaveConditionAttributes(CheckoutAttribute checkoutAttribute, CheckoutAttributeModel model)
        {
            string attributesXml = null;

            if (model.ConditionModel.EnableCondition)
            {
                var attribute = _checkoutAttributeService.GetCheckoutAttributeById(model.ConditionModel.SelectedAttributeId);
                if (attribute != null)
                {
                    switch (attribute.AttributeControlType)
                    {
                    case AttributeControlType.DropdownList:
                    case AttributeControlType.RadioList:
                    case AttributeControlType.ColorSquares:
                    case AttributeControlType.ImageSquares:
                    {
                        var selectedAttribute = model.ConditionModel.ConditionAttributes
                                                .FirstOrDefault(x => x.Id == model.ConditionModel.SelectedAttributeId);
                        var selectedValue = selectedAttribute != null ? selectedAttribute.SelectedValueId : null;
                        if (!String.IsNullOrEmpty(selectedValue))
                        {
                            attributesXml = _checkoutAttributeParser.AddCheckoutAttribute(attributesXml, attribute, selectedValue);
                        }
                        else
                        {
                            attributesXml = _checkoutAttributeParser.AddCheckoutAttribute(attributesXml, attribute, string.Empty);
                        }
                    }
                    break;

                    case AttributeControlType.Checkboxes:
                    {
                        var selectedAttribute = model.ConditionModel.ConditionAttributes
                                                .FirstOrDefault(x => x.Id == model.ConditionModel.SelectedAttributeId);
                        var selectedValues = selectedAttribute != null?selectedAttribute.Values.Where(x => x.Selected).Select(x => x.Value) : null;

                        if (selectedValues.Any())
                        {
                            foreach (var value in selectedValues)
                            {
                                attributesXml = _checkoutAttributeParser.AddCheckoutAttribute(attributesXml, attribute, value);
                            }
                        }
                        else
                        {
                            attributesXml = _checkoutAttributeParser.AddCheckoutAttribute(attributesXml, attribute, string.Empty);
                        }
                    }
                    break;

                    case AttributeControlType.ReadonlyCheckboxes:
                    case AttributeControlType.TextBox:
                    case AttributeControlType.MultilineTextbox:
                    case AttributeControlType.Datepicker:
                    case AttributeControlType.FileUpload:
                    default:
                        //these attribute types are not supported as conditions
                        break;
                    }
                }
            }
            checkoutAttribute.ConditionAttributeXml = attributesXml;
        }
        private void SyncCartWithKlarnaOrder(Customer customer, KlarnaCheckoutOrder klarnaCheckoutOrder)
        {
            var currentStoreId = _storeContext.CurrentStore.Id;

            var orderCurrency = _currencyService.GetCurrencyByCode(klarnaCheckoutOrder.PurchaseCurrency);

            if (orderCurrency != null)
            {
                _workContext.WorkingCurrency = orderCurrency;
            }

            ClearItemsInCart(customer, currentStoreId);
            ClearDiscountsAndShippingSelection(customer, currentStoreId);

            var physicalItems       = klarnaCheckoutOrder.Cart.Items.Where(x => x.Type == CartItem.TypePhysical);
            var appliedCoupons      = klarnaCheckoutOrder.Cart.Items.Where(x => x.Type == CartItem.TypeDiscount && x.HasOrderLevelDiscountCouponCode());
            var appliedGiftCards    = klarnaCheckoutOrder.Cart.Items.Where(x => x.Type == CartItem.TypeDiscount && x.IsDiscountGiftCardCartItem());
            var appliedRewardPoints = klarnaCheckoutOrder.Cart.Items.Where(x => x.Type == CartItem.TypeDiscount && x.IsRewardPointsCartItem());
            var checkoutAttributes  = klarnaCheckoutOrder.Cart.Items.Where(x => x.Type == CartItem.TypeDiscount && x.IsCheckoutAttribtue());
            var shippingItems       = klarnaCheckoutOrder.Cart.Items.Where(x => x.Type == CartItem.TypeShippingFee);

            foreach (var physicalItem in physicalItems)
            {
                AddPhysicalItemToCart(customer, physicalItem, currentStoreId);
                var couponCodes = physicalItem.GetCouponCodesFromPhysicalCartItem();
                foreach (var couponCode in couponCodes)
                {
                    UseCouponCode(customer, couponCode);
                }
            }

            foreach (var coupon in appliedCoupons)
            {
                var couponCode = coupon.GetCouponCodeFromDiscountCouponCartItem();
                UseCouponCode(customer, couponCode);
            }

            foreach (var giftCardCartItem in appliedGiftCards)
            {
                var giftCardId = giftCardCartItem.GetGiftCardIdFromDiscountGiftCardCartItem();
                var giftCard   = _giftCardService.GetGiftCardById(giftCardId);
                customer.ApplyGiftCardCouponCode(giftCard.GiftCardCouponCode);
            }

            if (appliedRewardPoints.Any())
            {
                _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.UseRewardPointsDuringCheckout, true, currentStoreId);
            }

            var checkoutAttributesXml = GetSelectedCheckoutAttributesThatHasNotBeenSentToKlarna(customer, currentStoreId);

            foreach (var item in checkoutAttributes)
            {
                var ca = _checkoutAttributeService.GetCheckoutAttributeById(item.GetCheckoutAttributeId());
                checkoutAttributesXml = _checkoutAttributeParser.AddCheckoutAttribute(checkoutAttributesXml, ca, item.GetCheckoutAttributeValue());
            }
            _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.CheckoutAttributes, checkoutAttributesXml, currentStoreId);

            foreach (var shippingItem in shippingItems)
            {
                AddShippingItemToCart(customer, shippingItem, currentStoreId);
                var couponCodes = shippingItem.GetCouponCodesFromShippingItem();
                foreach (var couponCode in couponCodes)
                {
                    UseCouponCode(customer, couponCode);
                }
            }
        }