diff --git a/core/lib/Thelia/Action/Order.php b/core/lib/Thelia/Action/Order.php
index fcbb38f98..25c223c3e 100755
--- a/core/lib/Thelia/Action/Order.php
+++ b/core/lib/Thelia/Action/Order.php
@@ -26,6 +26,7 @@ namespace Thelia\Action;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+use Thelia\Core\Event\OrderAddressEvent;
use Thelia\Core\Event\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Exception\OrderException;
@@ -313,6 +314,30 @@ class Order extends BaseAction implements EventSubscriberInterface
$event->setOrder($order);
}
+ /**
+ * @param OrderAddressEvent $event
+ */
+ public function updateAddress(OrderAddressEvent $event)
+ {
+ $orderAddress = $event->getOrderAddress();
+
+ $orderAddress
+ ->setCustomerTitleId($event->getTitle())
+ ->setCompany($event->getCompany())
+ ->setFirstname($event->getFirstname())
+ ->setLastname($event->getLastname())
+ ->setAddress1($event->getAddress1())
+ ->setAddress2($event->getAddress2())
+ ->setAddress3($event->getAddress3())
+ ->setZipcode($event->getZipcode())
+ ->setCity($event->getCity())
+ ->setPhone($event->getPhone())
+ ;
+ $orderAddress->save();
+
+ $event->setOrderAddress($orderAddress);
+ }
+
/**
* Returns an array of event names this subscriber wants to listen to.
*
@@ -344,6 +369,7 @@ class Order extends BaseAction implements EventSubscriberInterface
TheliaEvents::ORDER_BEFORE_PAYMENT => array("sendOrderEmail", 128),
TheliaEvents::ORDER_UPDATE_STATUS => array("updateStatus", 128),
TheliaEvents::ORDER_UPDATE_DELIVERY_REF => array("updateDeliveryRef", 128),
+ TheliaEvents::ORDER_UPDATE_ADDRESS => array("updateAddress", 128),
);
}
diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml
index e3ddeeb4f..4f46bae93 100755
--- a/core/lib/Thelia/Config/Resources/routing/admin.xml
+++ b/core/lib/Thelia/Config/Resources/routing/admin.xml
@@ -82,6 +82,10 @@
Thelia\Controller\Admin\OrderController::updateDeliveryRef
+
+ Thelia\Controller\Admin\OrderController::updateAddress
+
+
diff --git a/core/lib/Thelia/Controller/Admin/OrderController.php b/core/lib/Thelia/Controller/Admin/OrderController.php
index 1c4a708a4..9331cbe2f 100644
--- a/core/lib/Thelia/Controller/Admin/OrderController.php
+++ b/core/lib/Thelia/Controller/Admin/OrderController.php
@@ -23,9 +23,12 @@
namespace Thelia\Controller\Admin;
+use Thelia\Core\Event\OrderAddressEvent;
use Thelia\Core\Event\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Translation\Translator;
+use Thelia\Form\OrderUpdateAddress;
+use Thelia\Model\Base\OrderAddressQuery;
use Thelia\Model\OrderQuery;
use Thelia\Model\OrderStatusQuery;
use Thelia\Tools\URL;
@@ -136,4 +139,60 @@ class OrderController extends BaseAdminController
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute("admin.order.update.view", $params)));
}
+
+ public function updateAddress($order_id)
+ {
+ if (null !== $response = $this->checkAuth("admin.order.update")) return $response;
+
+ $message = null;
+
+ $orderUpdateAddress = new OrderUpdateAddress($this->getRequest());
+
+ try {
+ $order = OrderQuery::create()->findPk($order_id);
+
+ if(null === $order) {
+ throw new \InvalidArgumentException("The order you want to update does not exist");
+ }
+
+ $form = $this->validateForm($orderUpdateAddress, "post");
+
+ $orderAddress = OrderAddressQuery::create()->findPk($form->get("id")->getData());
+
+ if($orderAddress->getId() !== $order->getInvoiceOrderAddressId() && $orderAddress->getId() !== $order->getDeliveryOrderAddressId()) {
+ throw new \InvalidArgumentException("The order address you want to update does not belong to the current order not exist");
+ }
+
+ $event = new OrderAddressEvent(
+ $form->get("title")->getData(),
+ $form->get("firstname")->getData(),
+ $form->get("lastname")->getData(),
+ $form->get("address1")->getData(),
+ $form->get("address2")->getData(),
+ $form->get("address3")->getData(),
+ $form->get("zipcode")->getData(),
+ $form->get("city")->getData(),
+ $form->get("country")->getData(),
+ $form->get("phone")->getData(),
+ $form->get("company")->getData()
+ );
+ $event->setOrderAddress($orderAddress);
+ $event->setOrder($order);
+
+ $this->dispatch(TheliaEvents::ORDER_UPDATE_ADDRESS, $event);
+ } catch(\Exception $e) {
+ $message = $e->getMessage();
+ }
+
+ $params = array();
+
+ if ($message) {
+ $params["update_status_error_message"] = $message;
+ }
+
+ $params["order_id"] = $order_id;
+ $params["tab"] = $this->getRequest()->get("tab", 'bill');
+
+ $this->redirect(URL::getInstance()->absoluteUrl($this->getRoute("admin.order.update.view", $params)));
+ }
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Core/Event/OrderAddressEvent.php b/core/lib/Thelia/Core/Event/OrderAddressEvent.php
new file mode 100755
index 000000000..c9fb90a0e
--- /dev/null
+++ b/core/lib/Thelia/Core/Event/OrderAddressEvent.php
@@ -0,0 +1,230 @@
+. */
+/* */
+/*************************************************************************************/
+
+namespace Thelia\Core\Event;
+
+use Thelia\Model\Order;
+use Thelia\Model\OrderAddress;
+
+class OrderAddressEvent extends ActionEvent
+{
+ /**
+ * @var int title id
+ */
+ protected $title;
+
+ /**
+ * @var string|null company name
+ */
+ protected $company;
+
+ /**
+ * @var string first name
+ */
+ protected $firstname;
+
+ /**
+ * @var string last name
+ */
+ protected $lastname;
+
+ /**
+ * @var string address
+ */
+ protected $address1;
+
+ /**
+ * @var string address line 2
+ */
+ protected $address2;
+
+ /**
+ * @var string address line 3
+ */
+ protected $address3;
+
+ /**
+ * @var string zipcode
+ */
+ protected $zipcode;
+
+ /**
+ * @var string city
+ */
+ protected $city;
+
+ /**
+ * @var int country id
+ */
+ protected $country;
+
+ /**
+ * @var string phone
+ */
+ protected $phone;
+
+ /**
+ * @var \Thelia\Model\OrderAddress
+ */
+ protected $orderAddress;
+
+ /**
+ * @var \Thelia\Model\Order
+ */
+ protected $order;
+
+ public function __construct($title, $firstname, $lastname, $address1, $address2, $address3, $zipcode, $city, $country, $phone, $company)
+ {
+ $this->address1 = $address1;
+ $this->address2 = $address2;
+ $this->address3 = $address3;
+ $this->city = $city;
+ $this->company = $company;
+ $this->country = $country;
+ $this->firstname = $firstname;
+ $this->lastname = $lastname;
+ $this->phone = $phone;
+ $this->title = $title;
+ $this->zipcode = $zipcode;
+ }
+
+ /**
+ * @return string
+ */
+ public function getAddress1()
+ {
+ return $this->address1;
+ }
+
+ /**
+ * @return string
+ */
+ public function getAddress2()
+ {
+ return $this->address2;
+ }
+
+ /**
+ * @return string
+ */
+ public function getAddress3()
+ {
+ return $this->address3;
+ }
+
+ /**
+ * @return string
+ */
+ public function getCity()
+ {
+ return $this->city;
+ }
+
+ /**
+ * @return null|string
+ */
+ public function getCompany()
+ {
+ return $this->company;
+ }
+
+ /**
+ * @return int
+ */
+ public function getCountry()
+ {
+ return $this->country;
+ }
+
+ /**
+ * @return string
+ */
+ public function getFirstname()
+ {
+ return $this->firstname;
+ }
+
+ /**
+ * @return string
+ */
+ public function getLastname()
+ {
+ return $this->lastname;
+ }
+
+ /**
+ * @return string
+ */
+ public function getPhone()
+ {
+ return $this->phone;
+ }
+
+ /**
+ * @return int
+ */
+ public function getTitle()
+ {
+ return $this->title;
+ }
+
+ /**
+ * @return string
+ */
+ public function getZipcode()
+ {
+ return $this->zipcode;
+ }
+
+ /**
+ * @param \Thelia\Model\OrderAddress $orderAddress
+ */
+ public function setOrderAddress(OrderAddress $orderAddress)
+ {
+ $this->orderAddress = $orderAddress;
+ }
+
+ /**
+ * @param \Thelia\Model\Order $order
+ */
+ public function setOrder(Order $order)
+ {
+ $this->order = $order;
+ }
+
+ /**
+ * @return \Thelia\Model\OrderAddress
+ */
+ public function getOrderAddress()
+ {
+ return $this->orderAddress;
+ }
+
+ /**
+ * @return \Thelia\Model\Order
+ */
+ public function getOrder()
+ {
+ return $this->order;
+ }
+}
diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php
index 1833f838f..4c3151af6 100755
--- a/core/lib/Thelia/Core/Event/TheliaEvents.php
+++ b/core/lib/Thelia/Core/Event/TheliaEvents.php
@@ -303,6 +303,7 @@ final class TheliaEvents
const ORDER_UPDATE_STATUS = "action.order.updateStatus";
const ORDER_UPDATE_DELIVERY_REF = "action.order.updateDeliveryRef";
+ const ORDER_UPDATE_ADDRESS = "action.order.updateAddress";
const ORDER_PRODUCT_BEFORE_CREATE = "action.orderProduct.beforeCreate";
const ORDER_PRODUCT_AFTER_CREATE = "action.orderProduct.afterCreate";
diff --git a/core/lib/Thelia/Form/OrderUpdateAddress.php b/core/lib/Thelia/Form/OrderUpdateAddress.php
index 80cb92ba8..21ddbf340 100644
--- a/core/lib/Thelia/Form/OrderUpdateAddress.php
+++ b/core/lib/Thelia/Form/OrderUpdateAddress.php
@@ -22,8 +22,13 @@
/*************************************************************************************/
namespace Thelia\Form;
+use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Constraints\NotBlank;
+use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
+use Thelia\Model\CountryQuery;
+use Thelia\Model\CustomerTitleQuery;
+use Thelia\Model\OrderAddressQuery;
/**
* Class AddressUpdateForm
@@ -35,9 +40,25 @@ class OrderUpdateAddress extends BaseForm
protected function buildForm()
{
$this->formBuilder
+ ->add("id", "integer", array(
+ "constraints" => array(
+ new NotBlank(),
+ new Callback(array(
+ "methods" => array(
+ array($this, "verifyId")
+ )
+ ))
+ ),
+ "required" => true
+ ))
->add("title", "text", array(
"constraints" => array(
- new NotBlank()
+ new NotBlank(),
+ new Callback(array(
+ "methods" => array(
+ array($this, "verifyTitle")
+ )
+ ))
),
"label" => Translator::getInstance()->trans("Title"),
"label_attr" => array(
@@ -103,7 +124,12 @@ class OrderUpdateAddress extends BaseForm
))
->add("country", "text", array(
"constraints" => array(
- new NotBlank()
+ new NotBlank(),
+ new Callback(array(
+ "methods" => array(
+ array($this, "verifyCountry")
+ )
+ ))
),
"label" => Translator::getInstance()->trans("Country"),
"label_attr" => array(
@@ -133,4 +159,34 @@ class OrderUpdateAddress extends BaseForm
{
return "thelia_order_address_update";
}
+
+ public function verifyId($value, ExecutionContextInterface $context)
+ {
+ $address = OrderAddressQuery::create()
+ ->findPk($value);
+
+ if(null === $address) {
+ $context->addViolation("Order address ID not found");
+ }
+ }
+
+ public function verifyTitle($value, ExecutionContextInterface $context)
+ {
+ $address = CustomerTitleQuery::create()
+ ->findPk($value);
+
+ if(null === $address) {
+ $context->addViolation("Title ID not found");
+ }
+ }
+
+ public function verifyCountry($value, ExecutionContextInterface $context)
+ {
+ $address = CountryQuery::create()
+ ->findPk($value);
+
+ if(null === $address) {
+ $context->addViolation("Country ID not found");
+ }
+ }
}
diff --git a/templates/admin/default/order-edit.html b/templates/admin/default/order-edit.html
index 9def1beba..76e4b2465 100644
--- a/templates/admin/default/order-edit.html
+++ b/templates/admin/default/order-edit.html
@@ -196,7 +196,7 @@
{intl l='PDF | Invoice'}
-
+
@@ -212,47 +212,47 @@
{loop type="order_address" name="order-invoice-address" id=$INVOICE_ADDRESS}
-
+
| {intl l="Title"} |
{loop type="title" name="order-invoice-address-title" id=$TITLE}{$LONG}{/loop} |
-
+
| {intl l="Company"} |
{$COMPANY} |
-
+
| {intl l="Firstname"} |
{$FIRSTNAME} |
-
+
| {intl l="Lastname"} |
{$LASTNAME} |
-
+
| {intl l="Street address"} |
{$ADDRESS1} |
-
+
| {intl l="Additional address"} |
{$ADDRESS2} |
-
+
| {intl l="Additional address"} |
{$ADDRESS3} |
-
+
| {intl l="Zip code"} |
{$ZIPCODE} |
-
+
| {intl l="City"} |
{$CITY} |
-
+
| {intl l="Country"} |
{loop type="country" name="order-invoice-address-country" id=$COUNTRY}{$TITLE}{/loop} |
-
+
| {intl l="Phone"} |
{$PHONE} |
@@ -271,54 +271,54 @@
{intl l='PDF | Purchase order'}
-
+
{loop type="order_address" name="order-delivery-address" id=$DELIVERY_ADDRESS}
-
+
| {intl l="Title"} |
{loop type="title" name="order-delivery-address-title" id=$TITLE}{$LONG}{/loop} |
-
+
| {intl l="Company"} |
{$COMPANY} |
-
+
| {intl l="Firstname"} |
{$FIRSTNAME} |
-
+
| {intl l="Lastname"} |
{$LASTNAME} |
-
+
| {intl l="Street address"} |
{$ADDRESS1} |
-
+
| {intl l="Additional address"} |
{$ADDRESS2} |
-
+
| {intl l="Additional address"} |
{$ADDRESS3} |
-
+
| {intl l="Zip code"} |
{$ZIPCODE} |
-
+
| {intl l="City"} |
{$CITY} |
-
+
| {intl l="Country"} |
{loop type="country" name="order-delivery-address-country" id=$COUNTRY}{$TITLE}{/loop} |
-
+
| {intl l="Phone"} |
{$PHONE} |
@@ -355,22 +355,26 @@
{form name="thelia.order.update.address"}
{* Capture the dialog body, to pass it to the generic dialog *}
- {capture "edit_address_dialog"}
+ {capture "edit_order_address_dialog"}
{form_hidden_fields form=$form}
+ {form_field form=$form field='id'}
+
+ {/form_field}
+
{form_field form=$form field='company'}
-
+
{/form_field}
-
+
{form_field form=$form field='title'}