diff --git a/core/lib/Thelia/Model/Customer.php b/core/lib/Thelia/Model/Customer.php index 282b380ff..b3ee0085d 100644 --- a/core/lib/Thelia/Model/Customer.php +++ b/core/lib/Thelia/Model/Customer.php @@ -129,7 +129,7 @@ class Customer extends BaseCustomer implements UserInterface protected function generateRef() { - return uniqid(substr($this->getLastname(), 0, (strlen($this->getLastname()) >= 3) ? 3 : strlen($this->getLastname())), true); + return sprintf('CUS%s', str_pad($this->getId(), 12, 0, STR_PAD_LEFT)); } /** @@ -164,7 +164,7 @@ class Customer extends BaseCustomer implements UserInterface return $this; } - +/* public function setRef($ref) { if (null === $ref && null === $this->ref) { @@ -174,7 +174,7 @@ class Customer extends BaseCustomer implements UserInterface } return $this; - } + }*/ public function setEmail($email, $force = false) { @@ -273,10 +273,6 @@ class Customer extends BaseCustomer implements UserInterface // Set the serial number (for auto-login) $this->setRememberMeSerial(uniqid()); - if (null === $this->ref) { - $this->setRef($this->generateRef()); - } - $this->dispatchEvent(TheliaEvents::BEFORE_CREATECUSTOMER, new CustomerEvent($this)); return true; @@ -287,6 +283,11 @@ class Customer extends BaseCustomer implements UserInterface */ public function postInsert(ConnectionInterface $con = null) { + if (null === $this->getRef()) { + $this->setRef($this->generateRef()) + ->save($con); + } + $this->dispatchEvent(TheliaEvents::AFTER_CREATECUSTOMER, new CustomerEvent($this)); } diff --git a/core/lib/Thelia/Model/Map/CustomerTableMap.php b/core/lib/Thelia/Model/Map/CustomerTableMap.php index 14e14e330..795a4af03 100644 --- a/core/lib/Thelia/Model/Map/CustomerTableMap.php +++ b/core/lib/Thelia/Model/Map/CustomerTableMap.php @@ -202,7 +202,7 @@ class CustomerTableMap extends TableMap $this->setUseIdGenerator(true); // columns $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); - $this->addColumn('REF', 'Ref', 'VARCHAR', true, 50, null); + $this->addColumn('REF', 'Ref', 'VARCHAR', false, 50, null); $this->addForeignKey('TITLE_ID', 'TitleId', 'INTEGER', 'customer_title', 'ID', true, null, null); $this->addColumn('FIRSTNAME', 'Firstname', 'VARCHAR', true, 255, null); $this->addColumn('LASTNAME', 'Lastname', 'VARCHAR', true, 255, null); diff --git a/core/lib/Thelia/Model/Map/OrderTableMap.php b/core/lib/Thelia/Model/Map/OrderTableMap.php index 28613da80..2246af89c 100644 --- a/core/lib/Thelia/Model/Map/OrderTableMap.php +++ b/core/lib/Thelia/Model/Map/OrderTableMap.php @@ -217,7 +217,7 @@ class OrderTableMap extends TableMap $this->setUseIdGenerator(true); // columns $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); - $this->addColumn('REF', 'Ref', 'VARCHAR', true, 45, null); + $this->addColumn('REF', 'Ref', 'VARCHAR', false, 45, null); $this->addForeignKey('CUSTOMER_ID', 'CustomerId', 'INTEGER', 'customer', 'ID', true, null, null); $this->addForeignKey('INVOICE_ORDER_ADDRESS_ID', 'InvoiceOrderAddressId', 'INTEGER', 'order_address', 'ID', true, null, null); $this->addForeignKey('DELIVERY_ORDER_ADDRESS_ID', 'DeliveryOrderAddressId', 'INTEGER', 'order_address', 'ID', true, null, null); diff --git a/core/lib/Thelia/Model/Order.php b/core/lib/Thelia/Model/Order.php index d0fd7f43a..f19f29e03 100644 --- a/core/lib/Thelia/Model/Order.php +++ b/core/lib/Thelia/Model/Order.php @@ -23,8 +23,6 @@ class Order extends BaseOrder */ public function preInsert(ConnectionInterface $con = null) { - $this->setRef($this->generateRef()); - $this->dispatchEvent(TheliaEvents::ORDER_BEFORE_CREATE, new OrderEvent($this)); return true; @@ -35,6 +33,8 @@ class Order extends BaseOrder */ public function postInsert(ConnectionInterface $con = null) { + $this->setRef($this->generateRef()) + ->save($con); $this->dispatchEvent(TheliaEvents::ORDER_AFTER_CREATE, new OrderEvent($this)); } @@ -49,9 +49,7 @@ class Order extends BaseOrder public function generateRef() { - /* order addresses are unique */ - - return uniqid('ORD', true); + return sprintf('ORD%s', str_pad($this->getId(), 12, 0, STR_PAD_LEFT)); } /** diff --git a/local/config/schema.xml b/local/config/schema.xml index 7e9341bf4..52a0b4319 100644 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -109,9 +109,9 @@ - - - + + + @@ -161,11 +161,11 @@ - - - - - + + + + + @@ -225,11 +225,11 @@ - - - - - + + + + +
@@ -249,10 +249,10 @@ - - - - + + + +
@@ -326,11 +326,11 @@ - - - - - + + + + + @@ -375,7 +375,7 @@
- + @@ -461,9 +461,9 @@ - - - + + +
@@ -522,10 +522,10 @@ - - - - + + + + @@ -553,7 +553,7 @@
- + @@ -630,12 +630,12 @@ - - - - - - + + + + + + @@ -1079,10 +1079,10 @@ - - - - + + + + @@ -1103,10 +1103,10 @@ - - - - + + + + @@ -1127,10 +1127,10 @@ - - - - + + + + @@ -1250,16 +1250,16 @@ - - - - - - - - - - + + + + + + + + + +
@@ -1297,10 +1297,10 @@ - - - - + + + + diff --git a/local/modules/Klikandpay b/local/modules/Klikandpay index f356c9572..a72c066e7 160000 --- a/local/modules/Klikandpay +++ b/local/modules/Klikandpay @@ -1 +1 @@ -Subproject commit f356c95726cf25d7f156f8c349eb5a608de12add +Subproject commit a72c066e7400d2350dca24016a302582cb7e7b62 diff --git a/setup/thelia.sql b/setup/thelia.sql index 0bb823937..71c5c0e48 100644 --- a/setup/thelia.sql +++ b/setup/thelia.sql @@ -441,7 +441,7 @@ DROP TABLE IF EXISTS `customer`; CREATE TABLE `customer` ( `id` INTEGER NOT NULL AUTO_INCREMENT, - `ref` VARCHAR(50) NOT NULL, + `ref` VARCHAR(50), `title_id` INTEGER NOT NULL, `firstname` VARCHAR(255) NOT NULL, `lastname` VARCHAR(255) NOT NULL, @@ -651,7 +651,7 @@ DROP TABLE IF EXISTS `order`; CREATE TABLE `order` ( `id` INTEGER NOT NULL AUTO_INCREMENT, - `ref` VARCHAR(45) NOT NULL, + `ref` VARCHAR(45), `customer_id` INTEGER NOT NULL, `invoice_order_address_id` INTEGER NOT NULL, `delivery_order_address_id` INTEGER NOT NULL, diff --git a/setup/update/2.0.0.sql b/setup/update/2.0.0.sql index b4e84c04b..eef3bf051 100644 --- a/setup/update/2.0.0.sql +++ b/setup/update/2.0.0.sql @@ -28,6 +28,10 @@ ALTER TABLE `feature_template` ADD INDEX `idx_feature_template_template_id_posit ALTER TABLE `currency` ADD INDEX `idx_currency_code` (`code`); +ALTER TABLE `customer` CHANGE `ref` `ref` VARCHAR( 50 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL ; + +ALTER TABLE `order` CHANGE `ref` `ref` VARCHAR( 45 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL ; + SELECT @max := MAX(`id`) FROM `resource`; SET @max := @max+1;