This commit is contained in:
fBrignoli committed 2011-09-14 15:39:44 +00:00
1 parent 2e59d72884
commit 5428a6b6a7
1 file changed
+54 -54
+54 -54
View File
@@ -1,6 +1,6 @@
<?php <?php
/* /*
* 2007-2011 PrestaShop * 2007-2011 PrestaShop
* *
* NOTICE OF LICENSE * NOTICE OF LICENSE
* *
@@ -28,91 +28,91 @@
class AddressCore extends ObjectModel class AddressCore extends ObjectModel
{ {
/** @var integer Customer id which address belongs */ /** @var integer Customer id which address belongs */
public $id_customer = NULL; public $id_customer = null;
/** @var integer Manufacturer id which address belongs */ /** @var integer Manufacturer id which address belongs */
public $id_manufacturer = NULL; public $id_manufacturer = null;
/** @var integer Supplier id which address belongs */ /** @var integer Supplier id which address belongs */
public $id_supplier = NULL; public $id_supplier = null;
/** @var integer Country id */ /** @var integer Country id */
public $id_country; public $id_country;
/** @var integer State id */ /** @var integer State id */
public $id_state; public $id_state;
/** @var string Country name */ /** @var string Country name */
public $country; public $country;
/** @var string Alias (eg. Home, Work...) */ /** @var string Alias (eg. Home, Work...) */
public $alias; public $alias;
/** @var string Company (optional) */ /** @var string Company (optional) */
public $company; public $company;
/** @var string Lastname */ /** @var string Lastname */
public $lastname; public $lastname;
/** @var string Firstname */ /** @var string Firstname */
public $firstname; public $firstname;
/** @var string Address first line */ /** @var string Address first line */
public $address1; public $address1;
/** @var string Address second line (optional) */ /** @var string Address second line (optional) */
public $address2; public $address2;
/** @var string Postal code */ /** @var string Postal code */
public $postcode; public $postcode;
/** @var string City */ /** @var string City */
public $city; public $city;
/** @var string Any other useful information */ /** @var string Any other useful information */
public $other; public $other;
/** @var string Phone number */ /** @var string Phone number */
public $phone; public $phone;
/** @var string Mobile phone number */ /** @var string Mobile phone number */
public $phone_mobile; public $phone_mobile;
/** @var string VAT number */ /** @var string VAT number */
public $vat_number; public $vat_number;
/** @var string DNI number */ /** @var string DNI number */
public $dni; public $dni;
/** @var string Object creation date */ /** @var string Object creation date */
public $date_add; public $date_add;
/** @var string Object last modification date */ /** @var string Object last modification date */
public $date_upd; public $date_upd;
/** @var boolean True if address has been deleted (staying in database as deleted) */ /** @var boolean True if address has been deleted (staying in database as deleted) */
public $deleted = 0; public $deleted = 0;
protected static $_idZones = array(); protected static $_idZones = array();
protected static $_idCountries = array(); protected static $_idCountries = array();
protected $fieldsRequired = array('id_country', 'alias', 'lastname', 'firstname', 'address1', 'city'); protected $fieldsRequired = array('id_country', 'alias', 'lastname', 'firstname', 'address1', 'city');
protected $fieldsSize = array('alias' => 32, 'company' => 32, 'lastname' => 32, 'firstname' => 32, protected $fieldsSize = array('alias' => 32, 'company' => 32, 'lastname' => 32, 'firstname' => 32,
'address1' => 128, 'address2' => 128, 'postcode' => 12, 'city' => 64, 'address1' => 128, 'address2' => 128, 'postcode' => 12, 'city' => 64,
'other' => 300, 'phone' => 16, 'phone_mobile' => 16, 'dni' => 16); 'other' => 300, 'phone' => 16, 'phone_mobile' => 16, 'dni' => 16);
protected $fieldsValidate = array('id_customer' => 'isNullOrUnsignedId', 'id_manufacturer' => 'isNullOrUnsignedId', protected $fieldsValidate = array('id_customer' => 'isNullOrUnsignedId', 'id_manufacturer' => 'isNullOrUnsignedId',
'id_supplier' => 'isNullOrUnsignedId', 'id_country' => 'isUnsignedId', 'id_state' => 'isNullOrUnsignedId', 'id_supplier' => 'isNullOrUnsignedId', 'id_country' => 'isUnsignedId', 'id_state' => 'isNullOrUnsignedId',
'alias' => 'isGenericName', 'company' => 'isGenericName', 'lastname' => 'isName','vat_number' => 'isGenericName', 'alias' => 'isGenericName', 'company' => 'isGenericName', 'lastname' => 'isName','vat_number' => 'isGenericName',
'firstname' => 'isName', 'address1' => 'isAddress', 'address2' => 'isAddress', 'postcode'=>'isPostCode', 'firstname' => 'isName', 'address1' => 'isAddress', 'address2' => 'isAddress', 'postcode'=>'isPostCode',
'city' => 'isCityName', 'other' => 'isMessage', 'city' => 'isCityName', 'other' => 'isMessage',
'phone' => 'isPhoneNumber', 'phone_mobile' => 'isPhoneNumber', 'deleted' => 'isBool', 'dni' => 'isDniLite'); 'phone' => 'isPhoneNumber', 'phone_mobile' => 'isPhoneNumber', 'deleted' => 'isBool', 'dni' => 'isDniLite');
protected $table = 'address'; protected $table = 'address';
protected $identifier = 'id_address'; protected $identifier = 'id_address';
protected $_includeVars = array('addressType' => 'table'); protected $_includeVars = array('addressType' => 'table');
protected $_includeContainer = false; protected $_includeContainer = false;
protected $webserviceParameters = array( protected $webserviceParameters = array(
'objectsNodeName' => 'addresses', 'objectsNodeName' => 'addresses',
'fields' => array( 'fields' => array(
'id_customer' => array('xlink_resource'=> 'customers'), 'id_customer' => array('xlink_resource'=> 'customers'),
@@ -128,7 +128,7 @@ class AddressCore extends ObjectModel
* *
* @param integer $id_address Existing address id in order to load object (optional) * @param integer $id_address Existing address id in order to load object (optional)
*/ */
public function __construct($id_address = NULL, $id_lang = NULL) public function __construct($id_address = null, $id_lang = null)
{ {
parent::__construct($id_address); parent::__construct($id_address);
@@ -136,15 +136,15 @@ class AddressCore extends ObjectModel
if ($this->id) if ($this->id)
{ {
$result = Db::getInstance()->getRow('SELECT `name` FROM `'._DB_PREFIX_.'country_lang` $result = Db::getInstance()->getRow('SELECT `name` FROM `'._DB_PREFIX_.'country_lang`
WHERE `id_country` = '.(int)($this->id_country).' WHERE `id_country` = '.(int)$this->id_country.'
AND `id_lang` = '.($id_lang ? (int)($id_lang) : Configuration::get('PS_LANG_DEFAULT'))); AND `id_lang` = '.($id_lang ? (int)$id_lang : Configuration::get('PS_LANG_DEFAULT')));
$this->country = $result['name']; $this->country = $result['name'];
} }
} }
public function add($autodate = true, $nullValues = false) public function add($autodate = true, $null_values = false)
{ {
if (!parent::add($autodate, $nullValues)) if (!parent::add($autodate, $null_values))
return false; return false;
if (Validate::isUnsignedId($this->id_customer)) if (Validate::isUnsignedId($this->id_customer))
@@ -167,13 +167,13 @@ class AddressCore extends ObjectModel
} }
/** /**
* Returns fields required for an address in an array hash * Returns fields required for an address in an array hash
* @return array hash values * @return array hash values
*/ */
public static function getFieldsValidate() public static function getFieldsValidate()
{ {
$tmp_addr = new Address(); $tmp_addr = new Address();
$out = ($tmp_addr->fieldsValidate); $out = $tmp_addr->fieldsValidate;
unset($tmp_addr); unset($tmp_addr);
return $out; return $out;
@@ -186,12 +186,12 @@ class AddressCore extends ObjectModel
{ {
$this->validateFields(); $this->validateFields();
if (isset($this->id)) if (isset($this->id))
$fields['id_address'] = (int)($this->id); $fields['id_address'] = (int)$this->id;
$fields['id_customer'] = is_null($this->id_customer) ? 0 : (int)($this->id_customer); $fields['id_customer'] = is_null($this->id_customer) ? 0 : (int)$this->id_customer;
$fields['id_manufacturer'] = is_null($this->id_manufacturer) ? 0 : (int)($this->id_manufacturer); $fields['id_manufacturer'] = is_null($this->id_manufacturer) ? 0 : (int)$this->id_manufacturer;
$fields['id_supplier'] = is_null($this->id_supplier) ? 0 : (int)($this->id_supplier); $fields['id_supplier'] = is_null($this->id_supplier) ? 0 : (int)$this->id_supplier;
$fields['id_country'] = (int)($this->id_country); $fields['id_country'] = (int)$this->id_country;
$fields['id_state'] = (int)($this->id_state); $fields['id_state'] = (int)$this->id_state;
$fields['alias'] = pSQL($this->alias); $fields['alias'] = pSQL($this->alias);
$fields['company'] = pSQL($this->company); $fields['company'] = pSQL($this->company);
$fields['lastname'] = pSQL($this->lastname); $fields['lastname'] = pSQL($this->lastname);
@@ -205,7 +205,7 @@ class AddressCore extends ObjectModel
$fields['phone_mobile'] = pSQL($this->phone_mobile); $fields['phone_mobile'] = pSQL($this->phone_mobile);
$fields['vat_number'] = pSQL($this->vat_number); $fields['vat_number'] = pSQL($this->vat_number);
$fields['dni'] = pSQL($this->dni); $fields['dni'] = pSQL($this->dni);
$fields['deleted'] = (int)($this->deleted); $fields['deleted'] = (int)$this->deleted;
$fields['date_add'] = pSQL($this->date_add); $fields['date_add'] = pSQL($this->date_add);
$fields['date_upd'] = pSQL($this->date_upd); $fields['date_upd'] = pSQL($this->date_upd);
return $fields; return $fields;
@@ -237,9 +237,9 @@ class AddressCore extends ObjectModel
FROM `'._DB_PREFIX_.'address` a FROM `'._DB_PREFIX_.'address` a
LEFT JOIN `'._DB_PREFIX_.'country` c ON c.`id_country` = a.`id_country` LEFT JOIN `'._DB_PREFIX_.'country` c ON c.`id_country` = a.`id_country`
LEFT JOIN `'._DB_PREFIX_.'state` s ON s.`id_state` = a.`id_state` LEFT JOIN `'._DB_PREFIX_.'state` s ON s.`id_state` = a.`id_state`
WHERE a.`id_address` = '.(int)($id_address)); WHERE a.`id_address` = '.(int)$id_address);
self::$_idZones[$id_address] = (int)((int)($result['id_zone_state']) ? $result['id_zone_state'] : $result['id_zone']); self::$_idZones[$id_address] = (int)((int)$result['id_zone_state'] ? $result['id_zone_state'] : $result['id_zone']);
return self::$_idZones[$id_address]; return self::$_idZones[$id_address];
} }
@@ -255,7 +255,7 @@ class AddressCore extends ObjectModel
SELECT c.`active` SELECT c.`active`
FROM `'._DB_PREFIX_.'address` a FROM `'._DB_PREFIX_.'address` a
LEFT JOIN `'._DB_PREFIX_.'country` c ON c.`id_country` = a.`id_country` LEFT JOIN `'._DB_PREFIX_.'country` c ON c.`id_country` = a.`id_country`
WHERE a.`id_address` = '.(int)($id_address))) WHERE a.`id_address` = '.(int)$id_address))
return false; return false;
return ($result['active']); return ($result['active']);
} }
@@ -270,8 +270,8 @@ class AddressCore extends ObjectModel
$result = Db::getInstance()->getRow(' $result = Db::getInstance()->getRow('
SELECT COUNT(`id_order`) AS used SELECT COUNT(`id_order`) AS used
FROM `'._DB_PREFIX_.'orders` FROM `'._DB_PREFIX_.'orders`
WHERE `id_address_delivery` = '.(int)($this->id).' WHERE `id_address_delivery` = '.(int)$this->id.'
OR `id_address_invoice` = '.(int)($this->id)); OR `id_address_invoice` = '.(int)$this->id);
return isset($result['used']) ? $result['used'] : false; return isset($result['used']) ? $result['used'] : false;
} }
@@ -282,7 +282,7 @@ class AddressCore extends ObjectModel
return self::$_idCountries[$id_address]; return self::$_idCountries[$id_address];
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT `id_country`, `id_state`, `vat_number`, `postcode` FROM `'._DB_PREFIX_.'address` SELECT `id_country`, `id_state`, `vat_number`, `postcode` FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.(int)($id_address)); WHERE `id_address` = '.(int)$id_address);
self::$_idCountries[$id_address] = $result; self::$_idCountries[$id_address] = $result;
return $result; return $result;
} }
@@ -298,7 +298,7 @@ class AddressCore extends ObjectModel
$row = Db::getInstance()->getRow(' $row = Db::getInstance()->getRow('
SELECT `id_address` SELECT `id_address`
FROM '._DB_PREFIX_.'address a FROM '._DB_PREFIX_.'address a
WHERE a.`id_address` = '.(int)($id_address)); WHERE a.`id_address` = '.(int)$id_address);
return isset($row['id_address']); return isset($row['id_address']);
} }
@@ -308,7 +308,7 @@ class AddressCore extends ObjectModel
return Db::getInstance()->getValue(' return Db::getInstance()->getValue('
SELECT `id_address` SELECT `id_address`
FROM `'._DB_PREFIX_.'address` FROM `'._DB_PREFIX_.'address`
WHERE `id_customer` = '.(int)($id_customer).' AND `deleted` = 0'.($active ? ' AND `active` = 1' : '') WHERE `id_customer` = '.(int)$id_customer.' AND `deleted` = 0'.($active ? ' AND `active` = 1' : '')
); );
} }
} }