NopCommerce City Restriction Plugin

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 years ago
I am creating a plugin that doesn't allow shipping (Order completion) in the following circumstances
IF the cart has at least one grocery item and the shipping address (City) is anything else besides a specific city(Only within city shipping for grocery items)

I am creating a plugin and am a beginner to all this nopCommerce, c# and dotnet but if you give me some proper instructions i think i could manage it

I want to create my own plugin with only the minimum functionality i can even HARD CODEDLY write the city (during development)

Al tough i know this such question might have been asked a hundred times in the past.
Any help will be REALLY appreciated

P.S i already created a simple plugin with install and uninstall functionality 😅
3 years ago
If you are using fixed rates, then I recommend that you use/modify the existing shipping rate provider plugin "Fixed or By Weight and By Total" (Shipping.FixedByWeightByTotal).  Because, you will already have the shipping address (to check city), and contents of the cart (to check product category).

That said, I can recommend that you consider the plugin Shipping Director, where your requirement can easily be met by this rule (example category and city) :

ErrorExit
Items.Any(Product.HasCategory("Grocery")) and City <> "Karachi"
"Sorry, we can't ship grocery to your city"

Then you can follow with another rule to calculate shipping, or call an existing shipping rate provider plugin.

Note that City is just a free-form text field, so sometimes customers spell the city wrong.
Consider that you can set up the "State / Province" to have your list of cities.  In that case, then check  the StateProvince.Abbreviation property  (just "State" when used in a Shipping Director rule).
3 years ago
Can you please elaborate in some simpler defined steps how to implement this functionality as i am a beginner to Nopcommerce i don't know where to start. I can't seem to debug and stop the plugin after he has selected shipping address because logically thats the place where i should check his selected city.

Please Help Sir
3 years ago
Did you copy / "modify the existing shipping rate provider plugin "Fixed or By Weight and By Total" (Shipping.FixedByWeightByTotal).  Because, you will already have the shipping address (to check city), and contents of the cart (to check product category)."
3 years ago
Sir can you please tell (namely) in which file i need to make the changes as there as many different folders and many different files
3 years ago
Have you read the developer documentation - e.g. https://docs.nopcommerce.com/en/developer/plugins/shipping-plugin.html?

FixedByWeightByTotalComputationMethod.cs

public GetShippingOptionResponse GetShippingOptions(GetShippingOptionRequest getShippingOptionRequest)
{
    if (getShippingOptionRequest == null)
        throw new ArgumentNullException(nameof(getShippingOptionRequest));

    var response = new GetShippingOptionResponse();

    if (getShippingOptionRequest.Items == null || !getShippingOptionRequest.Items.Any())
    {
        response.AddError("No shipment items");
        return response;
    }
...


You would check either
  getShippingOptionRequest.ShippingAddress.StateProvinceId
  getShippingOptionRequest.ShippingAddress.City

And then do the same as above response.AddError / return ...
3 years ago
Thank you soo much really appreciate the help
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.