Merge pull request #179 from lunika/178-customer-ref-is-missing
This PR was merged into thelia:master branch.
Discussion
----------
Allow possiblity to specify a ref for a customer
| Q | A |
| --- | --- |
| Bug fix? | y |
| New feature? | y |
| BC breaks? | n |
| Deprecations? | n |
| Tests pass? | y |
| Fixed tickets | #178 |
| License | GPL |
| Doc PR | |
Commits
-------
4e1521775f alloow possibility to specify a ref for a customer lunika
This commit is contained in:
@@ -111,7 +111,8 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
||||
$event->getReseller(),
|
||||
$event->getSponsor(),
|
||||
$event->getDiscount(),
|
||||
$event->getCompany()
|
||||
$event->getCompany(),
|
||||
$event->getRef()
|
||||
);
|
||||
|
||||
$event->setCustomer($customer);
|
||||
|
||||
@@ -149,7 +149,8 @@ class CustomerController extends AbstractCrudController
|
||||
isset($data["reseller"])?$data["reseller"]:null,
|
||||
isset($data["sponsor"])?$data["sponsor"]:null,
|
||||
isset($data["discount"])?$data["discount"]:null,
|
||||
isset($data["company"])?$data["company"]:null
|
||||
isset($data["company"])?$data["company"]:null,
|
||||
null
|
||||
);
|
||||
|
||||
return $customerCreateEvent;
|
||||
|
||||
@@ -51,6 +51,7 @@ class CustomerCreateOrUpdateEvent extends CustomerEvent
|
||||
protected $sponsor;
|
||||
protected $discount;
|
||||
protected $company;
|
||||
protected $ref;
|
||||
|
||||
/**
|
||||
* @param int $title the title customer id
|
||||
@@ -71,8 +72,9 @@ class CustomerCreateOrUpdateEvent extends CustomerEvent
|
||||
* @param int $sponsor customer's id sponsor
|
||||
* @param float $discount
|
||||
* @param string $company
|
||||
* @param string $ref
|
||||
*/
|
||||
public function __construct($title, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $city, $country, $email, $password, $lang, $reseller, $sponsor, $discount, $company)
|
||||
public function __construct($title, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $city, $country, $email, $password, $lang, $reseller, $sponsor, $discount, $company, $ref)
|
||||
{
|
||||
$this->address1 = $address1;
|
||||
$this->address2 = $address2;
|
||||
@@ -92,6 +94,7 @@ class CustomerCreateOrUpdateEvent extends CustomerEvent
|
||||
$this->sponsor = $sponsor;
|
||||
$this->discount = $discount;
|
||||
$this->company = $company;
|
||||
$this->ref = $ref;
|
||||
}
|
||||
/**
|
||||
* @return mixed
|
||||
@@ -236,4 +239,14 @@ class CustomerCreateOrUpdateEvent extends CustomerEvent
|
||||
{
|
||||
return $this->sponsor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRef()
|
||||
{
|
||||
return $this->ref;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class Customer extends BaseCustomer implements UserInterface
|
||||
* @param int $discount
|
||||
* @throws \Exception|\Symfony\Component\Config\Definition\Exception\Exception
|
||||
*/
|
||||
public function createOrUpdate($titleId, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $city, $countryId, $email = null, $plainPassword = null, $lang = null, $reseller = 0, $sponsor = null, $discount = 0, $company = null)
|
||||
public function createOrUpdate($titleId, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $city, $countryId, $email = null, $plainPassword = null, $lang = null, $reseller = 0, $sponsor = null, $discount = 0, $company = null, $ref = null)
|
||||
{
|
||||
$this
|
||||
->setTitleId($titleId)
|
||||
@@ -65,6 +65,7 @@ class Customer extends BaseCustomer implements UserInterface
|
||||
->setReseller($reseller)
|
||||
->setSponsor($sponsor)
|
||||
->setDiscount($discount)
|
||||
->setRef($ref)
|
||||
;
|
||||
|
||||
if(!is_null($lang)) {
|
||||
@@ -162,6 +163,17 @@ class Customer extends BaseCustomer implements UserInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setRef($ref)
|
||||
{
|
||||
if(null === $ref && null === $this->ref) {
|
||||
parent::setRef($this->generateRef());
|
||||
} else if(null !== $ref) {
|
||||
parent::setRef($ref);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setEmail($email, $force = false)
|
||||
{
|
||||
$email = trim($email);
|
||||
@@ -242,7 +254,9 @@ class Customer extends BaseCustomer implements UserInterface
|
||||
// Set the serial number (for auto-login)
|
||||
$this->setRememberMeSerial(uniqid());
|
||||
|
||||
$this->setRef($this->generateRef());
|
||||
if (null === $this->ref) {
|
||||
$this->setRef($this->generateRef());
|
||||
}
|
||||
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_CREATECUSTOMER, new CustomerEvent($this));
|
||||
return true;
|
||||
|
||||
@@ -63,7 +63,8 @@ class CustomerTest extends \PHPUnit_Framework_TestCase
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
'My super company'
|
||||
'My super company',
|
||||
null
|
||||
);
|
||||
|
||||
$customerAction = new Customer($this->getContainer());
|
||||
@@ -79,9 +80,69 @@ class CustomerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($customerCreateEvent->getLastname(), $customerCreated->getLastname());
|
||||
$this->assertEquals($customerCreateEvent->getTitle(), $customerCreated->getTitleId());
|
||||
$this->assertEquals($customerCreateEvent->getEmail(), $customerCreated->getEmail());
|
||||
$this->assertEquals($customerCreated->getReseller(), $customerCreated->getReseller());
|
||||
$this->assertEquals($customerCreated->getSponsor(), $customerCreated->getSponsor());
|
||||
$this->assertEquals($customerCreated->getDiscount(), $customerCreated->getDiscount());
|
||||
$this->assertEquals($customerCreateEvent->getReseller(), $customerCreated->getReseller());
|
||||
$this->assertEquals($customerCreateEvent->getSponsor(), $customerCreated->getSponsor());
|
||||
$this->assertEquals($customerCreateEvent->getDiscount(), $customerCreated->getDiscount());
|
||||
|
||||
$addressCreated = $customerCreated->getDefaultAddress();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Address", $addressCreated);
|
||||
|
||||
$this->assertEquals($customerCreateEvent->getFirstname(), $addressCreated->getFirstname());
|
||||
$this->assertEquals($customerCreateEvent->getLastname(), $addressCreated->getLastname());
|
||||
$this->assertEquals($customerCreateEvent->getTitle(), $addressCreated->getTitleId());
|
||||
$this->assertEquals($customerCreateEvent->getAddress1(), $addressCreated->getAddress1());
|
||||
$this->assertEquals($customerCreateEvent->getAddress2(), $addressCreated->getAddress2());
|
||||
$this->assertEquals($customerCreateEvent->getAddress3(), $addressCreated->getAddress3());
|
||||
$this->assertEquals($customerCreateEvent->getZipcode(), $addressCreated->getZipcode());
|
||||
$this->assertEquals($customerCreateEvent->getCity(), $addressCreated->getCity());
|
||||
$this->assertEquals($customerCreateEvent->getCountry(), $addressCreated->getCountryId());
|
||||
$this->assertEquals($customerCreateEvent->getPhone(), $addressCreated->getPhone());
|
||||
$this->assertEquals($customerCreateEvent->getCellphone(), $addressCreated->getCellphone());
|
||||
$this->assertEquals($customerCreateEvent->getCompany(), $addressCreated->getCompany());
|
||||
}
|
||||
|
||||
public function testCreatedCustomerWithSpecifiedRef()
|
||||
{
|
||||
$customerCreateEvent = new CustomerCreateOrUpdateEvent(
|
||||
1,
|
||||
"thelia",
|
||||
"thelia",
|
||||
"street address 1",
|
||||
"street address 2",
|
||||
"street address 3",
|
||||
"0102030405",
|
||||
"0607080910",
|
||||
"63000",
|
||||
"clermont-ferrand",
|
||||
64,
|
||||
sprintf("%s@thelia.fr", uniqid()),
|
||||
uniqid(),
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
'My super company',
|
||||
'testRef'
|
||||
);
|
||||
|
||||
$customerAction = new Customer($this->getContainer());
|
||||
|
||||
$customerAction->create($customerCreateEvent);
|
||||
|
||||
$customerCreated = $customerCreateEvent->getCustomer();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Customer", $customerCreated, "new customer created must be an instance of Thelia\Model\Customer");
|
||||
$this->assertFalse($customerCreated->isNew());
|
||||
|
||||
$this->assertEquals($customerCreateEvent->getFirstname(), $customerCreated->getFirstname());
|
||||
$this->assertEquals($customerCreateEvent->getLastname(), $customerCreated->getLastname());
|
||||
$this->assertEquals($customerCreateEvent->getTitle(), $customerCreated->getTitleId());
|
||||
$this->assertEquals($customerCreateEvent->getEmail(), $customerCreated->getEmail());
|
||||
$this->assertEquals($customerCreateEvent->getReseller(), $customerCreated->getReseller());
|
||||
$this->assertEquals($customerCreateEvent->getSponsor(), $customerCreated->getSponsor());
|
||||
$this->assertEquals($customerCreateEvent->getDiscount(), $customerCreated->getDiscount());
|
||||
$this->assertEquals($customerCreateEvent->getRef(), $customerCreated->getRef());
|
||||
|
||||
$addressCreated = $customerCreated->getDefaultAddress();
|
||||
|
||||
|
||||
@@ -381,7 +381,8 @@ class CustomerController extends BaseFrontController
|
||||
isset($data["reseller"])?$data["reseller"]:null,
|
||||
isset($data["sponsor"])?$data["sponsor"]:null,
|
||||
isset($data["discount"])?$data["discount"]:null,
|
||||
isset($data["company"])?$data["company"]:null
|
||||
isset($data["company"])?$data["company"]:null,
|
||||
null
|
||||
);
|
||||
|
||||
return $customerCreateEvent;
|
||||
|
||||
Reference in New Issue
Block a user