diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index d4d63ac77..706c2f84d 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -111,6 +111,8 @@
+ + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 8121a1ef4..f8cd21c9b 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -779,11 +779,11 @@ - + Thelia\Controller\Admin\TaxRuleController::defaultAction - + Thelia\Controller\Admin\TaxRuleController::updateAction \d+ diff --git a/core/lib/Thelia/Controller/Admin/TaxRuleController.php b/core/lib/Thelia/Controller/Admin/TaxRuleController.php index 2a4f37a77..223e73fa1 100644 --- a/core/lib/Thelia/Controller/Admin/TaxRuleController.php +++ b/core/lib/Thelia/Controller/Admin/TaxRuleController.php @@ -23,23 +23,154 @@ namespace Thelia\Controller\Admin; -/** - * Class TaxRuleController - * @package Thelia\Controller\Admin - * @author Manuel Raynaud - */ -class TaxRuleController extends BaseAdminController +use Thelia\Core\Event\Tax\TaxRuleEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Form\TaxRuleCreationForm; +use Thelia\Form\TaxRuleModificationForm; +use Thelia\Model\CountryQuery; +use Thelia\Model\TaxRuleQuery; + +class TaxRuleController extends AbstractCrudController { - public function defaultAction() + public function __construct() { - if (null !== $response = $this->checkAuth("admin.taxes-rules.view")) return $response; - return $this->render("taxes-rules", array("display_taxes_rules" => 20)); + parent::__construct( + 'taxrule', + 'manual', + 'order', + + 'admin.configuration.taxrule.view', + 'admin.configuration.taxrule.create', + 'admin.configuration.taxrule.update', + 'admin.configuration.taxrule.delete', + + TheliaEvents::TAX_RULE_CREATE, + TheliaEvents::TAX_RULE_UPDATE, + TheliaEvents::TAX_RULE_DELETE + ); } - public function updateAction($tax_rule_id){ - return $this->render("tax-rule-edit", array( - "tax_rule_id" => $tax_rule_id - )); + protected function getCreationForm() + { + return new TaxRuleCreationForm($this->getRequest()); + } + + protected function getUpdateForm() + { + return new TaxRuleModificationForm($this->getRequest()); + } + + protected function getCreationEvent($formData) + { + $event = new TaxRuleEvent(); + + /* @todo fill event */ + + return $event; + } + + protected function getUpdateEvent($formData) + { + $event = new TaxRuleEvent(); + + /* @todo fill event */ + + return $event; + } + + protected function getDeleteEvent() + { + $event = new TaxRuleEvent(); + + /* @todo fill event */ + + return $event; + } + + protected function eventContainsObject($event) + { + return $event->hasTaxRule(); + } + + protected function hydrateObjectForm($object) + { + $data = array( + 'id' => $object->getId(), + 'locale' => $object->getLocale(), + 'title' => $object->getTitle(), + 'description' => $object->getDescription(), + ); + + // Setup the object form + return new TaxRuleModificationForm($this->getRequest(), "form", $data); + } + + protected function getObjectFromEvent($event) + { + return $event->hasTaxRule() ? $event->getTaxRule() : null; + } + + protected function getExistingObject() + { + return TaxRuleQuery::create() + ->joinWithI18n($this->getCurrentEditionLocale()) + ->findOneById($this->getRequest()->get('tax_rule_id')); + } + + protected function getObjectLabel($object) + { + return $object->getTitle(); + } + + protected function getObjectId($object) + { + return $object->getId(); + } + + protected function getViewArguments() + { + return array( + 'tax_rule_id' => $this->getRequest()->get('tax_rule_id'), + 'country_isoalpha3' => $this->getRequest()->get('country_isoalpha3'), + ); + } + + protected function renderListTemplate($currentOrder) + { + // We always return to the feature edition form + return $this->render( + 'taxes-rules', + array() + ); + } + + protected function renderEditionTemplate() + { + /* check the country exists */ + $country = CountryQuery::create()->findOneByIsoalpha3($this->getRequest()->get('country_isoalpha3')); + if(null === $country) { + $this->redirectToListTemplate(); + } + + // We always return to the feature edition form + return $this->render('tax-rule-edit', $this->getViewArguments()); + } + + protected function redirectToEditionTemplate() + { + // We always return to the feature edition form + $this->redirectToRoute( + "admin.configuration.taxes-rules.update", + $this->getViewArguments() + ); + } + + protected function redirectToListTemplate() + { + $this->redirectToRoute( + "admin.configuration.taxes-rules.list", + array() + ); } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/Tax/TaxRuleEvent.php b/core/lib/Thelia/Core/Event/Tax/TaxRuleEvent.php new file mode 100644 index 000000000..d12d81fba --- /dev/null +++ b/core/lib/Thelia/Core/Event/Tax/TaxRuleEvent.php @@ -0,0 +1,53 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Tax; +use Thelia\Core\Event\ActionEvent; +use Thelia\Model\TaxRule; + +class TaxRuleEvent extends ActionEvent +{ + protected $taxRule = null; + + public function __construct(TaxRule $taxRule = null) + { + $this->taxRule = $taxRule; + } + + public function hasTaxRule() + { + return ! is_null($this->taxRule); + } + + public function getTaxRule() + { + return $this->taxRule; + } + + public function setTaxRule(TaxRule $taxRule) + { + $this->taxRule = $taxRule; + + return $this; + } +} diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index f0dc68702..a6ca5b238 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -503,6 +503,13 @@ final class TheliaEvents const CHANGE_DEFAULT_CURRENCY = 'action.changeDefaultCurrency'; + // -- Tax Rules management --------------------------------------------- + + const TAX_RULE_CREATE = "action.createTaxRule"; + const TAX_RULE_UPDATE = "action.updateTaxRule"; + const TAX_RULE_DELETE = "action.deleteTaxRule"; + const TAX_RULE_SET_DEFAULT = "action.setDefaultTaxRule"; + // -- Product templates management ----------------------------------------- const TEMPLATE_CREATE = "action.createTemplate"; diff --git a/core/lib/Thelia/Core/Template/Loop/Country.php b/core/lib/Thelia/Core/Template/Loop/Country.php index 3a05b684a..f41173a33 100755 --- a/core/lib/Thelia/Core/Template/Loop/Country.php +++ b/core/lib/Thelia/Core/Template/Loop/Country.php @@ -113,6 +113,7 @@ class Country extends BaseI18nLoop ->set("CHAPO", $country->getVirtualColumn('i18n_CHAPO')) ->set("DESCRIPTION", $country->getVirtualColumn('i18n_DESCRIPTION')) ->set("POSTSCRIPTUM", $country->getVirtualColumn('i18n_POSTSCRIPTUM')) + ->set("IS_DEFAULT", $country->getByDefault() === 1 ? "1" : "0") ->set("ISOCODE", $country->getIsocode()) ->set("ISOALPHA2", $country->getIsoalpha2()) ->set("ISOALPHA3", $country->getIsoalpha3()); diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php index 17d9e37a3..594b45ae9 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php @@ -163,16 +163,16 @@ class DataAccessFunctions extends AbstractSmartyPlugin public function countryDataAccess($params, $smarty) { - if (array_key_exists('defaultCountry', self::$dataAccessCache)) { - $defaultCountry = self::$dataAccessCache['defaultCountry']; - } else { - $defaultCountry = CountryQuery::create()->findOneByByDefault(1); - self::$dataAccessCache['defaultCountry'] = $defaultCountry; - } - - switch ($params["attr"]) { + switch ($params["ask"]) { case "default": - return $defaultCountry->getId(); + /*if (array_key_exists('defaultCountry', self::$dataAccessCache)) { + $defaultCountry = self::$dataAccessCache['defaultCountry']; + } else { + $defaultCountry = CountryQuery::create()->findOneByByDefault(1); + self::$dataAccessCache['defaultCountry'] = $defaultCountry; + }*/ + $defaultCountry = CountryQuery::create()->filterByByDefault(1)->limit(1); + return $this->dataAccessWithI18n("defaultCountry", $params, $defaultCountry); } } diff --git a/core/lib/Thelia/Form/TaxRuleCreationForm.php b/core/lib/Thelia/Form/TaxRuleCreationForm.php new file mode 100644 index 000000000..a54e8b0c5 --- /dev/null +++ b/core/lib/Thelia/Form/TaxRuleCreationForm.php @@ -0,0 +1,60 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints; +use Symfony\Component\Validator\Constraints\NotBlank; +use Thelia\Core\Translation\Translator; + +class TaxRuleCreationForm 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("feature_id", "hidden", array( + "constraints" => array( + new NotBlank() + )) + ) + ; + } + + public function getName() + { + return "thelia_tax_rule_creation"; + } +} diff --git a/core/lib/Thelia/Form/TaxRuleModificationForm.php b/core/lib/Thelia/Form/TaxRuleModificationForm.php new file mode 100644 index 000000000..44cde86cd --- /dev/null +++ b/core/lib/Thelia/Form/TaxRuleModificationForm.php @@ -0,0 +1,52 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints; +use Symfony\Component\Validator\Constraints\GreaterThan; + +class TaxRuleModificationForm extends FeatureCreationForm +{ + use StandardDescriptionFieldsTrait; + + protected function buildForm() + { + $this->formBuilder + ->add("id", "hidden", array( + "constraints" => array( + new GreaterThan( + array('value' => 0) + ) + ) + )) + ; + + // Add standard description fields + $this->addStandardDescFields(); + } + + public function getName() + { + return "thelia_tax_rule_modification"; + } +} diff --git a/templates/admin/default/tax-rule-edit.html b/templates/admin/default/tax-rule-edit.html index b5ac36973..e58b67ddf 100644 --- a/templates/admin/default/tax-rule-edit.html +++ b/templates/admin/default/tax-rule-edit.html @@ -5,6 +5,9 @@ {block name="check-permissions"}admin.configuration.taxes-rules.edit{/block} {block name="main-content"} + +{assign oder_tab {$smarty.get.tab|default:"data"}} +
@@ -13,86 +16,106 @@
  • {intl l="Home"}
  • {intl l="Configuration"}
  • {intl l="Taxes rules"}
  • -
  • {intl l='Editing tax rule "%name"' name="{$TITLE}"}
  • +
  • {intl l='Editing tax rule'}
  • + {loop type="tax-rule" name="tax-rule" id=$tax_rule_id} +
    -
    - {intl l="Edit tax rule $TITLE"} -
    + - +
    +
    + + TODO + {form name="thelia.admin.taxrule.modification"} + + + + + + + + {/form} -
    - -
    - - - - -
    - +
    -

    {intl l="Countries that have the same tax rule"} :

    -

    - Italy - England - Japan -

    +
    + {intl l="Manage taxes"} +
    -
    -
    +
    + + +
    -
    -
    -

    Create a tax rule

    -
    -
    +

    {intl l="Countries that have the same tax rule"} :

    +

    + Italy + England + Japan +

    -
    -

    - - {intl l="Add tax to this group"} -

    +
    +
    + +
    +
    +

    Create a tax rule

    +
    +
    + +
    +

    + + {intl l="Add tax to this group"} +

    +
    + +
    +
    -
    - -
    + {intl l="Apply"} - {intl l="Apply"} - -
    -
    - -
    -
    -

    List of taxes

    -
    -
    Cras justo odio
    -
    Dapibus ac facilisis in
    -
    Morbi leo risus
    -
    Porta ac consectetur ac
    -
    Vestibulum at eros
    -
    - @@ -102,6 +125,8 @@
    + {/loop} +
    {* Confirmation dialog *} diff --git a/templates/admin/default/taxes-rules.html b/templates/admin/default/taxes-rules.html index f1edc9bd9..bc6cb4ed3 100644 --- a/templates/admin/default/taxes-rules.html +++ b/templates/admin/default/taxes-rules.html @@ -49,7 +49,7 @@
    {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.taxes-rules.change"} - + {/loop} {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.taxes-rules.change"}