We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44536
    • 7 Posts
    Hi,

    Wondering if anyone can help me I am currently implementing Minishop2 for a client really impressed with the package so far but having a bit of trouble with the validation on the postcode field. In the UK we have numbers and letters for the postcode/ZIP code but the validation is just set to numbers so it strips out the letters. Any ideas on how I can change this would be greatly appreciated.

    Thanks
      • 42046
      • 436 Posts
      You need to edit out line 160 of core/components/minishop2/model/minishop2/msorderhandler.class.php

      			case 'index': $value = substr(preg_replace('/[^-0-9]/iu', '',$value),0,10); break;


      If you upgrade package this will get broken again though. A better way is to make an extended order class handler to override default one as described in http://bezumkin.ru/modx/minishop2/classes/1126/ (Russian). I'm just about to have a go at this so will post the results if I get it working.
        • 44536
        • 7 Posts
        Hi Dan,

        Thank you for the response.

        I ended up editing the line to this:

        case 'index': $value = substr(preg_replace('/[^a-zA-Z0-9]/iu', '',$value),0,10); break;


        Currently seems to work OK.
          • 42046
          • 436 Posts
          Glad it's working. I'm just getting into writing a custom handler class for weight range postage for various Royal Mail methods so will post the results when I get it working.
            • 44536
            • 7 Posts
            That would be really useful. I look forward to seeing the results.
              • 42046
              • 436 Posts
              Just a quick update, for a neater method to stop the post codes having letters stripped out and which won't get broken if the package gets updated, create a file in /core/components/minishop2/custom/order/ called UKOrderHandler.class.php with this code in it:

              <?php
              class UKOrderHandler extends msOrderHandler {
              	
              public function validate($key, $value) {
              	if ($key == 'index') {
              		return substr(preg_replace('/[^a-zA-Z0-9]/iu', '',$value),0,10) ? trim($value) : @$this->order[$key];
              	}
              	return parent::validate($key,$value);
              }
              
              }


              Then change ms2_order_handler_class in the system settings to: UKOrderHandler

              This will override the default post code validation without changing the add-on's core code.
                • 42046
                • 436 Posts
                To get this working correctly through the entire check out process, you currently need to implement this fix until the next version is released: https://github.com/bezumkin/miniShop2/commit/e8120efaa9f5ab4588a9723b2c63ee726bc5426f