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
judy at Web2Market  
#1 Posted : Friday, June 23, 2023 10:32:44 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 303

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
9.0.8
If you add a product to the order, change the price, then change the Shipment dropdown, the price reverts to the original price.
If you work on recording an offline payment enter an amount then change any of the dropdowns, the amount reverts to the original amount.
This merchant is really, really irritated.

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

Katie S  
#2 Posted : Friday, June 23, 2023 11:14:39 AM(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)
I'm able to reproduce both issues. I'll get them reported.

Until a fix can be provided, they can change the payment method first, then change the amount.

For the order item, they can select the shipment first and then change the price.

I'm mention in the bug report that you'd like the fix posted here.
Thanks for your support!

Katie
Secure eCommerce Software and Hosting
shaharyar  
#3 Posted : Monday, June 26, 2023 10:16:07 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)
Quote:
If you add a product to the order, change the price, then change the Shipment dropdown, the price reverts to the original price.


To fix the issue, please follow the steps below:

1- Open Website\Areas\Admin\Controllers\OrdersController.cs
2- Search for
Code:
model = PrepareAddProductModel(model.ProductId, model.OrderId, model.ShipmentId, model.Quantity, model.Price, true && !string.IsNullOrEmpty(addToCart));

3- Replace with
Code:
model = PrepareAddProductModel(model.ProductId, model.OrderId, model.ShipmentId, model.Quantity, model.Price, !model.IsOptionChoiceSelected);
ModelState.Remove("IsOptionChoiceSelected");
model.IsOptionChoiceSelected = false;

4- Open Website\Areas\Admin\Models\OrderModels.cs
5- Find the class AddProductItemModel and add the property below
Code:
public bool IsOptionChoiceSelected { get; set; }

6- Open Website\Areas\Admin\Views\Orders\_AddProduct.cshtml
7- Search for
Code:
@Html.HiddenFor(model => model.IsShipmentTab)

8- Replace with
Code:
@Html.HiddenFor(model => model.IsShipmentTab)
@Html.HiddenFor(model => model.IsOptionChoiceSelected)

9- Search for
Code:
@Html.DropDownList("PRODUCT_OPTION_" + option.Id,
new SelectList(option.Choices, "Id", "Name", option.SelectedChoiceId.ToString()), new { @class = "form-control", onchange = "$(this.form).submit();" })

10- Replace with
Code:
@Html.DropDownList("PRODUCT_OPTION_" + option.Id,
new SelectList(option.Choices, "Id", "Name", option.SelectedChoiceId.ToString()), new { @class = "form-control", onchange = "$('#IsOptionChoiceSelected').val(true);$(this.form).submit();" })

11- Open file Website\Scripts\option_picker.js
12- Search for
Code:
    $('#HDN_SUBMIT').click();

12- Replace with
Code:
//This is only done to be used in Admin Side View Order Add Product Dialog.
    if ($("#IsOptionChoiceSelected").length) {
        $("#IsOptionChoiceSelected").val(true);
    }

    $('#HDN_SUBMIT').click();

Edited by user Tuesday, June 27, 2023 4:32:31 AM(UTC)  | Reason: Not specified

shaharyar  
#4 Posted : Monday, June 26, 2023 10:31:57 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)
Quote:
If you work on recording an offline payment enter an amount then change any of the dropdowns, and the amount reverts to the original amount.


To fix the issue.

