public ActionResult ValueCreatePopup(string btnId, string formId, CheckoutAttributeValueModel model)
        {
            var checkoutAttribute = _checkoutAttributeService.GetCheckoutAttributeById(model.CheckoutAttributeId);

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

            PrepareModel(model, checkoutAttribute);

            if (ModelState.IsValid)
            {
                var sao = model.ToEntity();

                _checkoutAttributeService.InsertCheckoutAttributeValue(sao);
                UpdateValueLocales(sao, model);

                ViewBag.RefreshPage = true;
                ViewBag.btnId       = btnId;
                ViewBag.formId      = formId;

                return(View(model));
            }

            return(View(model));
        }
        public ActionResult ValueCreatePopup(string btnId, string formId, CheckoutAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            var checkoutAttribute = _checkoutAttributeService.GetCheckoutAttributeById(model.CheckoutAttributeId);

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

            model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode;
            model.BaseWeightIn             = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Name;

            if (ModelState.IsValid)
            {
                var sao = model.ToEntity();

                _checkoutAttributeService.InsertCheckoutAttributeValue(sao);
                UpdateValueLocales(sao, model);

                ViewBag.RefreshPage = true;
                ViewBag.btnId       = btnId;
                ViewBag.formId      = formId;
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
        public ActionResult ValueCreatePopup(string btnId, string formId, CheckoutAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            var checkoutAttribute = _checkoutAttributeService.GetCheckoutAttributeById(model.CheckoutAttributeId);

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

            model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode;
            model.BaseWeightIn             = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Name;

            if (checkoutAttribute.AttributeControlType == AttributeControlType.ColorSquares)
            {
                //ensure valid color is chosen/entered
                if (String.IsNullOrEmpty(model.ColorSquaresRgb))
                {
                    ModelState.AddModelError("", "Color is required");
                }
                try
                {
                    var color = System.Drawing.ColorTranslator.FromHtml(model.ColorSquaresRgb);
                }
                catch (Exception exc)
                {
                    ModelState.AddModelError("", exc.Message);
                }
            }

            if (ModelState.IsValid)
            {
                var cav = new CheckoutAttributeValue()
                {
                    CheckoutAttributeId = model.CheckoutAttributeId,
                    Name             = model.Name,
                    ColorSquaresRgb  = model.ColorSquaresRgb,
                    PriceAdjustment  = model.PriceAdjustment,
                    WeightAdjustment = model.WeightAdjustment,
                    IsPreSelected    = model.IsPreSelected,
                    DisplayOrder     = model.DisplayOrder
                };

                _checkoutAttributeService.InsertCheckoutAttributeValue(cav);
                UpdateValueLocales(cav, model);

                ViewBag.RefreshPage = true;
                ViewBag.btnId       = btnId;
                ViewBag.formId      = formId;
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
        public ActionResult ValueCreatePopup(string btnId, string formId, CheckoutAttributeValueModel model)
        {
            var checkoutAttribute = _checkoutAttributeService.GetCheckoutAttributeById(model.CheckoutAttributeId);

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

            model.PrimaryStoreCurrencyCode = _services.StoreContext.CurrentStore.PrimaryStoreCurrency.CurrencyCode;
            model.BaseWeightIn             = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId)?.GetLocalized(x => x.Name) ?? string.Empty;

            if (ModelState.IsValid)
            {
                var sao = model.ToEntity();

                _checkoutAttributeService.InsertCheckoutAttributeValue(sao);
                UpdateValueLocales(sao, model);

                ViewBag.RefreshPage = true;
                ViewBag.btnId       = btnId;
                ViewBag.formId      = formId;

                return(View(model));
            }

            return(View(model));
        }
        public virtual IActionResult ValueCreatePopup(CheckoutAttributeValueModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes))
            {
                return(AccessDeniedView());
            }

            //try to get a checkout attribute with the specified id
            var checkoutAttribute = _checkoutAttributeService.GetCheckoutAttributeById(model.CheckoutAttributeId);

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

            model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode;
            model.BaseWeightIn             = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Name;

            if (checkoutAttribute.AttributeControlType == AttributeControlType.ColorSquares)
            {
                //ensure valid color is chosen/entered
                if (string.IsNullOrEmpty(model.ColorSquaresRgb))
                {
                    ModelState.AddModelError(string.Empty, "Color is required");
                }

                try
                {
                    //ensure color is valid (can be instantiated)
                    System.Drawing.ColorTranslator.FromHtml(model.ColorSquaresRgb);
                }
                catch (Exception exc)
                {
                    ModelState.AddModelError(string.Empty, exc.Message);
                }
            }

            if (ModelState.IsValid)
            {
                var checkoutAttributeValue = model.ToEntity <CheckoutAttributeValue>();
                _checkoutAttributeService.InsertCheckoutAttributeValue(checkoutAttributeValue);

                UpdateValueLocales(checkoutAttributeValue, model);

                ViewBag.RefreshPage = true;

                return(View(model));
            }

            //prepare model
            model = _checkoutAttributeModelFactory.PrepareCheckoutAttributeValueModel(model, checkoutAttribute, null, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
Beispiel #6
0
        public void SetUp()
        {
            _checkoutAttributeParser    = GetService <ICheckoutAttributeParser>();
            _checkoutAttributeFormatter = GetService <ICheckoutAttributeFormatter>();
            _checkoutAttributeService   = GetService <ICheckoutAttributeService>();

            //color (dropdownlist)
            _ca1 = new CheckoutAttribute
            {
                Name                 = "Color",
                TextPrompt           = "Select color:",
                IsRequired           = true,
                AttributeControlType = AttributeControlType.DropdownList,
                DisplayOrder         = 1
            };

            _checkoutAttributeService.InsertCheckoutAttribute(_ca1);

            _cav11 = new CheckoutAttributeValue
            {
                Name                = "Green",
                DisplayOrder        = 1,
                CheckoutAttributeId = _ca1.Id
            };
            _cav12 = new CheckoutAttributeValue
            {
                Name                = "Red",
                DisplayOrder        = 2,
                CheckoutAttributeId = _ca1.Id
            };

            _checkoutAttributeService.InsertCheckoutAttributeValue(_cav11);
            _checkoutAttributeService.InsertCheckoutAttributeValue(_cav12);

            //custom option (checkboxes)
            _ca2 = new CheckoutAttribute
            {
                Name                 = "Custom option",
                TextPrompt           = "Select custom option:",
                IsRequired           = true,
                AttributeControlType = AttributeControlType.Checkboxes,
                DisplayOrder         = 2
            };

            _checkoutAttributeService.InsertCheckoutAttribute(_ca2);

            _cav21 = new CheckoutAttributeValue
            {
                Name                = "Option 1",
                DisplayOrder        = 1,
                CheckoutAttributeId = _ca2.Id
            };
            _cav22 = new CheckoutAttributeValue
            {
                Name                = "Option 2",
                DisplayOrder        = 2,
                CheckoutAttributeId = _ca2.Id
            };

            _checkoutAttributeService.InsertCheckoutAttributeValue(_cav21);
            _checkoutAttributeService.InsertCheckoutAttributeValue(_cav22);

            //custom text
            _ca3 = new CheckoutAttribute
            {
                Name                 = "Custom text",
                TextPrompt           = "Enter custom text:",
                IsRequired           = true,
                AttributeControlType = AttributeControlType.MultilineTextbox,
                DisplayOrder         = 3
            };

            _checkoutAttributeService.InsertCheckoutAttribute(_ca3);
        }