refactor customer and order ref
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user