1- Open Website\Areas\Admin\Controllers\OrdersController.cs
2- Search for
Code:

        [HttpPost]
        [ValidateAjax]
        [ValidateAntiForgeryToken]
        public ActionResult RecordNewPayment(RecordNewPaymentModel model)
        {
            if (!ModelState.IsValid) return BadRequest();

            

3- Replace with
Code:

        [HttpPost]
        [ValidateAjax]
        [ValidateAntiForgeryToken]
        public ActionResult RecordNewPayment(RecordNewPaymentModel model)
        {
            if (!ModelState.IsValid) return BadRequest();

            // check if it is a payment method update request
            if (model.IsPaymentMethodUpdate)
            {
                return RecordNewPaymentForm(model.OrderNumber, model.PaymentMethodId);
            }

4- Search for the function
Code:
public ActionResult RecordNewPaymentForm(int orderNumber, int selectedPaymentMethodId = 0)
        {
            var order = _orderRepo.LoadForOrderNumber(orderNumber);
            var orderId = order.Id;
            List<SelectListItem> selPaymentStatus = new List<SelectListItem>();
            RecordNewPaymentModel model = new RecordNewPaymentModel
            {
                OrderId = order.Id,
                OrderNumber = order.OrderNumber,
                Amount = order.GetBalance(true),
                PaymentMethodId = selectedPaymentMethodId,
            };

            NHibernate.ICriteria criteria = NHibernateHelper.CreateCriteria<PaymentMethod>();
            criteria.Add(NHibernate.Criterion.Restrictions.Not(NHibernate.Criterion.Restrictions.Eq("PaymentInstrumentId", (short)PaymentInstrumentType.GiftCertificate)));
            criteria.Add(NHibernate.Criterion.Restrictions.Not(NHibernate.Criterion.Restrictions.Eq("PaymentInstrumentId", (short)PaymentInstrumentType.GoogleCheckout)));
            
            var methods = AbleContext.Resolve<IPaymentMethodRepository>().LoadForCriteria(criteria);
            PaymentMethod method = methods.FirstOrDefault();
            if (selectedPaymentMethodId > 0)
            {
                method = methods.FirstOrDefault(x => x.Id == selectedPaymentMethodId);
                if (method != null)
                {                    
                    if (method.IsCreditOrDebitCard())
                    {
                        foreach (PaymentStatus s in Enum.GetValues(typeof(PaymentStatus)))
                        {                            
                            selPaymentStatus.Add(new SelectListItem { Text = StringHelper.SpaceName(s.ToString()), Value = ((int)s).ToString() });
                        }
                    }
                    else
                    {                        
                        selPaymentStatus.Add(new SelectListItem { Text = StringHelper.SpaceName(PaymentStatus.Unprocessed.ToString()), Value = ((int)PaymentStatus.Unprocessed).ToString() });
                        selPaymentStatus.Add(new SelectListItem { Text = StringHelper.SpaceName(PaymentStatus.Completed.ToString()), Value = ((int)PaymentStatus.Completed).ToString() });                        
                    }
                    ViewBag.PaymentStatusList = selPaymentStatus;
                }
            }
            else
            {
                //LOAD PAYMENT STATUSES
                selPaymentStatus = new List<SelectListItem>();
                selPaymentStatus.Add(new SelectListItem { Text = "", Value = "0" });
                foreach (PaymentStatus status in Enum.GetValues(typeof(PaymentStatus)))
                {
                    selPaymentStatus.Add(new SelectListItem { Text = status.ToString(), Value = ((int)status).ToString() });
                }
                ViewBag.PaymentStatusList = selPaymentStatus;
            }
            
            if (method != null)
            {
                model.PaymentMethodId = method.Id;
            }

            var paymentmethods = methods.Select(item => new SelectListItem
            {
                Text = item.Name,
                Value = item.Id.ToString(),
                Selected = item.Id == model.PaymentMethodId,
            }).ToList();
            paymentmethods.Insert(0, new SelectListItem { Text = "", Value = "0" });
            ViewBag.PaymentMethodList = paymentmethods; 

            return PartialView("_RecordNewPaymentForm", model);
        }

5- Replace with
Code:
public ActionResult RecordNewPaymentForm(int orderNumber, int selectedPaymentMethodId = -1)
        {
            var order = _orderRepo.LoadForOrderNumber(orderNumber);
            var orderId = order.Id;
            List<SelectListItem> selPaymentStatus = new List<SelectListItem>();
            RecordNewPaymentModel model = new RecordNewPaymentModel
            {
                OrderId = order.Id,
                OrderNumber = order.OrderNumber,
                Amount = order.GetBalance(true),
                PaymentMethodId = selectedPaymentMethodId,
            };

            NHibernate.ICriteria criteria = NHibernateHelper.CreateCriteria<PaymentMethod>();
            criteria.Add(NHibernate.Criterion.Restrictions.Not(NHibernate.Criterion.Restrictions.Eq("PaymentInstrumentId", (short)PaymentInstrumentType.GiftCertificate)));
            criteria.Add(NHibernate.Criterion.Restrictions.Not(NHibernate.Criterion.Restrictions.Eq("PaymentInstrumentId", (short)PaymentInstrumentType.GoogleCheckout)));
            
            var methods = AbleContext.Resolve<IPaymentMethodRepository>().LoadForCriteria(criteria);
            PaymentMethod method = methods.FirstOrDefault();
            if (selectedPaymentMethodId > 0)
            {
                method = methods.FirstOrDefault(x => x.Id == selectedPaymentMethodId);
                if (method != null)
                {                    
                    if (method.IsCreditOrDebitCard())
                    {
                        foreach (PaymentStatus s in Enum.GetValues(typeof(PaymentStatus)))
                        {                            
                            selPaymentStatus.Add(new SelectListItem { Text = StringHelper.SpaceName(s.ToString()), Value = ((int)s).ToString() });
                        }
                    }
                    else
                    {                        
                        selPaymentStatus.Add(new SelectListItem { Text = StringHelper.SpaceName(PaymentStatus.Unprocessed.ToString()), Value = ((int)PaymentStatus.Unprocessed).ToString() });
                        selPaymentStatus.Add(new SelectListItem { Text = StringHelper.SpaceName(PaymentStatus.Completed.ToString()), Value = ((int)PaymentStatus.Completed).ToString() });                        
                    }
                    ViewBag.PaymentStatusList = selPaymentStatus;
                }
            }
            else
            {
                //LOAD PAYMENT STATUSES
                selPaymentStatus = new List<SelectListItem>();
                foreach (PaymentStatus status in Enum.GetValues(typeof(PaymentStatus)))
                {
                    selPaymentStatus.Add(new SelectListItem { Text = status.ToString(), Value = ((int)status).ToString() });
                }
                ViewBag.PaymentStatusList = selPaymentStatus;
            }
            
            if (method != null)
            {
                model.PaymentMethodId = method.Id;
            }

            var paymentmethods = methods.Select(item => new SelectListItem
            {
                Text = item.Name,
                Value = item.Id.ToString(),
                Selected = item.Id == model.PaymentMethodId,
            }).ToList();
            ViewBag.PaymentMethodList = paymentmethods; 

            if (selectedPaymentMethodId > -1)
                return Json(new { status = "OnChangeRequest", html = RenderRazorViewToString("_RecordNewPaymentForm", model) });
            else
                return PartialView("_RecordNewPaymentForm", model);
        }

6- Open Website\Areas\Admin\Models\OrderModels.cs
7- Find the class RecordNewPaymentModel and add the property below
Code:
public bool IsPaymentMethodUpdate { get; set; }

8- Open file Website\Areas\Admin\Views\Orders\_RecordNewPaymentForm.cshtml
9- Replace the complete content with the following content.
Code:
@model RecordNewPaymentModel
@using CommerceBuilder.Utility
@using CommerceBuilder.Extensions

@using (Ajax.BeginForm("RecordNewPayment", "Orders", new AjaxOptions() { HttpMethod = "POST", OnSuccess= "NewPaymentSuccess", UpdateTargetId = "record-payment-container" }))
{
    @Html.AntiForgeryToken()
    @Html.HiddenFor(model => model.OrderId)
    @Html.HiddenFor(model => model.OrderNumber)
    @Html.HiddenFor(model => Model.IsPaymentMethodUpdate)
    <div class="ibox">
        <div class="ibox-content">
            <p>Record a payment that was obtained from an alternate source.  The payment will be applied to this order.</p>
            <div class="row">
                <div class="col-lg-6">
                    <div class="form-group">
                        <label>Payment Method</label>                        
                        @Html.DropDownListFor(model => model.PaymentMethodId, (IEnumerable<SelectListItem>)ViewBag.PaymentMethodList, new { @class = "form-control", onchange = "document.getElementById(\"IsPaymentMethodUpdate\").value = \"True\";$(this.form).submit();" })
                        @Html.ValidationMessageFor(model => Model.PaymentMethodId)
                    </div>
                    <div class="form-group">
                        <label>Amount</label>
                        @Html.EditorFor(model => Model.Amount, new { @class = "form-control" })
                        @Html.ValidationMessageFor(model => Model.Amount)
                    </div>
                    <div class="form-group">
                        <label>Payment Note</label>
                        @Html.TextBoxFor(model => Model.PaymentStatusReason, new { @class = "form-control", placeholder = "Private note about this payment" })
                    </div>
                </div>
                <div class="col-lg-6">
                    <div class="form-group">
                        <label>Reference</label>
                        @Html.TextBoxFor(model => Model.ReferenceNumber, new { @class = "form-control", maxlength=50 })
                        @Html.ValidationMessageFor(model => Model.ReferenceNumber)
                    </div>
                    <div class="form-group">
                        <label>Status</label>
                        @Html.DropDownListFor(model => model.PaymentStatusId, (IEnumerable<SelectListItem>)ViewBag.PaymentStatusList, new { @class = "form-control" })                                
                    </div>
                </div>
            </div>
            <div class="row center">
                @Ajax.ActionLink("Cancel", "OrderPayments",
                        new { OrderNumber = Model.OrderNumber },
                        new AjaxOptions
                        {
                            UpdateTargetId = "view-order-tab-container",
                            OnSuccess = "SetActiveTab('Payments')",
                        }, new { @class = "btn btn-white" })
                <button type="submit" id="save" class="btn btn-primary" onclick="document.getElementById('IsPaymentMethodUpdate').value = 'False';">Record Payment</button>
            </div>
        </div>
    </div>
}

<script type="text/javascript">
    function NewPaymentSuccess(response)
    {
        if (response.status && response.status == "OnChangeRequest") {
            $("#record-payment-container").html(response.html);
        }
        else{
            toastr.success('New payment saved scuccessfully.', 'Payment Added');
            $('#view-order-tab-container').html(response);
        }
    }
</script>

Edited by user Thursday, July 6, 2023 5:21:34 AM(UTC)  | Reason: Not specified

Jay  
#5 Posted : Tuesday, June 27, 2023 1:07:12 PM(UTC)
Jay

Rank: Member

Groups: Authorized User, Developers
Joined: 11/12/2018(UTC)
Posts: 25

Thanks: 1 times
Was thanked: 4 time(s) in 3 post(s)
After applying the fix for the offline payment, selecting a different payment method from the drop-down records the payment. Not sure if it did that before the fix or not, I didn't test.
shaharyar  
#6 Posted : Monday, July 3, 2023 5:34:17 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)
The issue you are referring to could occur if the view side is updated without updating the controller side code.
Please make sure that you have updated the controller side code and placed the updated compiled DLL in the working site.

Jay  
#7 Posted : Wednesday, July 5, 2023 11:28:49 AM(UTC)
Jay

Rank: Member

Groups: Authorized User, Developers
Joined: 11/12/2018(UTC)
Posts: 25

Thanks: 1 times
Was thanked: 4 time(s) in 3 post(s)
I have verified that the RecordNewPaymentForm method in OrdersController is changed and the new DLL is in the bin folder. I can debug it, set breakpoints, etc. I click an order number from the list, Click on the Payments tab, remove any existing payments. Then click the Add New... button, choose Payment, click the Record Offline Payment tab, click the Payment Method drop-down, and choose MasterCard or Purchase Order (instead of Visa; I have Visa, MasterCard, and Purchase Order configured). The payment is posted. Note that the RecordNewPaymentForm method that you changed in the controller only runs when the Payment form is loaded; it doesn't run when something in the form is clicked. It looks like when the script at the end of the new _RecordNewPaymentForm.cshtml file runs,
Code:
if (response.status && response.status == "OnChangeRequest")

evaluates to false and/or it is running after the
Code:
[HttpPost]
[ValidateAjax]
[ValidateAntiForgeryToken]
public ActionResult RecordNewPayment(RecordNewPaymentModel model)

method in the OrdersController has already run.
shaharyar  
#8 Posted : Wednesday, July 5, 2023 12:30:51 PM(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)
Hi Jay,

I think I have missed another controller change. Sorry about that.

I ll try to update the fix as soon as possible.
shaharyar  
#9 Posted : Thursday, July 6, 2023 5:22:37 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)
Hi Jay,

I have updated the fix above. Please again follow the steps and see if it fixes the issue.

Thanks for your patience.
Jay  
#10 Posted : Thursday, July 6, 2023 8:46:57 AM(UTC)
Jay

Rank: Member

Groups: Authorized User, Developers
Joined: 11/12/2018(UTC)
Posts: 25

Thanks: 1 times
Was thanked: 4 time(s) in 3 post(s)
Thank you shaharyar, it works correctly now.
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.