Need the location in nop4.2 of where (method) PayPal Standard gets the Order or Cart Total for payment processing.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
It's a nice plugin but it is still on version 4.1.  They might be able to upgrade it to version 4.2 if I ask.

On the flip side, I am so close to finishing it.  so far, I was able to:
1. Correct the Cart total based on the subtotal and add the extra fee
2. update the details page of the cart during checkout to display the extra fee and display the adjusted total
3. Pass the corrected total to PayPal

All I need now is to filter the extra fee if it is UPS shipping or if it is a Greenhouse pickup, which has a pickup location ID.  I used the OrderTotalCalculationService.cs to make the adjustments.  Since I am selecting a pickup location or UPS shipping before I calculate the total, I am pretty sure there is a way to look for the type of shipping being requested and decide whether to charge the extra fee or not...  Any ideas how I can check for that right here?


            var discountAmountInclTax = discountAmountExclTax;
            //subtotal with discount (excl tax)
            var subTotalExclTaxWithDiscount = subTotalExclTaxWithoutDiscount - discountAmountExclTax;

            //calculate under $20 extra fee
            if (subTotalExclTaxWithDiscount < 20)
                subTotalExclTaxWithDiscount += 2;
4 years ago
You can try the following if you would like to do this in PayPalStandardPaymentProcessor.cs


            if (postProcessPaymentRequest.Order.PickupInStore)
            {
                // DO SOMETHING HERE
            }
            else if(postProcessPaymentRequest.Order.ShippingMethod == "Shipping.UPS")
            {
                // DO SOMETHING ELSE HERE
            }




or if you looking to do it in OrderTotalCalculationService.cs you can get the attributes like this and use that to check the value.



var pickUpPoint = _genericAttributeService.GetAttribute<PickupPoint>(_workContext.CurrentCustomer, NopCustomerDefaults.SelectedPickupPointAttribute, _storeContext.CurrentStore.Id);
var shippingOption = _genericAttributeService.GetAttribute<ShippingOption>(_workContext.CurrentCustomer, NopCustomerDefaults.SelectedShippingOptionAttribute, _storeContext.CurrentStore.Id);


Hope that helps.
4 years ago
I am trying to debug this piece of code but I do not think that it is working.  Can you please take a look?

My PickUp Location ID = 18.  Will this work to filter the location or shoudl I take another approach?


            //calculate under $20 extra fee
            if (subTotalExclTaxWithDiscount < 20)
            {
                var pickUpPoint = _genericAttributeService.GetAttribute<PickupPoint>(_workContext.CurrentCustomer, NopCustomerDefaults.SelectedPickupPointAttribute, _storeContext.CurrentStore.Id);

                if (pickUpPoint != null)
                {
                    var my = pickUpPoint.Id;

                    if (my.Contains("18"))
                    {
                        subTotalExclTaxWithDiscount += 2;
                    }                
                }
            }
4 years ago
What seems to not be working with it?

Keep in mind that if your pickup id ever changes you would need to update this code.


try this



            var subTotalExclTaxWithDiscount = subTotalExclTaxWithoutDiscount - discountAmountExclTax;
            //calculate under $20 extra fee
            if (subTotalExclTaxWithDiscount < 20)
            {
                var pickUpPoint = _genericAttributeService.GetAttribute<PickupPoint>(_workContext.CurrentCustomer, NopCustomerDefaults.SelectedPickupPointAttribute, _storeContext.CurrentStore.Id);

                if (pickUpPoint != null)
                {
                    if (pickUpPoint.Id.Equals("18"))
                    {
                        subTotalExclTaxWithDiscount += 2;
                    }
                }
            }
            var subTotalInclTaxWithDiscount = subTotalExclTaxWithDiscount;



I'm not sure where you placing this code but preferably have this line above:


            var subTotalExclTaxWithDiscount = subTotalExclTaxWithoutDiscount - discountAmountExclTax;


And this line below your section of code.

            var subTotalInclTaxWithDiscount = subTotalExclTaxWithDiscount;
4 years ago
The change to Id.Equals worked.  I am able to determine when to add the fee based on the pickup location; Thank You!

I was then able to logically determine when to show the extra fee alert in the Order Details page because it is using a Full Order model which contains the Selected Pickup location Address ID.  However, I also need to alert the Customer of the Fee in the Shopping Cart Totals block as well.  

I am looking at the Nop.Web.Components.OrderTotals.cs Invoke Method for this, but it does not contains the Pickup Location Address ID; nor does it have the OrderId value accessed anywhere.  Would you please help me to get that Address Id into OrderTotals so I can update the Cart totals accordingly?
4 years ago
You could try something like this maybe it will help you in the right direction.



            var pickUpPoint = _genericAttributeService.GetAttribute<PickupPoint>(_workContext.CurrentCustomer, NopCustomerDefaults.SelectedPickupPointAttribute, _storeContext.CurrentStore.Id);

            if (pickUpPoint != null)
            {
                if (pickUpPoint.Id.Equals("18"))
                {
                    // Add additional fee here
                }
            }

You would have to Inject the IGenericAttributeService in the constructor for you to use this.
4 years ago
Please disregard my last post; I know why it was null and corrected it.
4 years ago
Zambroff ITOS wrote:
You could try something like this maybe it will help you in the right direction.



            var pickUpPoint = _genericAttributeService.GetAttribute<PickupPoint>(_workContext.CurrentCustomer, NopCustomerDefaults.SelectedPickupPointAttribute, _storeContext.CurrentStore.Id);

       if (pickUpPoint != null)
       {
                if (pickUpPoint.Id.Equals("18"))
                {
                    // Add additional fee here
                }
            }

