logo
Welcome to our new AbleCommerce forums. As a guest, you may view the information here. To post to this forum, you must have a registered account with us, either as a new user evaluating AbleCommerce or an existing user of the application. For all questions related to the older version of Gold and earlier, please go to AbleCommerce Gold forum. Please use your AbleCommerce username and password to Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
rlopez397954  
#1 Posted : Friday, February 11, 2022 2:11:49 PM(UTC)
rlopez397954

Rank: Advanced Member

Groups: Authorized User, Registered, Developers, HelpDesk
Joined: 11/30/2018(UTC)
Posts: 86

Thanks: 8 times
Was thanked: 1 time(s) in 1 post(s)
When Working with Discounts Scopes in a 9.0.5 Dev site we can add a category or product level to a setup. However, when trying to remove the category or product complete a pop up box forces something to be checked after the initial set-up. This is leaving us with no way to change back to having no category's or products selected for that Discount scope if we choose not to.


Maybe we are just missing something here.

Wanna join the discussion?! Login to your AbleCommerce Forums forum account. New Registrations are disabled.

Katie S  
#2 Posted : Friday, February 11, 2022 5:01:30 PM(UTC)
Katie S

Rank: Advanced Member

Groups: System, Administrators, Developers, Registered, HelpDesk
Joined: 10/29/2018(UTC)
Posts: 472

Thanks: 4 times
Was thanked: 34 time(s) in 33 post(s)
Thanks for letting us know. It appears to be a bug. I will need to see if the dev team can provide a way to fix the issue. It's not working for me either. I can't remove a discount assigned to the category, but it does work when removing it from the product itself.

I'll have someone get back to you on Monday.

Thanks for your support!

Katie
Secure eCommerce Software and Hosting
rlopez397954  
#3 Posted : Friday, February 11, 2022 5:27:48 PM(UTC)
rlopez397954

Rank: Advanced Member

Groups: Authorized User, Registered, Developers, HelpDesk
Joined: 11/30/2018(UTC)
Posts: 86

Thanks: 8 times
Was thanked: 1 time(s) in 1 post(s)
Katie thank you for looking at this so quickly. We will wait to hear back from the Dev Team....
shaharyar  
#4 Posted : Monday, February 14, 2022 2:23:10 AM(UTC)
shaharyar

Rank: Advanced Member

Groups: Admin, Developers, Registered, HelpDesk, Authorized User
Joined: 10/5/2018(UTC)
Posts: 704

Thanks: 5 times
Was thanked: 113 time(s) in 112 post(s)
To fix the issue, you need to made the following code changes:

1- Open file \Website\Areas\Admin\Views\Discount\EditDiscountScopeCategory.cshtml
2- Search for
Code:
function submitMe(saveUrl) {
                var checked_ids = [];
                console.log($('#treeview').jstree("get_selected", true));
                var selectedElms = $('#treeview').jstree("get_selected", true);
                $.each(selectedElms, function () {
                    checked_ids.push(this.id);
                });
                if (checked_ids.length != 0)
                {
                    $.ajax({
                        url: saveUrl + '&categoriesIds=' + checked_ids,
                        type: "POST",
                        success: function (data) {
                            if (data.status == "Redirect") {
                                window.location = data.Url;
                            }
                            else {
                                toastr.success("Categories added Successfully", "Success");
                            }
                        },
                        error: function (data) {
                            console.log("Failure " + data)
                        }
                    });
                }
                else
                {
                    swal('Please Select at least one Category.')
                }
            }

3- Replace with
Code:
function submitMe(saveUrl) {
                var checked_ids = [];
                console.log($('#treeview').jstree("get_selected", true));
                var selectedElms = $('#treeview').jstree("get_selected", true);
                $.each(selectedElms, function () {
                    checked_ids.push(this.id);
                });
                $.ajax({
                    url: saveUrl + '&categoriesIds=' + checked_ids,
                    type: "POST",
                    success: function (data) {
                        if (data.status == "Redirect") {
                            window.location = data.Url;
                        }
                        else {
                            toastr.success("Categories added Successfully", "Success");
                        }
                    },
                    error: function (data) {
                        console.log("Failure " + data)
                    }
                });
            }

4- Open file \Website\Areas\Admin\Controllers\DiscountController.cs
5- Search for
Code:
public ActionResult SaveDiscountCategories(string categoriesIds, int DiscountId, bool SaveOnly)
        {
            var categoryRepo = AbleContext.Resolve<ICategoryRepository>();
            VolumeDiscount discount = _discountRepo.Load(DiscountId);
            List<int> categoriesIntIds = new List<int>();
            foreach (var cId in categoriesIds.Split(',')) { categoriesIntIds.Add(AlwaysConvert.ToInt(cId)); }
            if (categoriesIntIds.Count > 0)
            {
                //UPDATE CATEGORIES
                discount.Categories.Clear();
                foreach(int id in categoriesIntIds)
                {
                    var category = categoryRepo.Load(id);

                    discount.Categories.Add(category);
                }
                
                discount.Categories.Save();
                _discountRepo.Save(discount);
            }

            if (SaveOnly)
            {
                return Content("Success");
            }
            else
            {
                return Json(new { status = "Redirect", Url = Url.Action("EditDiscount", new { id = DiscountId}) });
            }
        }

6- Replace with
Code:
public ActionResult SaveDiscountCategories(string categoriesIds, int DiscountId, bool SaveOnly)
        {
            var categoryRepo = AbleContext.Resolve<ICategoryRepository>();
            VolumeDiscount discount = _discountRepo.Load(DiscountId);
            List<int> categoriesIntIds = new List<int>();
            if (!string.IsNullOrEmpty(categoriesIds))
                foreach (var cId in categoriesIds.Split(',')) { categoriesIntIds.Add(AlwaysConvert.ToInt(cId)); }
            //CLEAR CATEGORY ASSIGNMENT
            discount.Categories.Clear();
            if (categoriesIntIds.Count > 0)
            {
                //UPDATE CATEGORIES
                foreach(int id in categoriesIntIds)
                {
                    var category = categoryRepo.Load(id);

                    discount.Categories.Add(category);
                }
                
                discount.Categories.Save();
                _discountRepo.Save(discount);
            }

            if (SaveOnly)
            {
                return Content("Success");
            }
            else
            {
                return Json(new { status = "Redirect", Url = Url.Action("EditDiscount", new { id = DiscountId}) });
            }
        }

7- Compile the Ablecommerce project
nadeem  
#5 Posted : Monday, February 14, 2022 7:23:51 AM(UTC)
nadeem

Rank: Advanced Member

Groups: Administrators, Developers, Registered, HelpDesk, Authorized User, Admin, System
Joined: 10/11/2018(UTC)
Posts: 110

Thanks: 19 times
Was thanked: 18 time(s) in 18 post(s)
The fix provided above by Shaharyar should work great and will be available in the upcoming release. If you can't compile the code, you can apply a workaround to this issue. That is, create a private empty category and assign the discount to this private category by removing from the original category.
rlopez397954  
#6 Posted : Monday, February 14, 2022 9:08:42 AM(UTC)
rlopez397954

Rank: Advanced Member

Groups: Authorized User, Registered, Developers, HelpDesk
Joined: 11/30/2018(UTC)
Posts: 86

Thanks: 8 times
Was thanked: 1 time(s) in 1 post(s)
Thank you all for the quick fix. We will make the change and if we have any issue's, we will let you know.
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.