Login
Register

VirtueMart

WooCommerce

Others

Docs

Support

Blog

About

Shipping by Rules for VirtueMart

IMPORTANT ANNOUNCEMENT: Plugin development ceased, all plugins made available freely (GPL)

With great sadness we have to announce that we are ceasing development of all our VirtueMart, WooCommerce and Joomla plugins. Effective immediately, all our plugins -- even those that were paid downloads -- are made available for free from our homepage (GPL license still applies), but we cannot and will not provide any support anymore.

It has been a great pleasure to be part of the thriving development communities of VirtueMart as well as WooCommerce. However, during the last year it became painstakingly clear that in addition to a full-time job, a young family and several other time-consuming hobbies at professional level (like being a professional singer) the plugin development and the support that it requires is not sustainable and is taking its toll. It has been an honor, but it is now time to say good bye!

×

Notice

The forum is in read only mode.
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Rule limitation and get city list from file 03 Dec 2014 11:58 #1

  • ruhanda
  • ruhanda's Avatar Topic Author
I got problem to add the rule due to there are limitation, every time I add a rule it will disappear after I press save button.
Due to we have around 10000 ZIP and price based on sub-district seems current rule is not enough, is it possible to put ZIP or City into file the use that file as variable in rule, such as "list(file) in ZIP" or "list(file) in City", where the "file" is a file or file location.

Another problem is Typo when customer entering City and it's not match with the rule, is there any solution or plugin to hack City filed on registration page to be dropdown type instead of standard text in.

Rule limitation and get city list from file 15 Dec 2014 18:40 #2

1) VirtueMart 2.x has the limitation that each plugin (or rather, each shipping method in this case) can only store ~19000 characters of configuration in the database (the database field is set to this explicit length!). If your configuration is longer, VM will no longer save it...
There is not much you can do about this. All you can do is to try and split up the rules into two shipping methods.

2) Comparing a user-entered city name is always bound to troubles due to different spellings, upper-/lowercase or simple typos. If possible, I'd suggest using checks ono ZIP instead of City for your conditions. Converting the city input field to a dropdown is of course possible technically, but you'd have to manually implement this - and keep the list of city names up to date yourself.

3) Your suggestion to read a list of allowed postcodes from a file is currently not implemented. However, in version 4.99 of the plugin (a development/pre-release version), I added the possibility to extend the shipping plugin with its own plugins. There you could implement a function to make such a check. See
open-tools.net/virtuemart-2-extensions/e...rtuemart-detail.html
for a short documentation how to write such a plugin. Basically, you would implement it like:
class plgVmShipmentRulesZipFromFile extends VmPlugin {
    onVmShippingRulesGetCartValues(&$cartvals, $cart, $products, $method, $cart_prices) {
        $zip = $cartvals['zip'];
        // read in the postal codes from a file, or a database etc.
        $allowedzips = .....;
        // Set a variable in the $cartvals array to contain the result:
        $cartvals['zipinlist'] = in_array($zip, $allowedzips);
    }
}
You can then use a variable "ZipInList" (case-insensitive) in your rules:
Name="Zip in allowed list"; Condition=ZipInList; Shipping=3
Of course, if you have different shipping cost for each zip, you can simply set a variable in the $cartvals array to the shipping costs for that zip (here I hardcode a value of 123456, but in reality you would get that value either from the file or from a database query):
...
        $cartvals['zipinlist'] = in_array($zip, $allowedzips);
        $cartvals['zipshipping'] = 123456; // <= shipping cost depending on ZIP
...
and then use it in the rules like:
Name="Zip in allowed list"; Condition=ZipInList; Shipping=ZipShipping

Since you have so many zip codes, this approach is probably better performance-wise, because the plugin always has to parse the whole, long configuration string.

Best regards,
Reinhold
  • Page:
  • 1