You would have to Inject the IGenericAttributeService in the constructor for you to use this.


I was able to successfully manage the Extra Fee based on pickup location Id and updated both Detaisl page as well as Cart totals block.

For my last step, I am going to work on the PayPal piece and also forgo the extra fee if the customer decided to pickup the purchase from our Greenhouse.  Can I use the piece of code below?



      if (postProcessPaymentRequest.Order.PickupInStore)
      {
           var pickUpPoint = _genericAttributeService.GetAttribute<PickupPoint>(_workContext.CurrentCustomer,
           NopCustomerDefaults.SelectedPickupPointAttribute, _storeContext.CurrentStore.Id);

            if (pickUpPoint != null)
            {
                  if (pickUpPoint.Id.Equals("18"))
                  {
                    ViewBag.Pick = "18";
                  }
                  else
                    ViewBag.Pick = "88";
            }
            else
               ViewBag.Pick = "88";
              
            
       }
       else if(postProcessPaymentRequest.Order.ShippingMethod == "Shipping.UPS")
       {
                // DO SOMETHING ELSE HERE
       }
      
4 years ago
Zambroff ITOS wrote:
You can try the following if you would like to do this in PayPalStandardPaymentProcessor.cs


            if (postProcessPaymentRequest.Order.PickupInStore)
            {
                // DO SOMETHING HERE
            }
            else if(postProcessPaymentRequest.Order.ShippingMethod == "Shipping.UPS")
            {
                // DO SOMETHING ELSE HERE
            }




or if you looking to do it in OrderTotalCalculationService.cs you can get the attributes like this and use that to check the value.



var pickUpPoint = _genericAttributeService.GetAttribute<PickupPoint>(_workContext.CurrentCustomer, NopCustomerDefaults.SelectedPickupPointAttribute, _storeContext.CurrentStore.Id);
var shippingOption = _genericAttributeService.GetAttribute<ShippingOption>(_workContext.CurrentCustomer, NopCustomerDefaults.SelectedShippingOptionAttribute, _storeContext.CurrentStore.Id);


Hope that helps.



I tried this piece of code in the PayPal Payment Processor and failed to get the Store Id process.  How should I call for the PickUpLocation ID in PayPal?:


            if (cartTotal < 20)
            {
                var pickUpPoint = _genericAttributeService.GetAttribute<PickupPoint>(_workContext.CurrentCustomer, NopCustomerDefaults.SelectedPickupPointAttribute, _storeContext.CurrentStore.Id);
                if (pickUpPoint != null)
                {
                    if (!pickUpPoint.Id.Equals("18"))
                    {
                        var additionalPrice = 2.00m;
                        //add query parameters
                        parameters.Add($"item_name_{itemCount}", "Under $20 Fee");
                        parameters.Add($"amount_{itemCount}", additionalPrice.ToString("0.00", CultureInfo.InvariantCulture));
                        parameters.Add($"quantity_{itemCount}", "1");

                        cartTotal += additionalPrice;
                        roundedCartTotal += additionalPrice;
                        itemCount++;
                    }
                }
            }
4 years ago
Zambroff ITOS wrote:
You can try the following if you would like to do this in PayPalStandardPaymentProcessor.cs


            if (postProcessPaymentRequest.Order.PickupInStore)
            {
                // DO SOMETHING HERE
            }
            else if(postProcessPaymentRequest.Order.ShippingMethod == "Shipping.UPS")
            {
                // DO SOMETHING ELSE HERE
            }




or if you looking to do it in OrderTotalCalculationService.cs you can get the attributes like this and use that to check the value.



var pickUpPoint = _genericAttributeService.GetAttribute<PickupPoint>(_workContext.CurrentCustomer, NopCustomerDefaults.SelectedPickupPointAttribute, _storeContext.CurrentStore.Id);
var shippingOption = _genericAttributeService.GetAttribute<ShippingOption>(_workContext.CurrentCustomer, NopCustomerDefaults.SelectedShippingOptionAttribute, _storeContext.CurrentStore.Id);


Hope that helps.


Eurika!!!!!

I was finally able to get the filter to work in PayPalStandard, utilizing the following approach.  Thank you for your guidance and recommendations.


///
            if (cartTotal < 20)
            {
                if (postProcessPaymentRequest.Order.PickupInStore)
                {
                    // DO SOMETHING HERE
                    var orderAddress = postProcessPaymentRequest.Order.PickupInStore
                    ? postProcessPaymentRequest.Order.PickupAddress
                    : postProcessPaymentRequest.Order.ShippingAddress;

                    if (orderAddress != null)
                    {
                        if (!orderAddress.Id.Equals("18"))
                        {
                            var additionalPrice = 2.00m;
                            //add query parameters
                            parameters.Add($"item_name_{itemCount}", "Under $20 Fee");
                            parameters.Add($"amount_{itemCount}", additionalPrice.ToString("0.00", CultureInfo.InvariantCulture));
                            parameters.Add($"quantity_{itemCount}", "1");

                            cartTotal += additionalPrice;
                            roundedCartTotal += additionalPrice;
                            itemCount++;
                        }
                    }
                }
            }
///
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.