allow token to be null in cart table

This commit is contained in:
Manuel Raynaud
2013-08-06 11:53:30 +02:00
parent e0be762236
commit b18a09b94b
5 changed files with 40 additions and 9 deletions

View File

@@ -234,12 +234,14 @@ class Cart implements EventSubscriberInterface
protected function generateCookie()
{
$id = null;
if (ConfigQuery::read("cart.session_only", 0) == 0) {
$id = uniqid('', true);
setcookie("thelia_cart", $id, time()+ConfigQuery::read("cookie.lifetime", 60*60*24*365));
return $id;
}
return $id;
}
}

View File

@@ -45,6 +45,7 @@ class Customer extends BaseCustomer implements UserInterface
* @param string $phone customer phone number
* @param string $cellphone customer cellphone number
* @param string $zipcode customer zipcode
* @param string $city
* @param int $countryId customer country id (from Country table)
* @param string $email customer email, must be unique
* @param string $plainPassword customer plain password, hash is made calling setPassword method. Not mandatory parameter but an exception is thrown if customer is new without password
@@ -53,7 +54,7 @@ class Customer extends BaseCustomer implements UserInterface
* @param null $sponsor
* @param int $discount
*/
public function createOrUpdate($titleId, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $countryId, $email, $plainPassword = null, $lang = null, $reseller = 0, $sponsor = null, $discount = 0)
public function createOrUpdate($titleId, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $city, $countryId, $email, $plainPassword = null, $lang = null, $reseller = 0, $sponsor = null, $discount = 0)
{
$this
->setTitleId($titleId)
@@ -79,7 +80,7 @@ class Customer extends BaseCustomer implements UserInterface
$address = new Address();
$address
->setCustomerTitleId($titleId)
->setTitleId($titleId)
->setFirstname($firstname)
->setLastname($lastname)
->setAddress1($address1)
@@ -119,9 +120,15 @@ class Customer extends BaseCustomer implements UserInterface
return uniqid(substr($this->getLastname(), 0, (strlen($this->getLastname()) >= 3) ? 3 : strlen($this->getLastname())), true);
}
/**
* create hash for plain password and set it in Customer object
*
* @param string $password plain password before hashing
* @return $this|Customer
* @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
*/
public function setPassword($password)
{
\Thelia\Log\Tlog::getInstance()->debug($password);
if ($this->isNew() && ($password === null || trim($password) == "")) {
throw new InvalidArgumentException("customer password is mandatory on creation");
}

View File

@@ -20,6 +20,28 @@ try {
->find();
$product->delete();
$customer = Thelia\Model\CustomerQuery::create()
->find();
$customer->delete();
$customer = new Thelia\Model\Customer();
$customer->createOrUpdate(
1,
"thelia",
"thelia",
"5 rue rochon",
"",
"",
"0102030405",
"0601020304",
"63000",
"clermont-ferrand",
64,
"test@thelia.net",
"azerty"
);
//first category
$sweet = new Thelia\Model\Category();
$sweet->setParent(0);

View File

@@ -1271,7 +1271,7 @@ DROP TABLE IF EXISTS `cart`;
CREATE TABLE `cart`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`token` VARCHAR(255) NOT NULL,
`token` VARCHAR(255),
`customer_id` INTEGER,
`address_delivery_id` INTEGER,
`address_invoice_id` INTEGER,

View File

@@ -923,7 +923,7 @@
</table>
<table name="cart" namespace="Thelia\Model">
<column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER" />
<column name="token" required="true" size="255" type="VARCHAR" />
<column name="token" size="255" type="VARCHAR" />
<column name="customer_id" type="INTEGER" />
<column name="address_delivery_id" type="INTEGER" />
<column name="address_invoice_id" type="INTEGER" />
@@ -940,9 +940,6 @@
<foreign-key foreignTable="currency" name="fk_cart_currency_id">
<reference foreign="id" local="currency_id" />
</foreign-key>
<unique name="token_UNIQUE">
<unique-column name="token" />
</unique>
<index name="idx_cart_customer_id">
<index-column name="customer_id" />
</index>
@@ -955,6 +952,9 @@
<index name="idx_cart_currency_id">
<index-column name="currency_id" />
</index>
<unique name="token_UNIQUE">
<unique-column name="token" />
</unique>
<behavior name="timestampable" />
</table>
<table name="cart_item" namespace="Thelia\Model">