Пример #1
0
    /// <summary>
    /// Save changes in product allowed options
    /// </summary>
    private void SaveChanges()
    {
        SKUInfo product = SKUInfoProvider.GetSKUInfo(ProductID);

        if (product == null)
        {
            return;
        }

        // Check if user is authorized to modify product
        if (!ECommerceContext.IsUserAuthorizedToModifySKU(product))
        {
            RedirectToAccessDenied("CMS.Ecommerce", product.IsGlobal ? "EcommerceGlobalModify" : "EcommerceModify OR ModifyProducts");

            return;
        }

        if (!ECommerceContext.IsUserAuthorizedForDepartment(product.SKUDepartmentID))
        {
            DepartmentInfo departmentObj = DepartmentInfoProvider.GetDepartmentInfo(product.SKUDepartmentID);
            if (departmentObj != null)
            {
                RedirectToAccessDenied(String.Format(GetString("cmsdesk.notauthorizedtperdepartment"), departmentObj.DepartmentDisplayName));
                return;
            }
        }

        // Allow all option is enabled
        if (rbAllowAllOption.SelectedValue == ALLOW_ALL)
        {
            ProductHelper.AllowAllOptions(ProductID, CategoryID);
        }
        else
        {
            // Join users selection with previously selected items and options used in variants + remove deselected items
            var optionsToBeAllowedArray = ugOptions.SelectedItems.Union(SelectedOptionsIds).Except(ugOptions.DeselectedItems).ToArray();
            var optionsToBeAllowed      = ValidationHelper.GetIntegers(optionsToBeAllowedArray, 0);
            var optionsToBeRemoved      = ValidationHelper.GetIntegers(ugOptions.DeselectedItems.ToArray(), 0);

            // Add selected options to product
            if (optionsToBeAllowed.Count() > 0)
            {
                ProductHelper.AllowOptions(ProductID, CategoryID, optionsToBeAllowed);
            }
            // Disable allow all options if any option was deselected
            else
            {
                optionSKUCategoryInfo.AllowAllOptions = false;
                optionSKUCategoryInfo.Update();
            }

            // Remove deselected options from product
            if (optionsToBeRemoved.Count() > 0)
            {
                ProductHelper.RemoveOptions(ProductID, CategoryID, optionsToBeRemoved);
            }
        }
    }
    /// <summary>
    /// Save changes in product allowed options
    /// </summary>
    private void SaveChanges()
    {
        SKUInfo product = SKUInfo.Provider.Get(ProductID);

        if (product == null)
        {
            return;
        }

        // Check if user is authorized to modify product
        if (!ECommerceContext.IsUserAuthorizedToModifySKU(product))
        {
            RedirectToAccessDenied(ModuleName.ECOMMERCE, product.IsGlobal ? EcommercePermissions.ECOMMERCE_MODIFYGLOBAL : "EcommerceModify OR ModifyProducts");

            return;
        }

        // Allow all option is enabled
        if (rbAllowAllOption.SelectedValue == ALLOW_ALL)
        {
            ProductHelper.AllowAllOptions(ProductID, CategoryID);
        }
        else
        {
            // Join users selection with previously selected items and options used in variants + remove deselected items
            var optionsToBeAllowedArray = ugOptions.SelectedItems.Union(SelectedOptionsIds).Except(ugOptions.DeselectedItems).ToArray();
            var optionsToBeAllowed      = ValidationHelper.GetIntegers(optionsToBeAllowedArray, 0);
            var optionsToBeRemoved      = ValidationHelper.GetIntegers(ugOptions.DeselectedItems.ToArray(), 0);

            // Add selected options to product
            if (optionsToBeAllowed.Count() > 0)
            {
                ProductHelper.AllowOptions(ProductID, CategoryID, optionsToBeAllowed);
            }
            // Disable allow all options if any option was deselected
            else
            {
                optionSKUCategoryInfo.AllowAllOptions = false;
                optionSKUCategoryInfo.Update();
            }

            // Remove deselected options from product
            if (optionsToBeRemoved.Count() > 0)
            {
                ProductHelper.RemoveOptions(ProductID, CategoryID, optionsToBeRemoved);
            }
        }
    }