Need help saving new field on Order table by custom Plugin

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
1 ano atrás
Hi, I'm trying to develop a custom Plugin for banking transfer, I started copying  Nop.Plugin.Payments.Manual. When I select payment method In my PaymentInfo.cshtml I have a dropdownlist with a selection of various types of banking transfer (60 days, 90 days,etc), I need to save the selected value in a new field of Order table and I need also to show and calculate additional feeds based on the type of selected bank transfer type.
Fo the first point I added the new field in SQL "Order" table, I added it to Nop.Core\Orders\Order.cs, in Nop.Data\Mapping\Orders\OrderBuilder.cs but in my plugin I don't know ho to map the model of my dropdownlist for the selected value to new field to save iton database, can you help me ?

Can you help me to understand how to apply additional feeds before saving the order in the table?

thank you
1 ano atrás
The first problem you have is that the Order is not created at the time PaymentInfo is displayed
So you would need to store the values somewhere temporarily just as Nop.Plugin.Payments.Manual does to store the Credit Card details

Examine how Nop.Plugin.Payments.Manual stores the Credit Card details
You can use the same flow and methods to do similar for the information you create
Then you can store the data in the Order once it is created.

i.e. using ProcessPaymentResult
See SaveOrderDetailsAsync in src\Libraries\Nop.Services\Orders\OrderProcessingService.cs
Maybe you dont need new fields in the order and can reassign the fields used for Credit Card details
1 ano atrás
FYI - You don't necessarily have to create new fields in the Order table.  It has a CustomValuesXml column that can be used for your custom fields.
1 ano atrás
Yidna wrote:
The first problem you have is that the Order is not created at the time PaymentInfo is displayed
So you would need to store the values somewhere temporarily just as Nop.Plugin.Payments.Manual does to store the Credit Card details

Examine how Nop.Plugin.Payments.Manual stores the Credit Card details
You can use the same flow and methods to do similar for the information you create
Then you can store the data in the Order once it is created.

i.e. using ProcessPaymentResult
See SaveOrderDetailsAsync in src\Libraries\Nop.Services\Orders\OrderProcessingService.cs
Maybe you dont need new fields in the order and can reassign the fields used for Credit Card details


Hi, thank you for your support, I followed your suggestions and now I can save the new field on Order table.
The problem I have now is on the calculation of the fees when I select the payment from dropdownlist  I created in my bank transfer plugin.  I found  the method "GetAdditionalHandlingFeeAsync" in my plugin that calls CalculatePaymentAdditionalFeeAsync, I copyed the calculation logic inside CalculatePaymentAdditionalFeeAsync as here:

  public async Task<decimal> GetAdditionalHandlingFeeAsync(IList<ShoppingCartItem> cart )
        {
                    int fee = 10;
            var orderTotalWithoutPaymentFee = (await _orderTotalCalculationService.GetShoppingCartTotalAsync(cart, usePaymentMethodAdditionalFee: false)).shoppingCartTotal ?? 0;
            var result = (decimal)((float)orderTotalWithoutPaymentFee * (float)fee / 100f);
            return result;
            
        }

I need to call back inside this method two things for my calculation fee:
1) the value from selected payment dropdownlist
2) the selected shipment method in the previous view.
According to selected payment method and selected shipment method I need to select from my custom table a percentage fee I'll use in this method to calculate additonal fee that will substitute
  fee variable in my method (in this case int fee = 10).

I tryed to add to method signature "IFormCollection form" as parameter to get my selected dropdown payment:
  public async Task<decimal> GetAdditionalHandlingFeeAsync(IList<ShoppingCartItem> cart ,"IFormCollection form")
but it's broken other piece of codes.

Please help me
1 ano atrás
please can someone help me?
1 ano atrás
ezechiele2517 wrote:
now I can save the new field on Order table.

I am still a bit confused on the flow and don’t really understand what you are doing
Is the payment method a Post process method (redirection method) i.e. The system is creating an order then your payment method reads to order and saves the data.

But then you say you are calling GetAdditionalHandlingFeeAsync which is done before the system creates an order.

