Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added: new column phone in the customer table #1365

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 4 additions & 23 deletions classes/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ class CustomerCore extends ObjectModel
'last_passwd_gen' => array('setter' => null),
'secure_key' => array('setter' => null),
'deleted' => array(),
'passwd' => array('setter' => 'setWsPasswd'),
'phone' => array()
'passwd' => array('setter' => 'setWsPasswd')
),
'associations' => array(
'groups' => array('resource' => 'group'),
Expand Down Expand Up @@ -180,6 +179,7 @@ class CustomerCore extends ObjectModel
'company' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
'siret' => array('type' => self::TYPE_STRING, 'validate' => 'isSiret'),
'ape' => array('type' => self::TYPE_STRING, 'validate' => 'isApe'),
'phone' => array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32),
'outstanding_allow_amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'copy_post' => false),
'show_public_prices' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
'id_risk' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'copy_post' => false),
Expand All @@ -206,12 +206,8 @@ public function __construct($id = null)
$this->id_default_group = (int)Configuration::get('PS_CUSTOMER_GROUP');
parent::__construct($id);

if ($this->email) {
$this->phone = CartCustomerGuestDetail::getCustomerPhone($this->email);
}

if (Configuration::get('PS_ONE_PHONE_AT_LEAST')) {
$this->webserviceParameters['fields']['phone']['required'] = true;
self::$definition['fields']['phone']['required'] = true;
}
}

Expand Down Expand Up @@ -264,7 +260,7 @@ public function add($autodate = true, $null_values = true)
}
$success = parent::add($autodate, $null_values);
$this->updateGroup($this->groupBox);
$this->updateCustomerAdditionalDetails(CartCustomerGuestDetail::getIdCustomerGuest($this->email));

return $success;
}

Expand All @@ -289,22 +285,9 @@ public function update($nullValues = false)

$objOldCustomer = new Customer($this->id);
$success = parent::update(true);
$this->updateCustomerAdditionalDetails(CartCustomerGuestDetail::getIdCustomerGuest($objOldCustomer->email));
return $success;
}

public function updateCustomerAdditionalDetails($idCustomerGuest)
{
$objCartCustomerGuestDetail = new CartCustomerGuestDetail($idCustomerGuest);
$objCartCustomerGuestDetail->id_cart = 0;
$objCartCustomerGuestDetail->id_gender = $this->id_gender;
$objCartCustomerGuestDetail->firstname = $this->firstname;
$objCartCustomerGuestDetail->lastname = $this->lastname;
$objCartCustomerGuestDetail->email = $this->email;
$objCartCustomerGuestDetail->phone = $this->phone;
return $objCartCustomerGuestDetail->save();
}

public function delete()
{
if (!count(Order::getCustomerOrders((int)$this->id))) {
Expand Down Expand Up @@ -343,8 +326,6 @@ public function delete()

CartRule::deleteByIdCustomer((int)$this->id);
// delete customer data from customerGuest table
$objCartCustomerGuestDetail = new CartCustomerGuestDetail(CartCustomerGuestDetail::getIdCustomerGuest($this->email));
$objCartCustomerGuestDetail->delete();
return parent::delete();
}

Expand Down
5 changes: 5 additions & 0 deletions controllers/admin/AdminCustomersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ public function __construct()
'align' => 'text-right',
'badge_success' => true
),
'phone' => array(
'title' => $this->l('Phone'),
'optional' => true,
'visible_default' => false,
),
'active' => array(
'title' => $this->l('Enabled'),
'align' => 'text-center',
Expand Down
1 change: 1 addition & 0 deletions install/data/db_structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ CREATE TABLE `PREFIX_customer` (
`max_payment_days` int(10) unsigned NOT NULL DEFAULT '60',
`secure_key` varchar(32) NOT NULL DEFAULT '-1',
`note` text,
`phone` varchar(32) DEFAULT NULL,
`active` tinyint(1) unsigned NOT NULL DEFAULT '0',
`is_guest` tinyint(1) NOT NULL DEFAULT '0',
`deleted` tinyint(1) NOT NULL DEFAULT '0',
Expand Down