Creating a Plugin for Additional fees when Shipping out of state.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
1 year ago
Hello,
I followed the instructions to create a plugin in nop4.6 for an Extra Fee.
I am now using this block of code everywhere to update the total.
Please advise on how to update the final total so it can reflect everywhere from the Plugin, just like the UPS Shipping Plugin, which I looked at and tried to follow for my own plugin.

Any ideas on how to get that done?


            var store = await _storeContext.GetCurrentStoreAsync();
            var cart = await _shoppingCartService.GetShoppingCartAsync(await _workContext.GetCurrentCustomerAsync(), ShoppingCartType.ShoppingCart, store.Id);
            var pickUpPoint = await _genericAttributeService.GetAttributeAsync<PickupPoint>(customer, NopCustomerDefaults.SelectedPickupPointAttribute, store.Id);
            var orderTotal = (int)(paymentRequest.OrderTotal * 100);
            Address shipAdd = await _customerService.GetCustomerShippingAddressAsync(customer);

            if (pickUpPoint.Id != null)
            {
                if (!pickUpPoint.Id.Equals("18"))
                {
                    if (orderTotal < 2500)
                    {
                        orderTotal += 300;
                    }
                }

            }
            else
            {
                if (shipAdd != null)
                {
                    if (shipAdd.StateProvinceId != 41)
                    {
                        var orderItemQuant = 0;

                        foreach (var item in cart)
                        { orderItemQuant += item.Quantity; }

                        if (orderItemQuant <= 12)
                        { orderTotal += 5400; }
                        else
                        { orderTotal += 6000; }
                    }

                }
            }
1 year ago
You can override AdjustShippingRateAsync method and add your code in this method If you want to add amount in shipping rate when Shipping out of state.
1 year ago
Note that Shipping Provider (shipping rate caclulation) plugins "just like the UPS Shipping Plugin", do not really add an 'Extra Fee', or 'adjust' a shipping rate.  They calculate the full shipping rate.  So, it's not clear why you are "using this block of code everywhere to update the total", unless you want to show the fee as a separate line item.

You can create a shipping rate caclulation plugin that calls the UPS plugin to get rates, and then add an 'Extra Fee' there.   (If you do that, be sure that the UPS plugin is not an "Active" shipping provider)
1 year ago
@New York,
The Code that I am showing is what I am using now everywhere to generate the extra Fee based on Shipping State or Pick-Up selection destinations.  However, while am I starting to update the Upgrade to version 4.6, I wanted to reduce code duplication and create a Plug-In that will do this for me.  And, yes, I do want to add an extra line to the Total to indicate the Shipping & Handling fee, which depicts the cost of the Styrofoam container.  I hope that helps to clarify my goal for this upgrade.
1 year ago
webzest wrote:
...yes, I do want to add an extra line to the Total to indicate the Shipping & Handling fee...

If you want a separate line item showing the fee in the Order Totals section, then you don't want to add the fee to the amount calculated in a customized UPS Shipping (rate calculation) plugin.

In general, I think  it would be difficult to create a plugin to add a separate fee / line item.  For example, you can see how the Payment Fee is handled - e.g. just in .cshtml
@if (!string.IsNullOrEmpty(Model.PaymentMethodAdditionalFee))
{
    <tr class="additional-fees">
        <td class="cart-total-left">
            <label>@T("ShoppingCart.Totals.PaymentMethodAdditionalFee"):</label>
        </td>
        <td class="cart-total-right">
            <span class="value-summary">@Model.PaymentMethodAdditionalFee</span>
        </td>
    </tr>
}


If you are not using the PaymentMethodAdditionalFee, then it may be easier to just to have your custom plugin utilize it (and then change the localized string value).

The alternate is to customize the UPS plugin, and to conditionally 'append' to the method name - e.g.
"Ground - includes $25 container fee"
So that the customer can see that in the order totals.
(P.S.  Shipping Director can do that ;)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.