* @copyright 2007-2013 PrestaShop SA * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class Address extends AddressCore { /** * @see ObjectModel::$definition */ public static $definition = array( 'table' => 'address', 'primary' => 'id_address', 'fields' => array( 'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false), 'id_manufacturer' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false), 'id_supplier' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false), 'id_warehouse' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false), 'id_country' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'id_state' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId'), 'alias' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 32), 'company' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 64), 'lastname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32), 'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32), 'vat_number' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'), 'address1' => array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'required' => true, 'size' => 128), 'address2' => array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'size' => 128), 'postcode' => array('type' => self::TYPE_STRING, 'validate' => 'isPostCode', 'size' => 12), 'city' => array('type' => self::TYPE_STRING, 'validate' => 'isCityName', 'required' => true, 'size' => 64), 'other' => array('type' => self::TYPE_STRING, 'validate' => 'isMessage', 'size' => 300), 'phone' => array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber','required' => true, 'size' => 32), 'phone_mobile' => array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32), 'dni' => array('type' => self::TYPE_STRING, 'validate' => 'isDniLite', 'size' => 16), 'deleted' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat', 'copy_post' => false), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat', 'copy_post' => false), ), ); static $countries_fr_list = array( 8, //FRANCE 242, //Polynésie Française 183, //Saint-Pierre-et-Miquelon 182, //Saint-Martin 179, //Saint-Barthélemy 144, //Mayotte 98, //Guadeloupe 141, //Martinique 241, //Guyane Française 176, //Réunion, Île de la 225, //Wallis et Futuna 158, //Nouvelle-Calédonie ); static $postcode_fr_list = array( 98 => array( 97100, 97199 ), 141 => array( 97200, 97299 ), 144 => array( 97600, 97699 ), 158 => array( 98800, 98899 ), 176 => array( 97400, 97499 ), 179 => array( 97133, 97133 ), 182 => array( 97150, 97150 ), 183 => array( 97500, 97599 ), 225 => array( 98600, 98699 ), 241 => array( 97300, 97399 ), 242 => array( 98700, 98799 ), ); public function add($autodate = true, $null_values = false) { if(in_array($this->id_country, self::$countries_fr_list)) { $find = false; foreach(self::$postcode_fr_list as $id_country => $postcodes) { if ($this->postcode >= $postcodes[0] && $this->postcode <= $postcodes[1] ) { $find = true; $this->id_country = $id_country; } } if(!$find) { $this->id_country = 8; } } return parent::add($autodate, $null_values); } public function update($null_values = false) { if(in_array($this->id_country, self::$countries_fr_list)) { $find = false; foreach(self::$postcode_fr_list as $id_country => $postcodes) { if ($this->postcode >= $postcodes[0] && $this->postcode <= $postcodes[1] ) { $find = true; $this->id_country = $id_country; } } if(!$find) { $this->id_country = 8; } } return parent::update($null_values); } }