diff --git a/Readme.md b/Readme.md index 66d831f94..1134ccb68 100755 --- a/Readme.md +++ b/Readme.md @@ -16,6 +16,16 @@ Requirements ------------ * php 5.4 + * Required extensions : + * PDO_Mysql + * mcrypt + * intl + * gd + * curl + * safe_mode off + * memory_limit at least 150M, preferably 256. + * post_max_size 20M + * upload_max_filesize 2M * apache 2 * mysql 5 diff --git a/core/lib/Thelia/Action/Address.php b/core/lib/Thelia/Action/Address.php index b25c9c4ba..f6c6a81ad 100644 --- a/core/lib/Thelia/Action/Address.php +++ b/core/lib/Thelia/Action/Address.php @@ -60,6 +60,13 @@ class Address extends BaseAction implements EventSubscriberInterface $address->delete(); } + public function useDefault(AddressEvent $event) + { + $address = $event->getAddress(); + + $address->makeItDefault(); + } + protected function createOrUpdate(AddressModel $addressModel, AddressCreateOrUpdateEvent $event) { $addressModel->setDispatcher($this->getDispatcher()); @@ -125,7 +132,8 @@ class Address extends BaseAction implements EventSubscriberInterface return array( TheliaEvents::ADDRESS_CREATE => array("create", 128), TheliaEvents::ADDRESS_UPDATE => array("update", 128), - TheliaEvents::ADDRESS_DELETE => array("delete", 128) + TheliaEvents::ADDRESS_DELETE => array("delete", 128), + TheliaEvents::ADDRESS_DEFAULT => array('useDefault', 128), ); } } diff --git a/core/lib/Thelia/Action/Customer.php b/core/lib/Thelia/Action/Customer.php index 061dba028..85643cb88 100755 --- a/core/lib/Thelia/Action/Customer.php +++ b/core/lib/Thelia/Action/Customer.php @@ -25,6 +25,7 @@ namespace Thelia\Action; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\ActionEvent; +use Thelia\Core\Event\Customer\CustomerAddressEvent; use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent; use Thelia\Core\Event\Customer\CustomerEvent; use Thelia\Core\Event\TheliaEvents; @@ -148,11 +149,11 @@ class Customer extends BaseAction implements EventSubscriberInterface public static function getSubscribedEvents() { return array( - TheliaEvents::CUSTOMER_CREATEACCOUNT => array("create", 128), - TheliaEvents::CUSTOMER_UPDATEACCOUNT => array("modify", 128), - TheliaEvents::CUSTOMER_LOGOUT => array("logout", 128), - TheliaEvents::CUSTOMER_LOGIN => array("login" , 128), - TheliaEvents::CUSTOMER_DELETEACCOUNT => array("delete", 128), + TheliaEvents::CUSTOMER_CREATEACCOUNT => array('create', 128), + TheliaEvents::CUSTOMER_UPDATEACCOUNT => array('modify', 128), + TheliaEvents::CUSTOMER_LOGOUT => array('logout', 128), + TheliaEvents::CUSTOMER_LOGIN => array('login', 128), + TheliaEvents::CUSTOMER_DELETEACCOUNT => array('delete', 128), ); } } diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 509162cbf..2f85b57bc 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -123,6 +123,32 @@ + + + + Thelia\Controller\Admin\AddressController::deleteAction + + + + Thelia\Controller\Admin\AddressController::useAddressAction + + + + Thelia\Controller\Admin\AddressController::createAction + + + + Thelia\Controller\Admin\AddressController::updateAction + \d+ + + + + Thelia\Controller\Admin\AddressController::processUpdateAction + \d+ + + + + diff --git a/core/lib/Thelia/Controller/Admin/AddressController.php b/core/lib/Thelia/Controller/Admin/AddressController.php new file mode 100644 index 000000000..38ec9cb6b --- /dev/null +++ b/core/lib/Thelia/Controller/Admin/AddressController.php @@ -0,0 +1,306 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Controller\Admin; +use Thelia\Core\Event\Address\AddressCreateOrUpdateEvent; +use Thelia\Core\Event\Address\AddressEvent; +use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Form\AddressCreateForm; +use Thelia\Form\AddressUpdateForm; +use Thelia\Model\AddressQuery; +use Thelia\Model\CustomerQuery; + + +/** + * Class AddressController + * @package Thelia\Controller\Admin + * @author Manuel Raynaud + */ +class AddressController extends AbstractCrudController +{ + public function __construct() + { + parent::__construct( + 'address', + null, + null, + + 'admin.customer.update.view', + 'admin.address.create', + 'admin.address.update', + 'admin.address.delete', + + TheliaEvents::ADDRESS_CREATE, + TheliaEvents::ADDRESS_UPDATE, + TheliaEvents::ADDRESS_DELETE, + null, + null + + ); + } + + public function useAddressAction() + { + if (null !== $response = $this->checkAuth("admin.customer.update")) return $response; + + $address_id = $this->getRequest()->request->get('address_id'); + + try { + $address = AddressQuery::create()->findPk($address_id); + + if (null === $address) { + throw new \InvalidArgumentException(sprintf('%d address does not exists', $address_id)); + } + + $addressEvent = new AddressEvent($address); + + $this->dispatch(TheliaEvents::ADDRESS_DEFAULT, $addressEvent); + + $this->adminLogAppend(sprintf("address %d for customer %d removal", $address_id, $address->getCustomerId())); + } catch(\Exception $e) { + \Thelia\Log\Tlog::getInstance()->error(sprintf("error during address removal with message %s", $e->getMessage())); + } + + $this->redirectToRoute('admin.customer.update.view', array(), array('customer_id' => $address->getCustomerId())); + } + + /** + * Return the creation form for this object + */ + protected function getCreationForm() + { + return new AddressCreateForm($this->getRequest()); + } + + /** + * Return the update form for this object + */ + protected function getUpdateForm() + { + return new AddressUpdateForm($this->getRequest()); + } + + /** + * Hydrate the update form for this object, before passing it to the update template + * + * @param \Thelia\Model\Address $object + */ + protected function hydrateObjectForm($object) + { + $data = array( + "label" => $object->getLabel(), + "title" => $object->getTitleId(), + "firstname" => $object->getFirstname(), + "lastname" => $object->getLastname(), + "address1" => $object->getAddress1(), + "address2" => $object->getAddress2(), + "address3" => $object->getAddress3(), + "zipcode" => $object->getZipcode(), + "city" => $object->getCity(), + "country" => $object->getCountryId(), + "cellphone" => $object->getCellphone(), + "phone" => $object->getPhone(), + "company" => $object->getCompany() + ); + + return new AddressUpdateForm($this->getRequest(), "form", $data); + } + + /** + * Creates the creation event with the provided form data + * + * @param unknown $formData + */ + protected function getCreationEvent($formData) + { + $event = $this->getCreateOrUpdateEvent($formData); + + $customer = CustomerQuery::create()->findPk($this->getRequest()->get("customer_id")); + + $event->setCustomer($customer); + + return $event; + } + + /** + * Creates the update event with the provided form data + * + * @param unknown $formData + */ + protected function getUpdateEvent($formData) + { + $event = $this->getCreateOrUpdateEvent($formData); + + $event->setAddress($this->getExistingObject()); + + return $event; + } + + protected function getCreateOrUpdateEvent($formData) + { + $event = new AddressCreateOrUpdateEvent( + $formData["label"], + $formData["title"], + $formData["firstname"], + $formData["lastname"], + $formData["address1"], + $formData["address2"], + $formData["address3"], + $formData["zipcode"], + $formData["city"], + $formData["country"], + $formData["cellphone"], + $formData["phone"], + $formData["company"], + $formData["is_default"] + ); + + + + return $event; + + } + + /** + * Creates the delete event with the provided form data + */ + protected function getDeleteEvent() + { + return new AddressEvent($this->getExistingObject()); + } + + /** + * Return true if the event contains the object, e.g. the action has updated the object in the event. + * + * @param unknown $event + */ + protected function eventContainsObject($event) + { + return null !== $event->getAddress(); + } + + /** + * Get the created object from an event. + * + * @param unknown $createEvent + */ + protected function getObjectFromEvent($event) + { + return null; + } + + /** + * Load an existing object from the database + */ + protected function getExistingObject() + { + return AddressQuery::create()->findPk($this->getRequest()->get('address_id')); + } + + /** + * Returns the object label form the object event (name, title, etc.) + * + * @param unknown $object + */ + protected function getObjectLabel($object) + { + return $object->getLabel(); + } + + /** + * Returns the object ID from the object + * + * @param unknown $object + */ + protected function getObjectId($object) + { + return $object->getId(); + } + + /** + * Render the main list template + * + * @param unknown $currentOrder, if any, null otherwise. + */ + protected function renderListTemplate($currentOrder) + { + // TODO: Implement renderListTemplate() method. + } + + /** + * Render the edition template + */ + protected function renderEditionTemplate() + { + return $this->render('ajax/address-update-modal', array( + "address_id" => $this->getRequest()->get('address_id'), + "customer_id" => $this->getExistingObject()->getCustomerId() + )); + } + + /** + * Redirect to the edition template + */ + protected function redirectToEditionTemplate() + { + $address = $this->getExistingObject(); + $this->redirectToRoute('admin.customer.update.view', array(), array('customer_id' => $address->getCustomerId())); + } + + /** + * Redirect to the list template + */ + protected function redirectToListTemplate() + { + // TODO: Implement redirectToListTemplate() method. + } + + /** + * Put in this method post object delete processing if required. + * + * @param \Thelia\Core\Event\AddressEvent $deleteEvent the delete event + * @return Response a response, or null to continue normal processing + */ + protected function performAdditionalDeleteAction($deleteEvent) + { + $address = $deleteEvent->getAddress(); + $this->redirectToRoute('admin.customer.update.view', array(), array('customer_id' => $address->getCustomerId())); + } + + /** + * Put in this method post object creation processing if required. + * + * @param AddressCreateOrUpdateEvent $createEvent the create event + * @return Response a response, or null to continue normal processing + */ + protected function performAdditionalCreateAction($createEvent) + { + $this->redirectToEditionTemplate(); + } + + protected function performAdditionalUpdateAction($event) + { + $this->redirectToEditionTemplate(); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Controller/Admin/BaseAdminController.php b/core/lib/Thelia/Controller/Admin/BaseAdminController.php index 2401617f3..5d99a877b 100755 --- a/core/lib/Thelia/Controller/Admin/BaseAdminController.php +++ b/core/lib/Thelia/Controller/Admin/BaseAdminController.php @@ -51,7 +51,7 @@ class BaseAdminController extends BaseController /** * Helper to append a message to the admin log. * - * @param unknown $message + * @param string $message */ public function adminLogAppend($message) { @@ -246,9 +246,9 @@ class BaseAdminController extends BaseController * @param unknown $routeId the route ID, as found in Config/Resources/routing/admin.xml * @param unknown $urlParameters the URL parametrs, as a var/value pair array */ - public function redirectToRoute($routeId, $urlParameters = array()) + public function redirectToRoute($routeId, $urlParameters = array(), $routeParameters = array()) { - $this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId), $urlParameters)); + $this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId, $routeParameters), $urlParameters)); } /** diff --git a/core/lib/Thelia/Controller/Admin/CustomerController.php b/core/lib/Thelia/Controller/Admin/CustomerController.php index f559a5bb0..e4d24e9ad 100644 --- a/core/lib/Thelia/Controller/Admin/CustomerController.php +++ b/core/lib/Thelia/Controller/Admin/CustomerController.php @@ -22,13 +22,17 @@ /*************************************************************************************/ namespace Thelia\Controller\Admin; + use Propel\Runtime\Exception\PropelException; use Symfony\Component\Form\Form; +use Thelia\Core\Event\Address\AddressEvent; +use Thelia\Core\Event\Customer\CustomerAddressEvent; use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent; use Thelia\Core\Event\Customer\CustomerEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Form\CustomerModification; use Thelia\Form\Exception\FormValidationException; +use Thelia\Model\AddressQuery; use Thelia\Model\CustomerQuery; use Thelia\Core\Translation\Translator; @@ -53,6 +57,8 @@ class CustomerController extends BaseAdminController )); } + + /** * update customer action * diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 9ffe08bcb..f0dc68702 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -76,6 +76,11 @@ final class TheliaEvents */ const CUSTOMER_DELETEACCOUNT = "action.deleteCustomer"; + /** + * sent on customer address removal + */ + const CUSTOMER_ADDRESS_DELETE = "action.customer.deleteAddress"; + /** * sent when a customer need a new password */ @@ -134,6 +139,11 @@ final class TheliaEvents */ const ADDRESS_DELETE = "action.deleteAddress"; + /** + * sent when an address is tag as default + */ + const ADDRESS_DEFAULT = "action.defaultAddress"; + const BEFORE_CREATEADDRESS = "action.before_createAddress"; const AFTER_CREATEADDRESS = "action.after_createAddress"; diff --git a/core/lib/Thelia/Install/Database.php b/core/lib/Thelia/Install/Database.php index 648a6431a..d17bd7c3d 100644 --- a/core/lib/Thelia/Install/Database.php +++ b/core/lib/Thelia/Install/Database.php @@ -40,21 +40,33 @@ class Database /** * Insert all sql needed in database + * Default insert /install/thelia.sql and /install/insert.sql * - * @param $dbName + * @param string $dbName Database name + * @param array $extraSqlFiles SQL Files uri to insert */ - public function insertSql($dbName = null) + public function insertSql($dbName = null, array $extraSqlFiles = null) { - if($dbName) { + if ($dbName) { $this->connection->query(sprintf("use %s", $dbName)); } $sql = array(); - $sql = array_merge( - $sql, - $this->prepareSql(file_get_contents(THELIA_ROOT . "/install/thelia.sql")), - $this->prepareSql(file_get_contents(THELIA_ROOT . "/install/insert.sql")) - ); + + if (null === $extraSqlFiles) { + $sql = array_merge( + $sql, + $this->prepareSql(file_get_contents(THELIA_ROOT . '/install/thelia.sql')), + $this->prepareSql(file_get_contents(THELIA_ROOT . '/install/insert.sql')) + ); + } else { + foreach ($extraSqlFiles as $fileToInsert) { + $sql = array_merge( + $sql, + $this->prepareSql(file_get_contents($fileToInsert)) + ); + } + } for ($i = 0; $i < count($sql); $i ++) { if (!empty($sql[$i])) { @@ -75,7 +87,7 @@ class Database $sql = trim($sql); $query = array(); - $tab = explode(";", $sql); + $tab = explode(";\n", $sql); for ($i=0; $i + + + + {/form_field} + + {form_field form=$form field='company'} +
+ + +
+ {/form_field} + + {form_field form=$form field='title'} +
+ + + +
+ {/form_field} + + {form_field form=$form field='firstname'} +
+ + +
+ {/form_field} + + {form_field form=$form field='lastname'} +
+ + +
+ {/form_field} + + {form_field form=$form field='address1'} +
+ + +
+ +
+ {form_field form=$form field='address2'} + + {/form_field} +
+ +
+ {form_field form=$form field='address3'} + + {/form_field} +
+ {/form_field} + + {form_field form=$form field='zipcode'} +
+ + +
+ {/form_field} + + {form_field form=$form field='city'} +
+ + +
+ {/form_field} + + {form_field form=$form field='country'} +
+ + +
+ {/form_field} + +{/capture} + + {include + file = "includes/generic-create-dialog.html" + + dialog_id = "edit_address_dialog" + dialog_title = {intl l="Edit an address"} + dialog_body = {$smarty.capture.edit_address_dialog nofilter} + +dialog_ok_label = {intl l="Edit this address"} +dialog_cancel_label = {intl l="Cancel"} + +form_action = {url path="/admin/address/save/{$address_id}"} +form_enctype = {form_enctype form=$form} +form_error_message = $form_error_message +} + +{/form} \ No newline at end of file diff --git a/templates/admin/default/assets/less/thelia/thelia.less b/templates/admin/default/assets/less/thelia/thelia.less index fc2652004..11dc5bd74 100644 --- a/templates/admin/default/assets/less/thelia/thelia.less +++ b/templates/admin/default/assets/less/thelia/thelia.less @@ -295,6 +295,13 @@ width: auto; } +.modal-backdrop .loading { + left: 50%; + top: 50%; + right: auto; + position: absolute; +} + .existing-image .col-sm-6{ position: relative; diff --git a/templates/admin/default/customer-edit.html b/templates/admin/default/customer-edit.html index 9bcba75b9..69e1815f3 100644 --- a/templates/admin/default/customer-edit.html +++ b/templates/admin/default/customer-edit.html @@ -44,7 +44,7 @@ {/form_field} {if $form_error}
{$form_error_message}
{/if} - + {loop name="address" type="address" customer="$customer_id" backend_context="1" default="true"}

{intl l="Customer informations"}

@@ -74,7 +74,7 @@
{/form_field} - {loop name="address" type="address" customer="$customer_id" backend_context="1" default="true"} +

{intl l="Default address"}

@@ -171,15 +171,15 @@
- + - + - + @@ -218,7 +218,7 @@
- +
{* Add an Address *} {form name="thelia.address.create"} @@ -227,7 +227,10 @@ {capture "address_creation_dialog"} {form_hidden_fields form=$form} - + + {form_field form=$form field='success_url'} + + {/form_field} {form_field form=$form field='label'}
@@ -246,7 +249,7 @@
- {loop type="title" name="title1"} {/loop} @@ -257,21 +260,21 @@ {form_field form=$form field='firstname'}
- +
{/form_field} {form_field form=$form field='lastname'}
- +
{/form_field} {form_field form=$form field='address1'}
- +
@@ -290,21 +293,21 @@ {form_field form=$form field='zipcode'}
- +
{/form_field} {form_field form=$form field='city'}
- +
{/form_field} {form_field form=$form field='country'}
- {loop type="country" name="country1"} {/loop} @@ -331,117 +334,7 @@ {/form} - {* Update an Address *} - {form name="thelia.address.update"} - - {* Capture the dialog body, to pass it to the generic dialog *} - {capture "edit_address_dialog"} - - {form_hidden_fields form=$form} - - {form_field form=$form field='label'} -
- - -
- {/form_field} - - {form_field form=$form field='company'} -
- - -
- {/form_field} - - {form_field form=$form field='title'} -
- - - -
- {/form_field} - - {form_field form=$form field='firstname'} -
- - -
- {/form_field} - - {form_field form=$form field='lastname'} -
- - -
- {/form_field} - - {form_field form=$form field='address1'} -
- - -
- -
- {form_field form=$form field='address2'} - - {/form_field} -
- -
- {form_field form=$form field='address3'} - - {/form_field} -
- {/form_field} - - {form_field form=$form field='zipcode'} -
- - -
- {/form_field} - - {form_field form=$form field='city'} -
- - -
- {/form_field} - - {form_field form=$form field='country'} -
- - -
- {/form_field} - - {/capture} - - {include - file = "includes/generic-create-dialog.html" - - dialog_id = "edit_address_dialog" - dialog_title = {intl l="Edit an address"} - dialog_body = {$smarty.capture.edit_address_dialog nofilter} - - dialog_ok_label = {intl l="Edit this address"} - dialog_cancel_label = {intl l="Cancel"} - - form_action = {url path='/admin/address/update'} - form_enctype = {form_enctype form=$form} - form_error_message = $form_error_message - } - - {/form} {* Default confirmation dialog *} @@ -475,7 +368,7 @@ dialog_message = {intl l="Do you really want to delete this address ?"} form_action = {url path='/admin/address/delete'} - form_content = {$smarty.capture.delete_dialog nofilter} + form_content = {$smarty.capture.delete_address_dialog nofilter} } {/block} @@ -483,4 +376,35 @@ {javascripts file='assets/js/main.js'} {/javascripts} + + {/block} \ No newline at end of file diff --git a/templates/default/layout.tpl b/templates/default/layout.tpl index 731c6f685..2c8a56d44 100644 --- a/templates/default/layout.tpl +++ b/templates/default/layout.tpl @@ -62,24 +62,6 @@ URL: http://www.thelia.net