diff --git a/core/lib/Thelia/Action/Attribute.php b/core/lib/Thelia/Action/Attribute.php
new file mode 100644
index 000000000..8524f6054
--- /dev/null
+++ b/core/lib/Thelia/Action/Attribute.php
@@ -0,0 +1,149 @@
+. */
+/* */
+/*************************************************************************************/
+
+namespace Thelia\Action;
+
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+use Thelia\Model\AttributeQuery;
+use Thelia\Model\Attribute as AttributeModel;
+
+use Thelia\Core\Event\TheliaEvents;
+
+use Thelia\Core\Event\AttributeUpdateEvent;
+use Thelia\Core\Event\AttributeCreateEvent;
+use Thelia\Core\Event\AttributeDeleteEvent;
+use Thelia\Model\ConfigQuery;
+use Thelia\Model\AttributeAv;
+use Thelia\Model\AttributeAvQuery;
+use Thelia\Core\Event\UpdatePositionEvent;
+
+class Attribute extends BaseAction implements EventSubscriberInterface
+{
+ /**
+ * Create a new attribute entry
+ *
+ * @param AttributeCreateEvent $event
+ */
+ public function create(AttributeCreateEvent $event)
+ {
+ $attribute = new AttributeModel();
+
+ $attribute
+ ->setDispatcher($this->getDispatcher())
+
+ ->setLocale($event->getLocale())
+ ->setTitle($event->getTitle())
+
+ ->save()
+ ;
+
+ $event->setAttribute($attribute);
+
+ // Add atribute to all product templates if required
+ if ($event->getAddToAllTemplates() != 0) {
+ // TODO: add to all product template
+ }
+ }
+
+ /**
+ * Change a product attribute
+ *
+ * @param AttributeUpdateEvent $event
+ */
+ public function update(AttributeUpdateEvent $event)
+ {
+ $search = AttributeQuery::create();
+
+ if (null !== $attribute = AttributeQuery::create()->findPk($event->getAttributeId())) {
+
+ $attribute
+ ->setDispatcher($this->getDispatcher())
+
+ ->setLocale($event->getLocale())
+ ->setTitle($event->getTitle())
+ ->setDescription($event->getDescription())
+ ->setChapo($event->getChapo())
+ ->setPostscriptum($event->getPostscriptum())
+
+ ->save();
+
+ $event->setAttribute($attribute);
+ }
+ }
+
+ /**
+ * Delete a product attribute entry
+ *
+ * @param AttributeDeleteEvent $event
+ */
+ public function delete(AttributeDeleteEvent $event)
+ {
+
+ if (null !== ($attribute = AttributeQuery::create()->findPk($event->getAttributeId()))) {
+
+ $attribute
+ ->setDispatcher($this->getDispatcher())
+ ->delete()
+ ;
+
+ $event->setAttribute($attribute);
+ }
+ }
+
+ /**
+ * Changes position, selecting absolute ou relative change.
+ *
+ * @param CategoryChangePositionEvent $event
+ */
+ public function updatePosition(UpdatePositionEvent $event)
+ {
+ if (null !== $attribute = AttributeQuery::create()->findPk($event->getObjectId())) {
+
+ $attribute->setDispatcher($this->getDispatcher());
+
+ $mode = $event->getMode();
+
+ if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE)
+ return $attribute->changeAbsolutePosition($event->getPosition());
+ else if ($mode == UpdatePositionEvent::POSITION_UP)
+ return $attribute->movePositionUp();
+ else if ($mode == UpdatePositionEvent::POSITION_DOWN)
+ return $attribute->movePositionDown();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public static function getSubscribedEvents()
+ {
+ return array(
+ TheliaEvents::ATTRIBUTE_CREATE => array("create", 128),
+ TheliaEvents::ATTRIBUTE_UPDATE => array("update", 128),
+ TheliaEvents::ATTRIBUTE_DELETE => array("delete", 128),
+ TheliaEvents::ATTRIBUTE_UPDATE_POSITION => array("updatePosition", 128),
+ );
+ }
+}
\ No newline at end of file
diff --git a/core/lib/Thelia/Action/AttributeAv.php b/core/lib/Thelia/Action/AttributeAv.php
new file mode 100644
index 000000000..a6b442fa2
--- /dev/null
+++ b/core/lib/Thelia/Action/AttributeAv.php
@@ -0,0 +1,143 @@
+. */
+/* */
+/*************************************************************************************/
+
+namespace Thelia\Action;
+
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+use Thelia\Model\AttributeAvQuery;
+use Thelia\Model\AttributeAv as AttributeAvModel;
+
+use Thelia\Core\Event\TheliaEvents;
+
+use Thelia\Core\Event\AttributeAvUpdateEvent;
+use Thelia\Core\Event\AttributeAvCreateEvent;
+use Thelia\Core\Event\AttributeAvDeleteEvent;
+use Thelia\Model\ConfigQuery;
+use Thelia\Core\Event\UpdatePositionEvent;
+
+class AttributeAv extends BaseAction implements EventSubscriberInterface
+{
+ /**
+ * Create a new attribute entry
+ *
+ * @param AttributeAvCreateEvent $event
+ */
+ public function create(AttributeAvCreateEvent $event)
+ {
+ $attribute = new AttributeAvModel();
+
+ $attribute
+ ->setDispatcher($this->getDispatcher())
+
+ ->setAttributeId($event->getAttributeId())
+ ->setLocale($event->getLocale())
+ ->setTitle($event->getTitle())
+
+ ->save()
+ ;
+
+ $event->setAttributeAv($attribute);
+ }
+
+ /**
+ * Change a product attribute
+ *
+ * @param AttributeAvUpdateEvent $event
+ */
+ public function update(AttributeAvUpdateEvent $event)
+ {
+ $search = AttributeAvQuery::create();
+
+ if (null !== $attribute = AttributeAvQuery::create()->findPk($event->getAttributeAvId())) {
+
+ $attribute
+ ->setDispatcher($this->getDispatcher())
+
+ ->setLocale($event->getLocale())
+ ->setTitle($event->getTitle())
+ ->setDescription($event->getDescription())
+ ->setChapo($event->getChapo())
+ ->setPostscriptum($event->getPostscriptum())
+
+ ->save();
+
+ $event->setAttributeAv($attribute);
+ }
+ }
+
+ /**
+ * Delete a product attribute entry
+ *
+ * @param AttributeAvDeleteEvent $event
+ */
+ public function delete(AttributeAvDeleteEvent $event)
+ {
+
+ if (null !== ($attribute = AttributeAvQuery::create()->findPk($event->getAttributeAvId()))) {
+
+ $attribute
+ ->setDispatcher($this->getDispatcher())
+ ->delete()
+ ;
+
+ $event->setAttributeAv($attribute);
+ }
+ }
+
+ /**
+ * Changes position, selecting absolute ou relative change.
+ *
+ * @param CategoryChangePositionEvent $event
+ */
+ public function updatePosition(UpdatePositionEvent $event)
+ {
+ if (null !== $attribute = AttributeAvQuery::create()->findPk($event->getObjectId())) {
+
+ $attribute->setDispatcher($this->getDispatcher());
+
+ $mode = $event->getMode();
+
+ if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE)
+ return $attribute->changeAbsolutePosition($event->getPosition());
+ else if ($mode == UpdatePositionEvent::POSITION_UP)
+ return $attribute->movePositionUp();
+ else if ($mode == UpdatePositionEvent::POSITION_DOWN)
+ return $attribute->movePositionDown();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public static function getSubscribedEvents()
+ {
+ return array(
+ TheliaEvents::ATTRIBUTE_AV_CREATE => array("create", 128),
+ TheliaEvents::ATTRIBUTE_AV_UPDATE => array("update", 128),
+ TheliaEvents::ATTRIBUTE_AV_DELETE => array("delete", 128),
+ TheliaEvents::ATTRIBUTE_AV_UPDATE_POSITION => array("updatePosition", 128),
+ );
+ }
+}
\ No newline at end of file
diff --git a/core/lib/Thelia/Action/Currency.php b/core/lib/Thelia/Action/Currency.php
index 619374902..7908d1f0d 100644
--- a/core/lib/Thelia/Action/Currency.php
+++ b/core/lib/Thelia/Action/Currency.php
@@ -34,7 +34,7 @@ use Thelia\Core\Event\CurrencyUpdateEvent;
use Thelia\Core\Event\CurrencyCreateEvent;
use Thelia\Core\Event\CurrencyDeleteEvent;
use Thelia\Model\ConfigQuery;
-use Thelia\Core\Event\CurrencyUpdatePositionEvent;
+use Thelia\Core\Event\UpdatePositionEvent;
class Currency extends BaseAction implements EventSubscriberInterface
{
@@ -164,19 +164,20 @@ class Currency extends BaseAction implements EventSubscriberInterface
*
* @param CategoryChangePositionEvent $event
*/
- public function updatePosition(CurrencyUpdatePositionEvent $event)
+ public function updatePosition(UpdatePositionEvent $event)
{
- if (null !== $currency = CurrencyQuery::create()->findOneById($event->getObjectId())) {
+ if (null !== $currency = CurrencyQuery::create()->findPk($event->getObjectId())) {
$currency->setDispatcher($this->getDispatcher());
$mode = $event->getMode();
+ echo "loaded $mode !";
- if ($mode == CurrencyUpdatePositionEvent::POSITION_ABSOLUTE)
+ if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE)
return $currency->changeAbsolutePosition($event->getPosition());
- else if ($mode == CurrencyUpdatePositionEvent::POSITION_UP)
+ else if ($mode == UpdatePositionEvent::POSITION_UP)
return $currency->movePositionUp();
- else if ($mode == CurrencyUpdatePositionEvent::POSITION_DOWN)
+ else if ($mode == UpdatePositionEvent::POSITION_DOWN)
return $currency->movePositionDown();
}
}
diff --git a/core/lib/Thelia/Action/Customer.php b/core/lib/Thelia/Action/Customer.php
index 1b3ac6909..f132a01da 100755
--- a/core/lib/Thelia/Action/Customer.php
+++ b/core/lib/Thelia/Action/Customer.php
@@ -26,6 +26,7 @@ namespace Thelia\Action;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\ActionEvent;
use Thelia\Core\Event\CustomerCreateOrUpdateEvent;
+use Thelia\Core\Event\CustomerEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\Customer as CustomerModel;
use Thelia\Core\Event\CustomerLoginEvent;
@@ -59,6 +60,13 @@ class Customer extends BaseAction implements EventSubscriberInterface
}
+ public function delete(CustomerEvent $event)
+ {
+ $customer = $event->getCustomer();
+
+ $customer->delete();
+ }
+
private function createOrUpdateCustomer(CustomerModel $customer, CustomerCreateOrUpdateEvent $event)
{
$customer->setDispatcher($this->getDispatcher());
@@ -80,7 +88,8 @@ class Customer extends BaseAction implements EventSubscriberInterface
$event->getLang(),
$event->getReseller(),
$event->getSponsor(),
- $event->getDiscount()
+ $event->getDiscount(),
+ $event->getCompany()
);
$event->setCustomer($customer);
@@ -143,6 +152,7 @@ class Customer extends BaseAction implements EventSubscriberInterface
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/Action/PositionManagementTrait.php b/core/lib/Thelia/Action/PositionManagementTrait.php
deleted file mode 100644
index 5da085594..000000000
--- a/core/lib/Thelia/Action/PositionManagementTrait.php
+++ /dev/null
@@ -1,157 +0,0 @@
-. */
-/* */
-/*************************************************************************************/
-
-namespace Thelia\Action;
-
-use Thelia\Core\Event\BaseChangePositionEvent;
-
-trait PositionManagementTrait
-{
- const POSITION_UP
- /**
- * Changes object position, selecting absolute ou relative change.
- *
- * @param BaseChangePositionEvent $event
- */
- public function changePosition(BaseChangePositionEvent $event)
- {
- if ($event->getMode() == BaseChangePositionEvent::POSITION_ABSOLUTE)
- return $this->changeAbsolutePosition($event);
- else
- return $this->exchangePosition($event);
- }
-
- /**
- * Move up or down a object
- *
- * @param BaseChangePositionEvent $event
- */
- protected function exchangePosition(BaseChangePositionEvent $event)
- {
- $object = CategoryQuery::create()->findPk($event->getCategoryId());
-
- if ($object !== null) {
-
- // The current position of the object
- $my_position = $object->getPosition();
-
- // Find object to exchange position with
- $search = CategoryQuery::create()
- ->filterByParent($object->getParent());
-
- // Up or down ?
- if ($event->getMode() == BaseChangePositionEvent::POSITION_UP) {
- // Find the object immediately before me
- $search->filterByPosition(array('max' => $my_position-1))->orderByPosition(Criteria::DESC);
- } elseif ($event->getMode() == BaseChangePositionEvent::POSITION_DOWN) {
- // Find the object immediately after me
- $search->filterByPosition(array('min' => $my_position+1))->orderByPosition(Criteria::ASC);
- } else
-
- return;
-
- $result = $search->findOne();
-
- // If we found the proper object, exchange their positions
- if ($result) {
-
- $cnx = Propel::getWriteConnection(CategoryTableMap::DATABASE_NAME);
-
- $cnx->beginTransaction();
-
- try {
- $object
- ->setDispatcher($this->getDispatcher())
- ->setPosition($result->getPosition())
- ->save()
- ;
-
- $result->setPosition($my_position)->save();
-
- $cnx->commit();
- } catch (Exception $e) {
- $cnx->rollback();
- }
- }
- }
- }
-
- /**
- * Changes object position
- *
- * @param BaseChangePositionEvent $event
- */
- protected function changeAbsolutePosition(BaseChangePositionEvent $event)
- {
- $object = CategoryQuery::create()->findPk($event->getCategoryId());
-
- if ($object !== null) {
-
- // The required position
- $new_position = $event->getPosition();
-
- // The current position
- $current_position = $object->getPosition();
-
- if ($new_position != null && $new_position > 0 && $new_position != $current_position) {
-
- // Find categories to offset
- $search = CategoryQuery::create()->filterByParent($object->getParent());
-
- if ($new_position > $current_position) {
- // The new position is after the current position -> we will offset + 1 all categories located between us and the new position
- $search->filterByPosition(array('min' => 1+$current_position, 'max' => $new_position));
-
- $delta = -1;
- } else {
- // The new position is brefore the current position -> we will offset - 1 all categories located between us and the new position
- $search->filterByPosition(array('min' => $new_position, 'max' => $current_position - 1));
-
- $delta = 1;
- }
-
- $results = $search->find();
-
- $cnx = Propel::getWriteConnection(CategoryTableMap::DATABASE_NAME);
-
- $cnx->beginTransaction();
-
- try {
- foreach ($results as $result) {
- $result->setPosition($result->getPosition() + $delta)->save($cnx);
- }
-
- $object
- ->setDispatcher($this->getDispatcher())
- ->setPosition($new_position)
- ->save($cnx)
- ;
-
- $cnx->commit();
- } catch (Exception $e) {
- $cnx->rollback();
- }
- }
- }
- }
-}
diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml
index dd43bbb91..842acdc6f 100755
--- a/core/lib/Thelia/Config/Resources/action.xml
+++ b/core/lib/Thelia/Config/Resources/action.xml
@@ -57,6 +57,16 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml
index a73d28434..ddb32cf65 100755
--- a/core/lib/Thelia/Config/Resources/config.xml
+++ b/core/lib/Thelia/Config/Resources/config.xml
@@ -67,6 +67,11 @@
+
+
+
+
+
diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml
index 5fe4c452a..6b09b6fca 100755
--- a/core/lib/Thelia/Config/Resources/routing/admin.xml
+++ b/core/lib/Thelia/Config/Resources/routing/admin.xml
@@ -37,18 +37,32 @@
Thelia\Controller\Admin\CustomerController::indexAction
-
+
Thelia\Controller\Admin\CustomerController::viewAction
\d+
+
+ Thelia\Controller\Admin\CustomerController::updateAction
+ \d+
+
+
+
+ Thelia\Controller\Admin\CustomerController::deleteAction
+
+
Thelia\Controller\Admin\OrderController::indexAction
-
+
+
+
+ Thelia\Controller\Admin\OrderController::viewAction
+ \d+
+
@@ -63,11 +77,11 @@
- Thelia\Controller\Admin\CategoryController::changeAction
+ Thelia\Controller\Admin\CategoryController::updateAction
- Thelia\Controller\Admin\CategoryController::saveChangeAction
+ Thelia\Controller\Admin\CategoryController::processUpdateAction
@@ -87,12 +101,8 @@
-
-
-
-
-
+
Thelia\Controller\Admin\CouponController::browseAction
@@ -115,10 +125,6 @@
Thelia\Controller\Admin\CouponController::consumeAction
-
-
-
-
@@ -134,11 +140,11 @@
- Thelia\Controller\Admin\ConfigController::changeAction
+ Thelia\Controller\Admin\ConfigController::updateAction
- Thelia\Controller\Admin\ConfigController::saveChangeAction
+ Thelia\Controller\Admin\ConfigController::processUpdateAction
@@ -156,11 +162,11 @@
- Thelia\Controller\Admin\MessageController::changeAction
+ Thelia\Controller\Admin\MessageController::updateAction
- Thelia\Controller\Admin\MessageController::saveChangeAction
+ Thelia\Controller\Admin\MessageController::processUpdateAction
@@ -178,11 +184,11 @@
- Thelia\Controller\Admin\CurrencyController::changeAction
+ Thelia\Controller\Admin\CurrencyController::updateAction
- Thelia\Controller\Admin\CurrencyController::saveChangeAction
+ Thelia\Controller\Admin\CurrencyController::processUpdateAction
@@ -205,16 +211,54 @@
Thelia\Controller\Admin\CurrencyController::updatePositionAction
-
-
+
+
+
Thelia\Controller\Admin\AttributeController::defaultAction
-
+
+ Thelia\Controller\Admin\AttributeController::createAction
+
+
+
Thelia\Controller\Admin\AttributeController::updateAction
+
+ Thelia\Controller\Admin\AttributeController::processUpdateAction
+
+
+
+ Thelia\Controller\Admin\AttributeController::deleteAction
+
+
+
+ Thelia\Controller\Admin\AttributeController::updatePositionAction
+
+
+
+
+ Thelia\Controller\Admin\AttributeAvController::createAction
+
+
+
+ Thelia\Controller\Admin\AttributeAvController::updateAction
+
+
+
+ Thelia\Controller\Admin\AttributeAvController::processUpdateAction
+
+
+
+ Thelia\Controller\Admin\AttributeAvController::deleteAction
+
+
+
+ Thelia\Controller\Admin\AttributeAvController::updatePositionAction
+
+
diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml
index e83dd7f07..49713b938 100755
--- a/core/lib/Thelia/Config/Resources/routing/front.xml
+++ b/core/lib/Thelia/Config/Resources/routing/front.xml
@@ -10,15 +10,31 @@
+
+ Thelia\Controller\Front\DefaultController::noAction
+ register
+
+
+
+
+ Thelia\Controller\Front\DefaultController::noAction
+ login
+
+
+
+ Thelia\Controller\Front\CustomerController::logoutAction
+
+
+
+ Thelia\Controller\Front\DefaultController::noAction
+ account
+
+
Thelia\Controller\Front\CustomerController::createAction
register
-
- Thelia\Controller\Front\DefaultController::noAction
- register
-
Thelia\Controller\Front\CustomerController::updateAction
@@ -29,14 +45,6 @@
login
-
- Thelia\Controller\Front\DefaultController::noAction
- login
-
-
-
- Thelia\Controller\Front\CustomerController::logoutAction
-
Thelia\Controller\Front\DefaultController::noAction
diff --git a/core/lib/Thelia/Controller/Admin/AbstractCrudController.php b/core/lib/Thelia/Controller/Admin/AbstractCrudController.php
new file mode 100644
index 000000000..1dcbca01f
--- /dev/null
+++ b/core/lib/Thelia/Controller/Admin/AbstractCrudController.php
@@ -0,0 +1,473 @@
+. */
+/* */
+/*************************************************************************************/
+
+namespace Thelia\Controller\Admin;
+
+use Thelia\Form\Exception\FormValidationException;
+use Thelia\Core\Event\UpdatePositionEvent;
+use Thelia\Core\Event\ToggleVisibilityEvent;
+
+/**
+ * An abstract CRUD controller for Thelia ADMIN, to manage basic CRUD operations on a givent object.
+ *
+ * @author Franck Allimant
+ */
+abstract class AbstractCrudController extends BaseAdminController
+{
+ protected $objectName;
+
+ // List ordering
+ protected $defaultListOrder;
+
+ // Permissions
+ protected $viewPermissionIdentifier;
+ protected $createPermissionIdentifier;
+ protected $updatePermissionIdentifier;
+ protected $deletePermissionIdentifier;
+
+ // Events
+ protected $createEventIdentifier;
+ protected $updateEventIdentifier;
+ protected $deleteEventIdentifier;
+ protected $visibilityToggleEventIdentifier;
+ protected $changePositionEventIdentifier;
+
+
+ /**
+ * @param string $objectName the lower case object name. Example. "message"
+ *
+ * @param string $defaultListOrder the default object list order, or null if list is not sortable. Example: manual
+ *
+ * @param string $viewPermissionIdentifier the 'view' permission identifier. Example: "admin.configuration.message.view"
+ * @param string $createPermissionIdentifier the 'create' permission identifier. Example: "admin.configuration.message.create"
+ * @param string $updatePermissionIdentifier the 'update' permission identifier. Example: "admin.configuration.message.update"
+ * @param string $deletePermissionIdentifier the 'delete' permission identifier. Example: "admin.configuration.message.delete"
+ *
+ * @param string $createEventIdentifier the dispatched create TheliaEvent identifier. Example: TheliaEvents::MESSAGE_CREATE
+ * @param string $updateEventIdentifier the dispatched update TheliaEvent identifier. Example: TheliaEvents::MESSAGE_UPDATE
+ * @param string $deleteEventIdentifier the dispatched delete TheliaEvent identifier. Example: TheliaEvents::MESSAGE_DELETE
+ *
+ * @param string $visibilityToggleEventIdentifier the dispatched visibility toggle TheliaEvent identifier, or null if the object has no visible options. Example: TheliaEvents::MESSAGE_TOGGLE_VISIBILITY
+ * @param string $changePositionEventIdentifier the dispatched position change TheliaEvent identifier, or null if the object has no position. Example: TheliaEvents::MESSAGE_UPDATE_POSITION
+ */
+ public function __construct(
+ $objectName,
+
+ $defaultListOrder = null,
+
+ $viewPermissionIdentifier,
+ $createPermissionIdentifier,
+ $updatePermissionIdentifier,
+ $deletePermissionIdentifier,
+
+ $createEventIdentifier,
+ $updateEventIdentifier,
+ $deleteEventIdentifier,
+ $visibilityToggleEventIdentifier = null,
+ $changePositionEventIdentifier = null
+ ) {
+ $this->objectName = $objectName;
+
+ $this->defaultListOrder = $defaultListOrder;
+
+ $this->viewPermissionIdentifier = $viewPermissionIdentifier;
+ $this->createPermissionIdentifier = $createPermissionIdentifier;
+ $this->updatePermissionIdentifier = $updatePermissionIdentifier;
+ $this->deletePermissionIdentifier = $deletePermissionIdentifier;
+
+ $this->createEventIdentifier = $createEventIdentifier;
+ $this->updateEventIdentifier = $updateEventIdentifier;
+ $this->deleteEventIdentifier = $deleteEventIdentifier;
+ $this->visibilityToggleEventIdentifier = $visibilityToggleEventIdentifier;
+ $this->changePositionEventIdentifier = $changePositionEventIdentifier;
+ }
+
+ /**
+ * Return the creation form for this object
+ */
+ protected abstract function getCreationForm();
+
+ /**
+ * Return the update form for this object
+ */
+ protected abstract function getUpdateForm();
+
+ /**
+ * Hydrate the update form for this object, before passing it to the update template
+ *
+ * @param unknown $object
+ */
+ protected abstract function hydrateObjectForm($object);
+
+ /**
+ * Creates the creation event with the provided form data
+ *
+ * @param unknown $formData
+ */
+ protected abstract function getCreationEvent($formData);
+
+ /**
+ * Creates the update event with the provided form data
+ *
+ * @param unknown $formData
+ */
+ protected abstract function getUpdateEvent($formData);
+
+ /**
+ * Creates the delete event with the provided form data
+ */
+ protected abstract function getDeleteEvent();
+
+ /**
+ * Return true if the event contains the object, e.g. the action has updated the object in the event.
+ *
+ * @param unknown $event
+ */
+ protected abstract function eventContainsObject($event);
+
+ /**
+ * Get the created object from an event.
+ *
+ * @param unknown $createEvent
+ */
+ protected abstract function getObjectFromEvent($event);
+
+ /**
+ * Load an existing object from the database
+ */
+ protected abstract function getExistingObject();
+
+ /**
+ * Returns the object label form the object event (name, title, etc.)
+ *
+ * @param unknown $object
+ */
+ protected abstract function getObjectLabel($object);
+
+ /**
+ * Returns the object ID from the object
+ *
+ * @param unknown $object
+ */
+ protected abstract function getObjectId($object);
+
+ /**
+ * Render the main list template
+ *
+ * @param unknown $currentOrder, if any, null otherwise.
+ */
+ protected abstract function renderListTemplate($currentOrder);
+
+ /**
+ * Render the edition template
+ */
+ protected abstract function renderEditionTemplate();
+
+ /**
+ * Redirect to the edition template
+ */
+ protected abstract function redirectToEditionTemplate();
+
+ /**
+ * Redirect to the list template
+ */
+ protected abstract function redirectToListTemplate();
+
+
+ protected function createUpdatePositionEvent($positionChangeMode, $positionValue) {
+ throw new \LogicException ("Position Update is not supported for this object");
+ }
+
+ protected function createToggleVisibilityEvent() {
+
+ throw new \LogicException ("Toggle Visibility is not supported for this object");
+ }
+
+ /**
+ * Return the current list order identifier, updating it in the same time.
+ */
+ protected function getCurrentListOrder($update_session = true) {
+
+ $order = null;
+
+ if ($this->defaultListOrder) {
+
+ $orderSessionIdentifier = sprintf("admin.%s.currentListOrder", $this->objectName);
+
+ // Find the current order
+ $order = $this->getRequest()->get(
+ 'order',
+ $this->getSession()->get($orderSessionIdentifier, $this->defaultListOrder)
+ );
+
+ if ($update_session) $this->getSession()->set($orderSessionIdentifier, $order);
+ }
+
+ return $order;
+ }
+
+ /**
+ * Render the object list, ensuring the sort order is set.
+ *
+ * @return Symfony\Component\HttpFoundation\Response the response
+ */
+ protected function renderList()
+ {
+ return $this->renderListTemplate($this->getCurrentListOrder());
+ }
+
+ /**
+ * The default action is displaying the list.
+ *
+ * @return Symfony\Component\HttpFoundation\Response the response
+ */
+ public function defaultAction()
+ {
+ if (null !== $response = $this->checkAuth($this->viewPermissionIdentifier)) return $response;
+
+ return $this->renderList();
+ }
+
+ /**
+ * Create a new object
+ *
+ * @return Symfony\Component\HttpFoundation\Response the response
+ */
+ public function createAction()
+ {
+ // Check current user authorization
+ if (null !== $response = $this->checkAuth($this->createPermissionIdentifier)) return $response;
+
+ $error_msg = false;
+
+ // Create the Creation Form
+ $creationForm = $this->getCreationForm($this->getRequest());
+
+ try {
+
+ // Validate the form, create the event and dispatch it.
+ $form = $this->validateForm($creationForm, "POST");
+
+ $data = $form->getData();
+
+ $createEvent = $this->getCreationEvent($data);
+
+ $this->dispatch($this->createEventIdentifier, $createEvent);
+
+ if (! $this->eventContainsObject($createEvent))
+ throw new \LogicException(
+ $this->getTranslator()->trans("No %obj was created.", array('%obj', $this->objectName)));
+
+ if (null !== $createdObject = $this->getObjectFromEvent($createEvent)) {
+ // Log object creation
+ $this->adminLogAppend(sprintf("%s %s (ID %s) created", ucfirst($this->objectName), $this->getObjectLabel($createdObject), $this->getObjectId($createdObject)));
+ }
+
+ // Substitute _ID_ in the URL with the ID of the created object
+ $successUrl = str_replace('_ID_', $this->getObjectId($createdObject), $creationForm->getSuccessUrl());
+
+ // Redirect to the success URL
+ $this->redirect($successUrl);
+
+ }
+ catch (FormValidationException $ex) {
+ // Form cannot be validated
+ $error_msg = $this->createStandardFormValidationErrorMessage($ex);
+ }
+ catch (\Exception $ex) {
+ // Any other error
+ $error_msg = $ex->getMessage();
+ }
+
+ $this->setupFormErrorContext(
+ $this->getTranslator()->trans("%obj creation", array('%obj' => $this->objectName)), $error_msg, $creationForm, $ex);
+
+ // At this point, the form has error, and should be redisplayed.
+ return $this->renderList();
+ }
+
+ /**
+ * Load a object for modification, and display the edit template.
+ *
+ * @return Symfony\Component\HttpFoundation\Response the response
+ */
+ public function updateAction()
+ {
+ // Check current user authorization
+ if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response;
+
+ // Load the object
+ $object = $this->getExistingObject($this->getRequest());
+
+ if ($object != null) {
+
+ // Hydrate the form abd pass it to the parser
+ $changeForm = $this->hydrateObjectForm($object);
+
+ // Pass it to the parser
+ $this->getParserContext()->addForm($changeForm);
+ }
+
+ // Render the edition template.
+ return $this->renderEditionTemplate();
+ }
+
+ /**
+ * Save changes on a modified object, and either go back to the object list, or stay on the edition page.
+ *
+ * @return Symfony\Component\HttpFoundation\Response the response
+ */
+ public function processUpdateAction()
+ {
+ // Check current user authorization
+ if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response;
+
+ $error_msg = false;
+
+ // Create the form from the request
+ $changeForm = $this->getUpdateForm($this->getRequest());
+
+ try {
+
+ // Check the form against constraints violations
+ $form = $this->validateForm($changeForm, "POST");
+
+ // Get the form field values
+ $data = $form->getData();
+
+ $changeEvent = $this->getUpdateEvent($data);
+
+ $this->dispatch($this->updateEventIdentifier, $changeEvent);
+
+ if (! $this->eventContainsObject($changeEvent))
+ throw new \LogicException(
+ $this->getTranslator()->trans("No %obj was updated.", array('%obj', $this->objectName)));
+
+ // Log object modification
+ if (null !== $changedObject = $this->getObjectFromEvent($changeEvent)) {
+ $this->adminLogAppend(sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
+ }
+
+ // If we have to stay on the same page, do not redirect to the succesUrl,
+ // just redirect to the edit page again.
+ if ($this->getRequest()->get('save_mode') == 'stay') {
+ $this->redirectToEditionTemplate($this->getRequest());
+ }
+
+ // Redirect to the success URL
+ $this->redirect($changeForm->getSuccessUrl());
+ }
+ catch (FormValidationException $ex) {
+ // Form cannot be validated
+ $error_msg = $this->createStandardFormValidationErrorMessage($ex);
+ }
+ catch (\Exception $ex) {
+ // Any other error
+ $error_msg = $ex->getMessage();
+ }
+
+ $this->setupFormErrorContext(
+ $this->getTranslator()->trans("%obj modification", array('%obj' => $this->objectName)), $error_msg, $changeForm, $ex);
+
+ // At this point, the form has errors, and should be redisplayed.
+ return $this->renderEditionTemplate();
+ }
+
+ /**
+ * Update object position (only for objects whichsupport that)
+ */
+ public function updatePositionAction()
+ {
+ // Check current user authorization
+ if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response;
+
+ try {
+ $mode = $this->getRequest()->get('mode', null);
+
+ if ($mode == 'up')
+ $mode = UpdatePositionEvent::POSITION_UP;
+ else if ($mode == 'down')
+ $mode = UpdatePositionEvent::POSITION_DOWN;
+ else
+ $mode = UpdatePositionEvent::POSITION_ABSOLUTE;
+
+ $position = $this->getRequest()->get('position', null);
+
+ $event = $this->createUpdatePositionEvent($mode, $position);
+
+ $this->dispatch($this->changePositionEventIdentifier, $event);
+ }
+ catch (\Exception $ex) {
+ // Any error
+ return $this->errorPage($ex);
+ }
+
+ $this->redirectToListTemplate();
+ }
+
+ /**
+ * Online status toggle (only for object which support it)
+ */
+ public function setToggleVisibilityAction()
+ {
+ // Check current user authorization
+ if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response;
+
+ $changeEvent = $this->createToggleVisibilityEvent($this->getRequest());
+
+ // Create and dispatch the change event
+ $changeEvent->setIsDefault(true);
+
+ try {
+ $this->dispatch($this->visibilityToggleEventIdentifier, $changeEvent);
+ } catch (\Exception $ex) {
+ // Any error
+ return $this->errorPage($ex);
+ }
+
+ $this->redirectToRoute('admin.categories.default');
+ }
+
+ /**
+ * Delete an object
+ *
+ * @return Symfony\Component\HttpFoundation\Response the response
+ */
+ public function deleteAction()
+ {
+ // Check current user authorization
+ if (null !== $response = $this->checkAuth($this->deletePermissionIdentifier)) return $response;
+
+ // Get the currency id, and dispatch the delet request
+ $deleteEvent = $this->getDeleteEvent();
+
+ $this->dispatch($this->deleteEventIdentifier, $deleteEvent);
+
+ if (null !== $deletedObject = $this->getObjectFromEvent($deleteEvent)) {
+ $this->adminLogAppend(
+ sprintf("%s %s (ID %s) deleted", ucfirst($this->objectName), $this->getObjectLabel($deletedObject), $this->getObjectId($deletedObject)));
+ }
+
+ $this->redirectToListTemplate();
+ }
+}
diff --git a/core/lib/Thelia/Controller/Admin/AttributeAvController.php b/core/lib/Thelia/Controller/Admin/AttributeAvController.php
new file mode 100644
index 000000000..b7118b53a
--- /dev/null
+++ b/core/lib/Thelia/Controller/Admin/AttributeAvController.php
@@ -0,0 +1,180 @@
+. */
+/* */
+/*************************************************************************************/
+
+namespace Thelia\Controller\Admin;
+
+use Thelia\Core\Event\AttributeAvDeleteEvent;
+use Thelia\Core\Event\TheliaEvents;
+use Thelia\Core\Event\AttributeAvUpdateEvent;
+use Thelia\Core\Event\AttributeAvCreateEvent;
+use Thelia\Model\AttributeAvQuery;
+use Thelia\Form\AttributeAvModificationForm;
+use Thelia\Form\AttributeAvCreationForm;
+use Thelia\Core\Event\UpdatePositionEvent;
+
+/**
+ * Manages attributes-av sent by mail
+ *
+ * @author Franck Allimant
+ */
+class AttributeAvController extends AbstractCrudController
+{
+ public function __construct() {
+ parent::__construct(
+ 'attribute',
+ 'manual',
+
+ 'admin.configuration.attributes-av.view',
+ 'admin.configuration.attributes-av.create',
+ 'admin.configuration.attributes-av.update',
+ 'admin.configuration.attributes-av.delete',
+
+ TheliaEvents::ATTRIBUTE_AV_CREATE,
+ TheliaEvents::ATTRIBUTE_AV_UPDATE,
+ TheliaEvents::ATTRIBUTE_AV_DELETE,
+ null, // No visibility toggle
+ TheliaEvents::ATTRIBUTE_AV_UPDATE_POSITION
+ );
+ }
+
+ protected function getCreationForm() {
+ return new AttributeAvCreationForm($this->getRequest());
+ }
+
+ protected function getUpdateForm() {
+ return new AttributeAvModificationForm($this->getRequest());
+ }
+
+ protected function getCreationEvent($formData) {
+ $createEvent = new AttributeAvCreateEvent();
+
+ $createEvent
+ ->setAttributeId($formData['attribute_id'])
+ ->setTitle($formData['title'])
+ ->setLocale($formData["locale"])
+ ;
+
+ return $createEvent;
+ }
+
+ protected function getUpdateEvent($formData) {
+
+ $changeEvent = new AttributeAvUpdateEvent($formData['id']);
+
+ // Create and dispatch the change event
+ $changeEvent
+ ->setLocale($formData["locale"])
+ ->setTitle($formData['title'])
+ ->setChapo($formData['chapo'])
+ ->setDescription($formData['description'])
+ ->setPostscriptum($formData['postscriptum'])
+ ;
+
+ return $changeEvent;
+ }
+
+ protected function createUpdatePositionEvent($positionChangeMode, $positionValue) {
+
+ return new UpdatePositionEvent(
+ $this->getRequest()->get('attributeav_id', null),
+ $positionChangeMode,
+ $positionValue
+ );
+ }
+
+ protected function getDeleteEvent() {
+ return new AttributeAvDeleteEvent($this->getRequest()->get('attributeav_id'));
+ }
+
+ protected function eventContainsObject($event) {
+ return $event->hasAttributeAv();
+ }
+
+ protected function hydrateObjectForm($object) {
+
+ $data = array(
+ 'id' => $object->getId(),
+ 'locale' => $object->getLocale(),
+ 'title' => $object->getTitle(),
+ 'chapo' => $object->getChapo(),
+ 'description' => $object->getDescription(),
+ 'postscriptum' => $object->getPostscriptum()
+ );
+
+ // Setup the object form
+ return new AttributeAvModificationForm($this->getRequest(), "form", $data);
+ }
+
+ protected function getObjectFromEvent($event) {
+ return $event->hasAttributeAv() ? $event->getAttributeAv() : null;
+ }
+
+ protected function getExistingObject() {
+ return AttributeAvQuery::create()
+ ->joinWithI18n($this->getCurrentEditionLocale())
+ ->findOneById($this->getRequest()->get('attributeav_id'));
+ }
+
+ protected function getObjectLabel($object) {
+ return $object->getTitle();
+ }
+
+ protected function getObjectId($object) {
+ return $object->getId();
+ }
+
+ protected function getViewArguments() {
+ return array(
+ 'attribute_id' => $this->getRequest()->get('attribute_id'),
+ 'order' => $this->getCurrentListOrder()
+ );
+ }
+
+ protected function renderListTemplate($currentOrder) {
+ // We always return to the attribute edition form
+ return $this->render(
+ 'attribute-edit',
+ $this->getViewArguments()
+ );
+ }
+
+ protected function renderEditionTemplate() {
+ // We always return to the attribute edition form
+ return $this->render('attribute-edit', $this->getViewArguments());
+ }
+
+ protected function redirectToEditionTemplate() {
+ // We always return to the attribute edition form
+ $this->redirectToRoute(
+ "admin.configuration.attributes.update",
+ $this->getViewArguments()
+ );
+ }
+
+ protected function redirectToListTemplate() {
+ $this->redirectToRoute(
+ "admin.configuration.attributes.update",
+ $this->getViewArguments()
+ );
+ }
+}
\ No newline at end of file
diff --git a/core/lib/Thelia/Controller/Admin/AttributeController.php b/core/lib/Thelia/Controller/Admin/AttributeController.php
index 50e32955d..f6b76c0df 100644
--- a/core/lib/Thelia/Controller/Admin/AttributeController.php
+++ b/core/lib/Thelia/Controller/Admin/AttributeController.php
@@ -23,27 +23,142 @@
namespace Thelia\Controller\Admin;
+use Thelia\Core\Event\AttributeDeleteEvent;
+use Thelia\Core\Event\TheliaEvents;
+use Thelia\Core\Event\AttributeUpdateEvent;
+use Thelia\Core\Event\AttributeCreateEvent;
+use Thelia\Model\AttributeQuery;
+use Thelia\Form\AttributeModificationForm;
+use Thelia\Form\AttributeCreationForm;
+use Thelia\Core\Event\UpdatePositionEvent;
+
/**
- * Manages messages sent by mail
+ * Manages attributes sent by mail
*
* @author Franck Allimant
*/
-class AttributeController extends BaseAdminController
+class AttributeController extends AbstractCrudController
{
- /**
- * The default action is displaying the attributes list.
- *
- * @return Symfony\Component\HttpFoundation\Response the response
- */
- public function defaultAction()
- {
- if (null !== $response = $this->checkAuth("admin.configuration.attributes.view")) return $response;
- return $this->render('product-attributes');
+ public function __construct() {
+ parent::__construct(
+ 'attribute',
+ 'manual',
+
+ 'admin.configuration.attributes.view',
+ 'admin.configuration.attributes.create',
+ 'admin.configuration.attributes.update',
+ 'admin.configuration.attributes.delete',
+
+ TheliaEvents::ATTRIBUTE_CREATE,
+ TheliaEvents::ATTRIBUTE_UPDATE,
+ TheliaEvents::ATTRIBUTE_DELETE,
+ null, // No visibility toggle
+ TheliaEvents::ATTRIBUTE_UPDATE_POSITION
+ );
}
- public function updateAction()
- {
- if (null !== $response = $this->checkAuth("admin.configuration.attributes.update")) return $response;
- return $this->render('product-attributes-edit');
+ protected function getCreationForm() {
+ return new AttributeCreationForm($this->getRequest());
}
-}
+
+ protected function getUpdateForm() {
+ return new AttributeModificationForm($this->getRequest());
+ }
+
+ protected function getCreationEvent($formData) {
+ $createEvent = new AttributeCreateEvent();
+
+ $createEvent
+ ->setTitle($formData['title'])
+ ->setLocale($formData["locale"])
+ ->setAddToAllTemplates($formData['add_to_all'])
+ ;
+
+ return $createEvent;
+ }
+
+ protected function getUpdateEvent($formData) {
+
+ $changeEvent = new AttributeUpdateEvent($formData['id']);
+
+ // Create and dispatch the change event
+ $changeEvent
+ ->setLocale($formData["locale"])
+ ->setTitle($formData['title'])
+ ->setChapo($formData['chapo'])
+ ->setDescription($formData['description'])
+ ->setPostscriptum($formData['postscriptum'])
+ ;
+
+ return $changeEvent;
+ }
+
+ protected function createUpdatePositionEvent($positionChangeMode, $positionValue) {
+
+ return new UpdatePositionEvent(
+ $this->getRequest()->get('attribute_id', null),
+ $positionChangeMode,
+ $positionValue
+ );
+ }
+
+ protected function getDeleteEvent() {
+ return new AttributeDeleteEvent($this->getRequest()->get('attribute_id'));
+ }
+
+ protected function eventContainsObject($event) {
+ return $event->hasAttribute();
+ }
+
+ protected function hydrateObjectForm($object) {
+
+ $data = array(
+ 'id' => $object->getId(),
+ 'locale' => $object->getLocale(),
+ 'title' => $object->getTitle(),
+ 'chapo' => $object->getChapo(),
+ 'description' => $object->getDescription(),
+ 'postscriptum' => $object->getPostscriptum()
+ );
+
+ // Setup the object form
+ return new AttributeModificationForm($this->getRequest(), "form", $data);
+ }
+
+ protected function getObjectFromEvent($event) {
+ return $event->hasAttribute() ? $event->getAttribute() : null;
+ }
+
+ protected function getExistingObject() {
+ return AttributeQuery::create()
+ ->joinWithI18n($this->getCurrentEditionLocale())
+ ->findOneById($this->getRequest()->get('attribute_id'));
+ }
+
+ protected function getObjectLabel($object) {
+ return $object->getTitle();
+ }
+
+ protected function getObjectId($object) {
+ return $object->getId();
+ }
+
+ protected function renderListTemplate($currentOrder) {
+ return $this->render('attributes', array('order' => $currentOrder));
+ }
+
+ protected function renderEditionTemplate() {
+ return $this->render('attribute-edit', array('attribute_id' => $this->getRequest()->get('attribute_id')));
+ }
+
+ protected function redirectToEditionTemplate() {
+ $this->redirectToRoute(
+ "admin.configuration.attributes.update",
+ array('attribute_id' => $this->getRequest()->get('attribute_id'))
+ );
+ }
+
+ protected function redirectToListTemplate() {
+ $this->redirectToRoute('admin.configuration.attributes.default');
+ }
+}
\ No newline at end of file
diff --git a/core/lib/Thelia/Controller/Admin/ConfigController.php b/core/lib/Thelia/Controller/Admin/ConfigController.php
index 397266677..ee88e99e0 100644
--- a/core/lib/Thelia/Controller/Admin/ConfigController.php
+++ b/core/lib/Thelia/Controller/Admin/ConfigController.php
@@ -25,228 +25,144 @@ namespace Thelia\Controller\Admin;
use Thelia\Core\Event\ConfigDeleteEvent;
use Thelia\Core\Event\TheliaEvents;
-use Thelia\Tools\URL;
use Thelia\Core\Event\ConfigUpdateEvent;
use Thelia\Core\Event\ConfigCreateEvent;
-use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\ConfigQuery;
use Thelia\Form\ConfigModificationForm;
use Thelia\Form\ConfigCreationForm;
+use Thelia\Core\Event\UpdatePositionEvent;
/**
- * Manages Thelmia system variables, aka Config objects.
+ * Manages variables sent by mail
*
* @author Franck Allimant
*/
-class ConfigController extends BaseAdminController
+class ConfigController extends AbstractCrudController
{
- /**
- * Render the currencies list, ensuring the sort order is set.
- *
- * @return Symfony\Component\HttpFoundation\Response the response
- */
- protected function renderList()
- {
- // Find the current order
- $order = $this->getRequest()->get(
- 'order',
- $this->getSession()->get('admin.variables_order', 'name')
+ public function __construct() {
+ parent::__construct(
+ 'variable',
+ 'name',
+
+ 'admin.configuration.variables.view',
+ 'admin.configuration.variables.create',
+ 'admin.configuration.variables.update',
+ 'admin.configuration.variables.delete',
+
+ TheliaEvents::CONFIG_CREATE,
+ TheliaEvents::CONFIG_UPDATE,
+ TheliaEvents::CONFIG_DELETE,
+ null, // No visibility toggle
+ null // no position change
+ );
+ }
+
+ protected function getCreationForm() {
+ return new ConfigCreationForm($this->getRequest());
+ }
+
+ protected function getUpdateForm() {
+ return new ConfigModificationForm($this->getRequest());
+ }
+
+ protected function getCreationEvent($data) {
+ $createEvent = new ConfigCreateEvent();
+
+ $createEvent
+ ->setEventName($data['name'])
+ ->setValue($data['value'])
+ ->setLocale($data["locale"])
+ ->setTitle($data['title'])
+ ->setHidden($data['hidden'])
+ ->setSecured($data['secured'])
+ ;
+
+
+ return $createEvent;
+ }
+
+ protected function getUpdateEvent($data) {
+ $changeEvent = new ConfigUpdateEvent($data['id']);
+
+ // Create and dispatch the change event
+ $changeEvent
+ ->setEventName($data['name'])
+ ->setValue($data['value'])
+ ->setHidden($data['hidden'])
+ ->setSecured($data['secured'])
+ ->setLocale($data["locale"])
+ ->setTitle($data['title'])
+ ->setChapo($data['chapo'])
+ ->setDescription($data['description'])
+ ->setPostscriptum($data['postscriptum'])
+ ;
+
+ return $changeEvent;
+ }
+
+ protected function getDeleteEvent() {
+ return new ConfigDeleteEvent($this->getRequest()->get('variable_id'));
+ }
+
+ protected function eventContainsObject($event) {
+ return $event->hasConfig();
+ }
+
+ protected function hydrateObjectForm($object) {
+
+ // Prepare the data that will hydrate the form
+ $data = array(
+ 'id' => $object->getId(),
+ 'name' => $object->getName(),
+ 'value' => $object->getValue(),
+ 'hidden' => $object->getHidden(),
+ 'secured' => $object->getSecured(),
+ 'locale' => $object->getLocale(),
+ 'title' => $object->getTitle(),
+ 'chapo' => $object->getChapo(),
+ 'description' => $object->getDescription(),
+ 'postscriptum' => $object->getPostscriptum()
);
- // Store the current sort order in session
- $this->getSession()->set('admin.variables_order', $order);
-
- return $this->render('variables', array('order' => $order));
+ // Setup the object form
+ return new ConfigModificationForm($this->getRequest(), "form", $data);
}
- /**
- * The default action is displaying the variables list.
- *
- * @return Symfony\Component\HttpFoundation\Response the response
- */
- public function defaultAction()
- {
- if (null !== $response = $this->checkAuth("admin.configuration.variables.view")) return $response;
- return $this->renderList();
+ protected function getObjectFromEvent($event) {
+ return $event->hasConfig() ? $event->getConfig() : null;
}
- /**
- * Create a new config object
- *
- * @return Symfony\Component\HttpFoundation\Response the response
- */
- public function createAction()
- {
- // Check current user authorization
- if (null !== $response = $this->checkAuth("admin.configuration.variables.create")) return $response;
-
- $message = false;
-
- // Create the Creation Form
- $creationForm = new ConfigCreationForm($this->getRequest());
-
- try {
-
- // Validate the form, create the ConfigCreation event and dispatch it.
- $form = $this->validateForm($creationForm, "POST");
-
- $data = $form->getData();
-
- $createEvent = new ConfigCreateEvent();
-
- $createEvent
- ->setEventName($data['name'])
- ->setValue($data['value'])
- ->setLocale($data["locale"])
- ->setTitle($data['title'])
- ->setHidden($data['hidden'])
- ->setSecured($data['secured'])
- ;
-
- $this->dispatch(TheliaEvents::CONFIG_CREATE, $createEvent);
-
- if (! $createEvent->hasConfig()) throw new \LogicException($this->getTranslator()->trans("No variable was created."));
-
- $createdObject = $createEvent->getConfig();
-
- // Log config creation
- $this->adminLogAppend(sprintf("Variable %s (ID %s) created", $createdObject->getName(), $createdObject->getId()));
-
- // Substitute _ID_ in the URL with the ID of the created object
- $successUrl = str_replace('_ID_', $createdObject->getId(), $creationForm->getSuccessUrl());
-
- // Redirect to the success URL
- $this->redirect($successUrl);
- } catch (FormValidationException $ex) {
- // Form cannot be validated
- $message = $this->createStandardFormValidationErrorMessage($ex);
- } catch (\Exception $ex) {
- // Any other error
- $message = $ex->getMessage();
- }
-
- $this->setupFormErrorContext("variable creation", $message, $creationForm, $ex);
-
- // At this point, the form has error, and should be redisplayed.
- return $this->renderList();
+ protected function getExistingObject() {
+ return ConfigQuery::create()
+ ->joinWithI18n($this->getCurrentEditionLocale())
+ ->findOneById($this->getRequest()->get('variable_id'));
}
- /**
- * Load a config object for modification, and display the edit template.
- *
- * @return Symfony\Component\HttpFoundation\Response the response
- */
- public function changeAction()
- {
- // Check current user authorization
- if (null !== $response = $this->checkAuth("admin.configuration.variables.update")) return $response;
+ protected function getObjectLabel($object) {
+ return $object->getName();
+ }
- // Load the config object
- $config = ConfigQuery::create()
- ->joinWithI18n($this->getCurrentEditionLocale())
- ->findOneById($this->getRequest()->get('variable_id'));
+ protected function getObjectId($object) {
+ return $object->getId();
+ }
- if ($config != null) {
+ protected function renderListTemplate($currentOrder) {
+ return $this->render('variables', array('order' => $currentOrder));
+ }
- // Prepare the data that will hydrate the form
- $data = array(
- 'id' => $config->getId(),
- 'name' => $config->getName(),
- 'value' => $config->getValue(),
- 'hidden' => $config->getHidden(),
- 'secured' => $config->getSecured(),
- 'locale' => $config->getLocale(),
- 'title' => $config->getTitle(),
- 'chapo' => $config->getChapo(),
- 'description' => $config->getDescription(),
- 'postscriptum' => $config->getPostscriptum()
- );
-
- // Setup the object form
- $changeForm = new ConfigModificationForm($this->getRequest(), "form", $data);
-
- // Pass it to the parser
- $this->getParserContext()->addForm($changeForm);
- }
-
- // Render the edition template.
+ protected function renderEditionTemplate() {
return $this->render('variable-edit', array('variable_id' => $this->getRequest()->get('variable_id')));
}
- /**
- * Save changes on a modified config object, and either go back to the variable list, or stay on the edition page.
- *
- * @return Symfony\Component\HttpFoundation\Response the response
- */
- public function saveChangeAction()
- {
- // Check current user authorization
- if (null !== $response = $this->checkAuth("admin.configuration.variables.update")) return $response;
+ protected function redirectToEditionTemplate() {
+ $this->redirectToRoute(
+ "admin.configuration.variables.update",
+ array('variable_id' => $this->getRequest()->get('variable_id'))
+ );
+ }
- $message = false;
-
- // Create the form from the request
- $changeForm = new ConfigModificationForm($this->getRequest());
-
- // Get the variable ID
- $variable_id = $this->getRequest()->get('variable_id');
-
- try {
-
- // Check the form against constraints violations
- $form = $this->validateForm($changeForm, "POST");
-
- // Get the form field values
- $data = $form->getData();
-
- $changeEvent = new ConfigUpdateEvent($data['id']);
-
- // Create and dispatch the change event
- $changeEvent
- ->setEventName($data['name'])
- ->setValue($data['value'])
- ->setHidden($data['hidden'])
- ->setSecured($data['secured'])
- ->setLocale($data["locale"])
- ->setTitle($data['title'])
- ->setChapo($data['chapo'])
- ->setDescription($data['description'])
- ->setPostscriptum($data['postscriptum'])
- ;
-
- $this->dispatch(TheliaEvents::CONFIG_UPDATE, $changeEvent);
-
- if (! $changeEvent->hasConfig()) throw new \LogicException($this->getTranslator()->trans("No variable was updated."));
-
- // Log config modification
- $changedObject = $changeEvent->getConfig();
-
- $this->adminLogAppend(sprintf("Variable %s (ID %s) modified", $changedObject->getName(), $changedObject->getId()));
-
- // If we have to stay on the same page, do not redirect to the succesUrl,
- // just redirect to the edit page again.
- if ($this->getRequest()->get('save_mode') == 'stay') {
-
- $this->redirectToRoute(
- "admin.configuration.variables.update",
- array('variable_id' => $variable_id)
- );
- }
-
- // Redirect to the success URL
- $this->redirect($changeForm->getSuccessUrl());
- } catch (FormValidationException $ex) {
- // Form cannot be validated
- $message = $this->createStandardFormValidationErrorMessage($ex);
- } catch (\Exception $ex) {
- // Any other error
- $message = $ex->getMessage();
- }
-
- $this->setupFormErrorContext("variable edition", $message, $changeForm, $ex);
-
- // At this point, the form has errors, and should be redisplayed.
- return $this->render('variable-edit', array('variable_id' => $variable_id));
+ protected function redirectToListTemplate() {
+ $this->redirectToRoute('admin.configuration.variables.default');
}
/**
@@ -271,25 +187,4 @@ class ConfigController extends BaseAdminController
$this->redirectToRoute('admin.configuration.variables.default');
}
-
- /**
- * Delete a config object
- *
- * @return Symfony\Component\HttpFoundation\Response the response
- */
- public function deleteAction()
- {
- // Check current user authorization
- if (null !== $response = $this->checkAuth("admin.configuration.variables.delete")) return $response;
-
- // Get the config id, and dispatch the delet request
- $event = new ConfigDeleteEvent($this->getRequest()->get('variable_id'));
-
- $this->dispatch(TheliaEvents::CONFIG_DELETE, $event);
-
- if ($event->hasConfig())
- $this->adminLogAppend(sprintf("Variable %s (ID %s) modified", $event->getConfig()->getName(), $event->getConfig()->getId()));
-
- $this->redirectToRoute('admin.configuration.variables.default');
- }
-}
+}
\ No newline at end of file
diff --git a/core/lib/Thelia/Controller/Admin/CurrencyController.php b/core/lib/Thelia/Controller/Admin/CurrencyController.php
index ff2db0ab2..2df950984 100644
--- a/core/lib/Thelia/Controller/Admin/CurrencyController.php
+++ b/core/lib/Thelia/Controller/Admin/CurrencyController.php
@@ -25,219 +25,162 @@ namespace Thelia\Controller\Admin;
use Thelia\Core\Event\CurrencyDeleteEvent;
use Thelia\Core\Event\TheliaEvents;
-use Thelia\Tools\URL;
use Thelia\Core\Event\CurrencyUpdateEvent;
use Thelia\Core\Event\CurrencyCreateEvent;
-use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\CurrencyQuery;
use Thelia\Form\CurrencyModificationForm;
use Thelia\Form\CurrencyCreationForm;
-use Thelia\Core\Event\CurrencyUpdatePositionEvent;
+use Thelia\Core\Event\UpdatePositionEvent;
/**
* Manages currencies sent by mail
*
* @author Franck Allimant
*/
-class CurrencyController extends BaseAdminController
+class CurrencyController extends AbstractCrudController
{
- /**
- * Render the currencies list, ensuring the sort order is set.
- *
- * @return Symfony\Component\HttpFoundation\Response the response
- */
- protected function renderList()
- {
- // Find the current order
- $order = $this->getRequest()->get(
- 'order',
- $this->getSession()->get('admin.currency_order', 'manual')
+ public function __construct() {
+ parent::__construct(
+ 'currency',
+ 'manual',
+
+ 'admin.configuration.currencies.view',
+ 'admin.configuration.currencies.create',
+ 'admin.configuration.currencies.update',
+ 'admin.configuration.currencies.delete',
+
+ TheliaEvents::CURRENCY_CREATE,
+ TheliaEvents::CURRENCY_UPDATE,
+ TheliaEvents::CURRENCY_DELETE,
+ null, // No visibility toggle
+ TheliaEvents::CURRENCY_UPDATE_POSITION
+ );
+ }
+
+ protected function getCreationForm() {
+ return new CurrencyCreationForm($this->getRequest());
+ }
+
+ protected function getUpdateForm() {
+ return new CurrencyModificationForm($this->getRequest());
+ }
+
+ protected function getCreationEvent($formData) {
+ $createEvent = new CurrencyCreateEvent();
+
+ $createEvent
+ ->setCurrencyName($formData['name'])
+ ->setLocale($formData["locale"])
+ ->setSymbol($formData['symbol'])
+ ->setCode($formData['code'])
+ ->setRate($formData['rate'])
+ ;
+
+ return $createEvent;
+ }
+
+ protected function getUpdateEvent($formData) {
+ $changeEvent = new CurrencyUpdateEvent($formData['id']);
+
+ // Create and dispatch the change event
+ $changeEvent
+ ->setCurrencyName($formData['name'])
+ ->setLocale($formData["locale"])
+ ->setSymbol($formData['symbol'])
+ ->setCode($formData['code'])
+ ->setRate($formData['rate'])
+ ;
+
+ return $changeEvent;
+ }
+
+ protected function createUpdatePositionEvent($positionChangeMode, $positionValue) {
+
+ return new UpdatePositionEvent(
+ $this->getRequest()->get('currency_id', null),
+ $positionChangeMode,
+ $positionValue
+ );
+ }
+
+ protected function getDeleteEvent() {
+ return new CurrencyDeleteEvent($this->getRequest()->get('currency_id'));
+ }
+
+ protected function eventContainsObject($event) {
+ return $event->hasCurrency();
+ }
+
+ protected function hydrateObjectForm($object) {
+
+ // Prepare the data that will hydrate the form
+ $data = array(
+ 'id' => $object->getId(),
+ 'name' => $object->getName(),
+ 'locale' => $object->getLocale(),
+ 'code' => $object->getCode(),
+ 'symbol' => $object->getSymbol(),
+ 'rate' => $object->getRate()
);
- // Store the current sort order in session
- $this->getSession()->set('admin.currency_order', $order);
-
- return $this->render('currencies', array('order' => $order));
+ // Setup the object form
+ return new CurrencyModificationForm($this->getRequest(), "form", $data);
}
- /**
- * The default action is displaying the currencies list.
- *
- * @return Symfony\Component\HttpFoundation\Response the response
- */
- public function defaultAction()
- {
- if (null !== $response = $this->checkAuth("admin.configuration.currencies.view")) return $response;
- return $this->renderList();
+ protected function getObjectFromEvent($event) {
+ return $event->hasCurrency() ? $event->getCurrency() : null;
}
- /**
- * Create a new currency object
- *
- * @return Symfony\Component\HttpFoundation\Response the response
- */
- public function createAction()
- {
- // Check current user authorization
- if (null !== $response = $this->checkAuth("admin.configuration.currencies.create")) return $response;
-
- $error_msg = false;
-
- // Create the Creation Form
- $creationForm = new CurrencyCreationForm($this->getRequest());
-
- try {
-
- // Validate the form, create the CurrencyCreation event and dispatch it.
- $form = $this->validateForm($creationForm, "POST");
-
- $data = $form->getData();
-
- $createEvent = new CurrencyCreateEvent();
-
- $createEvent
- ->setCurrencyName($data['name'])
- ->setLocale($data["locale"])
- ->setSymbol($data['symbol'])
- ->setCode($data['code'])
- ->setRate($data['rate'])
- ;
-
- $this->dispatch(TheliaEvents::CURRENCY_CREATE, $createEvent);
-
- if (! $createEvent->hasCurrency()) throw new \LogicException($this->getTranslator()->trans("No currency was created."));
-
- $createdObject = $createEvent->getCurrency();
-
- // Log currency creation
- $this->adminLogAppend(sprintf("Currency %s (ID %s) created", $createdObject->getName(), $createdObject->getId()));
-
- // Substitute _ID_ in the URL with the ID of the created object
- $successUrl = str_replace('_ID_', $createdObject->getId(), $creationForm->getSuccessUrl());
-
- // Redirect to the success URL
- $this->redirect($successUrl);
- } catch (FormValidationException $ex) {
- // Form cannot be validated
- $error_msg = $this->createStandardFormValidationErrorMessage($ex);
- } catch (\Exception $ex) {
- // Any other error
- $error_msg = $ex->getMessage();
- }
-
- $this->setupFormErrorContext("currency creation", $error_msg, $creationForm, $ex);
-
- // At this point, the form has error, and should be redisplayed.
- return $this->renderList();
+ protected function getExistingObject() {
+ return CurrencyQuery::create()
+ ->joinWithI18n($this->getCurrentEditionLocale())
+ ->findOneById($this->getRequest()->get('currency_id'));
}
- /**
- * Load a currency object for modification, and display the edit template.
- *
- * @return Symfony\Component\HttpFoundation\Response the response
- */
- public function changeAction()
- {
- // Check current user authorization
- if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response;
+ protected function getObjectLabel($object) {
+ return $object->getName();
+ }
- // Load the currency object
- $currency = CurrencyQuery::create()
- ->joinWithI18n($this->getCurrentEditionLocale())
- ->findOneById($this->getRequest()->get('currency_id'));
+ protected function getObjectId($object) {
+ return $object->getId();
+ }
- if ($currency != null) {
+ protected function renderListTemplate($currentOrder) {
+ return $this->render('currencies', array('order' => $currentOrder));
+ }
- // Prepare the data that will hydrate the form
- $data = array(
- 'id' => $currency->getId(),
- 'name' => $currency->getName(),
- 'locale' => $currency->getLocale(),
- 'code' => $currency->getCode(),
- 'symbol' => $currency->getSymbol(),
- 'rate' => $currency->getRate()
- );
-
- // Setup the object form
- $changeForm = new CurrencyModificationForm($this->getRequest(), "form", $data);
-
- // Pass it to the parser
- $this->getParserContext()->addForm($changeForm);
- }
-
- // Render the edition template.
+ protected function renderEditionTemplate() {
return $this->render('currency-edit', array('currency_id' => $this->getRequest()->get('currency_id')));
}
+ protected function redirectToEditionTemplate() {
+ $this->redirectToRoute(
+ "admin.configuration.currencies.update",
+ array('currency_id' => $this->getRequest()->get('currency_id'))
+ );
+ }
+
+ protected function redirectToListTemplate() {
+ $this->redirectToRoute('admin.configuration.currencies.default');
+ }
+
+
/**
- * Save changes on a modified currency object, and either go back to the currency list, or stay on the edition page.
- *
- * @return Symfony\Component\HttpFoundation\Response the response
+ * Update currencies rates
*/
- public function saveChangeAction()
+ public function updateRatesAction()
{
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response;
- $error_msg = false;
-
- // Create the form from the request
- $changeForm = new CurrencyModificationForm($this->getRequest());
-
- // Get the currency ID
- $currency_id = $this->getRequest()->get('currency_id');
-
try {
-
- // Check the form against constraints violations
- $form = $this->validateForm($changeForm, "POST");
-
- // Get the form field values
- $data = $form->getData();
-
- $changeEvent = new CurrencyUpdateEvent($data['id']);
-
- // Create and dispatch the change event
- $changeEvent
- ->setCurrencyName($data['name'])
- ->setLocale($data["locale"])
- ->setSymbol($data['symbol'])
- ->setCode($data['code'])
- ->setRate($data['rate'])
- ;
-
- $this->dispatch(TheliaEvents::CURRENCY_UPDATE, $changeEvent);
-
- if (! $changeEvent->hasCurrency()) throw new \LogicException($this->getTranslator()->trans("No currency was updated."));
-
- // Log currency modification
- $changedObject = $changeEvent->getCurrency();
-
- $this->adminLogAppend(sprintf("Currency %s (ID %s) modified", $changedObject->getName(), $changedObject->getId()));
-
- // If we have to stay on the same page, do not redirect to the succesUrl,
- // just redirect to the edit page again.
- if ($this->getRequest()->get('save_mode') == 'stay') {
- $this->redirectToRoute(
- "admin.configuration.currencies.update",
- array('currency_id' => $currency_id)
- );
- }
-
- // Redirect to the success URL
- $this->redirect($changeForm->getSuccessUrl());
- } catch (FormValidationException $ex) {
- // Form cannot be validated
- $error_msg = $this->createStandardFormValidationErrorMessage($ex);
+ $this->dispatch(TheliaEvents::CURRENCY_UPDATE_RATES);
} catch (\Exception $ex) {
- // Any other error
- $error_msg = $ex->getMessage();
+ // Any error
+ return $this->errorPage($ex);
}
- $this->setupFormErrorContext("currency modification", $error_msg, $changeForm, $ex);
-
- // At this point, the form has errors, and should be redisplayed.
- return $this->render('currency-edit', array('currency_id' => $currency_id));
+ $this->redirectToListTemplate();
}
/**
@@ -260,80 +203,7 @@ class CurrencyController extends BaseAdminController
return $this->errorPage($ex);
}
- $this->redirectToRoute('admin.configuration.currencies.default');
+ $this->redirectToListTemplate();
}
- /**
- * Update currencies rates
- */
- public function updateRatesAction()
- {
- // Check current user authorization
- if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response;
-
- try {
- $this->dispatch(TheliaEvents::CURRENCY_UPDATE_RATES);
- } catch (\Exception $ex) {
- // Any error
- return $this->errorPage($ex);
- }
-
- $this->redirectToRoute('admin.configuration.currencies.default');
- }
-
- /**
- * Update currencyposition
- */
- public function updatePositionAction()
- {
- // Check current user authorization
- if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response;
-
- try {
- $mode = $this->getRequest()->get('mode', null);
-
- if ($mode == 'up')
- $mode = CurrencyUpdatePositionEvent::POSITION_UP;
- else if ($mode == 'down')
- $mode = CurrencyUpdatePositionEvent::POSITION_DOWN;
- else
- $mode = CurrencyUpdatePositionEvent::POSITION_ABSOLUTE;
-
- $position = $this->getRequest()->get('position', null);
-
- $event = new CurrencyUpdatePositionEvent(
- $this->getRequest()->get('currency_id', null),
- $mode,
- $this->getRequest()->get('position', null)
- );
-
- $this->dispatch(TheliaEvents::CURRENCY_UPDATE_POSITION, $event);
- } catch (\Exception $ex) {
- // Any error
- return $this->errorPage($ex);
- }
-
- $this->redirectToRoute('admin.configuration.currencies.default');
- }
-
- /**
- * Delete a currency object
- *
- * @return Symfony\Component\HttpFoundation\Response the response
- */
- public function deleteAction()
- {
- // Check current user authorization
- if (null !== $response = $this->checkAuth("admin.configuration.currencies.delete")) return $response;
-
- // Get the currency id, and dispatch the delet request
- $event = new CurrencyDeleteEvent($this->getRequest()->get('currency_id'));
-
- $this->dispatch(TheliaEvents::CURRENCY_DELETE, $event);
-
- if ($event->hasCurrency())
- $this->adminLogAppend(sprintf("Currency %s (ID %s) modified", $event->getCurrency()->getName(), $event->getCurrency()->getId()));
-
- $this->redirectToRoute('admin.configuration.currencies.default');
- }
}
diff --git a/core/lib/Thelia/Controller/Admin/CustomerController.php b/core/lib/Thelia/Controller/Admin/CustomerController.php
index ddf4681b9..9209cb361 100644
--- a/core/lib/Thelia/Controller/Admin/CustomerController.php
+++ b/core/lib/Thelia/Controller/Admin/CustomerController.php
@@ -22,6 +22,15 @@
/*************************************************************************************/
namespace Thelia\Controller\Admin;
+use Propel\Runtime\Exception\PropelException;
+use Symfony\Component\Form\Form;
+use Thelia\Core\Event\CustomerCreateOrUpdateEvent;
+use Thelia\Core\Event\CustomerEvent;
+use Thelia\Core\Event\TheliaEvents;
+use Thelia\Form\CustomerModification;
+use Thelia\Form\Exception\FormValidationException;
+use Thelia\Model\CustomerQuery;
+use Thelia\Core\Translation\Translator;
/**
* Class CustomerController
@@ -32,15 +41,141 @@ class CustomerController extends BaseAdminController
{
public function indexAction()
{
- if (null !== $response = $this->checkAuth("admin.customers.view")) return $response;
+ if (null !== $response = $this->checkAuth("admin.customer.view")) return $response;
return $this->render("customers", array("display_customer" => 20));
}
public function viewAction($customer_id)
{
+ if (null !== $response = $this->checkAuth("admin.customer.view")) return $response;
return $this->render("customer-edit", array(
"customer_id" => $customer_id
));
}
+
+ /**
+ * update customer action
+ *
+ * @param $customer_id
+ * @return mixed|\Symfony\Component\HttpFoundation\Response
+ */
+ public function updateAction($customer_id)
+ {
+ if (null !== $response = $this->checkAuth("admin.customer.update")) return $response;
+
+ $message = false;
+
+ $customerModification = new CustomerModification($this->getRequest());
+
+ try {
+ $customer = CustomerQuery::create()->findPk($customer_id);
+
+ if(null === $customer) {
+ throw new \InvalidArgumentException(sprintf("%d customer id does not exists", $customer_id));
+ }
+
+ $form = $this->validateForm($customerModification);
+
+ $event = $this->createEventInstance($form->getData());
+ $event->setCustomer($customer);
+
+ $this->dispatch(TheliaEvents::CUSTOMER_UPDATEACCOUNT, $event);
+
+ $customerUpdated = $event->getCustomer();
+
+ $this->adminLogAppend(sprintf("Customer with Ref %s (ID %d) modified", $customerUpdated->getRef() , $customerUpdated->getId()));
+
+ if($this->getRequest()->get("save_mode") == "close") {
+ $this->redirectToRoute("admin.customers");
+ } else {
+ $this->redirectSuccess($customerModification);
+ }
+
+ } catch (FormValidationException $e) {
+ $message = sprintf("Please check your input: %s", $e->getMessage());
+ } catch (PropelException $e) {
+ $message = $e->getMessage();
+ } catch (\Exception $e) {
+ $message = sprintf("Sorry, an error occured: %s", $e->getMessage()." ".$e->getFile());
+ }
+
+ if ($message !== false) {
+ \Thelia\Log\Tlog::getInstance()->error(sprintf("Error during customer login process : %s.", $message));
+
+ $customerModification->setErrorMessage($message);
+
+ $this->getParserContext()
+ ->addForm($customerModification)
+ ->setGeneralError($message)
+ ;
+ }
+
+ return $this->render("customer-edit", array(
+ "customer_id" => $customer_id
+ ));
+ }
+
+ public function deleteAction()
+ {
+ if (null !== $response = $this->checkAuth("admin.customer.delete")) return $response;
+
+ $message = null;
+
+ try {
+ $customer_id = $this->getRequest()->get("customer_id");
+ $customer = CustomerQuery::create()->findPk($customer_id);
+
+ if(null === $customer) {
+ throw new \InvalidArgumentException(Translator::getInstance("The customer you want to delete does not exists"));
+ }
+
+ $event = new CustomerEvent($customer);
+
+ $this->dispatch(TheliaEvents::CUSTOMER_DELETEACCOUNT, $event);
+ } catch(\Exception $e) {
+ $message = $e->getMessage();
+ }
+
+ $params = array(
+ "customer_page" => $this->getRequest()->get("customer_page", 1)
+ );
+
+ if ($message) {
+ $params["delete_error_message"] = $message;
+ }
+
+ $this->redirectToRoute("admin.customers", $params);
+
+ }
+
+ /**
+ * @param $data
+ * @return CustomerCreateOrUpdateEvent
+ */
+ private function createEventInstance($data)
+ {
+ $customerCreateEvent = new CustomerCreateOrUpdateEvent(
+ $data["title"],
+ $data["firstname"],
+ $data["lastname"],
+ $data["address1"],
+ $data["address2"],
+ $data["address3"],
+ $data["phone"],
+ $data["cellphone"],
+ $data["zipcode"],
+ $data["city"],
+ $data["country"],
+ isset($data["email"])?$data["email"]:null,
+ isset($data["password"]) ? $data["password"]:null,
+ $this->getRequest()->getSession()->getLang()->getId(),
+ isset($data["reseller"])?$data["reseller"]:null,
+ isset($data["sponsor"])?$data["sponsor"]:null,
+ isset($data["discount"])?$data["discount"]:null,
+ isset($data["company"])?$data["company"]:null
+ );
+
+ return $customerCreateEvent;
+ }
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Controller/Admin/MessageController.php b/core/lib/Thelia/Controller/Admin/MessageController.php
index b5316efdd..f87218116 100644
--- a/core/lib/Thelia/Controller/Admin/MessageController.php
+++ b/core/lib/Thelia/Controller/Admin/MessageController.php
@@ -24,11 +24,8 @@
namespace Thelia\Controller\Admin;
use Thelia\Core\Event\MessageDeleteEvent;
-use Thelia\Core\Event\TheliaEvents;
-use Thelia\Tools\URL;
-use Thelia\Core\Event\MessageUpdateEvent;
+use Thelia\Core\Event\TheliaEvents;use Thelia\Core\Event\MessageUpdateEvent;
use Thelia\Core\Event\MessageCreateEvent;
-use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\MessageQuery;
use Thelia\Form\MessageModificationForm;
use Thelia\Form\MessageCreationForm;
@@ -38,217 +35,124 @@ use Thelia\Form\MessageCreationForm;
*
* @author Franck Allimant
*/
-class MessageController extends BaseAdminController
+class MessageController extends AbstractCrudController
{
- /**
- * Render the messages list
- *
- * @return Symfony\Component\HttpFoundation\Response the response
- */
- protected function renderList()
- {
+ public function __construct() {
+ parent::__construct(
+ 'message',
+ null,
+
+ 'admin.configuration.messages.view',
+ 'admin.configuration.messages.create',
+ 'admin.configuration.messages.update',
+ 'admin.configuration.messages.delete',
+
+ TheliaEvents::MESSAGE_CREATE,
+ TheliaEvents::MESSAGE_UPDATE,
+ TheliaEvents::MESSAGE_DELETE,
+ null, // No visibility toggle
+ null // No position update
+ );
+ }
+
+ protected function getCreationForm() {
+ return new MessageCreationForm($this->getRequest());
+ }
+
+ protected function getUpdateForm() {
+ return new MessageModificationForm($this->getRequest());
+ }
+
+ protected function getCreationEvent($formData) {
+ $createEvent = new MessageCreateEvent();
+
+ $createEvent
+ ->setMessageName($formData['name'])
+ ->setLocale($formData["locale"])
+ ->setTitle($formData['title'])
+ ->setSecured($formData['secured'])
+ ;
+
+ return $createEvent;
+ }
+
+ protected function getUpdateEvent($formData) {
+ $changeEvent = new MessageUpdateEvent($formData['id']);
+
+ // Create and dispatch the change event
+ $changeEvent
+ ->setMessageName($formData['name'])
+ ->setSecured($formData['secured'])
+ ->setLocale($formData["locale"])
+ ->setTitle($formData['title'])
+ ->setSubject($formData['subject'])
+ ->setHtmlMessage($formData['html_message'])
+ ->setTextMessage($formData['text_message'])
+ ;
+
+ return $changeEvent;
+ }
+
+ protected function getDeleteEvent() {
+ return new MessageDeleteEvent($this->getRequest()->get('message_id'));
+ }
+
+ protected function eventContainsObject($event) {
+ return $event->hasMessage();
+ }
+
+ protected function hydrateObjectForm($object) {
+
+ // Prepare the data that will hydrate the form
+ $data = array(
+ 'id' => $object->getId(),
+ 'name' => $object->getName(),
+ 'secured' => $object->getSecured(),
+ 'locale' => $object->getLocale(),
+ 'title' => $object->getTitle(),
+ 'subject' => $object->getSubject(),
+ 'html_message' => $object->getHtmlMessage(),
+ 'text_message' => $object->getTextMessage()
+ );
+
+ // Setup the object form
+ return new MessageModificationForm($this->getRequest(), "form", $data);
+ }
+
+ protected function getObjectFromEvent($event) {
+ return $event->hasMessage() ? $event->getMessage() : null;
+ }
+
+ protected function getExistingObject() {
+ return MessageQuery::create()
+ ->joinWithI18n($this->getCurrentEditionLocale())
+ ->findOneById($this->getRequest()->get('message_id'));
+ }
+
+ protected function getObjectLabel($object) {
+ return $object->getName();
+ }
+
+ protected function getObjectId($object) {
+ return $object->getId();
+ }
+
+ protected function renderListTemplate($currentOrder) {
return $this->render('messages');
}
- /**
- * The default action is displaying the messages list.
- *
- * @return Symfony\Component\HttpFoundation\Response the response
- */
- public function defaultAction()
- {
- if (null !== $response = $this->checkAuth("admin.configuration.messages.view")) return $response;
- return $this->renderList();
- }
-
- /**
- * Create a new message object
- *
- * @return Symfony\Component\HttpFoundation\Response the response
- */
- public function createAction()
- {
- // Check current user authorization
- if (null !== $response = $this->checkAuth("admin.configuration.messages.create")) return $response;
-
- $message = false;
-
- // Create the creation Form
- $creationForm = new MessageCreationForm($this->getRequest());
-
- try {
-
- // Validate the form, create the MessageCreation event and dispatch it.
- $form = $this->validateForm($creationForm, "POST");
-
- $data = $form->getData();
-
- $createEvent = new MessageCreateEvent();
-
- $createEvent
- ->setMessageName($data['name'])
- ->setLocale($data["locale"])
- ->setTitle($data['title'])
- ->setSecured($data['secured'])
- ;
-
- $this->dispatch(TheliaEvents::MESSAGE_CREATE, $createEvent);
-
- if (! $createEvent->hasMessage()) throw new \LogicException($this->getTranslator()->trans("No message was created."));
-
- $createdObject = $createEvent->getMessage();
-
- $this->adminLogAppend(sprintf("Message %s (ID %s) created", $createdObject->getName(), $createdObject->getId()));
-
- // Substitute _ID_ in the URL with the ID of the created object
- $successUrl = str_replace('_ID_', $createdObject->getId(), $creationForm->getSuccessUrl());
-
- // Redirect to the success URL
- $this->redirect($successUrl);
- } catch (FormValidationException $ex) {
- // Form cannot be validated
- $message = $this->createStandardFormValidationErrorMessage($ex);
- } catch (\Exception $ex) {
- // Any other error
- $message = $ex->getMessage();
- }
-
- $this->setupFormErrorContext("message modification", $message, $creationForm, $ex);
-
- // At this point, the form has error, and should be redisplayed.
- return $this->render('messages');
- }
-
- /**
- * Load a message object for modification, and display the edit template.
- *
- * @return Symfony\Component\HttpFoundation\Response the response
- */
- public function changeAction()
- {
- // Check current user authorization
- if (null !== $response = $this->checkAuth("admin.configuration.messages.update")) return $response;
-
- // Load the message object
- $message = MessageQuery::create()
- ->joinWithI18n($this->getCurrentEditionLocale())
- ->findOneById($this->getRequest()->get('message_id'));
-
- if ($message != null) {
-
- // Prepare the data that will hydrate the form
- $data = array(
- 'id' => $message->getId(),
- 'name' => $message->getName(),
- 'secured' => $message->getSecured(),
- 'locale' => $message->getLocale(),
- 'title' => $message->getTitle(),
- 'subject' => $message->getSubject(),
- 'html_message' => $message->getHtmlMessage(),
- 'text_message' => $message->getTextMessage()
- );
-
- // Setup the object form
- $changeForm = new MessageModificationForm($this->getRequest(), "form", $data);
-
- // Pass it to the parser
- $this->getParserContext()->addForm($changeForm);
- }
-
- // Render the edition template.
+ protected function renderEditionTemplate() {
return $this->render('message-edit', array('message_id' => $this->getRequest()->get('message_id')));
}
- /**
- * Save changes on a modified message object, and either go back to the message list, or stay on the edition page.
- *
- * @return Symfony\Component\HttpFoundation\Response the response
- */
- public function saveChangeAction()
- {
- // Check current user authorization
- if (null !== $response = $this->checkAuth("admin.configuration.messages.update")) return $response;
-
- $message = false;
-
- // Create the form from the request
- $changeForm = new MessageModificationForm($this->getRequest());
-
- // Get the message ID
- $message_id = $this->getRequest()->get('message_id');
-
- try {
-
- // Check the form against constraints violations
- $form = $this->validateForm($changeForm, "POST");
-
- // Get the form field values
- $data = $form->getData();
-
- $changeEvent = new MessageUpdateEvent($data['id']);
-
- // Create and dispatch the change event
- $changeEvent
- ->setMessageName($data['name'])
- ->setSecured($data['secured'])
- ->setLocale($data["locale"])
- ->setTitle($data['title'])
- ->setSubject($data['subject'])
- ->setHtmlMessage($data['html_message'])
- ->setTextMessage($data['text_message'])
- ;
-
- $this->dispatch(TheliaEvents::MESSAGE_UPDATE, $changeEvent);
-
- if (! $changeEvent->hasMessage()) throw new \LogicException($this->getTranslator()->trans("No message was updated."));
-
- $changedObject = $changeEvent->getMessage();
-
- $this->adminLogAppend(sprintf("Variable %s (ID %s) modified", $changedObject->getName(), $changedObject->getId()));
-
- // If we have to stay on the same page, do not redirect to the succesUrl,
- // just redirect to the edit page again.
- if ($this->getRequest()->get('save_mode') == 'stay') {
- $this->redirectToRoute(
- "admin.configuration.messages.update",
- array('message_id' => $message_id)
- );
- }
-
- // Redirect to the success URL
- $this->redirect($changeForm->getSuccessUrl());
- } catch (FormValidationException $ex) {
- // Form cannot be validated
- $message = $this->createStandardFormValidationErrorMessage($ex);
- } catch (\Exception $ex) {
- // Any other error
- $message = $ex->getMessage();
- }
-
- $this->setupFormErrorContext("message modification", $message, $changeForm, $ex);
-
- // At this point, the form has errors, and should be redisplayed.
- return $this->render('message-edit', array('message_id' => $message_id));
+ protected function redirectToEditionTemplate() {
+ $this->redirectToRoute(
+ "admin.configuration.messages.update",
+ array('message_id' => $this->getRequest()->get('message_id'))
+ );
}
- /**
- * Delete a message object
- *
- * @return Symfony\Component\HttpFoundation\Response the response
- */
- public function deleteAction()
- {
- // Check current user authorization
- if (null !== $response = $this->checkAuth("admin.configuration.messages.delete")) return $response;
-
- // Get the message id, and dispatch the delet request
- $event = new MessageDeleteEvent($this->getRequest()->get('message_id'));
-
- $this->dispatch(TheliaEvents::MESSAGE_DELETE, $event);
-
- if ($event->hasMessage())
- $this->adminLogAppend(sprintf("Message %s (ID %s) modified", $event->getMessage()->getName(), $event->getMessage()->getId()));
-
+ protected function redirectToListTemplate() {
$this->redirectToRoute('admin.configuration.messages.default');
}
}
diff --git a/core/lib/Thelia/Controller/Admin/OrderController.php b/core/lib/Thelia/Controller/Admin/OrderController.php
index b7e2b00ce..b2047cc31 100644
--- a/core/lib/Thelia/Controller/Admin/OrderController.php
+++ b/core/lib/Thelia/Controller/Admin/OrderController.php
@@ -36,4 +36,12 @@ class OrderController extends BaseAdminController
return $this->render("orders", array("display_order" => 20));
}
+ public function viewAction($order_id)
+ {
+
+ return $this->render("order-edit", array(
+ "order_id" => $order_id
+ ));
+ }
+
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Controller/Front/CustomerController.php b/core/lib/Thelia/Controller/Front/CustomerController.php
index a0fd74abc..3b8c2ccff 100755
--- a/core/lib/Thelia/Controller/Front/CustomerController.php
+++ b/core/lib/Thelia/Controller/Front/CustomerController.php
@@ -278,7 +278,8 @@ class CustomerController extends BaseFrontController
$this->getRequest()->getSession()->getLang()->getId(),
isset($data["reseller"])?$data["reseller"]:null,
isset($data["sponsor"])?$data["sponsor"]:null,
- isset($data["discount"])?$data["discount"]:null
+ isset($data["discount"])?$data["discount"]:null,
+ isset($data["company"])?$data["company"]:null
);
return $customerCreateEvent;
diff --git a/core/lib/Thelia/Core/Event/AttributeAvCreateEvent.php b/core/lib/Thelia/Core/Event/AttributeAvCreateEvent.php
new file mode 100644
index 000000000..81d22cfb9
--- /dev/null
+++ b/core/lib/Thelia/Core/Event/AttributeAvCreateEvent.php
@@ -0,0 +1,68 @@
+. */
+/* */
+/*************************************************************************************/
+
+namespace Thelia\Core\Event;
+
+class AttributeAvCreateEvent extends AttributeAvEvent
+{
+ protected $title;
+ protected $locale;
+ protected $attribute_id;
+
+ public function getLocale()
+ {
+ return $this->locale;
+ }
+
+ public function setLocale($locale)
+ {
+ $this->locale = $locale;
+
+ return $this;
+ }
+
+ public function getTitle()
+ {
+ return $this->title;
+ }
+
+ public function setTitle($title)
+ {
+ $this->title = $title;
+
+ return $this;
+ }
+
+ public function getAttributeId()
+ {
+ return $this->attribute_id;
+ }
+
+ public function setAttributeId($attribute_id)
+ {
+ $this->attribute_id = $attribute_id;
+
+ return $this;
+ }
+
+}
diff --git a/core/lib/Thelia/Core/Event/CategoryToggleVisibilityEvent.php b/core/lib/Thelia/Core/Event/AttributeAvDeleteEvent.php
similarity index 73%
rename from core/lib/Thelia/Core/Event/CategoryToggleVisibilityEvent.php
rename to core/lib/Thelia/Core/Event/AttributeAvDeleteEvent.php
index 506904ec8..d710dc23f 100644
--- a/core/lib/Thelia/Core/Event/CategoryToggleVisibilityEvent.php
+++ b/core/lib/Thelia/Core/Event/AttributeAvDeleteEvent.php
@@ -1,7 +1,7 @@
. */
+/* along with this program. If not, see . */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event;
-class CategoryToggleVisibilityEvent extends BaseToggleVisibilityEvent
+class AttributeAvDeleteEvent extends AttributeAvEvent
{
+ protected $attributeAv_id;
+
+ public function __construct($attributeAv_id)
+ {
+ $this->setAttributeAvId($attributeAv_id);
+ }
+
+ public function getAttributeAvId()
+ {
+ return $this->attributeAv_id;
+ }
+
+ public function setAttributeAvId($attributeAv_id)
+ {
+ $this->attributeAv_id = $attributeAv_id;
+
+ return $this;
+ }
}
diff --git a/core/lib/Thelia/Core/Event/AttributeAvEvent.php b/core/lib/Thelia/Core/Event/AttributeAvEvent.php
new file mode 100644
index 000000000..c6c1726bd
--- /dev/null
+++ b/core/lib/Thelia/Core/Event/AttributeAvEvent.php
@@ -0,0 +1,52 @@
+. */
+/* */
+/*************************************************************************************/
+
+namespace Thelia\Core\Event;
+use Thelia\Model\AttributeAv;
+
+class AttributeAvEvent extends ActionEvent
+{
+ protected $attributeAv = null;
+
+ public function __construct(AttributeAv $attributeAv = null)
+ {
+ $this->attributeAv = $attributeAv;
+ }
+
+ public function hasAttributeAv()
+ {
+ return ! is_null($this->attributeAv);
+ }
+
+ public function getAttributeAv()
+ {
+ return $this->attributeAv;
+ }
+
+ public function setAttributeAv($attributeAv)
+ {
+ $this->attributeAv = $attributeAv;
+
+ return $this;
+ }
+}
diff --git a/core/lib/Thelia/Core/Event/AttributeAvUpdateEvent.php b/core/lib/Thelia/Core/Event/AttributeAvUpdateEvent.php
new file mode 100644
index 000000000..c76198954
--- /dev/null
+++ b/core/lib/Thelia/Core/Event/AttributeAvUpdateEvent.php
@@ -0,0 +1,86 @@
+. */
+/* */
+/*************************************************************************************/
+
+namespace Thelia\Core\Event;
+
+class AttributeAvUpdateEvent extends AttributeAvCreateEvent
+{
+ protected $attributeAv_id;
+
+ protected $description;
+ protected $chapo;
+ protected $postscriptum;
+
+ public function __construct($attributeAv_id)
+ {
+ $this->setAttributeAvId($attributeAv_id);
+ }
+
+ public function getAttributeAvId()
+ {
+ return $this->attributeAv_id;
+ }
+
+ public function setAttributeAvId($attributeAv_id)
+ {
+ $this->attributeAv_id = $attributeAv_id;
+
+ return $this;
+ }
+
+ public function getDescription()
+ {
+ return $this->description;
+ }
+
+ public function setDescription($description)
+ {
+ $this->description = $description;
+
+ return $this;
+ }
+
+ public function getChapo()
+ {
+ return $this->chapo;
+ }
+
+ public function setChapo($chapo)
+ {
+ $this->chapo = $chapo;
+
+ return $this;
+ }
+
+ public function getPostscriptum()
+ {
+ return $this->postscriptum;
+ }
+
+ public function setPostscriptum($postscriptum)
+ {
+ $this->postscriptum = $postscriptum;
+
+ return $this;
+ }
+}
diff --git a/core/lib/Thelia/Core/Event/AttributeCreateEvent.php b/core/lib/Thelia/Core/Event/AttributeCreateEvent.php
new file mode 100644
index 000000000..0787b34e3
--- /dev/null
+++ b/core/lib/Thelia/Core/Event/AttributeCreateEvent.php
@@ -0,0 +1,68 @@
+. */
+/* */
+/*************************************************************************************/
+
+namespace Thelia\Core\Event;
+
+class AttributeCreateEvent extends AttributeEvent
+{
+ protected $title;
+ protected $locale;
+ protected $add_to_all_templates;
+
+ public function getLocale()
+ {
+ return $this->locale;
+ }
+
+ public function setLocale($locale)
+ {
+ $this->locale = $locale;
+
+ return $this;
+ }
+
+ public function getTitle()
+ {
+ return $this->title;
+ }
+
+ public function setTitle($title)
+ {
+ $this->title = $title;
+
+ return $this;
+ }
+
+ public function getAddToAllTemplates()
+ {
+ return $this->add_to_all_templates;
+ }
+
+ public function setAddToAllTemplates($add_to_all_templates)
+ {
+ $this->add_to_all_templates = $add_to_all_templates;
+
+ return $this;
+ }
+
+}
diff --git a/core/lib/Thelia/Core/Event/CurrencyUpdatePositionEvent.php b/core/lib/Thelia/Core/Event/AttributeDeleteEvent.php
similarity index 74%
rename from core/lib/Thelia/Core/Event/CurrencyUpdatePositionEvent.php
rename to core/lib/Thelia/Core/Event/AttributeDeleteEvent.php
index fad51f2c7..d7f359f9a 100644
--- a/core/lib/Thelia/Core/Event/CurrencyUpdatePositionEvent.php
+++ b/core/lib/Thelia/Core/Event/AttributeDeleteEvent.php
@@ -1,7 +1,7 @@
. */
+/* along with this program. If not, see . */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event;
-class CurrencyUpdatePositionEvent extends BaseUpdatePositionEvent
+class AttributeDeleteEvent extends AttributeEvent
{
+ protected $attribute_id;
+
+ public function __construct($attribute_id)
+ {
+ $this->setAttributeId($attribute_id);
+ }
+
+ public function getAttributeId()
+ {
+ return $this->attribute_id;
+ }
+
+ public function setAttributeId($attribute_id)
+ {
+ $this->attribute_id = $attribute_id;
+
+ return $this;
+ }
}
diff --git a/core/lib/Thelia/Core/Event/AttributeEvent.php b/core/lib/Thelia/Core/Event/AttributeEvent.php
new file mode 100644
index 000000000..7ce78938c
--- /dev/null
+++ b/core/lib/Thelia/Core/Event/AttributeEvent.php
@@ -0,0 +1,52 @@
+. */
+/* */
+/*************************************************************************************/
+
+namespace Thelia\Core\Event;
+use Thelia\Model\Attribute;
+
+class AttributeEvent extends ActionEvent
+{
+ protected $attribute = null;
+
+ public function __construct(Attribute $attribute = null)
+ {
+ $this->attribute = $attribute;
+ }
+
+ public function hasAttribute()
+ {
+ return ! is_null($this->attribute);
+ }
+
+ public function getAttribute()
+ {
+ return $this->attribute;
+ }
+
+ public function setAttribute($attribute)
+ {
+ $this->attribute = $attribute;
+
+ return $this;
+ }
+}
diff --git a/core/lib/Thelia/Core/Event/AttributeUpdateEvent.php b/core/lib/Thelia/Core/Event/AttributeUpdateEvent.php
new file mode 100644
index 000000000..a1bf124d9
--- /dev/null
+++ b/core/lib/Thelia/Core/Event/AttributeUpdateEvent.php
@@ -0,0 +1,86 @@
+. */
+/* */
+/*************************************************************************************/
+
+namespace Thelia\Core\Event;
+
+class AttributeUpdateEvent extends AttributeCreateEvent
+{
+ protected $attribute_id;
+
+ protected $description;
+ protected $chapo;
+ protected $postscriptum;
+
+ public function __construct($attribute_id)
+ {
+ $this->setAttributeId($attribute_id);
+ }
+
+ public function getAttributeId()
+ {
+ return $this->attribute_id;
+ }
+
+ public function setAttributeId($attribute_id)
+ {
+ $this->attribute_id = $attribute_id;
+
+ return $this;
+ }
+
+ public function getDescription()
+ {
+ return $this->description;
+ }
+
+ public function setDescription($description)
+ {
+ $this->description = $description;
+
+ return $this;
+ }
+
+ public function getChapo()
+ {
+ return $this->chapo;
+ }
+
+ public function setChapo($chapo)
+ {
+ $this->chapo = $chapo;
+
+ return $this;
+ }
+
+ public function getPostscriptum()
+ {
+ return $this->postscriptum;
+ }
+
+ public function setPostscriptum($postscriptum)
+ {
+ $this->postscriptum = $postscriptum;
+
+ return $this;
+ }
+}
diff --git a/core/lib/Thelia/Core/Event/CustomerCreateOrUpdateEvent.php b/core/lib/Thelia/Core/Event/CustomerCreateOrUpdateEvent.php
index 3a57d53a4..d3ae6f62d 100755
--- a/core/lib/Thelia/Core/Event/CustomerCreateOrUpdateEvent.php
+++ b/core/lib/Thelia/Core/Event/CustomerCreateOrUpdateEvent.php
@@ -1,17 +1,35 @@
. */
+/* */
+/*************************************************************************************/
namespace Thelia\Core\Event;
use Symfony\Component\EventDispatcher\Event;
use Thelia\Model\Customer;
+/**
+ * Class CustomerCreateOrUpdateEvent
+ * @package Thelia\Core\Event
+ * @author Manuel Raynaud
+ */
class CustomerCreateOrUpdateEvent extends ActionEvent
{
//base parameters for creating new customer
@@ -32,6 +50,7 @@ class CustomerCreateOrUpdateEvent extends ActionEvent
protected $reseller;
protected $sponsor;
protected $discount;
+ protected $company;
/**
* @var \Thelia\Model\Customer
@@ -39,7 +58,7 @@ class CustomerCreateOrUpdateEvent extends ActionEvent
protected $customer;
/**
- * @param int $title the title customer id
+ * @param int $title the title customer id
* @param string $firstname
* @param string $lastname
* @param string $address1
@@ -49,15 +68,16 @@ class CustomerCreateOrUpdateEvent extends ActionEvent
* @param string $cellphone
* @param string $zipcode
* @param string $city
- * @param int $country the country id
+ * @param int $country the country id
* @param string $email
* @param string $password plain password, don't put hash password, it will hashes again
* @param $lang
- * @param int $reseller if customer is a reseller
- * @param int $sponsor customer's id sponsor
+ * @param int $reseller if customer is a reseller
+ * @param int $sponsor customer's id sponsor
* @param float $discount
+ * @param string $company
*/
- public function __construct($title, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $city, $country, $email, $password, $lang, $reseller, $sponsor, $discount)
+ public function __construct($title, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $city, $country, $email, $password, $lang, $reseller, $sponsor, $discount, $company)
{
$this->address1 = $address1;
$this->address2 = $address2;
@@ -72,9 +92,18 @@ class CustomerCreateOrUpdateEvent extends ActionEvent
$this->cellphone = $cellphone;
$this->title = $title;
$this->zipcode = $zipcode;
+ $this->city = $city;
$this->reseller = $reseller;
$this->sponsor = $sponsor;
$this->discount = $discount;
+ $this->company = $company;
+ }
+ /**
+ * @return mixed
+ */
+ public function getCompany()
+ {
+ return $this->company;
}
/**
diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php
index c67963a2e..f6e584eb2 100755
--- a/core/lib/Thelia/Core/Event/TheliaEvents.php
+++ b/core/lib/Thelia/Core/Event/TheliaEvents.php
@@ -71,6 +71,11 @@ final class TheliaEvents
*/
const CUSTOMER_UPDATEACCOUNT = "action.updateCustomer";
+ /**
+ * sent on customer removal
+ */
+ const CUSTOMER_DELETEACCOUNT = "action.deleteCustomer";
+
/**
* sent when a customer need a new password
*/
@@ -103,6 +108,16 @@ final class TheliaEvents
*/
const AFTER_UPDATECUSTOMER = "action.after_updateCustomer";
+ /**
+ * sent just before customer removal
+ */
+ const BEFORE_DELETECUSTOMER = "action.before_updateCustomer";
+
+ /**
+ * sent just after customer removal
+ */
+ const AFTER_DELETECUSTOMER = "action.after_deleteCustomer";
+
// -- ADDRESS MANAGEMENT ---------------------------------------------------------
/**
* sent for address creation
@@ -317,5 +332,35 @@ final class TheliaEvents
const BEFORE_DELETECURRENCY = "action.before_deleteCurrency";
const AFTER_DELETECURRENCY = "action.after_deleteCurrency";
+ // -- Attributes management ---------------------------------------------
+ const ATTRIBUTE_CREATE = "action.createAttribute";
+ const ATTRIBUTE_UPDATE = "action.updateAttribute";
+ const ATTRIBUTE_DELETE = "action.deleteAttribute";
+ const ATTRIBUTE_UPDATE_POSITION = "action.updateAttributePosition";
+
+ const BEFORE_CREATEATTRIBUTE = "action.before_createAttribute";
+ const AFTER_CREATEATTRIBUTE = "action.after_createAttribute";
+
+ const BEFORE_UPDATEATTRIBUTE = "action.before_updateAttribute";
+ const AFTER_UPDATEATTRIBUTE = "action.after_updateAttribute";
+
+ const BEFORE_DELETEATTRIBUTE = "action.before_deleteAttribute";
+ const AFTER_DELETEATTRIBUTE = "action.after_deleteAttribute";
+
+ // -- Attributes values management ----------------------------------------
+
+ const ATTRIBUTE_AV_CREATE = "action.createAttributeAv";
+ const ATTRIBUTE_AV_UPDATE = "action.updateAttributeAv";
+ const ATTRIBUTE_AV_DELETE = "action.deleteAttributeAv";
+ const ATTRIBUTE_AV_UPDATE_POSITION = "action.updateAttributeAvPosition";
+
+ const BEFORE_CREATEATTRIBUTE_AV = "action.before_createAttributeAv";
+ const AFTER_CREATEATTRIBUTE_AV = "action.after_createAttributeAv";
+
+ const BEFORE_UPDATEATTRIBUTE_AV = "action.before_updateAttributeAv";
+ const AFTER_UPDATEATTRIBUTE_AV = "action.after_updateAttributeAv";
+
+ const BEFORE_DELETEATTRIBUTE_AV = "action.before_deleteAttributeAv";
+ const AFTER_DELETEATTRIBUTE_AV = "action.after_deleteAttributeAv";
}
diff --git a/core/lib/Thelia/Core/Event/BaseToggleVisibilityEvent.php b/core/lib/Thelia/Core/Event/ToggleVisibilityEvent.php
similarity index 97%
rename from core/lib/Thelia/Core/Event/BaseToggleVisibilityEvent.php
rename to core/lib/Thelia/Core/Event/ToggleVisibilityEvent.php
index 65be75292..996292c8e 100644
--- a/core/lib/Thelia/Core/Event/BaseToggleVisibilityEvent.php
+++ b/core/lib/Thelia/Core/Event/ToggleVisibilityEvent.php
@@ -23,7 +23,7 @@
namespace Thelia\Core\Event;
-class BaseToggleVisibilityEvent extends ActionEvent
+class ToggleVisibilityEvent extends ActionEvent
{
protected $object_id;
diff --git a/core/lib/Thelia/Core/Event/BaseUpdatePositionEvent.php b/core/lib/Thelia/Core/Event/UpdatePositionEvent.php
similarity index 98%
rename from core/lib/Thelia/Core/Event/BaseUpdatePositionEvent.php
rename to core/lib/Thelia/Core/Event/UpdatePositionEvent.php
index 9b58ecfeb..e75e30b98 100644
--- a/core/lib/Thelia/Core/Event/BaseUpdatePositionEvent.php
+++ b/core/lib/Thelia/Core/Event/UpdatePositionEvent.php
@@ -23,7 +23,7 @@
namespace Thelia\Core\Event;
-class BaseUpdatePositionEvent extends ActionEvent
+class UpdatePositionEvent extends ActionEvent
{
const POSITION_UP = 1;
const POSITION_DOWN = 2;
diff --git a/core/lib/Thelia/Core/Template/Element/BaseLoop.php b/core/lib/Thelia/Core/Template/Element/BaseLoop.php
index 254560453..b684d06e2 100755
--- a/core/lib/Thelia/Core/Template/Element/BaseLoop.php
+++ b/core/lib/Thelia/Core/Template/Element/BaseLoop.php
@@ -129,6 +129,7 @@ abstract class BaseLoop
$loopType = isset($nameValuePairs['type']) ? $nameValuePairs['type'] : "undefined";
$loopName = isset($nameValuePairs['name']) ? $nameValuePairs['name'] : "undefined";
+ $this->args->rewind();
while (($argument = $this->args->current()) !== false) {
$this->args->next();
diff --git a/core/lib/Thelia/Core/Template/Loop/Address.php b/core/lib/Thelia/Core/Template/Loop/Address.php
index 831a8dca1..1321592f4 100755
--- a/core/lib/Thelia/Core/Template/Loop/Address.php
+++ b/core/lib/Thelia/Core/Template/Loop/Address.php
@@ -63,7 +63,7 @@ class Address extends BaseLoop
),
'current'
),
- Argument::createBooleanTypeArgument('default', false),
+ Argument::createBooleanTypeArgument('default'),
Argument::createIntListTypeArgument('exclude')
);
}
@@ -100,6 +100,8 @@ class Address extends BaseLoop
if ($default === true) {
$search->filterByIsDefault(1, Criteria::EQUAL);
+ } else if($default === false) {
+ $search->filterByIsDefault(0, Criteria::EQUAL);
}
$exclude = $this->getExclude();
diff --git a/core/lib/Thelia/Core/Template/Loop/Attribute.php b/core/lib/Thelia/Core/Template/Loop/Attribute.php
index 5ab4a2b4e..cb3a25e17 100755
--- a/core/lib/Thelia/Core/Template/Loop/Attribute.php
+++ b/core/lib/Thelia/Core/Template/Loop/Attribute.php
@@ -66,7 +66,7 @@ class Attribute extends BaseI18nLoop
new Argument(
'order',
new TypeCollection(
- new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse'))
+ new Type\EnumListType(array('id', 'id_reverse', 'alpha', 'alpha_reverse', 'manual', 'manual_reverse'))
),
'manual'
)
@@ -129,6 +129,12 @@ class Attribute extends BaseI18nLoop
foreach ($orders as $order) {
switch ($order) {
+ case "id":
+ $search->orderById(Criteria::ASC);
+ break;
+ case "id_reverse":
+ $search->orderById(Criteria::DESC);
+ break;
case "alpha":
$search->addAscendingOrderByColumn('i18n_TITLE');
break;
diff --git a/core/lib/Thelia/Core/Template/Loop/Category.php b/core/lib/Thelia/Core/Template/Loop/Category.php
index 91cb90b0a..2b1156b98 100755
--- a/core/lib/Thelia/Core/Template/Loop/Category.php
+++ b/core/lib/Thelia/Core/Template/Loop/Category.php
@@ -79,7 +79,7 @@ class Category extends BaseI18nLoop
new Argument(
'order',
new TypeCollection(
- new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse', 'visible', 'visible_reverse', 'random'))
+ new Type\EnumListType(array('id', 'id_reverse', 'alpha', 'alpha_reverse', 'manual', 'manual_reverse', 'visible', 'visible_reverse', 'random'))
),
'manual'
),
@@ -132,6 +132,12 @@ class Category extends BaseI18nLoop
foreach ($orders as $order) {
switch ($order) {
+ case "id":
+ $search->orderById(Criteria::ASC);
+ break;
+ case "id_reverse":
+ $search->orderById(Criteria::DESC);
+ break;
case "alpha":
$search->addAscendingOrderByColumn('i18n_TITLE');
break;
diff --git a/core/lib/Thelia/Form/AttributeAvCreationForm.php b/core/lib/Thelia/Form/AttributeAvCreationForm.php
new file mode 100644
index 000000000..2ad202e1d
--- /dev/null
+++ b/core/lib/Thelia/Form/AttributeAvCreationForm.php
@@ -0,0 +1,62 @@
+. */
+/* */
+/*************************************************************************************/
+namespace Thelia\Form;
+
+use Symfony\Component\Validator\Constraints;
+use Thelia\Model\CurrencyQuery;
+use Symfony\Component\Validator\ExecutionContextInterface;
+use Symfony\Component\Validator\Constraints\NotBlank;
+use Thelia\Core\Translation\Translator;
+
+class AttributeAvCreationForm extends BaseForm
+{
+ protected function buildForm()
+ {
+ $this->formBuilder
+ ->add("title" , "text" , array(
+ "constraints" => array(
+ new NotBlank()
+ ),
+ "label" => Translator::getInstance()->trans("Title *"),
+ "label_attr" => array(
+ "for" => "title"
+ ))
+ )
+ ->add("locale" , "text" , array(
+ "constraints" => array(
+ new NotBlank()
+ ))
+ )
+ ->add("attribute_id", "hidden", array(
+ "constraints" => array(
+ new NotBlank()
+ ))
+ )
+ ;
+ }
+
+ public function getName()
+ {
+ return "thelia_attributeav_creation";
+ }
+}
\ No newline at end of file
diff --git a/core/lib/Thelia/Form/AttributeCreationForm.php b/core/lib/Thelia/Form/AttributeCreationForm.php
new file mode 100644
index 000000000..a4c6d402f
--- /dev/null
+++ b/core/lib/Thelia/Form/AttributeCreationForm.php
@@ -0,0 +1,66 @@
+. */
+/* */
+/*************************************************************************************/
+namespace Thelia\Form;
+
+use Symfony\Component\Validator\Constraints;
+use Thelia\Model\CurrencyQuery;
+use Symfony\Component\Validator\ExecutionContextInterface;
+use Symfony\Component\Validator\Constraints\NotBlank;
+use Thelia\Core\Translation\Translator;
+
+class AttributeCreationForm extends BaseForm
+{
+ protected function buildForm()
+ {
+ $this->formBuilder
+ ->add("title" , "text" , array(
+ "constraints" => array(
+ new NotBlank()
+ ),
+ "label" => Translator::getInstance()->trans("Title *"),
+ "label_attr" => array(
+ "for" => "title"
+ ))
+ )
+ ->add("locale" , "text" , array(
+ "constraints" => array(
+ new NotBlank()
+ ))
+ )
+ ->add("add_to_all" , "checkbox" , array(
+ "constraints" => array(
+ new NotBlank()
+ ),
+ "label" => Translator::getInstance()->trans("Add to all product templates"),
+ "label_attr" => array(
+ "for" => "add_to_all"
+ ))
+ )
+ ;
+ }
+
+ public function getName()
+ {
+ return "thelia_attribute_creation";
+ }
+}
diff --git a/core/lib/Thelia/Form/AttributeModificationForm.php b/core/lib/Thelia/Form/AttributeModificationForm.php
new file mode 100644
index 000000000..62b0b707a
--- /dev/null
+++ b/core/lib/Thelia/Form/AttributeModificationForm.php
@@ -0,0 +1,60 @@
+. */
+/* */
+/*************************************************************************************/
+namespace Thelia\Form;
+
+use Symfony\Component\Validator\Constraints;
+use Thelia\Model\CurrencyQuery;
+use Symfony\Component\Validator\ExecutionContextInterface;
+use Symfony\Component\Validator\Constraints\NotBlank;
+use Thelia\Core\Translation\Translator;
+use Symfony\Component\Validator\Constraints\GreaterThan;
+
+class AttributeModificationForm extends AttributeCreationForm
+{
+ use StandardDescriptionFieldsTrait;
+
+ protected function buildForm()
+ {
+ $this->formBuilder
+ ->add("id", "hidden", array(
+ "constraints" => array(
+ new GreaterThan(
+ array('value' => 0)
+ )
+ )
+ ))
+ ->add('attribute_values', 'collection', array(
+ 'type' => 'text',
+ 'options' => array('required' => false)
+ ))
+ ;
+
+ // Add standard description fields
+ $this->addStandardDescFields();
+ }
+
+ public function getName()
+ {
+ return "thelia_attribute_modification";
+ }
+}
diff --git a/core/lib/Thelia/Form/CustomerModification.php b/core/lib/Thelia/Form/CustomerModification.php
index 358154a18..4f12c6013 100755
--- a/core/lib/Thelia/Form/CustomerModification.php
+++ b/core/lib/Thelia/Form/CustomerModification.php
@@ -58,6 +58,12 @@ class CustomerModification extends BaseForm
$this->formBuilder
->add('update_logged_in_user', 'integer') // In a front office context, update the in-memory logged-in user data
+ ->add("company", "text", array(
+ "label" => Translator::getInstance()->trans("Company"),
+ "label_attr" => array(
+ "for" => "company"
+ )
+ ))
->add("firstname", "text", array(
"constraints" => array(
new Constraints\NotBlank()
diff --git a/core/lib/Thelia/Model/Attribute.php b/core/lib/Thelia/Model/Attribute.php
index 34512b33b..b4101da8c 100755
--- a/core/lib/Thelia/Model/Attribute.php
+++ b/core/lib/Thelia/Model/Attribute.php
@@ -3,7 +3,69 @@
namespace Thelia\Model;
use Thelia\Model\Base\Attribute as BaseAttribute;
+use Propel\Runtime\Connection\ConnectionInterface;
+use Thelia\Core\Event\TheliaEvents;
+use Thelia\Core\Event\AttributeEvent;
class Attribute extends BaseAttribute {
+ use \Thelia\Model\Tools\ModelEventDispatcherTrait;
+ use \Thelia\Model\Tools\PositionManagementTrait;
+
+ /**
+ * {@inheritDoc}
+ */
+ public function preInsert(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::BEFORE_CREATEATTRIBUTE, new AttributeEvent($this));
+
+ // Set the current position for the new object
+ $this->setPosition($this->getNextPosition());
+
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function postInsert(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::AFTER_CREATEATTRIBUTE, new AttributeEvent($this));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function preUpdate(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::BEFORE_UPDATEATTRIBUTE, new AttributeEvent($this));
+
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function postUpdate(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::AFTER_UPDATEATTRIBUTE, new AttributeEvent($this));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function preDelete(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::BEFORE_DELETEATTRIBUTE, new AttributeEvent($this));
+
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function postDelete(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::AFTER_DELETEATTRIBUTE, new AttributeEvent($this));
+ }
}
diff --git a/core/lib/Thelia/Model/AttributeAv.php b/core/lib/Thelia/Model/AttributeAv.php
index a09db787c..d45b16192 100755
--- a/core/lib/Thelia/Model/AttributeAv.php
+++ b/core/lib/Thelia/Model/AttributeAv.php
@@ -3,7 +3,78 @@
namespace Thelia\Model;
use Thelia\Model\Base\AttributeAv as BaseAttributeAv;
+use Thelia\Core\Event\AttributeAvEvent;
+use Propel\Runtime\Connection\ConnectionInterface;
+use Thelia\Core\Event\TheliaEvents;
+use Propel\Runtime\ActiveQuery\Criteria;
class AttributeAv extends BaseAttributeAv {
-}
+ use \Thelia\Model\Tools\ModelEventDispatcherTrait;
+
+ use \Thelia\Model\Tools\PositionManagementTrait;
+
+ /**
+ * when dealing with position, be sure to work insite the current attribute.
+ */
+ protected function addCriteriaToPositionQuery($query) {
+ $query->filterByAttributeId($this->getAttributeId());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function preInsert(ConnectionInterface $con = null)
+ {
+ // Set the current position for the new object
+ $this->setPosition($this->getNextPosition());
+
+ $this->dispatchEvent(TheliaEvents::BEFORE_CREATEATTRIBUTE_AV, new AttributeAvEvent($this));
+
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function postInsert(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::AFTER_CREATEATTRIBUTE_AV, new AttributeAvEvent($this));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function preUpdate(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::BEFORE_UPDATEATTRIBUTE_AV, new AttributeAvEvent($this));
+
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function postUpdate(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::AFTER_UPDATEATTRIBUTE_AV, new AttributeAvEvent($this));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function preDelete(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::BEFORE_DELETEATTRIBUTE_AV, new AttributeAvEvent($this));
+
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function postDelete(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::AFTER_DELETEATTRIBUTE_AV, new AttributeAvEvent($this));
+ }
+}
\ No newline at end of file
diff --git a/core/lib/Thelia/Model/Base/Cart.php b/core/lib/Thelia/Model/Base/Cart.php
index 20a2d9a5c..2ef18297c 100644
--- a/core/lib/Thelia/Model/Base/Cart.php
+++ b/core/lib/Thelia/Model/Base/Cart.php
@@ -99,6 +99,13 @@ abstract class Cart implements ActiveRecordInterface
*/
protected $currency_id;
+ /**
+ * The value for the discount field.
+ * Note: this column has a database default value of: 0
+ * @var double
+ */
+ protected $discount;
+
/**
* The value for the created_at field.
* @var string
@@ -151,11 +158,24 @@ abstract class Cart implements ActiveRecordInterface
*/
protected $cartItemsScheduledForDeletion = null;
+ /**
+ * Applies default values to this object.
+ * This method should be called from the object's constructor (or
+ * equivalent initialization method).
+ * @see __construct()
+ */
+ public function applyDefaultValues()
+ {
+ $this->discount = 0;
+ }
+
/**
* Initializes internal state of Thelia\Model\Base\Cart object.
+ * @see applyDefaults()
*/
public function __construct()
{
+ $this->applyDefaultValues();
}
/**
@@ -471,6 +491,17 @@ abstract class Cart implements ActiveRecordInterface
return $this->currency_id;
}
+ /**
+ * Get the [discount] column value.
+ *
+ * @return double
+ */
+ public function getDiscount()
+ {
+
+ return $this->discount;
+ }
+
/**
* Get the [optionally formatted] temporal [created_at] column value.
*
@@ -653,6 +684,27 @@ abstract class Cart implements ActiveRecordInterface
return $this;
} // setCurrencyId()
+ /**
+ * Set the value of [discount] column.
+ *
+ * @param double $v new value
+ * @return \Thelia\Model\Cart The current object (for fluent API support)
+ */
+ public function setDiscount($v)
+ {
+ if ($v !== null) {
+ $v = (double) $v;
+ }
+
+ if ($this->discount !== $v) {
+ $this->discount = $v;
+ $this->modifiedColumns[] = CartTableMap::DISCOUNT;
+ }
+
+
+ return $this;
+ } // setDiscount()
+
/**
* Sets the value of [created_at] column to a normalized version of the date/time value specified.
*
@@ -705,6 +757,10 @@ abstract class Cart implements ActiveRecordInterface
*/
public function hasOnlyDefaultValues()
{
+ if ($this->discount !== 0) {
+ return false;
+ }
+
// otherwise, everything was equal, so return TRUE
return true;
} // hasOnlyDefaultValues()
@@ -750,13 +806,16 @@ abstract class Cart implements ActiveRecordInterface
$col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : CartTableMap::translateFieldName('CurrencyId', TableMap::TYPE_PHPNAME, $indexType)];
$this->currency_id = (null !== $col) ? (int) $col : null;
- $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : CartTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
+ $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : CartTableMap::translateFieldName('Discount', TableMap::TYPE_PHPNAME, $indexType)];
+ $this->discount = (null !== $col) ? (double) $col : null;
+
+ $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : CartTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
if ($col === '0000-00-00 00:00:00') {
$col = null;
}
$this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null;
- $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : CartTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
+ $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : CartTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
if ($col === '0000-00-00 00:00:00') {
$col = null;
}
@@ -769,7 +828,7 @@ abstract class Cart implements ActiveRecordInterface
$this->ensureConsistency();
}
- return $startcol + 8; // 8 = CartTableMap::NUM_HYDRATE_COLUMNS.
+ return $startcol + 9; // 9 = CartTableMap::NUM_HYDRATE_COLUMNS.
} catch (Exception $e) {
throw new PropelException("Error populating \Thelia\Model\Cart object", 0, $e);
@@ -1075,6 +1134,9 @@ abstract class Cart implements ActiveRecordInterface
if ($this->isColumnModified(CartTableMap::CURRENCY_ID)) {
$modifiedColumns[':p' . $index++] = 'CURRENCY_ID';
}
+ if ($this->isColumnModified(CartTableMap::DISCOUNT)) {
+ $modifiedColumns[':p' . $index++] = 'DISCOUNT';
+ }
if ($this->isColumnModified(CartTableMap::CREATED_AT)) {
$modifiedColumns[':p' . $index++] = 'CREATED_AT';
}
@@ -1110,6 +1172,9 @@ abstract class Cart implements ActiveRecordInterface
case 'CURRENCY_ID':
$stmt->bindValue($identifier, $this->currency_id, PDO::PARAM_INT);
break;
+ case 'DISCOUNT':
+ $stmt->bindValue($identifier, $this->discount, PDO::PARAM_STR);
+ break;
case 'CREATED_AT':
$stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
break;
@@ -1197,9 +1262,12 @@ abstract class Cart implements ActiveRecordInterface
return $this->getCurrencyId();
break;
case 6:
- return $this->getCreatedAt();
+ return $this->getDiscount();
break;
case 7:
+ return $this->getCreatedAt();
+ break;
+ case 8:
return $this->getUpdatedAt();
break;
default:
@@ -1237,8 +1305,9 @@ abstract class Cart implements ActiveRecordInterface
$keys[3] => $this->getAddressDeliveryId(),
$keys[4] => $this->getAddressInvoiceId(),
$keys[5] => $this->getCurrencyId(),
- $keys[6] => $this->getCreatedAt(),
- $keys[7] => $this->getUpdatedAt(),
+ $keys[6] => $this->getDiscount(),
+ $keys[7] => $this->getCreatedAt(),
+ $keys[8] => $this->getUpdatedAt(),
);
$virtualColumns = $this->virtualColumns;
foreach($virtualColumns as $key => $virtualColumn)
@@ -1315,9 +1384,12 @@ abstract class Cart implements ActiveRecordInterface
$this->setCurrencyId($value);
break;
case 6:
- $this->setCreatedAt($value);
+ $this->setDiscount($value);
break;
case 7:
+ $this->setCreatedAt($value);
+ break;
+ case 8:
$this->setUpdatedAt($value);
break;
} // switch()
@@ -1350,8 +1422,9 @@ abstract class Cart implements ActiveRecordInterface
if (array_key_exists($keys[3], $arr)) $this->setAddressDeliveryId($arr[$keys[3]]);
if (array_key_exists($keys[4], $arr)) $this->setAddressInvoiceId($arr[$keys[4]]);
if (array_key_exists($keys[5], $arr)) $this->setCurrencyId($arr[$keys[5]]);
- if (array_key_exists($keys[6], $arr)) $this->setCreatedAt($arr[$keys[6]]);
- if (array_key_exists($keys[7], $arr)) $this->setUpdatedAt($arr[$keys[7]]);
+ if (array_key_exists($keys[6], $arr)) $this->setDiscount($arr[$keys[6]]);
+ if (array_key_exists($keys[7], $arr)) $this->setCreatedAt($arr[$keys[7]]);
+ if (array_key_exists($keys[8], $arr)) $this->setUpdatedAt($arr[$keys[8]]);
}
/**
@@ -1369,6 +1442,7 @@ abstract class Cart implements ActiveRecordInterface
if ($this->isColumnModified(CartTableMap::ADDRESS_DELIVERY_ID)) $criteria->add(CartTableMap::ADDRESS_DELIVERY_ID, $this->address_delivery_id);
if ($this->isColumnModified(CartTableMap::ADDRESS_INVOICE_ID)) $criteria->add(CartTableMap::ADDRESS_INVOICE_ID, $this->address_invoice_id);
if ($this->isColumnModified(CartTableMap::CURRENCY_ID)) $criteria->add(CartTableMap::CURRENCY_ID, $this->currency_id);
+ if ($this->isColumnModified(CartTableMap::DISCOUNT)) $criteria->add(CartTableMap::DISCOUNT, $this->discount);
if ($this->isColumnModified(CartTableMap::CREATED_AT)) $criteria->add(CartTableMap::CREATED_AT, $this->created_at);
if ($this->isColumnModified(CartTableMap::UPDATED_AT)) $criteria->add(CartTableMap::UPDATED_AT, $this->updated_at);
@@ -1439,6 +1513,7 @@ abstract class Cart implements ActiveRecordInterface
$copyObj->setAddressDeliveryId($this->getAddressDeliveryId());
$copyObj->setAddressInvoiceId($this->getAddressInvoiceId());
$copyObj->setCurrencyId($this->getCurrencyId());
+ $copyObj->setDiscount($this->getDiscount());
$copyObj->setCreatedAt($this->getCreatedAt());
$copyObj->setUpdatedAt($this->getUpdatedAt());
@@ -1982,10 +2057,12 @@ abstract class Cart implements ActiveRecordInterface
$this->address_delivery_id = null;
$this->address_invoice_id = null;
$this->currency_id = null;
+ $this->discount = null;
$this->created_at = null;
$this->updated_at = null;
$this->alreadyInSave = false;
$this->clearAllReferences();
+ $this->applyDefaultValues();
$this->resetModified();
$this->setNew(true);
$this->setDeleted(false);
diff --git a/core/lib/Thelia/Model/Base/CartItem.php b/core/lib/Thelia/Model/Base/CartItem.php
index 827a4c5ec..5dd573d39 100644
--- a/core/lib/Thelia/Model/Base/CartItem.php
+++ b/core/lib/Thelia/Model/Base/CartItem.php
@@ -109,6 +109,13 @@ abstract class CartItem implements ActiveRecordInterface
*/
protected $price_end_of_life;
+ /**
+ * The value for the discount field.
+ * Note: this column has a database default value of: 0
+ * @var double
+ */
+ protected $discount;
+
/**
* The value for the created_at field.
* @var string
@@ -153,6 +160,7 @@ abstract class CartItem implements ActiveRecordInterface
public function applyDefaultValues()
{
$this->quantity = 1;
+ $this->discount = 0;
}
/**
@@ -508,6 +516,17 @@ abstract class CartItem implements ActiveRecordInterface
}
}
+ /**
+ * Get the [discount] column value.
+ *
+ * @return double
+ */
+ public function getDiscount()
+ {
+
+ return $this->discount;
+ }
+
/**
* Get the [optionally formatted] temporal [created_at] column value.
*
@@ -728,6 +747,27 @@ abstract class CartItem implements ActiveRecordInterface
return $this;
} // setPriceEndOfLife()
+ /**
+ * Set the value of [discount] column.
+ *
+ * @param double $v new value
+ * @return \Thelia\Model\CartItem The current object (for fluent API support)
+ */
+ public function setDiscount($v)
+ {
+ if ($v !== null) {
+ $v = (double) $v;
+ }
+
+ if ($this->discount !== $v) {
+ $this->discount = $v;
+ $this->modifiedColumns[] = CartItemTableMap::DISCOUNT;
+ }
+
+
+ return $this;
+ } // setDiscount()
+
/**
* Sets the value of [created_at] column to a normalized version of the date/time value specified.
*
@@ -784,6 +824,10 @@ abstract class CartItem implements ActiveRecordInterface
return false;
}
+ if ($this->discount !== 0) {
+ return false;
+ }
+
// otherwise, everything was equal, so return TRUE
return true;
} // hasOnlyDefaultValues()
@@ -838,13 +882,16 @@ abstract class CartItem implements ActiveRecordInterface
}
$this->price_end_of_life = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null;
- $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : CartItemTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
+ $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : CartItemTableMap::translateFieldName('Discount', TableMap::TYPE_PHPNAME, $indexType)];
+ $this->discount = (null !== $col) ? (double) $col : null;
+
+ $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : CartItemTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
if ($col === '0000-00-00 00:00:00') {
$col = null;
}
$this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null;
- $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : CartItemTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
+ $col = $row[TableMap::TYPE_NUM == $indexType ? 10 + $startcol : CartItemTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
if ($col === '0000-00-00 00:00:00') {
$col = null;
}
@@ -857,7 +904,7 @@ abstract class CartItem implements ActiveRecordInterface
$this->ensureConsistency();
}
- return $startcol + 10; // 10 = CartItemTableMap::NUM_HYDRATE_COLUMNS.
+ return $startcol + 11; // 11 = CartItemTableMap::NUM_HYDRATE_COLUMNS.
} catch (Exception $e) {
throw new PropelException("Error populating \Thelia\Model\CartItem object", 0, $e);
@@ -1139,6 +1186,9 @@ abstract class CartItem implements ActiveRecordInterface
if ($this->isColumnModified(CartItemTableMap::PRICE_END_OF_LIFE)) {
$modifiedColumns[':p' . $index++] = 'PRICE_END_OF_LIFE';
}
+ if ($this->isColumnModified(CartItemTableMap::DISCOUNT)) {
+ $modifiedColumns[':p' . $index++] = 'DISCOUNT';
+ }
if ($this->isColumnModified(CartItemTableMap::CREATED_AT)) {
$modifiedColumns[':p' . $index++] = 'CREATED_AT';
}
@@ -1180,6 +1230,9 @@ abstract class CartItem implements ActiveRecordInterface
case 'PRICE_END_OF_LIFE':
$stmt->bindValue($identifier, $this->price_end_of_life ? $this->price_end_of_life->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
break;
+ case 'DISCOUNT':
+ $stmt->bindValue($identifier, $this->discount, PDO::PARAM_STR);
+ break;
case 'CREATED_AT':
$stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
break;
@@ -1273,9 +1326,12 @@ abstract class CartItem implements ActiveRecordInterface
return $this->getPriceEndOfLife();
break;
case 8:
- return $this->getCreatedAt();
+ return $this->getDiscount();
break;
case 9:
+ return $this->getCreatedAt();
+ break;
+ case 10:
return $this->getUpdatedAt();
break;
default:
@@ -1315,8 +1371,9 @@ abstract class CartItem implements ActiveRecordInterface
$keys[5] => $this->getPrice(),
$keys[6] => $this->getPromoPrice(),
$keys[7] => $this->getPriceEndOfLife(),
- $keys[8] => $this->getCreatedAt(),
- $keys[9] => $this->getUpdatedAt(),
+ $keys[8] => $this->getDiscount(),
+ $keys[9] => $this->getCreatedAt(),
+ $keys[10] => $this->getUpdatedAt(),
);
$virtualColumns = $this->virtualColumns;
foreach($virtualColumns as $key => $virtualColumn)
@@ -1393,9 +1450,12 @@ abstract class CartItem implements ActiveRecordInterface
$this->setPriceEndOfLife($value);
break;
case 8:
- $this->setCreatedAt($value);
+ $this->setDiscount($value);
break;
case 9:
+ $this->setCreatedAt($value);
+ break;
+ case 10:
$this->setUpdatedAt($value);
break;
} // switch()
@@ -1430,8 +1490,9 @@ abstract class CartItem implements ActiveRecordInterface
if (array_key_exists($keys[5], $arr)) $this->setPrice($arr[$keys[5]]);
if (array_key_exists($keys[6], $arr)) $this->setPromoPrice($arr[$keys[6]]);
if (array_key_exists($keys[7], $arr)) $this->setPriceEndOfLife($arr[$keys[7]]);
- if (array_key_exists($keys[8], $arr)) $this->setCreatedAt($arr[$keys[8]]);
- if (array_key_exists($keys[9], $arr)) $this->setUpdatedAt($arr[$keys[9]]);
+ if (array_key_exists($keys[8], $arr)) $this->setDiscount($arr[$keys[8]]);
+ if (array_key_exists($keys[9], $arr)) $this->setCreatedAt($arr[$keys[9]]);
+ if (array_key_exists($keys[10], $arr)) $this->setUpdatedAt($arr[$keys[10]]);
}
/**
@@ -1451,6 +1512,7 @@ abstract class CartItem implements ActiveRecordInterface
if ($this->isColumnModified(CartItemTableMap::PRICE)) $criteria->add(CartItemTableMap::PRICE, $this->price);
if ($this->isColumnModified(CartItemTableMap::PROMO_PRICE)) $criteria->add(CartItemTableMap::PROMO_PRICE, $this->promo_price);
if ($this->isColumnModified(CartItemTableMap::PRICE_END_OF_LIFE)) $criteria->add(CartItemTableMap::PRICE_END_OF_LIFE, $this->price_end_of_life);
+ if ($this->isColumnModified(CartItemTableMap::DISCOUNT)) $criteria->add(CartItemTableMap::DISCOUNT, $this->discount);
if ($this->isColumnModified(CartItemTableMap::CREATED_AT)) $criteria->add(CartItemTableMap::CREATED_AT, $this->created_at);
if ($this->isColumnModified(CartItemTableMap::UPDATED_AT)) $criteria->add(CartItemTableMap::UPDATED_AT, $this->updated_at);
@@ -1523,6 +1585,7 @@ abstract class CartItem implements ActiveRecordInterface
$copyObj->setPrice($this->getPrice());
$copyObj->setPromoPrice($this->getPromoPrice());
$copyObj->setPriceEndOfLife($this->getPriceEndOfLife());
+ $copyObj->setDiscount($this->getDiscount());
$copyObj->setCreatedAt($this->getCreatedAt());
$copyObj->setUpdatedAt($this->getUpdatedAt());
if ($makeNew) {
@@ -1719,6 +1782,7 @@ abstract class CartItem implements ActiveRecordInterface
$this->price = null;
$this->promo_price = null;
$this->price_end_of_life = null;
+ $this->discount = null;
$this->created_at = null;
$this->updated_at = null;
$this->alreadyInSave = false;
diff --git a/core/lib/Thelia/Model/Base/CartItemQuery.php b/core/lib/Thelia/Model/Base/CartItemQuery.php
index d26ceb965..83705aeac 100644
--- a/core/lib/Thelia/Model/Base/CartItemQuery.php
+++ b/core/lib/Thelia/Model/Base/CartItemQuery.php
@@ -29,6 +29,7 @@ use Thelia\Model\Map\CartItemTableMap;
* @method ChildCartItemQuery orderByPrice($order = Criteria::ASC) Order by the price column
* @method ChildCartItemQuery orderByPromoPrice($order = Criteria::ASC) Order by the promo_price column
* @method ChildCartItemQuery orderByPriceEndOfLife($order = Criteria::ASC) Order by the price_end_of_life column
+ * @method ChildCartItemQuery orderByDiscount($order = Criteria::ASC) Order by the discount column
* @method ChildCartItemQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column
* @method ChildCartItemQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column
*
@@ -40,6 +41,7 @@ use Thelia\Model\Map\CartItemTableMap;
* @method ChildCartItemQuery groupByPrice() Group by the price column
* @method ChildCartItemQuery groupByPromoPrice() Group by the promo_price column
* @method ChildCartItemQuery groupByPriceEndOfLife() Group by the price_end_of_life column
+ * @method ChildCartItemQuery groupByDiscount() Group by the discount column
* @method ChildCartItemQuery groupByCreatedAt() Group by the created_at column
* @method ChildCartItemQuery groupByUpdatedAt() Group by the updated_at column
*
@@ -70,6 +72,7 @@ use Thelia\Model\Map\CartItemTableMap;
* @method ChildCartItem findOneByPrice(double $price) Return the first ChildCartItem filtered by the price column
* @method ChildCartItem findOneByPromoPrice(double $promo_price) Return the first ChildCartItem filtered by the promo_price column
* @method ChildCartItem findOneByPriceEndOfLife(string $price_end_of_life) Return the first ChildCartItem filtered by the price_end_of_life column
+ * @method ChildCartItem findOneByDiscount(double $discount) Return the first ChildCartItem filtered by the discount column
* @method ChildCartItem findOneByCreatedAt(string $created_at) Return the first ChildCartItem filtered by the created_at column
* @method ChildCartItem findOneByUpdatedAt(string $updated_at) Return the first ChildCartItem filtered by the updated_at column
*
@@ -81,6 +84,7 @@ use Thelia\Model\Map\CartItemTableMap;
* @method array findByPrice(double $price) Return ChildCartItem objects filtered by the price column
* @method array findByPromoPrice(double $promo_price) Return ChildCartItem objects filtered by the promo_price column
* @method array findByPriceEndOfLife(string $price_end_of_life) Return ChildCartItem objects filtered by the price_end_of_life column
+ * @method array findByDiscount(double $discount) Return ChildCartItem objects filtered by the discount column
* @method array findByCreatedAt(string $created_at) Return ChildCartItem objects filtered by the created_at column
* @method array findByUpdatedAt(string $updated_at) Return ChildCartItem objects filtered by the updated_at column
*
@@ -171,7 +175,7 @@ abstract class CartItemQuery extends ModelCriteria
*/
protected function findPkSimple($key, $con)
{
- $sql = 'SELECT ID, CART_ID, PRODUCT_ID, QUANTITY, PRODUCT_SALE_ELEMENTS_ID, PRICE, PROMO_PRICE, PRICE_END_OF_LIFE, CREATED_AT, UPDATED_AT FROM cart_item WHERE ID = :p0';
+ $sql = 'SELECT ID, CART_ID, PRODUCT_ID, QUANTITY, PRODUCT_SALE_ELEMENTS_ID, PRICE, PROMO_PRICE, PRICE_END_OF_LIFE, DISCOUNT, CREATED_AT, UPDATED_AT FROM cart_item WHERE ID = :p0';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);
@@ -596,6 +600,47 @@ abstract class CartItemQuery extends ModelCriteria
return $this->addUsingAlias(CartItemTableMap::PRICE_END_OF_LIFE, $priceEndOfLife, $comparison);
}
+ /**
+ * Filter the query on the discount column
+ *
+ * Example usage:
+ *
+ * $query->filterByDiscount(1234); // WHERE discount = 1234
+ * $query->filterByDiscount(array(12, 34)); // WHERE discount IN (12, 34)
+ * $query->filterByDiscount(array('min' => 12)); // WHERE discount > 12
+ *
+ *
+ * @param mixed $discount The value to use as filter.
+ * Use scalar values for equality.
+ * Use array values for in_array() equivalent.
+ * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
+ * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
+ *
+ * @return ChildCartItemQuery The current query, for fluid interface
+ */
+ public function filterByDiscount($discount = null, $comparison = null)
+ {
+ if (is_array($discount)) {
+ $useMinMax = false;
+ if (isset($discount['min'])) {
+ $this->addUsingAlias(CartItemTableMap::DISCOUNT, $discount['min'], Criteria::GREATER_EQUAL);
+ $useMinMax = true;
+ }
+ if (isset($discount['max'])) {
+ $this->addUsingAlias(CartItemTableMap::DISCOUNT, $discount['max'], Criteria::LESS_EQUAL);
+ $useMinMax = true;
+ }
+ if ($useMinMax) {
+ return $this;
+ }
+ if (null === $comparison) {
+ $comparison = Criteria::IN;
+ }
+ }
+
+ return $this->addUsingAlias(CartItemTableMap::DISCOUNT, $discount, $comparison);
+ }
+
/**
* Filter the query on the created_at column
*
diff --git a/core/lib/Thelia/Model/Base/CartQuery.php b/core/lib/Thelia/Model/Base/CartQuery.php
index 24473bd5a..2628aa893 100644
--- a/core/lib/Thelia/Model/Base/CartQuery.php
+++ b/core/lib/Thelia/Model/Base/CartQuery.php
@@ -27,6 +27,7 @@ use Thelia\Model\Map\CartTableMap;
* @method ChildCartQuery orderByAddressDeliveryId($order = Criteria::ASC) Order by the address_delivery_id column
* @method ChildCartQuery orderByAddressInvoiceId($order = Criteria::ASC) Order by the address_invoice_id column
* @method ChildCartQuery orderByCurrencyId($order = Criteria::ASC) Order by the currency_id column
+ * @method ChildCartQuery orderByDiscount($order = Criteria::ASC) Order by the discount column
* @method ChildCartQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column
* @method ChildCartQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column
*
@@ -36,6 +37,7 @@ use Thelia\Model\Map\CartTableMap;
* @method ChildCartQuery groupByAddressDeliveryId() Group by the address_delivery_id column
* @method ChildCartQuery groupByAddressInvoiceId() Group by the address_invoice_id column
* @method ChildCartQuery groupByCurrencyId() Group by the currency_id column
+ * @method ChildCartQuery groupByDiscount() Group by the discount column
* @method ChildCartQuery groupByCreatedAt() Group by the created_at column
* @method ChildCartQuery groupByUpdatedAt() Group by the updated_at column
*
@@ -72,6 +74,7 @@ use Thelia\Model\Map\CartTableMap;
* @method ChildCart findOneByAddressDeliveryId(int $address_delivery_id) Return the first ChildCart filtered by the address_delivery_id column
* @method ChildCart findOneByAddressInvoiceId(int $address_invoice_id) Return the first ChildCart filtered by the address_invoice_id column
* @method ChildCart findOneByCurrencyId(int $currency_id) Return the first ChildCart filtered by the currency_id column
+ * @method ChildCart findOneByDiscount(double $discount) Return the first ChildCart filtered by the discount column
* @method ChildCart findOneByCreatedAt(string $created_at) Return the first ChildCart filtered by the created_at column
* @method ChildCart findOneByUpdatedAt(string $updated_at) Return the first ChildCart filtered by the updated_at column
*
@@ -81,6 +84,7 @@ use Thelia\Model\Map\CartTableMap;
* @method array findByAddressDeliveryId(int $address_delivery_id) Return ChildCart objects filtered by the address_delivery_id column
* @method array findByAddressInvoiceId(int $address_invoice_id) Return ChildCart objects filtered by the address_invoice_id column
* @method array findByCurrencyId(int $currency_id) Return ChildCart objects filtered by the currency_id column
+ * @method array findByDiscount(double $discount) Return ChildCart objects filtered by the discount column
* @method array findByCreatedAt(string $created_at) Return ChildCart objects filtered by the created_at column
* @method array findByUpdatedAt(string $updated_at) Return ChildCart objects filtered by the updated_at column
*
@@ -171,7 +175,7 @@ abstract class CartQuery extends ModelCriteria
*/
protected function findPkSimple($key, $con)
{
- $sql = 'SELECT ID, TOKEN, CUSTOMER_ID, ADDRESS_DELIVERY_ID, ADDRESS_INVOICE_ID, CURRENCY_ID, CREATED_AT, UPDATED_AT FROM cart WHERE ID = :p0';
+ $sql = 'SELECT ID, TOKEN, CUSTOMER_ID, ADDRESS_DELIVERY_ID, ADDRESS_INVOICE_ID, CURRENCY_ID, DISCOUNT, CREATED_AT, UPDATED_AT FROM cart WHERE ID = :p0';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);
@@ -502,6 +506,47 @@ abstract class CartQuery extends ModelCriteria
return $this->addUsingAlias(CartTableMap::CURRENCY_ID, $currencyId, $comparison);
}
+ /**
+ * Filter the query on the discount column
+ *
+ * Example usage:
+ *
+ * $query->filterByDiscount(1234); // WHERE discount = 1234
+ * $query->filterByDiscount(array(12, 34)); // WHERE discount IN (12, 34)
+ * $query->filterByDiscount(array('min' => 12)); // WHERE discount > 12
+ *
+ *
+ * @param mixed $discount The value to use as filter.
+ * Use scalar values for equality.
+ * Use array values for in_array() equivalent.
+ * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
+ * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
+ *
+ * @return ChildCartQuery The current query, for fluid interface
+ */
+ public function filterByDiscount($discount = null, $comparison = null)
+ {
+ if (is_array($discount)) {
+ $useMinMax = false;
+ if (isset($discount['min'])) {
+ $this->addUsingAlias(CartTableMap::DISCOUNT, $discount['min'], Criteria::GREATER_EQUAL);
+ $useMinMax = true;
+ }
+ if (isset($discount['max'])) {
+ $this->addUsingAlias(CartTableMap::DISCOUNT, $discount['max'], Criteria::LESS_EQUAL);
+ $useMinMax = true;
+ }
+ if ($useMinMax) {
+ return $this;
+ }
+ if (null === $comparison) {
+ $comparison = Criteria::IN;
+ }
+ }
+
+ return $this->addUsingAlias(CartTableMap::DISCOUNT, $discount, $comparison);
+ }
+
/**
* Filter the query on the created_at column
*
diff --git a/core/lib/Thelia/Model/Base/ProductSaleElements.php b/core/lib/Thelia/Model/Base/ProductSaleElements.php
index 4c14580ff..fa887dc8a 100644
--- a/core/lib/Thelia/Model/Base/ProductSaleElements.php
+++ b/core/lib/Thelia/Model/Base/ProductSaleElements.php
@@ -75,6 +75,12 @@ abstract class ProductSaleElements implements ActiveRecordInterface
*/
protected $product_id;
+ /**
+ * The value for the ref field.
+ * @var string
+ */
+ protected $ref;
+
/**
* The value for the quantity field.
* @var double
@@ -452,6 +458,17 @@ abstract class ProductSaleElements implements ActiveRecordInterface
return $this->product_id;
}
+ /**
+ * Get the [ref] column value.
+ *
+ * @return string
+ */
+ public function getRef()
+ {
+
+ return $this->ref;
+ }
+
/**
* Get the [quantity] column value.
*
@@ -582,6 +599,27 @@ abstract class ProductSaleElements implements ActiveRecordInterface
return $this;
} // setProductId()
+ /**
+ * Set the value of [ref] column.
+ *
+ * @param string $v new value
+ * @return \Thelia\Model\ProductSaleElements The current object (for fluent API support)
+ */
+ public function setRef($v)
+ {
+ if ($v !== null) {
+ $v = (string) $v;
+ }
+
+ if ($this->ref !== $v) {
+ $this->ref = $v;
+ $this->modifiedColumns[] = ProductSaleElementsTableMap::REF;
+ }
+
+
+ return $this;
+ } // setRef()
+
/**
* Set the value of [quantity] column.
*
@@ -759,25 +797,28 @@ abstract class ProductSaleElements implements ActiveRecordInterface
$col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : ProductSaleElementsTableMap::translateFieldName('ProductId', TableMap::TYPE_PHPNAME, $indexType)];
$this->product_id = (null !== $col) ? (int) $col : null;
- $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ProductSaleElementsTableMap::translateFieldName('Quantity', TableMap::TYPE_PHPNAME, $indexType)];
+ $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ProductSaleElementsTableMap::translateFieldName('Ref', TableMap::TYPE_PHPNAME, $indexType)];
+ $this->ref = (null !== $col) ? (string) $col : null;
+
+ $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ProductSaleElementsTableMap::translateFieldName('Quantity', TableMap::TYPE_PHPNAME, $indexType)];
$this->quantity = (null !== $col) ? (double) $col : null;
- $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ProductSaleElementsTableMap::translateFieldName('Promo', TableMap::TYPE_PHPNAME, $indexType)];
+ $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : ProductSaleElementsTableMap::translateFieldName('Promo', TableMap::TYPE_PHPNAME, $indexType)];
$this->promo = (null !== $col) ? (int) $col : null;
- $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : ProductSaleElementsTableMap::translateFieldName('Newness', TableMap::TYPE_PHPNAME, $indexType)];
+ $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : ProductSaleElementsTableMap::translateFieldName('Newness', TableMap::TYPE_PHPNAME, $indexType)];
$this->newness = (null !== $col) ? (int) $col : null;
- $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : ProductSaleElementsTableMap::translateFieldName('Weight', TableMap::TYPE_PHPNAME, $indexType)];
+ $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : ProductSaleElementsTableMap::translateFieldName('Weight', TableMap::TYPE_PHPNAME, $indexType)];
$this->weight = (null !== $col) ? (double) $col : null;
- $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : ProductSaleElementsTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
+ $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : ProductSaleElementsTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
if ($col === '0000-00-00 00:00:00') {
$col = null;
}
$this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null;
- $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : ProductSaleElementsTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
+ $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : ProductSaleElementsTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
if ($col === '0000-00-00 00:00:00') {
$col = null;
}
@@ -790,7 +831,7 @@ abstract class ProductSaleElements implements ActiveRecordInterface
$this->ensureConsistency();
}
- return $startcol + 8; // 8 = ProductSaleElementsTableMap::NUM_HYDRATE_COLUMNS.
+ return $startcol + 9; // 9 = ProductSaleElementsTableMap::NUM_HYDRATE_COLUMNS.
} catch (Exception $e) {
throw new PropelException("Error populating \Thelia\Model\ProductSaleElements object", 0, $e);
@@ -1089,6 +1130,9 @@ abstract class ProductSaleElements implements ActiveRecordInterface
if ($this->isColumnModified(ProductSaleElementsTableMap::PRODUCT_ID)) {
$modifiedColumns[':p' . $index++] = 'PRODUCT_ID';
}
+ if ($this->isColumnModified(ProductSaleElementsTableMap::REF)) {
+ $modifiedColumns[':p' . $index++] = 'REF';
+ }
if ($this->isColumnModified(ProductSaleElementsTableMap::QUANTITY)) {
$modifiedColumns[':p' . $index++] = 'QUANTITY';
}
@@ -1124,6 +1168,9 @@ abstract class ProductSaleElements implements ActiveRecordInterface
case 'PRODUCT_ID':
$stmt->bindValue($identifier, $this->product_id, PDO::PARAM_INT);
break;
+ case 'REF':
+ $stmt->bindValue($identifier, $this->ref, PDO::PARAM_STR);
+ break;
case 'QUANTITY':
$stmt->bindValue($identifier, $this->quantity, PDO::PARAM_STR);
break;
@@ -1211,21 +1258,24 @@ abstract class ProductSaleElements implements ActiveRecordInterface
return $this->getProductId();
break;
case 2:
- return $this->getQuantity();
+ return $this->getRef();
break;
case 3:
- return $this->getPromo();
+ return $this->getQuantity();
break;
case 4:
- return $this->getNewness();
+ return $this->getPromo();
break;
case 5:
- return $this->getWeight();
+ return $this->getNewness();
break;
case 6:
- return $this->getCreatedAt();
+ return $this->getWeight();
break;
case 7:
+ return $this->getCreatedAt();
+ break;
+ case 8:
return $this->getUpdatedAt();
break;
default:
@@ -1259,12 +1309,13 @@ abstract class ProductSaleElements implements ActiveRecordInterface
$result = array(
$keys[0] => $this->getId(),
$keys[1] => $this->getProductId(),
- $keys[2] => $this->getQuantity(),
- $keys[3] => $this->getPromo(),
- $keys[4] => $this->getNewness(),
- $keys[5] => $this->getWeight(),
- $keys[6] => $this->getCreatedAt(),
- $keys[7] => $this->getUpdatedAt(),
+ $keys[2] => $this->getRef(),
+ $keys[3] => $this->getQuantity(),
+ $keys[4] => $this->getPromo(),
+ $keys[5] => $this->getNewness(),
+ $keys[6] => $this->getWeight(),
+ $keys[7] => $this->getCreatedAt(),
+ $keys[8] => $this->getUpdatedAt(),
);
$virtualColumns = $this->virtualColumns;
foreach($virtualColumns as $key => $virtualColumn)
@@ -1326,21 +1377,24 @@ abstract class ProductSaleElements implements ActiveRecordInterface
$this->setProductId($value);
break;
case 2:
- $this->setQuantity($value);
+ $this->setRef($value);
break;
case 3:
- $this->setPromo($value);
+ $this->setQuantity($value);
break;
case 4:
- $this->setNewness($value);
+ $this->setPromo($value);
break;
case 5:
- $this->setWeight($value);
+ $this->setNewness($value);
break;
case 6:
- $this->setCreatedAt($value);
+ $this->setWeight($value);
break;
case 7:
+ $this->setCreatedAt($value);
+ break;
+ case 8:
$this->setUpdatedAt($value);
break;
} // switch()
@@ -1369,12 +1423,13 @@ abstract class ProductSaleElements implements ActiveRecordInterface
if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
if (array_key_exists($keys[1], $arr)) $this->setProductId($arr[$keys[1]]);
- if (array_key_exists($keys[2], $arr)) $this->setQuantity($arr[$keys[2]]);
- if (array_key_exists($keys[3], $arr)) $this->setPromo($arr[$keys[3]]);
- if (array_key_exists($keys[4], $arr)) $this->setNewness($arr[$keys[4]]);
- if (array_key_exists($keys[5], $arr)) $this->setWeight($arr[$keys[5]]);
- if (array_key_exists($keys[6], $arr)) $this->setCreatedAt($arr[$keys[6]]);
- if (array_key_exists($keys[7], $arr)) $this->setUpdatedAt($arr[$keys[7]]);
+ if (array_key_exists($keys[2], $arr)) $this->setRef($arr[$keys[2]]);
+ if (array_key_exists($keys[3], $arr)) $this->setQuantity($arr[$keys[3]]);
+ if (array_key_exists($keys[4], $arr)) $this->setPromo($arr[$keys[4]]);
+ if (array_key_exists($keys[5], $arr)) $this->setNewness($arr[$keys[5]]);
+ if (array_key_exists($keys[6], $arr)) $this->setWeight($arr[$keys[6]]);
+ if (array_key_exists($keys[7], $arr)) $this->setCreatedAt($arr[$keys[7]]);
+ if (array_key_exists($keys[8], $arr)) $this->setUpdatedAt($arr[$keys[8]]);
}
/**
@@ -1388,6 +1443,7 @@ abstract class ProductSaleElements implements ActiveRecordInterface
if ($this->isColumnModified(ProductSaleElementsTableMap::ID)) $criteria->add(ProductSaleElementsTableMap::ID, $this->id);
if ($this->isColumnModified(ProductSaleElementsTableMap::PRODUCT_ID)) $criteria->add(ProductSaleElementsTableMap::PRODUCT_ID, $this->product_id);
+ if ($this->isColumnModified(ProductSaleElementsTableMap::REF)) $criteria->add(ProductSaleElementsTableMap::REF, $this->ref);
if ($this->isColumnModified(ProductSaleElementsTableMap::QUANTITY)) $criteria->add(ProductSaleElementsTableMap::QUANTITY, $this->quantity);
if ($this->isColumnModified(ProductSaleElementsTableMap::PROMO)) $criteria->add(ProductSaleElementsTableMap::PROMO, $this->promo);
if ($this->isColumnModified(ProductSaleElementsTableMap::NEWNESS)) $criteria->add(ProductSaleElementsTableMap::NEWNESS, $this->newness);
@@ -1458,6 +1514,7 @@ abstract class ProductSaleElements implements ActiveRecordInterface
public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
{
$copyObj->setProductId($this->getProductId());
+ $copyObj->setRef($this->getRef());
$copyObj->setQuantity($this->getQuantity());
$copyObj->setPromo($this->getPromo());
$copyObj->setNewness($this->getNewness());
@@ -2383,6 +2440,7 @@ abstract class ProductSaleElements implements ActiveRecordInterface
{
$this->id = null;
$this->product_id = null;
+ $this->ref = null;
$this->quantity = null;
$this->promo = null;
$this->newness = null;
diff --git a/core/lib/Thelia/Model/Base/ProductSaleElementsQuery.php b/core/lib/Thelia/Model/Base/ProductSaleElementsQuery.php
index 9892bff51..6e9068002 100644
--- a/core/lib/Thelia/Model/Base/ProductSaleElementsQuery.php
+++ b/core/lib/Thelia/Model/Base/ProductSaleElementsQuery.php
@@ -23,6 +23,7 @@ use Thelia\Model\Map\ProductSaleElementsTableMap;
*
* @method ChildProductSaleElementsQuery orderById($order = Criteria::ASC) Order by the id column
* @method ChildProductSaleElementsQuery orderByProductId($order = Criteria::ASC) Order by the product_id column
+ * @method ChildProductSaleElementsQuery orderByRef($order = Criteria::ASC) Order by the ref column
* @method ChildProductSaleElementsQuery orderByQuantity($order = Criteria::ASC) Order by the quantity column
* @method ChildProductSaleElementsQuery orderByPromo($order = Criteria::ASC) Order by the promo column
* @method ChildProductSaleElementsQuery orderByNewness($order = Criteria::ASC) Order by the newness column
@@ -32,6 +33,7 @@ use Thelia\Model\Map\ProductSaleElementsTableMap;
*
* @method ChildProductSaleElementsQuery groupById() Group by the id column
* @method ChildProductSaleElementsQuery groupByProductId() Group by the product_id column
+ * @method ChildProductSaleElementsQuery groupByRef() Group by the ref column
* @method ChildProductSaleElementsQuery groupByQuantity() Group by the quantity column
* @method ChildProductSaleElementsQuery groupByPromo() Group by the promo column
* @method ChildProductSaleElementsQuery groupByNewness() Group by the newness column
@@ -64,6 +66,7 @@ use Thelia\Model\Map\ProductSaleElementsTableMap;
*
* @method ChildProductSaleElements findOneById(int $id) Return the first ChildProductSaleElements filtered by the id column
* @method ChildProductSaleElements findOneByProductId(int $product_id) Return the first ChildProductSaleElements filtered by the product_id column
+ * @method ChildProductSaleElements findOneByRef(string $ref) Return the first ChildProductSaleElements filtered by the ref column
* @method ChildProductSaleElements findOneByQuantity(double $quantity) Return the first ChildProductSaleElements filtered by the quantity column
* @method ChildProductSaleElements findOneByPromo(int $promo) Return the first ChildProductSaleElements filtered by the promo column
* @method ChildProductSaleElements findOneByNewness(int $newness) Return the first ChildProductSaleElements filtered by the newness column
@@ -73,6 +76,7 @@ use Thelia\Model\Map\ProductSaleElementsTableMap;
*
* @method array findById(int $id) Return ChildProductSaleElements objects filtered by the id column
* @method array findByProductId(int $product_id) Return ChildProductSaleElements objects filtered by the product_id column
+ * @method array findByRef(string $ref) Return ChildProductSaleElements objects filtered by the ref column
* @method array findByQuantity(double $quantity) Return ChildProductSaleElements objects filtered by the quantity column
* @method array findByPromo(int $promo) Return ChildProductSaleElements objects filtered by the promo column
* @method array findByNewness(int $newness) Return ChildProductSaleElements objects filtered by the newness column
@@ -167,7 +171,7 @@ abstract class ProductSaleElementsQuery extends ModelCriteria
*/
protected function findPkSimple($key, $con)
{
- $sql = 'SELECT ID, PRODUCT_ID, QUANTITY, PROMO, NEWNESS, WEIGHT, CREATED_AT, UPDATED_AT FROM product_sale_elements WHERE ID = :p0';
+ $sql = 'SELECT ID, PRODUCT_ID, REF, QUANTITY, PROMO, NEWNESS, WEIGHT, CREATED_AT, UPDATED_AT FROM product_sale_elements WHERE ID = :p0';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);
@@ -340,6 +344,35 @@ abstract class ProductSaleElementsQuery extends ModelCriteria
return $this->addUsingAlias(ProductSaleElementsTableMap::PRODUCT_ID, $productId, $comparison);
}
+ /**
+ * Filter the query on the ref column
+ *
+ * Example usage:
+ *
+ * $query->filterByRef('fooValue'); // WHERE ref = 'fooValue'
+ * $query->filterByRef('%fooValue%'); // WHERE ref LIKE '%fooValue%'
+ *
+ *
+ * @param string $ref The value to use as filter.
+ * Accepts wildcards (* and % trigger a LIKE)
+ * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
+ *
+ * @return ChildProductSaleElementsQuery The current query, for fluid interface
+ */
+ public function filterByRef($ref = null, $comparison = null)
+ {
+ if (null === $comparison) {
+ if (is_array($ref)) {
+ $comparison = Criteria::IN;
+ } elseif (preg_match('/[\%\*]/', $ref)) {
+ $ref = str_replace('*', '%', $ref);
+ $comparison = Criteria::LIKE;
+ }
+ }
+
+ return $this->addUsingAlias(ProductSaleElementsTableMap::REF, $ref, $comparison);
+ }
+
/**
* Filter the query on the quantity column
*
diff --git a/core/lib/Thelia/Model/Customer.php b/core/lib/Thelia/Model/Customer.php
index 080c02ed6..f839d5f5b 100755
--- a/core/lib/Thelia/Model/Customer.php
+++ b/core/lib/Thelia/Model/Customer.php
@@ -54,7 +54,7 @@ class Customer extends BaseCustomer implements UserInterface
* @param int $discount
* @throws \Exception|\Symfony\Component\Config\Definition\Exception\Exception
*/
- public function createOrUpdate($titleId, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $city, $countryId, $email = null, $plainPassword = null, $lang = null, $reseller = 0, $sponsor = null, $discount = 0)
+ public function createOrUpdate($titleId, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $city, $countryId, $email = null, $plainPassword = null, $lang = null, $reseller = 0, $sponsor = null, $discount = 0, $company = null)
{
$this
->setTitleId($titleId)
@@ -79,6 +79,7 @@ class Customer extends BaseCustomer implements UserInterface
$address = new Address();
$address
+ ->setCompany($company)
->setTitleId($titleId)
->setFirstname($firstname)
->setLastname($lastname)
@@ -88,6 +89,7 @@ class Customer extends BaseCustomer implements UserInterface
->setPhone($phone)
->setCellphone($cellphone)
->setZipcode($zipcode)
+ ->setCity($city)
->setCountryId($countryId)
->setIsDefault(1)
;
@@ -98,6 +100,7 @@ class Customer extends BaseCustomer implements UserInterface
$address = $this->getDefaultAddress();
$address
+ ->setCompany($company)
->setTitleId($titleId)
->setFirstname($firstname)
->setLastname($lastname)
@@ -107,6 +110,7 @@ class Customer extends BaseCustomer implements UserInterface
->setPhone($phone)
->setCellphone($cellphone)
->setZipcode($zipcode)
+ ->setCity($city)
->setCountryId($countryId)
->save($con)
;
@@ -242,7 +246,7 @@ class Customer extends BaseCustomer implements UserInterface
*/
public function preDelete(ConnectionInterface $con = null)
{
- $this->dispatchEvent(TheliaEvents::BEFORE_DELETECONFIG, new CustomerEvent($this));
+ $this->dispatchEvent(TheliaEvents::BEFORE_DELETECUSTOMER, new CustomerEvent($this));
return true;
}
@@ -251,6 +255,6 @@ class Customer extends BaseCustomer implements UserInterface
*/
public function postDelete(ConnectionInterface $con = null)
{
- $this->dispatchEvent(TheliaEvents::AFTER_DELETECONFIG, new CustomerEvent($this));
+ $this->dispatchEvent(TheliaEvents::AFTER_DELETECUSTOMER, new CustomerEvent($this));
}
}
diff --git a/core/lib/Thelia/Model/Map/CartItemTableMap.php b/core/lib/Thelia/Model/Map/CartItemTableMap.php
index 687b1cd68..7520b39c9 100644
--- a/core/lib/Thelia/Model/Map/CartItemTableMap.php
+++ b/core/lib/Thelia/Model/Map/CartItemTableMap.php
@@ -57,7 +57,7 @@ class CartItemTableMap extends TableMap
/**
* The total number of columns
*/
- const NUM_COLUMNS = 10;
+ const NUM_COLUMNS = 11;
/**
* The number of lazy-loaded columns
@@ -67,7 +67,7 @@ class CartItemTableMap extends TableMap
/**
* The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
*/
- const NUM_HYDRATE_COLUMNS = 10;
+ const NUM_HYDRATE_COLUMNS = 11;
/**
* the column name for the ID field
@@ -109,6 +109,11 @@ class CartItemTableMap extends TableMap
*/
const PRICE_END_OF_LIFE = 'cart_item.PRICE_END_OF_LIFE';
+ /**
+ * the column name for the DISCOUNT field
+ */
+ const DISCOUNT = 'cart_item.DISCOUNT';
+
/**
* the column name for the CREATED_AT field
*/
@@ -131,12 +136,12 @@ class CartItemTableMap extends TableMap
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
protected static $fieldNames = array (
- self::TYPE_PHPNAME => array('Id', 'CartId', 'ProductId', 'Quantity', 'ProductSaleElementsId', 'Price', 'PromoPrice', 'PriceEndOfLife', 'CreatedAt', 'UpdatedAt', ),
- self::TYPE_STUDLYPHPNAME => array('id', 'cartId', 'productId', 'quantity', 'productSaleElementsId', 'price', 'promoPrice', 'priceEndOfLife', 'createdAt', 'updatedAt', ),
- self::TYPE_COLNAME => array(CartItemTableMap::ID, CartItemTableMap::CART_ID, CartItemTableMap::PRODUCT_ID, CartItemTableMap::QUANTITY, CartItemTableMap::PRODUCT_SALE_ELEMENTS_ID, CartItemTableMap::PRICE, CartItemTableMap::PROMO_PRICE, CartItemTableMap::PRICE_END_OF_LIFE, CartItemTableMap::CREATED_AT, CartItemTableMap::UPDATED_AT, ),
- self::TYPE_RAW_COLNAME => array('ID', 'CART_ID', 'PRODUCT_ID', 'QUANTITY', 'PRODUCT_SALE_ELEMENTS_ID', 'PRICE', 'PROMO_PRICE', 'PRICE_END_OF_LIFE', 'CREATED_AT', 'UPDATED_AT', ),
- self::TYPE_FIELDNAME => array('id', 'cart_id', 'product_id', 'quantity', 'product_sale_elements_id', 'price', 'promo_price', 'price_end_of_life', 'created_at', 'updated_at', ),
- self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, )
+ self::TYPE_PHPNAME => array('Id', 'CartId', 'ProductId', 'Quantity', 'ProductSaleElementsId', 'Price', 'PromoPrice', 'PriceEndOfLife', 'Discount', 'CreatedAt', 'UpdatedAt', ),
+ self::TYPE_STUDLYPHPNAME => array('id', 'cartId', 'productId', 'quantity', 'productSaleElementsId', 'price', 'promoPrice', 'priceEndOfLife', 'discount', 'createdAt', 'updatedAt', ),
+ self::TYPE_COLNAME => array(CartItemTableMap::ID, CartItemTableMap::CART_ID, CartItemTableMap::PRODUCT_ID, CartItemTableMap::QUANTITY, CartItemTableMap::PRODUCT_SALE_ELEMENTS_ID, CartItemTableMap::PRICE, CartItemTableMap::PROMO_PRICE, CartItemTableMap::PRICE_END_OF_LIFE, CartItemTableMap::DISCOUNT, CartItemTableMap::CREATED_AT, CartItemTableMap::UPDATED_AT, ),
+ self::TYPE_RAW_COLNAME => array('ID', 'CART_ID', 'PRODUCT_ID', 'QUANTITY', 'PRODUCT_SALE_ELEMENTS_ID', 'PRICE', 'PROMO_PRICE', 'PRICE_END_OF_LIFE', 'DISCOUNT', 'CREATED_AT', 'UPDATED_AT', ),
+ self::TYPE_FIELDNAME => array('id', 'cart_id', 'product_id', 'quantity', 'product_sale_elements_id', 'price', 'promo_price', 'price_end_of_life', 'discount', 'created_at', 'updated_at', ),
+ self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, )
);
/**
@@ -146,12 +151,12 @@ class CartItemTableMap extends TableMap
* e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
*/
protected static $fieldKeys = array (
- self::TYPE_PHPNAME => array('Id' => 0, 'CartId' => 1, 'ProductId' => 2, 'Quantity' => 3, 'ProductSaleElementsId' => 4, 'Price' => 5, 'PromoPrice' => 6, 'PriceEndOfLife' => 7, 'CreatedAt' => 8, 'UpdatedAt' => 9, ),
- self::TYPE_STUDLYPHPNAME => array('id' => 0, 'cartId' => 1, 'productId' => 2, 'quantity' => 3, 'productSaleElementsId' => 4, 'price' => 5, 'promoPrice' => 6, 'priceEndOfLife' => 7, 'createdAt' => 8, 'updatedAt' => 9, ),
- self::TYPE_COLNAME => array(CartItemTableMap::ID => 0, CartItemTableMap::CART_ID => 1, CartItemTableMap::PRODUCT_ID => 2, CartItemTableMap::QUANTITY => 3, CartItemTableMap::PRODUCT_SALE_ELEMENTS_ID => 4, CartItemTableMap::PRICE => 5, CartItemTableMap::PROMO_PRICE => 6, CartItemTableMap::PRICE_END_OF_LIFE => 7, CartItemTableMap::CREATED_AT => 8, CartItemTableMap::UPDATED_AT => 9, ),
- self::TYPE_RAW_COLNAME => array('ID' => 0, 'CART_ID' => 1, 'PRODUCT_ID' => 2, 'QUANTITY' => 3, 'PRODUCT_SALE_ELEMENTS_ID' => 4, 'PRICE' => 5, 'PROMO_PRICE' => 6, 'PRICE_END_OF_LIFE' => 7, 'CREATED_AT' => 8, 'UPDATED_AT' => 9, ),
- self::TYPE_FIELDNAME => array('id' => 0, 'cart_id' => 1, 'product_id' => 2, 'quantity' => 3, 'product_sale_elements_id' => 4, 'price' => 5, 'promo_price' => 6, 'price_end_of_life' => 7, 'created_at' => 8, 'updated_at' => 9, ),
- self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, )
+ self::TYPE_PHPNAME => array('Id' => 0, 'CartId' => 1, 'ProductId' => 2, 'Quantity' => 3, 'ProductSaleElementsId' => 4, 'Price' => 5, 'PromoPrice' => 6, 'PriceEndOfLife' => 7, 'Discount' => 8, 'CreatedAt' => 9, 'UpdatedAt' => 10, ),
+ self::TYPE_STUDLYPHPNAME => array('id' => 0, 'cartId' => 1, 'productId' => 2, 'quantity' => 3, 'productSaleElementsId' => 4, 'price' => 5, 'promoPrice' => 6, 'priceEndOfLife' => 7, 'discount' => 8, 'createdAt' => 9, 'updatedAt' => 10, ),
+ self::TYPE_COLNAME => array(CartItemTableMap::ID => 0, CartItemTableMap::CART_ID => 1, CartItemTableMap::PRODUCT_ID => 2, CartItemTableMap::QUANTITY => 3, CartItemTableMap::PRODUCT_SALE_ELEMENTS_ID => 4, CartItemTableMap::PRICE => 5, CartItemTableMap::PROMO_PRICE => 6, CartItemTableMap::PRICE_END_OF_LIFE => 7, CartItemTableMap::DISCOUNT => 8, CartItemTableMap::CREATED_AT => 9, CartItemTableMap::UPDATED_AT => 10, ),
+ self::TYPE_RAW_COLNAME => array('ID' => 0, 'CART_ID' => 1, 'PRODUCT_ID' => 2, 'QUANTITY' => 3, 'PRODUCT_SALE_ELEMENTS_ID' => 4, 'PRICE' => 5, 'PROMO_PRICE' => 6, 'PRICE_END_OF_LIFE' => 7, 'DISCOUNT' => 8, 'CREATED_AT' => 9, 'UPDATED_AT' => 10, ),
+ self::TYPE_FIELDNAME => array('id' => 0, 'cart_id' => 1, 'product_id' => 2, 'quantity' => 3, 'product_sale_elements_id' => 4, 'price' => 5, 'promo_price' => 6, 'price_end_of_life' => 7, 'discount' => 8, 'created_at' => 9, 'updated_at' => 10, ),
+ self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, )
);
/**
@@ -178,6 +183,7 @@ class CartItemTableMap extends TableMap
$this->addColumn('PRICE', 'Price', 'FLOAT', false, null, null);
$this->addColumn('PROMO_PRICE', 'PromoPrice', 'FLOAT', false, null, null);
$this->addColumn('PRICE_END_OF_LIFE', 'PriceEndOfLife', 'TIMESTAMP', false, null, null);
+ $this->addColumn('DISCOUNT', 'Discount', 'FLOAT', false, null, 0);
$this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null);
$this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null);
} // initialize()
@@ -351,6 +357,7 @@ class CartItemTableMap extends TableMap
$criteria->addSelectColumn(CartItemTableMap::PRICE);
$criteria->addSelectColumn(CartItemTableMap::PROMO_PRICE);
$criteria->addSelectColumn(CartItemTableMap::PRICE_END_OF_LIFE);
+ $criteria->addSelectColumn(CartItemTableMap::DISCOUNT);
$criteria->addSelectColumn(CartItemTableMap::CREATED_AT);
$criteria->addSelectColumn(CartItemTableMap::UPDATED_AT);
} else {
@@ -362,6 +369,7 @@ class CartItemTableMap extends TableMap
$criteria->addSelectColumn($alias . '.PRICE');
$criteria->addSelectColumn($alias . '.PROMO_PRICE');
$criteria->addSelectColumn($alias . '.PRICE_END_OF_LIFE');
+ $criteria->addSelectColumn($alias . '.DISCOUNT');
$criteria->addSelectColumn($alias . '.CREATED_AT');
$criteria->addSelectColumn($alias . '.UPDATED_AT');
}
diff --git a/core/lib/Thelia/Model/Map/CartTableMap.php b/core/lib/Thelia/Model/Map/CartTableMap.php
index 80d371f66..d839b4e91 100644
--- a/core/lib/Thelia/Model/Map/CartTableMap.php
+++ b/core/lib/Thelia/Model/Map/CartTableMap.php
@@ -57,7 +57,7 @@ class CartTableMap extends TableMap
/**
* The total number of columns
*/
- const NUM_COLUMNS = 8;
+ const NUM_COLUMNS = 9;
/**
* The number of lazy-loaded columns
@@ -67,7 +67,7 @@ class CartTableMap extends TableMap
/**
* The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
*/
- const NUM_HYDRATE_COLUMNS = 8;
+ const NUM_HYDRATE_COLUMNS = 9;
/**
* the column name for the ID field
@@ -99,6 +99,11 @@ class CartTableMap extends TableMap
*/
const CURRENCY_ID = 'cart.CURRENCY_ID';
+ /**
+ * the column name for the DISCOUNT field
+ */
+ const DISCOUNT = 'cart.DISCOUNT';
+
/**
* the column name for the CREATED_AT field
*/
@@ -121,12 +126,12 @@ class CartTableMap extends TableMap
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
protected static $fieldNames = array (
- self::TYPE_PHPNAME => array('Id', 'Token', 'CustomerId', 'AddressDeliveryId', 'AddressInvoiceId', 'CurrencyId', 'CreatedAt', 'UpdatedAt', ),
- self::TYPE_STUDLYPHPNAME => array('id', 'token', 'customerId', 'addressDeliveryId', 'addressInvoiceId', 'currencyId', 'createdAt', 'updatedAt', ),
- self::TYPE_COLNAME => array(CartTableMap::ID, CartTableMap::TOKEN, CartTableMap::CUSTOMER_ID, CartTableMap::ADDRESS_DELIVERY_ID, CartTableMap::ADDRESS_INVOICE_ID, CartTableMap::CURRENCY_ID, CartTableMap::CREATED_AT, CartTableMap::UPDATED_AT, ),
- self::TYPE_RAW_COLNAME => array('ID', 'TOKEN', 'CUSTOMER_ID', 'ADDRESS_DELIVERY_ID', 'ADDRESS_INVOICE_ID', 'CURRENCY_ID', 'CREATED_AT', 'UPDATED_AT', ),
- self::TYPE_FIELDNAME => array('id', 'token', 'customer_id', 'address_delivery_id', 'address_invoice_id', 'currency_id', 'created_at', 'updated_at', ),
- self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, )
+ self::TYPE_PHPNAME => array('Id', 'Token', 'CustomerId', 'AddressDeliveryId', 'AddressInvoiceId', 'CurrencyId', 'Discount', 'CreatedAt', 'UpdatedAt', ),
+ self::TYPE_STUDLYPHPNAME => array('id', 'token', 'customerId', 'addressDeliveryId', 'addressInvoiceId', 'currencyId', 'discount', 'createdAt', 'updatedAt', ),
+ self::TYPE_COLNAME => array(CartTableMap::ID, CartTableMap::TOKEN, CartTableMap::CUSTOMER_ID, CartTableMap::ADDRESS_DELIVERY_ID, CartTableMap::ADDRESS_INVOICE_ID, CartTableMap::CURRENCY_ID, CartTableMap::DISCOUNT, CartTableMap::CREATED_AT, CartTableMap::UPDATED_AT, ),
+ self::TYPE_RAW_COLNAME => array('ID', 'TOKEN', 'CUSTOMER_ID', 'ADDRESS_DELIVERY_ID', 'ADDRESS_INVOICE_ID', 'CURRENCY_ID', 'DISCOUNT', 'CREATED_AT', 'UPDATED_AT', ),
+ self::TYPE_FIELDNAME => array('id', 'token', 'customer_id', 'address_delivery_id', 'address_invoice_id', 'currency_id', 'discount', 'created_at', 'updated_at', ),
+ self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, )
);
/**
@@ -136,12 +141,12 @@ class CartTableMap extends TableMap
* e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
*/
protected static $fieldKeys = array (
- self::TYPE_PHPNAME => array('Id' => 0, 'Token' => 1, 'CustomerId' => 2, 'AddressDeliveryId' => 3, 'AddressInvoiceId' => 4, 'CurrencyId' => 5, 'CreatedAt' => 6, 'UpdatedAt' => 7, ),
- self::TYPE_STUDLYPHPNAME => array('id' => 0, 'token' => 1, 'customerId' => 2, 'addressDeliveryId' => 3, 'addressInvoiceId' => 4, 'currencyId' => 5, 'createdAt' => 6, 'updatedAt' => 7, ),
- self::TYPE_COLNAME => array(CartTableMap::ID => 0, CartTableMap::TOKEN => 1, CartTableMap::CUSTOMER_ID => 2, CartTableMap::ADDRESS_DELIVERY_ID => 3, CartTableMap::ADDRESS_INVOICE_ID => 4, CartTableMap::CURRENCY_ID => 5, CartTableMap::CREATED_AT => 6, CartTableMap::UPDATED_AT => 7, ),
- self::TYPE_RAW_COLNAME => array('ID' => 0, 'TOKEN' => 1, 'CUSTOMER_ID' => 2, 'ADDRESS_DELIVERY_ID' => 3, 'ADDRESS_INVOICE_ID' => 4, 'CURRENCY_ID' => 5, 'CREATED_AT' => 6, 'UPDATED_AT' => 7, ),
- self::TYPE_FIELDNAME => array('id' => 0, 'token' => 1, 'customer_id' => 2, 'address_delivery_id' => 3, 'address_invoice_id' => 4, 'currency_id' => 5, 'created_at' => 6, 'updated_at' => 7, ),
- self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, )
+ self::TYPE_PHPNAME => array('Id' => 0, 'Token' => 1, 'CustomerId' => 2, 'AddressDeliveryId' => 3, 'AddressInvoiceId' => 4, 'CurrencyId' => 5, 'Discount' => 6, 'CreatedAt' => 7, 'UpdatedAt' => 8, ),
+ self::TYPE_STUDLYPHPNAME => array('id' => 0, 'token' => 1, 'customerId' => 2, 'addressDeliveryId' => 3, 'addressInvoiceId' => 4, 'currencyId' => 5, 'discount' => 6, 'createdAt' => 7, 'updatedAt' => 8, ),
+ self::TYPE_COLNAME => array(CartTableMap::ID => 0, CartTableMap::TOKEN => 1, CartTableMap::CUSTOMER_ID => 2, CartTableMap::ADDRESS_DELIVERY_ID => 3, CartTableMap::ADDRESS_INVOICE_ID => 4, CartTableMap::CURRENCY_ID => 5, CartTableMap::DISCOUNT => 6, CartTableMap::CREATED_AT => 7, CartTableMap::UPDATED_AT => 8, ),
+ self::TYPE_RAW_COLNAME => array('ID' => 0, 'TOKEN' => 1, 'CUSTOMER_ID' => 2, 'ADDRESS_DELIVERY_ID' => 3, 'ADDRESS_INVOICE_ID' => 4, 'CURRENCY_ID' => 5, 'DISCOUNT' => 6, 'CREATED_AT' => 7, 'UPDATED_AT' => 8, ),
+ self::TYPE_FIELDNAME => array('id' => 0, 'token' => 1, 'customer_id' => 2, 'address_delivery_id' => 3, 'address_invoice_id' => 4, 'currency_id' => 5, 'discount' => 6, 'created_at' => 7, 'updated_at' => 8, ),
+ self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, )
);
/**
@@ -166,6 +171,7 @@ class CartTableMap extends TableMap
$this->addForeignKey('ADDRESS_DELIVERY_ID', 'AddressDeliveryId', 'INTEGER', 'address', 'ID', false, null, null);
$this->addForeignKey('ADDRESS_INVOICE_ID', 'AddressInvoiceId', 'INTEGER', 'address', 'ID', false, null, null);
$this->addForeignKey('CURRENCY_ID', 'CurrencyId', 'INTEGER', 'currency', 'ID', false, null, null);
+ $this->addColumn('DISCOUNT', 'Discount', 'FLOAT', false, null, 0);
$this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null);
$this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null);
} // initialize()
@@ -339,6 +345,7 @@ class CartTableMap extends TableMap
$criteria->addSelectColumn(CartTableMap::ADDRESS_DELIVERY_ID);
$criteria->addSelectColumn(CartTableMap::ADDRESS_INVOICE_ID);
$criteria->addSelectColumn(CartTableMap::CURRENCY_ID);
+ $criteria->addSelectColumn(CartTableMap::DISCOUNT);
$criteria->addSelectColumn(CartTableMap::CREATED_AT);
$criteria->addSelectColumn(CartTableMap::UPDATED_AT);
} else {
@@ -348,6 +355,7 @@ class CartTableMap extends TableMap
$criteria->addSelectColumn($alias . '.ADDRESS_DELIVERY_ID');
$criteria->addSelectColumn($alias . '.ADDRESS_INVOICE_ID');
$criteria->addSelectColumn($alias . '.CURRENCY_ID');
+ $criteria->addSelectColumn($alias . '.DISCOUNT');
$criteria->addSelectColumn($alias . '.CREATED_AT');
$criteria->addSelectColumn($alias . '.UPDATED_AT');
}
diff --git a/core/lib/Thelia/Model/Map/ProductSaleElementsTableMap.php b/core/lib/Thelia/Model/Map/ProductSaleElementsTableMap.php
index 21c005f5c..9025784bc 100644
--- a/core/lib/Thelia/Model/Map/ProductSaleElementsTableMap.php
+++ b/core/lib/Thelia/Model/Map/ProductSaleElementsTableMap.php
@@ -57,7 +57,7 @@ class ProductSaleElementsTableMap extends TableMap
/**
* The total number of columns
*/
- const NUM_COLUMNS = 8;
+ const NUM_COLUMNS = 9;
/**
* The number of lazy-loaded columns
@@ -67,7 +67,7 @@ class ProductSaleElementsTableMap extends TableMap
/**
* The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
*/
- const NUM_HYDRATE_COLUMNS = 8;
+ const NUM_HYDRATE_COLUMNS = 9;
/**
* the column name for the ID field
@@ -79,6 +79,11 @@ class ProductSaleElementsTableMap extends TableMap
*/
const PRODUCT_ID = 'product_sale_elements.PRODUCT_ID';
+ /**
+ * the column name for the REF field
+ */
+ const REF = 'product_sale_elements.REF';
+
/**
* the column name for the QUANTITY field
*/
@@ -121,12 +126,12 @@ class ProductSaleElementsTableMap extends TableMap
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
protected static $fieldNames = array (
- self::TYPE_PHPNAME => array('Id', 'ProductId', 'Quantity', 'Promo', 'Newness', 'Weight', 'CreatedAt', 'UpdatedAt', ),
- self::TYPE_STUDLYPHPNAME => array('id', 'productId', 'quantity', 'promo', 'newness', 'weight', 'createdAt', 'updatedAt', ),
- self::TYPE_COLNAME => array(ProductSaleElementsTableMap::ID, ProductSaleElementsTableMap::PRODUCT_ID, ProductSaleElementsTableMap::QUANTITY, ProductSaleElementsTableMap::PROMO, ProductSaleElementsTableMap::NEWNESS, ProductSaleElementsTableMap::WEIGHT, ProductSaleElementsTableMap::CREATED_AT, ProductSaleElementsTableMap::UPDATED_AT, ),
- self::TYPE_RAW_COLNAME => array('ID', 'PRODUCT_ID', 'QUANTITY', 'PROMO', 'NEWNESS', 'WEIGHT', 'CREATED_AT', 'UPDATED_AT', ),
- self::TYPE_FIELDNAME => array('id', 'product_id', 'quantity', 'promo', 'newness', 'weight', 'created_at', 'updated_at', ),
- self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, )
+ self::TYPE_PHPNAME => array('Id', 'ProductId', 'Ref', 'Quantity', 'Promo', 'Newness', 'Weight', 'CreatedAt', 'UpdatedAt', ),
+ self::TYPE_STUDLYPHPNAME => array('id', 'productId', 'ref', 'quantity', 'promo', 'newness', 'weight', 'createdAt', 'updatedAt', ),
+ self::TYPE_COLNAME => array(ProductSaleElementsTableMap::ID, ProductSaleElementsTableMap::PRODUCT_ID, ProductSaleElementsTableMap::REF, ProductSaleElementsTableMap::QUANTITY, ProductSaleElementsTableMap::PROMO, ProductSaleElementsTableMap::NEWNESS, ProductSaleElementsTableMap::WEIGHT, ProductSaleElementsTableMap::CREATED_AT, ProductSaleElementsTableMap::UPDATED_AT, ),
+ self::TYPE_RAW_COLNAME => array('ID', 'PRODUCT_ID', 'REF', 'QUANTITY', 'PROMO', 'NEWNESS', 'WEIGHT', 'CREATED_AT', 'UPDATED_AT', ),
+ self::TYPE_FIELDNAME => array('id', 'product_id', 'ref', 'quantity', 'promo', 'newness', 'weight', 'created_at', 'updated_at', ),
+ self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, )
);
/**
@@ -136,12 +141,12 @@ class ProductSaleElementsTableMap extends TableMap
* e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
*/
protected static $fieldKeys = array (
- self::TYPE_PHPNAME => array('Id' => 0, 'ProductId' => 1, 'Quantity' => 2, 'Promo' => 3, 'Newness' => 4, 'Weight' => 5, 'CreatedAt' => 6, 'UpdatedAt' => 7, ),
- self::TYPE_STUDLYPHPNAME => array('id' => 0, 'productId' => 1, 'quantity' => 2, 'promo' => 3, 'newness' => 4, 'weight' => 5, 'createdAt' => 6, 'updatedAt' => 7, ),
- self::TYPE_COLNAME => array(ProductSaleElementsTableMap::ID => 0, ProductSaleElementsTableMap::PRODUCT_ID => 1, ProductSaleElementsTableMap::QUANTITY => 2, ProductSaleElementsTableMap::PROMO => 3, ProductSaleElementsTableMap::NEWNESS => 4, ProductSaleElementsTableMap::WEIGHT => 5, ProductSaleElementsTableMap::CREATED_AT => 6, ProductSaleElementsTableMap::UPDATED_AT => 7, ),
- self::TYPE_RAW_COLNAME => array('ID' => 0, 'PRODUCT_ID' => 1, 'QUANTITY' => 2, 'PROMO' => 3, 'NEWNESS' => 4, 'WEIGHT' => 5, 'CREATED_AT' => 6, 'UPDATED_AT' => 7, ),
- self::TYPE_FIELDNAME => array('id' => 0, 'product_id' => 1, 'quantity' => 2, 'promo' => 3, 'newness' => 4, 'weight' => 5, 'created_at' => 6, 'updated_at' => 7, ),
- self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, )
+ self::TYPE_PHPNAME => array('Id' => 0, 'ProductId' => 1, 'Ref' => 2, 'Quantity' => 3, 'Promo' => 4, 'Newness' => 5, 'Weight' => 6, 'CreatedAt' => 7, 'UpdatedAt' => 8, ),
+ self::TYPE_STUDLYPHPNAME => array('id' => 0, 'productId' => 1, 'ref' => 2, 'quantity' => 3, 'promo' => 4, 'newness' => 5, 'weight' => 6, 'createdAt' => 7, 'updatedAt' => 8, ),
+ self::TYPE_COLNAME => array(ProductSaleElementsTableMap::ID => 0, ProductSaleElementsTableMap::PRODUCT_ID => 1, ProductSaleElementsTableMap::REF => 2, ProductSaleElementsTableMap::QUANTITY => 3, ProductSaleElementsTableMap::PROMO => 4, ProductSaleElementsTableMap::NEWNESS => 5, ProductSaleElementsTableMap::WEIGHT => 6, ProductSaleElementsTableMap::CREATED_AT => 7, ProductSaleElementsTableMap::UPDATED_AT => 8, ),
+ self::TYPE_RAW_COLNAME => array('ID' => 0, 'PRODUCT_ID' => 1, 'REF' => 2, 'QUANTITY' => 3, 'PROMO' => 4, 'NEWNESS' => 5, 'WEIGHT' => 6, 'CREATED_AT' => 7, 'UPDATED_AT' => 8, ),
+ self::TYPE_FIELDNAME => array('id' => 0, 'product_id' => 1, 'ref' => 2, 'quantity' => 3, 'promo' => 4, 'newness' => 5, 'weight' => 6, 'created_at' => 7, 'updated_at' => 8, ),
+ self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, )
);
/**
@@ -162,6 +167,7 @@ class ProductSaleElementsTableMap extends TableMap
// columns
$this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null);
$this->addForeignKey('PRODUCT_ID', 'ProductId', 'INTEGER', 'product', 'ID', true, null, null);
+ $this->addColumn('REF', 'Ref', 'VARCHAR', true, 45, null);
$this->addColumn('QUANTITY', 'Quantity', 'FLOAT', true, null, null);
$this->addColumn('PROMO', 'Promo', 'TINYINT', false, null, 0);
$this->addColumn('NEWNESS', 'Newness', 'TINYINT', false, null, 0);
@@ -343,6 +349,7 @@ class ProductSaleElementsTableMap extends TableMap
if (null === $alias) {
$criteria->addSelectColumn(ProductSaleElementsTableMap::ID);
$criteria->addSelectColumn(ProductSaleElementsTableMap::PRODUCT_ID);
+ $criteria->addSelectColumn(ProductSaleElementsTableMap::REF);
$criteria->addSelectColumn(ProductSaleElementsTableMap::QUANTITY);
$criteria->addSelectColumn(ProductSaleElementsTableMap::PROMO);
$criteria->addSelectColumn(ProductSaleElementsTableMap::NEWNESS);
@@ -352,6 +359,7 @@ class ProductSaleElementsTableMap extends TableMap
} else {
$criteria->addSelectColumn($alias . '.ID');
$criteria->addSelectColumn($alias . '.PRODUCT_ID');
+ $criteria->addSelectColumn($alias . '.REF');
$criteria->addSelectColumn($alias . '.QUANTITY');
$criteria->addSelectColumn($alias . '.PROMO');
$criteria->addSelectColumn($alias . '.NEWNESS');
diff --git a/core/lib/Thelia/Model/Tax.php b/core/lib/Thelia/Model/Tax.php
index 738f16508..7b9b22b6f 100755
--- a/core/lib/Thelia/Model/Tax.php
+++ b/core/lib/Thelia/Model/Tax.php
@@ -40,13 +40,13 @@ class Tax extends BaseTax
/* test type */
if(!class_exists($class)) {
- throw new TaxEngineException('Recorded type does not exists', TaxEngineException::BAD_RECORDED_TYPE);
+ throw new TaxEngineException('Recorded type `' . $class . '` does not exists', TaxEngineException::BAD_RECORDED_TYPE);
}
$instance = new $class;
if(!$instance instanceof BaseTaxType) {
- throw new TaxEngineException('Recorded type does not extends BaseTaxType', TaxEngineException::BAD_RECORDED_TYPE);
+ throw new TaxEngineException('Recorded type `' . $class . '` does not extends BaseTaxType', TaxEngineException::BAD_RECORDED_TYPE);
}
return $instance;
@@ -54,7 +54,7 @@ class Tax extends BaseTax
public function setRequirements($requirements)
{
- parent::setSerializedRequirements(base64_encode(json_encode($requirements)));
+ return parent::setSerializedRequirements(base64_encode(json_encode($requirements)));
}
public function getRequirements()
diff --git a/core/lib/Thelia/Model/Tools/PositionManagementTrait.php b/core/lib/Thelia/Model/Tools/PositionManagementTrait.php
index eb71564eb..70da830ac 100644
--- a/core/lib/Thelia/Model/Tools/PositionManagementTrait.php
+++ b/core/lib/Thelia/Model/Tools/PositionManagementTrait.php
@@ -45,22 +45,28 @@ trait PositionManagementTrait {
return $class->getConstant('DATABASE_NAME');
}
+ /**
+ * Implementors may add some search criteria (e.g., parent id) to the queries
+ * used to change/get position by overloading this method.
+ */
+ protected function addCriteriaToPositionQuery($query) {
+ // Add required criteria here...
+ }
/**
* Get the position of the next inserted object
*/
- public function getNextPosition($parent = null) {
+ public function getNextPosition() {
$query = $this->createQuery()
->orderByPosition(Criteria::DESC)
->limit(1);
- if ($parent !== null) $query->filterByParent($parent);
+ $this->addCriteriaToPositionQuery($query);
- $last = $query->findOne()
- ;
+ $last = $query->findOne();
- return $last != null ? $last->getPosition() + 1 : 1;
+ return $last != null ? $last->getPosition() + 1 : 1;
}
/**
@@ -90,7 +96,7 @@ trait PositionManagementTrait {
// Find object to exchange position with
$search = $this->createQuery();
- if (method_exists($this, 'getParent')) $search->filterByParent($this->getParent());
+ $this->addCriteriaToPositionQuery($search);
// Up or down ?
if ($up === true) {
@@ -151,7 +157,7 @@ trait PositionManagementTrait {
// Find categories to offset
$search = $this->createQuery();
- if (method_exists($this, 'getParent')) $search->filterByParent($this->getParent());
+ $this->addCriteriaToPositionQuery($search);
if ($newPosition > $current_position) {
// The new position is after the current position -> we will offset + 1 all categories located between us and the new position
diff --git a/core/lib/Thelia/TaxEngine/Calculator.php b/core/lib/Thelia/TaxEngine/Calculator.php
index 2708e88c6..f8c527cd1 100755
--- a/core/lib/Thelia/TaxEngine/Calculator.php
+++ b/core/lib/Thelia/TaxEngine/Calculator.php
@@ -39,6 +39,9 @@ class Calculator
*/
protected $taxRuleQuery = null;
+ /**
+ * @var null|\Propel\Runtime\Collection\ObjectCollection
+ */
protected $taxRulesCollection = null;
protected $product = null;
@@ -71,6 +74,11 @@ class Calculator
}
public function getTaxAmount($untaxedPrice)
+ {
+ return $this->getTaxedPrice($untaxedPrice) - $untaxedPrice;
+ }
+
+ public function getTaxedPrice($untaxedPrice)
{
if(null === $this->taxRulesCollection) {
throw new TaxEngineException('Tax rules collection is empty in Calculator::getTaxAmount', TaxEngineException::UNDEFINED_TAX_RULES_COLLECTION);
@@ -80,23 +88,27 @@ class Calculator
throw new TaxEngineException('BAD AMOUNT FORMAT', TaxEngineException::BAD_AMOUNT_FORMAT);
}
- $totalTaxAmount = 0;
+ $taxedPrice = $untaxedPrice;
+ $currentPosition = 1;
+ $currentTax = 0;
+
foreach($this->taxRulesCollection as $taxRule) {
+ $position = (int)$taxRule->getTaxRuleCountryPosition();
+
$taxType = $taxRule->getTypeInstance();
+ $taxType->loadRequirements( $taxRule->getRequirements() );
- $taxType->loadRequirements($taxRule->getRequirements());
+ if($currentPosition !== $position) {
+ $taxedPrice += $currentTax;
+ $currentTax = 0;
+ $currentPosition = $position;
+ }
- $taxAmount = $taxType->calculate($untaxedPrice);
-
- $totalTaxAmount += $taxAmount;
- $untaxedPrice += $taxAmount;
+ $currentTax += $taxType->calculate($taxedPrice);
}
- return $totalTaxAmount;
- }
+ $taxedPrice += $currentTax;
- public function getTaxedPrice($untaxedPrice)
- {
- return $untaxedPrice + $this->getTaxAmount($untaxedPrice);
+ return $taxedPrice;
}
}
diff --git a/core/lib/Thelia/Core/Event/CategoryUpdatePositionEvent.php b/core/lib/Thelia/TaxEngine/TaxType/FixAmountTaxType.php
old mode 100644
new mode 100755
similarity index 82%
rename from core/lib/Thelia/Core/Event/CategoryUpdatePositionEvent.php
rename to core/lib/Thelia/TaxEngine/TaxType/FixAmountTaxType.php
index 701fd4c8a..c533d0ec3
--- a/core/lib/Thelia/Core/Event/CategoryUpdatePositionEvent.php
+++ b/core/lib/Thelia/TaxEngine/TaxType/FixAmountTaxType.php
@@ -20,9 +20,26 @@
/* along with this program. If not, see . */
/* */
/*************************************************************************************/
+namespace Thelia\TaxEngine\TaxType;
-namespace Thelia\Core\Event;
+use Thelia\Type\FloatType;
-class CategoryUpdatePositionEvent extends BaseUpdatePositionEvent
+/**
+ *
+ * @author Etienne Roudeix
+ *
+ */
+class FixAmountTaxType extends BaseTaxType
{
+ public function calculate($untaxedPrice)
+ {
+ return $this->getRequirement("amount");
+ }
+
+ public function getRequirementsList()
+ {
+ return array(
+ 'amount' => new FloatType(),
+ );
+ }
}
diff --git a/core/lib/Thelia/Tests/Action/CustomerTest.php b/core/lib/Thelia/Tests/Action/CustomerTest.php
new file mode 100644
index 000000000..b70d39428
--- /dev/null
+++ b/core/lib/Thelia/Tests/Action/CustomerTest.php
@@ -0,0 +1,102 @@
+. */
+/* */
+/*************************************************************************************/
+
+namespace Thelia\Tests\Action\ImageTest;
+use Thelia\Action\Customer;
+use Thelia\Core\Event\CustomerCreateOrUpdateEvent;
+
+
+/**
+ * Class CustomerTest
+ * @package Thelia\Tests\Action\ImageTest
+ * @author Manuel Raynaud
+ */
+class CustomerTest extends \PHPUnit_Framework_TestCase
+{
+ public function getContainer()
+ {
+ $container = new \Symfony\Component\DependencyInjection\ContainerBuilder();
+
+ $dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
+
+ $container->set("event_dispatcher", $dispatcher);
+
+ return $container;
+ }
+
+ public function testCreatedCustomer()
+ {
+ $customerCreateEvent = new CustomerCreateOrUpdateEvent(
+ 1,
+ "thelia",
+ "thelia",
+ "street address 1",
+ "street address 2",
+ "street address 3",
+ "0102030405",
+ "0607080910",
+ "63000",
+ "clermont-ferrand",
+ 64,
+ sprintf("%s@thelia.fr", uniqid()),
+ uniqid(),
+ 1,
+ 0,
+ 0,
+ 0,
+ 'My super company'
+ );
+
+ $customerAction = new Customer($this->getContainer());
+
+ $customerAction->create($customerCreateEvent);
+
+ $customerCreated = $customerCreateEvent->getCustomer();
+
+ $this->assertInstanceOf("Thelia\Model\Customer", $customerCreated, "new customer created must be an instance of Thelia\Model\Customer");
+ $this->assertFalse($customerCreated->isNew());
+
+ $this->assertEquals($customerCreateEvent->getFirstname(), $customerCreated->getFirstname());
+ $this->assertEquals($customerCreateEvent->getLastname(), $customerCreated->getLastname());
+ $this->assertEquals($customerCreateEvent->getTitle(), $customerCreated->getTitleId());
+ $this->assertEquals($customerCreateEvent->getEmail(), $customerCreated->getEmail());
+ $this->assertEquals($customerCreated->getReseller(), $customerCreated->getReseller());
+ $this->assertEquals($customerCreated->getSponsor(), $customerCreated->getSponsor());
+ $this->assertEquals($customerCreated->getDiscount(), $customerCreated->getDiscount());
+
+ $addressCreated = $customerCreated->getDefaultAddress();
+
+ $this->assertEquals($customerCreateEvent->getFirstname(), $addressCreated->getFirstname());
+ $this->assertEquals($customerCreateEvent->getLastname(), $addressCreated->getLastname());
+ $this->assertEquals($customerCreateEvent->getTitle(), $addressCreated->getTitleId());
+ $this->assertEquals($customerCreateEvent->getAddress1(), $addressCreated->getAddress1());
+ $this->assertEquals($customerCreateEvent->getAddress2(), $addressCreated->getAddress2());
+ $this->assertEquals($customerCreateEvent->getAddress3(), $addressCreated->getAddress3());
+ $this->assertEquals($customerCreateEvent->getZipcode(), $addressCreated->getZipcode());
+ $this->assertEquals($customerCreateEvent->getCity(), $addressCreated->getCity());
+ $this->assertEquals($customerCreateEvent->getCountry(), $addressCreated->getCountryId());
+ $this->assertEquals($customerCreateEvent->getPhone(), $addressCreated->getPhone());
+ $this->assertEquals($customerCreateEvent->getCellphone(), $addressCreated->getCellphone());
+ $this->assertEquals($customerCreateEvent->getCompany(), $addressCreated->getCompany());
+ }
+}
\ No newline at end of file
diff --git a/core/lib/Thelia/Tests/Core/Template/Element/BaseLoopTestor.php b/core/lib/Thelia/Tests/Core/Template/Element/BaseLoopTestor.php
index 4a9cb4158..2b31d265a 100755
--- a/core/lib/Thelia/Tests/Core/Template/Element/BaseLoopTestor.php
+++ b/core/lib/Thelia/Tests/Core/Template/Element/BaseLoopTestor.php
@@ -29,6 +29,7 @@ use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\Security\SecurityContext;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Thelia\Core\HttpFoundation\Session\Session;
+use Thelia\Tools\URL;
/**
*
@@ -82,9 +83,32 @@ abstract class BaseLoopTestor extends \PHPUnit_Framework_TestCase
$this->securityContext = new SecurityContext($this->request);*/
+ $stubRouterAdmin = $this->getMockBuilder('\Symfony\Component\Routing\Router')
+ ->disableOriginalConstructor()
+ ->setMethods(array('getContext'))
+ ->getMock();
+
+ $stubRequestContext = $this->getMockBuilder('\Symfony\Component\Routing\RequestContext')
+ ->disableOriginalConstructor()
+ ->setMethods(array('getHost'))
+ ->getMock();
+
+ $stubRequestContext->expects($this->any())
+ ->method('getHost')
+ ->will($this->returnValue('localhost'));
+
+ $stubRouterAdmin->expects($this->any())
+ ->method('getContext')
+ ->will($this->returnValue(
+ $stubRequestContext
+ ));
+
+
$this->container->set('request', $request);
$this->container->set('event_dispatcher', new EventDispatcher());
$this->container->set('thelia.securityContext', new SecurityContext($request));
+ $this->container->set('router.admin', $stubRouterAdmin);
+ $this->container->set('thelia.url.manager', new URL($this->container));
$this->instance = $this->getTestedInstance();
$this->instance->initializeArgs($this->getMandatoryArguments());
@@ -107,4 +131,42 @@ abstract class BaseLoopTestor extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('\Thelia\Core\Template\Element\LoopResult', $methodReturn);
}
+
+ public function baseTestSearchById($id)
+ {
+ $this->instance->initializeArgs(array_merge(
+ $this->getMandatoryArguments(),
+ array(
+ "type" => "foo",
+ "name" => "foo",
+ "id" => $id,
+ )
+ ));
+
+ $dummy = null;
+ $loopResults = $this->instance->exec($dummy);
+
+ $this->assertEquals(1, $loopResults->getCount());
+
+ $substitutions = $loopResults->current()->getVarVal();
+
+ $this->assertEquals($id, $substitutions['ID']);
+ }
+
+ public function baseTestSearchWithLimit($limit)
+ {
+ $this->instance->initializeArgs(array_merge(
+ $this->getMandatoryArguments(),
+ array(
+ "type" => "foo",
+ "name" => "foo",
+ "limit" => $limit,
+ )
+ ));
+
+ $dummy = null;
+ $loopResults = $this->instance->exec($dummy);
+
+ $this->assertEquals($limit, $loopResults->getCount());
+ }
}
diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/CategoryTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/CategoryTest.php
index a2a320693..ce5f56747 100755
--- a/core/lib/Thelia/Tests/Core/Template/Loop/CategoryTest.php
+++ b/core/lib/Thelia/Tests/Core/Template/Loop/CategoryTest.php
@@ -23,6 +23,7 @@
namespace Thelia\Tests\Core\Template\Loop;
+use Thelia\Model\CategoryQuery;
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
use Thelia\Core\Template\Loop\Category;
@@ -48,4 +49,16 @@ class CategoryTest extends BaseLoopTestor
{
return array();
}
+
+ public function testSearchById()
+ {
+ $category = CategoryQuery::create()->findOne();
+
+ $this->baseTestSearchById($category->getId());
+ }
+
+ public function testSearchLimit()
+ {
+ $this->baseTestSearchWithLimit(3);
+ }
}
diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/ContentTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/ContentTest.php
index b6f9d0e3d..3a286200a 100755
--- a/core/lib/Thelia/Tests/Core/Template/Loop/ContentTest.php
+++ b/core/lib/Thelia/Tests/Core/Template/Loop/ContentTest.php
@@ -23,6 +23,7 @@
namespace Thelia\Tests\Core\Template\Loop;
+use Thelia\Model\ContentQuery;
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
use Thelia\Core\Template\Loop\Content;
@@ -48,4 +49,16 @@ class ContentTest extends BaseLoopTestor
{
return array();
}
+
+ public function testSearchById()
+ {
+ $content = ContentQuery::create()->findOne();
+
+ $this->baseTestSearchById($content->getId());
+ }
+
+ public function testSearchLimit()
+ {
+ $this->baseTestSearchWithLimit(3);
+ }
}
diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/FolderTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/FolderTest.php
index 2388a86c0..15ea3968c 100755
--- a/core/lib/Thelia/Tests/Core/Template/Loop/FolderTest.php
+++ b/core/lib/Thelia/Tests/Core/Template/Loop/FolderTest.php
@@ -23,6 +23,7 @@
namespace Thelia\Tests\Core\Template\Loop;
+use Thelia\Model\FolderQuery;
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
use Thelia\Core\Template\Loop\Folder;
@@ -48,4 +49,16 @@ class FolderTest extends BaseLoopTestor
{
return array();
}
+
+ public function testSearchById()
+ {
+ $folder = FolderQuery::create()->findOne();
+
+ $this->baseTestSearchById($folder->getId());
+ }
+
+ public function testSearchLimit()
+ {
+ $this->baseTestSearchWithLimit(3);
+ }
}
diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/ProductTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/ProductTest.php
index 8fc7d5ae5..1b307c5b5 100755
--- a/core/lib/Thelia/Tests/Core/Template/Loop/ProductTest.php
+++ b/core/lib/Thelia/Tests/Core/Template/Loop/ProductTest.php
@@ -23,6 +23,7 @@
namespace Thelia\Tests\Core\Template\Loop;
+use Thelia\Model\ProductQuery;
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
use Thelia\Core\Template\Loop\Product;
@@ -48,4 +49,16 @@ class ProductTest extends BaseLoopTestor
{
return array();
}
+
+ public function testSearchById()
+ {
+ $product = ProductQuery::create()->findOne();
+
+ $this->baseTestSearchById($product->getId());
+ }
+
+ public function testSearchLimit()
+ {
+ $this->baseTestSearchWithLimit(3);
+ }
}
diff --git a/core/lib/Thelia/Tests/Rewriting/RewritingRetrieverTest.php b/core/lib/Thelia/Tests/Rewriting/RewritingRetrieverTest.php
index 8723e0096..1a47dc10a 100755
--- a/core/lib/Thelia/Tests/Rewriting/RewritingRetrieverTest.php
+++ b/core/lib/Thelia/Tests/Rewriting/RewritingRetrieverTest.php
@@ -23,6 +23,7 @@
namespace Thelia\Tests\Rewriting;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
use Thelia\Model\RewritingUrl;
use Thelia\Rewriting\RewritingRetriever;
use Thelia\Tools\URL;
@@ -34,6 +35,36 @@ use Thelia\Tools\URL;
*/
class RewritingRetrieverTest extends \PHPUnit_Framework_TestCase
{
+ protected $container = null;
+
+ public function setUp()
+ {
+ $this->container = new ContainerBuilder();
+
+ $stubRouterAdmin = $this->getMockBuilder('\Symfony\Component\Routing\Router')
+ ->disableOriginalConstructor()
+ ->setMethods(array('getContext'))
+ ->getMock();
+
+ $stubRequestContext = $this->getMockBuilder('\Symfony\Component\Routing\RequestContext')
+ ->disableOriginalConstructor()
+ ->setMethods(array('getHost'))
+ ->getMock();
+
+ $stubRequestContext->expects($this->any())
+ ->method('getHost')
+ ->will($this->returnValue('localhost'));
+
+ $stubRouterAdmin->expects($this->any())
+ ->method('getContext')
+ ->will($this->returnValue(
+ $stubRequestContext
+ ));
+
+ $this->container->set('router.admin', $stubRouterAdmin);
+ $this->container->set('thelia.url.manager', new URL($this->container));
+ }
+
protected function getMethod($name)
{
$class = new \ReflectionClass('\Thelia\Rewriting\RewritingRetriever');
diff --git a/core/lib/Thelia/Tests/TaxEngine/CalculatorTest.php b/core/lib/Thelia/Tests/TaxEngine/CalculatorTest.php
index 719d90835..165d5d517 100755
--- a/core/lib/Thelia/Tests/TaxEngine/CalculatorTest.php
+++ b/core/lib/Thelia/Tests/TaxEngine/CalculatorTest.php
@@ -136,18 +136,21 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase
public function testGetTaxAmountAndGetTaxedPrice()
{
+ /* consecutives taxes */
$taxRulesCollection = new ObjectCollection();
$taxRulesCollection->setModel('\Thelia\Model\Tax');
$tax = new Tax();
$tax->setType('PricePercentTaxType')
- ->setRequirements(array('percent' => 10));
+ ->setRequirements(array('percent' => 10))
+ ->setVirtualColumn('taxRuleCountryPosition', 1);
$taxRulesCollection->append($tax);
$tax = new Tax();
$tax->setType('PricePercentTaxType')
- ->setRequirements(array('percent' => 8));
+ ->setRequirements(array('percent' => 8))
+ ->setVirtualColumn('taxRuleCountryPosition', 2);
$taxRulesCollection->append($tax);
@@ -167,5 +170,40 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase
*/
$this->assertEquals(94, $taxAmount);
$this->assertEquals(594, $taxedPrice);
+
+ /* same position taxes */
+ $taxRulesCollection = new ObjectCollection();
+ $taxRulesCollection->setModel('\Thelia\Model\Tax');
+
+ $tax = new Tax();
+ $tax->setType('PricePercentTaxType')
+ ->setRequirements(array('percent' => 10))
+ ->setVirtualColumn('taxRuleCountryPosition', 1);
+
+ $taxRulesCollection->append($tax);
+
+ $tax = new Tax();
+ $tax->setType('PricePercentTaxType')
+ ->setRequirements(array('percent' => 8))
+ ->setVirtualColumn('taxRuleCountryPosition', 1);
+
+ $taxRulesCollection->append($tax);
+
+ $calculator = new Calculator();
+
+ $rewritingUrlQuery = $this->getProperty('taxRulesCollection');
+ $rewritingUrlQuery->setValue($calculator, $taxRulesCollection);
+
+ $taxAmount = $calculator->getTaxAmount(500);
+ $taxedPrice = $calculator->getTaxedPrice(500);
+
+ /*
+ * expect :
+ * tax 1 = 500*0.10 = 50 // amout with tax 1 : 550
+ * tax 2 = 500*0.08 = 40 // amout with tax 2 : 590
+ * total tax amount = 90
+ */
+ $this->assertEquals(90, $taxAmount);
+ $this->assertEquals(590, $taxedPrice);
}
}
diff --git a/install/INSTALL-TODO.txt b/install/INSTALL-TODO.txt
index 0b8001fe9..df1e39a8d 100755
--- a/install/INSTALL-TODO.txt
+++ b/install/INSTALL-TODO.txt
@@ -23,3 +23,4 @@ Variables Config à initialiser:
- images_library_path : chemin vers le répertoire où sont stockés les images source (defaut: local/media/images)
- image_cache_dir_from_web_root : le repértoire de base où sont cachées les images, relatif à /web (cache/images)
- imagine_graphic_driver : le drivers utilisé par Imagine (gd, imagik, gmagick), defaut: 'gd'
+- process_assets : ne pas processer les assets pour de meilleurs perfs (attention, les modifs sur les fichiers ne seront plus reportées !)
diff --git a/install/faker.php b/install/faker.php
index 5bb21d4fa..fdcf6212c 100755
--- a/install/faker.php
+++ b/install/faker.php
@@ -156,6 +156,45 @@ try {
"azerty"
);
+ for($i = 0; $i < 50; $i++) {
+ $customer = new Thelia\Model\Customer();
+ $customer->createOrUpdate(
+ rand(1,3),
+ $faker->firstname,
+ $faker->lastname,
+ $faker->streetAddress,
+ $faker->streetAddress,
+ $faker->streetAddress,
+ $faker->phoneNumber,
+ $faker->phoneNumber,
+ $faker->postcode,
+ $faker->city,
+ 64,
+ $faker->email,
+ "azerty".$i
+ );
+
+ for ($j = 0; $j <= 3; $j++) {
+ $address = new Thelia\Model\Address();
+ $address->setLabel($faker->text(20))
+ ->setTitleId(rand(1,3))
+ ->setFirstname($faker->firstname)
+ ->setLastname($faker->lastname)
+ ->setAddress1($faker->streetAddress)
+ ->setAddress2($faker->streetAddress)
+ ->setAddress3($faker->streetAddress)
+ ->setCellphone($faker->phoneNumber)
+ ->setPhone($faker->phoneNumber)
+ ->setZipcode($faker->postcode)
+ ->setCity($faker->city)
+ ->setCountryId(64)
+ ->setCustomer($customer)
+ ->save()
+ ;
+
+ }
+ }
+
//features and features_av
$featureList = array();
for($i=0; $i<4; $i++) {
@@ -319,6 +358,7 @@ try {
for($i=0; $isetProductId($productId);
+ $stock->setRef($productId . '_' . $i . '_' . $faker->randomNumber(8));
$stock->setQuantity($faker->randomNumber(1,50));
$stock->setPromo($faker->randomNumber(0,1));
$stock->setNewness($faker->randomNumber(0,1));
diff --git a/install/insert.sql b/install/insert.sql
index 253b6cb30..d91035382 100755
--- a/install/insert.sql
+++ b/install/insert.sql
@@ -32,10 +32,10 @@ INSERT INTO `customer_title`(`id`, `by_default`, `position`, `created_at`, `upda
INSERT INTO `customer_title_i18n` (`id`, `locale`, `short`, `long`) VALUES
(1, 'fr_FR', 'Mr', 'Monsieur'),
(1, 'en_US', 'M', 'Mister'),
-(2, 'fr_FR', 'Mrs', 'Madame'),
-(2, 'en_US', 'Mme', 'Misses'),
-(3, 'fr_FR', 'Miss', 'Madamemoiselle'),
-(3, 'en_US', 'Mlle', 'Miss');
+(2, 'fr_FR', 'Mme', 'Madame'),
+(2, 'en_US', 'Mrs', 'Misses'),
+(3, 'fr_FR', 'Mlle', 'Madamemoiselle'),
+(3, 'en_US', 'Miss', 'Miss');
INSERT INTO `currency` (`id` ,`code` ,`symbol` ,`rate`, `position` ,`by_default` ,`created_at` ,`updated_at`)
VALUES
diff --git a/install/tax_faker.php b/install/tax_faker.php
new file mode 100755
index 000000000..5d534e2ef
--- /dev/null
+++ b/install/tax_faker.php
@@ -0,0 +1,116 @@
+boot();
+
+$faker = Faker\Factory::create();
+
+$con = \Propel\Runtime\Propel::getConnection(
+ Thelia\Model\Map\ProductTableMap::DATABASE_NAME
+);
+$con->beginTransaction();
+
+$currency = \Thelia\Model\CurrencyQuery::create()->filterByCode('EUR')->findOne();
+
+try {
+ $stmt = $con->prepare("SET foreign_key_checks = 0");
+ $stmt->execute();
+
+ \Thelia\Model\TaxQuery::create()
+ ->find()
+ ->delete();
+
+ \Thelia\Model\Base\TaxRuleQuery::create()
+ ->find()
+ ->delete();
+
+ \Thelia\Model\Base\TaxRuleCountryQuery::create()
+ ->find()
+ ->delete();
+
+ $stmt = $con->prepare("SET foreign_key_checks = 1");
+ $stmt->execute();
+
+ /* 10% tax */
+ $tax10p = new \Thelia\Model\Tax();
+ $tax10p->setType('PricePercentTaxType')
+ ->setRequirements(array('percent' => 10))
+ ->save();
+
+ /* 8% tax */
+ $tax8p = new \Thelia\Model\Tax();
+ $tax8p->setType('PricePercentTaxType')
+ ->setRequirements(array('percent' => 8))
+ ->save();
+
+ /* fix 5 tax */
+ $tax5 = new \Thelia\Model\Tax();
+ $tax5->setType('FixAmountTaxType')
+ ->setRequirements(array('amount' => 5))
+ ->save();
+
+ /* 1% tax */
+ $tax1p = new \Thelia\Model\Tax();
+ $tax1p->setType('PricePercentTaxType')
+ ->setRequirements(array('percent' => 1))
+ ->save();
+
+ /* tax rule */
+ $taxRule = new \Thelia\Model\TaxRule();
+ $taxRule->save();
+
+ /* add 4 taxes to the rule for France (64) */
+ $taxRuleCountry = new \Thelia\Model\TaxRuleCountry();
+ $taxRuleCountry->setTaxRule($taxRule)
+ ->setCountryId(64)
+ ->setTax($tax10p)
+ ->setPosition(1)
+ ->save();
+
+ $taxRuleCountry = new \Thelia\Model\TaxRuleCountry();
+ $taxRuleCountry->setTaxRule($taxRule)
+ ->setCountryId(64)
+ ->setTax($tax8p)
+ ->setPosition(1)
+ ->save();
+
+ $taxRuleCountry = new \Thelia\Model\TaxRuleCountry();
+ $taxRuleCountry->setTaxRule($taxRule)
+ ->setCountryId(64)
+ ->setTax($tax5)
+ ->setPosition(2)
+ ->save();
+
+ $taxRuleCountry = new \Thelia\Model\TaxRuleCountry();
+ $taxRuleCountry->setTaxRule($taxRule)
+ ->setCountryId(64)
+ ->setTax($tax1p)
+ ->setPosition(3)
+ ->save();
+
+ foreach(\Thelia\Model\ProductQuery::create()->find() as $productActiveRecord) {
+ $productActiveRecord->setTaxRule($taxRule)
+ ->save();
+ }
+
+ $con->commit();
+
+} catch (Exception $e) {
+ echo "error : ".$e->getMessage()."\n";
+ $con->rollBack();
+}
diff --git a/install/thelia.sql b/install/thelia.sql
index e4e5fb6b7..dd0e9a79c 100755
--- a/install/thelia.sql
+++ b/install/thelia.sql
@@ -349,6 +349,7 @@ CREATE TABLE `product_sale_elements`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`product_id` INTEGER NOT NULL,
+ `ref` VARCHAR(45) NOT NULL,
`quantity` FLOAT NOT NULL,
`promo` TINYINT DEFAULT 0,
`newness` TINYINT DEFAULT 0,
@@ -356,6 +357,7 @@ CREATE TABLE `product_sale_elements`
`created_at` DATETIME,
`updated_at` DATETIME,
PRIMARY KEY (`id`),
+ UNIQUE INDEX `ref_UNIQUE` (`ref`),
INDEX `idx_product_sale_element_product_id` (`product_id`),
CONSTRAINT `fk_product_sale_element_product_id`
FOREIGN KEY (`product_id`)
@@ -1151,6 +1153,7 @@ CREATE TABLE `cart`
`address_delivery_id` INTEGER,
`address_invoice_id` INTEGER,
`currency_id` INTEGER,
+ `discount` FLOAT DEFAULT 0,
`created_at` DATETIME,
`updated_at` DATETIME,
PRIMARY KEY (`id`),
@@ -1189,6 +1192,7 @@ CREATE TABLE `cart_item`
`price` FLOAT,
`promo_price` FLOAT,
`price_end_of_life` DATETIME,
+ `discount` FLOAT DEFAULT 0,
`created_at` DATETIME,
`updated_at` DATETIME,
PRIMARY KEY (`id`),
diff --git a/local/config/schema.xml b/local/config/schema.xml
index 7590da1e4..1d928bc7b 100755
--- a/local/config/schema.xml
+++ b/local/config/schema.xml
@@ -264,6 +264,7 @@
+
@@ -274,6 +275,9 @@
+
+
+
@@ -866,6 +870,7 @@
+
@@ -904,6 +909,7 @@
+
diff --git a/templates/admin/default/admin-layout.tpl b/templates/admin/default/admin-layout.tpl
index 188ba75f4..b15c624f3 100644
--- a/templates/admin/default/admin-layout.tpl
+++ b/templates/admin/default/admin-layout.tpl
@@ -144,9 +144,9 @@
{/loop}
- {loop name="menu-auth-discount" type="auth" roles="ADMIN" permissions="admin.discount.view"}
-
{/loop}
@@ -224,17 +224,18 @@
{debugbar_renderjs}
-
+ {debugbar_renderresult}
{block name="after-javascript-include"}{/block}
+ {javascripts file='assets/js/bootstrap/bootstrap.js'}
+
+ {/javascripts}
+
{block name="javascript-initialization"}{/block}
{* Modules scripts are included now *}
{module_include location='footer_js'}
- {javascripts file='assets/js/bootstrap/bootstrap.js'}
-
- {/javascripts}