VirtueMart

WooCommerce

Others

Docs

Support

Demo

Blog

About

Forum
Welcome, Guest
Username: Password: Remember me

TOPIC: Rule limitation and get city list from file

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

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.
The administrator has disabled public write access.

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
The administrator has disabled public write access.

VM - Shopping cart

 x 

Cart empty

Login Formular