fiw non saving customer title

This commit is contained in:
Manuel Raynaud
2013-07-02 15:00:34 +02:00
parent 33aba6b3d5
commit 363e0ab8ae
4 changed files with 45 additions and 1 deletions

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Event\ActionEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\BaseForm;
use Thelia\Form\CustomerCreation;
use Thelia\Log\Tlog;
class Customer implements EventSubscriberInterface
{
@@ -48,6 +49,26 @@ class Customer implements EventSubscriberInterface
$form->bind($request);
if ($form->isValid()) {
$data = $form->getData();
$customer = new \Thelia\Model\Customer();
try {
$customer->createOrUpdate(
$data["title"],
$data["firstname"],
$data["lastname"],
$data["address1"],
$data["address2"],
$data["address3"],
$data["phone"],
$data["cellphone"],
$data["zipcode"],
$data["country"],
$data["email"],
$data["password"]
);
} catch (\PropelException $e) {
Tlog::getInstance()->error(sprintf('error during creating customer on action/createCustomer with message "%s"', $e->getMessage()));
}
echo "ok"; exit;
} else {

View File

@@ -85,6 +85,12 @@ class CustomerCreation extends BaseForm
),
"label" => "country"
))
->add("title", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "title"
))
->add("email", "email", array(
"constraints" => array(
new Constraints\NotBlank(),

View File

@@ -18,9 +18,10 @@ use Thelia\Model\om\BaseCustomer;
*/
class Customer extends BaseCustomer
{
public function create($titleId, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $countryId, $email, $plainPassword, $reseller = 0, $sponsor = null, $discount = 0 )
public function createOrUpdate($titleId, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $countryId, $email, $plainPassword, $reseller = 0, $sponsor = null, $discount = 0 )
{
$this
->setCustomerTitleId($titleId)
->setFirstname($firstname)
->setLastname($lastname)
->setAddress1($address1)
@@ -35,6 +36,7 @@ class Customer extends BaseCustomer
->setReseller($reseller)
->setSponsor($sponsor)
->setDiscount($discount)
->save()
;
}

View File

@@ -4,6 +4,21 @@
<form method="post" action="index_dev.php?action=createCustomer&view=connexion" {form_enctype form=$form} >
{form_field_hidden form=$form}
{form_field form=$form.title}
{form_error form=$form.title}
{$message}
{/form_error}
<label> <span>{intl l="{$label}"} : </span></label>
<select name="{$name}">
<option value="1">M.</option>
<option value="2">Mme.</option>
</select>
<br />
{/form_field}
{form_field form=$form.firstname}
{form_error form=$form.firstname}
{$message}