allow to make an address as default on update action
This commit is contained in:
@@ -73,6 +73,10 @@ class Address extends BaseAction implements EventSubscriberInterface
|
||||
->save()
|
||||
;
|
||||
|
||||
if($event->getIsDefault()) {
|
||||
$addressModel->makeItDefault();
|
||||
}
|
||||
|
||||
$event->setAddress($addressModel);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,12 @@
|
||||
<!-- end customer routes -->
|
||||
|
||||
<!-- customer address routes -->
|
||||
<route id="address.create" path="/address/create" >
|
||||
<route id="address.create.view" path="/address/create" methods="get">
|
||||
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
||||
<default key="_view">address</default>
|
||||
</route>
|
||||
|
||||
<route id="address.create" path="/address/create" methods="post" >
|
||||
<default key="_controller">Thelia\Controller\Front\AddressController::createAction</default>
|
||||
<default key="_view">address</default>
|
||||
</route>
|
||||
|
||||
@@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
{check_auth context="front" roles="CUSTOMER" login_tpl="login"}
|
||||
{extends file="layout.tpl"}
|
||||
|
||||
{block name="breadcrumb"}
|
||||
@@ -74,7 +75,7 @@
|
||||
</div>
|
||||
<div id="account-address" class="panel-collapse collapse">
|
||||
<div class="panel-body">
|
||||
<a href="address.php" class="btn btn-add-address">{intl l="Add a new address"}</a>
|
||||
<a href="{url path="/address/create"}" class="btn btn-add-address">{intl l="Add a new address"}</a>
|
||||
<table class="table table-address" role="presentation" summary="{intl l="My Address Books"}">
|
||||
<tbody>
|
||||
{loop type="address" name="customer.addresses"}
|
||||
|
||||
@@ -96,7 +96,7 @@
|
||||
<div class="form-group group-phone {if $error}has-error{elseif $value != "" && !$error}has-success{/if}">
|
||||
<label class="control-label" for="{$label_attr.for}">{$label}</label>
|
||||
<div class="control-input">
|
||||
<input type="text" name="{$name}" id="{$label_attr.for}" class="form-control" placeholder="John" value="{$value}" autofocus>
|
||||
<input type="text" name="{$name}" id="{$label_attr.for}" class="form-control" placeholder="" value="{$value}" autofocus>
|
||||
{if $error }
|
||||
<span class="help-block"><i class="icon-remove"></i> {$message}</span>
|
||||
{elseif $value != "" && !$error}
|
||||
@@ -109,7 +109,7 @@
|
||||
<div class="form-group group-cellphone {if $error}has-error{elseif $value != "" && !$error}has-success{/if}">
|
||||
<label class="control-label" for="{$label_attr.for}">{$label}</label>
|
||||
<div class="control-input">
|
||||
<input type="text" name="{$name}" id="{$label_attr.for}" class="form-control" placeholder="John" value="{$value}" autofocus>
|
||||
<input type="text" name="{$name}" id="{$label_attr.for}" class="form-control" placeholder="" value="{$value}" autofocus>
|
||||
{if $error }
|
||||
<span class="help-block"><i class="icon-remove"></i> {$message}</span>
|
||||
{elseif $value != "" && !$error}
|
||||
|
||||
Reference in New Issue
Block a user