How are you generating the order / orderId  ?
Because to read the order back again and get the values you stored you need the orderId

ezechiele2517 wrote:
I need to call back inside this method two things for my calculation fee:  

Refer to See Source\Presentation\Nop.Web\Controllers\CheckoutController.cs

RE 1) the value from selected payment dropdownlist
If you check the code for Nop.Plugin.Payments.Manual you will see the information that was gathered in the form is saved in ProcessPaymentRequest which is then saved as a session variable which is saved
HttpContext.Session.Set("OrderPaymentInfo", paymentInfo);
then retrieved
var processPaymentRequest = HttpContext.Session.Get<ProcessPaymentRequest>("OrderPaymentInfo");

RE 2) the selected shipment method in the previous view.
The Shipping Method is saved as a generic attribute
var shippingOptions = await _genericAttributeService.GetAttributeAsync<List<ShippingOption>>(await _workContext.GetCurrentCustomerAsync(),
                NopCustomerDefaults.OfferedShippingOptionsAttribute, (await _storeContext.GetCurrentStoreAsync()).Id);
1 ano atrás
Yidna wrote:
now I can save the new field on Order table.
I am still a bit confused on the flow and don’t really understand what you are doing
Is the payment method a Post process method (redirection method) i.e. The system is creating an order then your payment method reads to order and saves the data.

But then you say you are calling GetAdditionalHandlingFeeAsync which is done before the system creates an order.

How are you generating the order / orderId  ?
Because to read the order back again and get the values you stored you need the orderId

I need to call back inside this method two things for my calculation fee:  
Refer to See Source\Presentation\Nop.Web\Controllers\CheckoutController.cs

RE 1) the value from selected payment dropdownlist
If you check the code for Nop.Plugin.Payments.Manual you will see the information that was gathered in the form is saved in ProcessPaymentRequest which is then saved as a session variable which is saved
HttpContext.Session.Set("OrderPaymentInfo", paymentInfo);
then retrieved
var processPaymentRequest = HttpContext.Session.Get<ProcessPaymentRequest>("OrderPaymentInfo");

RE 2) the selected shipment method in the previous view.
The Shipping Method is saved as a generic attribute
var shippingOptions = await _genericAttributeService.GetAttributeAsync<List<ShippingOption>>(await _workContext.GetCurrentCustomerAsync(),
                NopCustomerDefaults.OfferedShippingOptionsAttribute, (await _storeContext.GetCurrentStoreAsync()).Id);


Hi, my flow provides that based on the shipping method (COLLECTION AT HOME,
SHIPPING COURIER,ASSIGNED PORT) and to the payment method selected in custom drop-down list, I make a calculation to apply a fee on the payment method that is displayed on the screen.
The first method you suggested me returns "object reference etc .. error" I think because of at that point I have not yet selected the payment method. The second method gives me an array but I only need the shipping method selected in the previous screen so that based on the selected payment method  I can make the calculation of the fee (reading from a custom table the value of the percentage to be multiplied).
Can you suggest me how to do that? can you tell me where is the code when the software calculate the fee e show to last view of order before confirm that? I could put it here.

thanks
1 ano atrás
Sorry wrong Attribute
shippingOption = await _genericAttributeService.GetAttributeAsync<ShippingOption>(customer, NopCustomerDefaults.SelectedShippingOptionAttribute, store.Id);
1 ano atrás
RE: " ... [fee based on ...] payment method selected in custom drop-down list,
Why not just show the calculated fees along with method names in the drop-down?

RE: "...where is the code when the software calculate the fee e show to last view of order before confirm that? "
As mentioned above, you do that in GetAdditionalHandlingFeeAsync
1 ano atrás
Yidna wrote:
Sorry wrong Attribute
shippingOption = await _genericAttributeService.GetAttributeAsync<ShippingOption>(customer, NopCustomerDefaults.SelectedShippingOptionAttribute, store.Id);

how can I get customer and store.id variables inside GetAdditionalHandlingFeeAsync method ?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.