diff --git a/core/lib/Thelia/Action/Address.php b/core/lib/Thelia/Action/Address.php index 278f71a5b..27d46a4b7 100644 --- a/core/lib/Thelia/Action/Address.php +++ b/core/lib/Thelia/Action/Address.php @@ -73,6 +73,10 @@ class Address extends BaseAction implements EventSubscriberInterface ->save() ; + if($event->getIsDefault()) { + $addressModel->makeItDefault(); + } + $event->setAddress($addressModel); } diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index c50fd97b9..c30e576b9 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -59,7 +59,12 @@ - + + Thelia\Controller\Front\DefaultController::noAction + address + + + Thelia\Controller\Front\AddressController::createAction address diff --git a/core/lib/Thelia/Controller/Front/AddressController.php b/core/lib/Thelia/Controller/Front/AddressController.php index 5f3fb4799..c4a40d951 100644 --- a/core/lib/Thelia/Controller/Front/AddressController.php +++ b/core/lib/Thelia/Controller/Front/AddressController.php @@ -46,14 +46,13 @@ class AddressController extends BaseFrontController */ public function generateModalAction($address_id) { - if ($this->getSecurityContext()->hasCustomerUser() === false) { - $this->accessDenied(); - } - + $this->checkAuth(); $this->checkXmlHttpRequest(); } + + /** * Create controller. * Check if customer is logged in @@ -62,9 +61,7 @@ class AddressController extends BaseFrontController */ public function createAction() { - if ($this->getSecurityContext()->hasCustomerUser() === false) { - $this->accessDenied() - } + $this->checkAuth(); $addressCreate = new AddressCreateForm($this->getRequest()); @@ -98,11 +95,9 @@ class AddressController extends BaseFrontController public function updateAction() { + $this->checkAuth(); $request = $this->getRequest(); - if ($this->getSecurityContext()->hasCustomerUser() === false) { - $this->redirectToRoute("home"); - } if (null === $address_id = $request->get("address_id")) { $this->redirectToRoute("home"); @@ -164,7 +159,8 @@ class AddressController extends BaseFrontController $form->get("country")->getData(), $form->get("cellphone")->getData(), $form->get("phone")->getData(), - $form->get("company")->getData() + $form->get("company")->getData(), + $form->get("is_default")->getData() ); } } diff --git a/core/lib/Thelia/Controller/Front/BaseFrontController.php b/core/lib/Thelia/Controller/Front/BaseFrontController.php index cf83e865d..1c4a13977 100755 --- a/core/lib/Thelia/Controller/Front/BaseFrontController.php +++ b/core/lib/Thelia/Controller/Front/BaseFrontController.php @@ -50,4 +50,11 @@ class BaseFrontController extends BaseController { $this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId, array(), $referenceType), $urlParameters)); } + + public function checkAuth() + { + if($this->getSecurityContext()->hasCustomerUser() === false) { + $this->redirectToRoute("customer.login.view"); + } + } } diff --git a/core/lib/Thelia/Core/Event/AddressCreateOrUpdateEvent.php b/core/lib/Thelia/Core/Event/AddressCreateOrUpdateEvent.php index af69ae0b4..01e615ff6 100644 --- a/core/lib/Thelia/Core/Event/AddressCreateOrUpdateEvent.php +++ b/core/lib/Thelia/Core/Event/AddressCreateOrUpdateEvent.php @@ -108,7 +108,12 @@ class AddressCreateOrUpdateEvent extends ActionEvent */ protected $address; - public function __construct($label, $title, $firstname, $lastname, $address1, $address2, $address3, $zipcode, $city, $country, $cellphone, $phone, $company) + /** + * @var int + */ + protected $isDefault; + + public function __construct($label, $title, $firstname, $lastname, $address1, $address2, $address3, $zipcode, $city, $country, $cellphone, $phone, $company, $isDefault = 0) { $this->address1 = $address1; $this->address2 = $address2; @@ -123,6 +128,7 @@ class AddressCreateOrUpdateEvent extends ActionEvent $this->phone = $phone; $this->title = $title; $this->zipcode = $zipcode; + $this->isDefault = $isDefault; } /** @@ -229,6 +235,16 @@ class AddressCreateOrUpdateEvent extends ActionEvent return $this->zipcode; } + /** + * @return int + */ + public function getIsDefault() + { + return $this->isDefault; + } + + + /** * @param \Thelia\Model\Customer $customer */ diff --git a/core/lib/Thelia/Form/AddressCreateForm.php b/core/lib/Thelia/Form/AddressCreateForm.php index ed1750047..483366a1f 100644 --- a/core/lib/Thelia/Form/AddressCreateForm.php +++ b/core/lib/Thelia/Form/AddressCreateForm.php @@ -60,7 +60,7 @@ class AddressCreateForm extends BaseForm "constraints" => array( new NotBlank() ), - "label" => Translator::getInstance()->trans("Address label *"), + "label" => Translator::getInstance()->trans("Address label"), "label_attr" => array( "for" => "label_create" ), @@ -154,11 +154,17 @@ class AddressCreateForm extends BaseForm ) )) ->add("company", "text", array( - "label" => Translator::getInstance()->trans("Compagny"), + "label" => Translator::getInstance()->trans("Company"), "label_attr" => array( "for" => "company_create" ) )) + ->add("is_default", "integer", array( + "label" => Translator::getInstance()->trans("Make this address has my primary address"), + "label_attr" => array( + "for" => "default_address" + ) + )) ; } diff --git a/core/lib/Thelia/Model/Address.php b/core/lib/Thelia/Model/Address.php index dbd334ba2..9c2a390b5 100755 --- a/core/lib/Thelia/Model/Address.php +++ b/core/lib/Thelia/Model/Address.php @@ -7,10 +7,24 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Thelia\Core\Event\AddressEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Base\Address as BaseAddress; +use Thelia\Model\AddressQuery; class Address extends BaseAddress { use \Thelia\Model\Tools\ModelEventDispatcherTrait; + /** + * put the the current address as default one + */ + public function makeItDefault() + { + + AddressQuery::create()->filterByCustomerId($this->getCustomerId()) + ->update(array('isDefault' => '0')); + + $this->setIsDefault(1); + $this->save(); + } + /** * Code to be run before inserting to database * @param ConnectionInterface $con diff --git a/templates/default/account.html b/templates/default/account.html index c7edeb449..b67d6424c 100644 --- a/templates/default/account.html +++ b/templates/default/account.html @@ -1,3 +1,4 @@ +{check_auth context="front" roles="CUSTOMER" login_tpl="login"} {extends file="layout.tpl"} {block name="breadcrumb"} @@ -74,7 +75,7 @@
- {intl l="Add a new address"} + {intl l="Add a new address"} {loop type="address" name="customer.addresses"} diff --git a/templates/default/register.html b/templates/default/register.html index 7100737bc..a3448932b 100644 --- a/templates/default/register.html +++ b/templates/default/register.html @@ -96,7 +96,7 @@
- + {if $error } {$message} {elseif $value != "" && !$error} @@ -109,7 +109,7 @@
- + {if $error } {$message} {elseif $value != "" && !$error}