From 0ae9c562e4567b90a2f7bc383c26060e5ff9095c Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Mon, 14 Oct 2013 14:58:08 +0200 Subject: [PATCH 01/12] tax rule edition --- .../Core/Template/Loop/TaxRuleCountry.php | 112 +++++++++++------- templates/admin/default/tax-rule-edit.html | 44 +++++-- 2 files changed, 105 insertions(+), 51 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Loop/TaxRuleCountry.php b/core/lib/Thelia/Core/Template/Loop/TaxRuleCountry.php index 91616f398..ee20a3d20 100644 --- a/core/lib/Thelia/Core/Template/Loop/TaxRuleCountry.php +++ b/core/lib/Thelia/Core/Template/Loop/TaxRuleCountry.php @@ -32,6 +32,7 @@ use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\Argument; +use Thelia\Model\CountryQuery; use Thelia\Model\Map\CountryTableMap; use Thelia\Model\Map\TaxRuleCountryTableMap; use Thelia\Model\Map\TaxTableMap; @@ -58,8 +59,14 @@ class TaxRuleCountry extends BaseI18nLoop protected function getArgDefinitions() { return new ArgumentCollection( - Argument::createIntTypeArgument('country'), - Argument::createIntListTypeArgument('taxes'), + Argument::createIntTypeArgument('country', null, true), + new Argument( + 'ask', + new TypeCollection( + new Type\EnumType(array('taxes', 'countries')) + ), + 'taxes' + ), Argument::createIntTypeArgument('tax_rule', null, true) ); } @@ -73,40 +80,54 @@ class TaxRuleCountry extends BaseI18nLoop { $search = TaxRuleCountryQuery::create(); + $ask = $this->getAsk(); + $country = $this->getCountry(); - $taxes = $this->getTaxes(); + $taxRule = $this->getTax_rule(); - if((null === $country && null === $taxes)) { - throw new \InvalidArgumentException('You must provide either `country` or `taxes` parameter in tax-rule-country loop'); - } + if($ask === 'countries') { + $taxCountForOriginCountry = TaxRuleCountryQuery::create()->filterByCountryId($country)->count(); - if((null === $country && null !== $taxes)) { - throw new \InvalidArgumentException('You must provide `country` parameter with `taxes` parameter in tax-rule-country loop'); - } + if($taxCountForOriginCountry > 0) { + $search->groupByCountryId(); - if(null !== $taxes) { - $search->groupByCountryId(); + $originalCountryJoin = new Join(); + $originalCountryJoin->addExplicitCondition(TaxRuleCountryTableMap::TABLE_NAME, 'TAX_RULE_ID', null, TaxRuleCountryTableMap::TABLE_NAME, 'TAX_RULE_ID', 'origin'); + $originalCountryJoin->addExplicitCondition(TaxRuleCountryTableMap::TABLE_NAME, 'TAX_ID', null, TaxRuleCountryTableMap::TABLE_NAME, 'TAX_ID', 'origin'); + $originalCountryJoin->addExplicitCondition(TaxRuleCountryTableMap::TABLE_NAME, 'POSITION', null, TaxRuleCountryTableMap::TABLE_NAME, 'POSITION', 'origin'); + $originalCountryJoin->addExplicitCondition(TaxRuleCountryTableMap::TABLE_NAME, 'COUNTRY_ID', null, TaxRuleCountryTableMap::TABLE_NAME, 'COUNTRY_ID', 'origin', Criteria::NOT_EQUAL); + $originalCountryJoin->setJoinType(Criteria::LEFT_JOIN); - $originalCountryJoin = new Join(); - $originalCountryJoin->addExplicitCondition(TaxRuleCountryTableMap::TABLE_NAME, 'TAX_RULE_ID', null, TaxRuleCountryTableMap::TABLE_NAME, 'TAX_RULE_ID', 'origin'); - $originalCountryJoin->addExplicitCondition(TaxRuleCountryTableMap::TABLE_NAME, 'TAX_ID', null, TaxRuleCountryTableMap::TABLE_NAME, 'TAX_ID', 'origin'); - $originalCountryJoin->addExplicitCondition(TaxRuleCountryTableMap::TABLE_NAME, 'POSITION', null, TaxRuleCountryTableMap::TABLE_NAME, 'POSITION', 'origin'); - $originalCountryJoin->addExplicitCondition(TaxRuleCountryTableMap::TABLE_NAME, 'COUNTRY_ID', null, TaxRuleCountryTableMap::TABLE_NAME, 'COUNTRY_ID', 'origin', Criteria::NOT_EQUAL); - $originalCountryJoin->setJoinType(Criteria::LEFT_JOIN); + $search->addJoinObject($originalCountryJoin, 's_to_o'); + $search->where('`origin`.`COUNTRY_ID`' . Criteria::EQUAL . '?', $country, \PDO::PARAM_INT); - $search->addJoinObject($originalCountryJoin, 's_to_o'); - $search->where('`origin`.`COUNTRY_ID`' . Criteria::EQUAL . '?', $country, \PDO::PARAM_INT); + $search->having('COUNT(*)=?', $taxCountForOriginCountry, \PDO::PARAM_INT); - $search->having('COUNT(*)=?', count($taxes), \PDO::PARAM_INT); + $search->filterByTaxRuleId($taxRule); - /* manage tax translation */ - $this->configureI18nProcessing( - $search, - array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), - CountryTableMap::TABLE_NAME, - 'COUNTRY_ID' - ); - } elseif(null !== $country) { + /* manage tax translation */ + $this->configureI18nProcessing( + $search, + array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), + CountryTableMap::TABLE_NAME, + 'COUNTRY_ID' + ); + + $search->addAscendingOrderByColumn('`' . CountryTableMap::TABLE_NAME . '_i18n_TITLE`'); + } else { + $search = CountryQuery::create() + ->joinTaxRuleCountry('trc', Criteria::LEFT_JOIN); + + /* manage tax translation */ + $this->configureI18nProcessing( + $search + ); + + $search->where('ISNULL(`trc`.`COUNTRY_ID`)'); + + $search->addAscendingOrderByColumn('i18n_TITLE'); + } + } elseif($ask === 'taxes') { $search->filterByCountryId($country); /* manage tax translation */ @@ -116,13 +137,11 @@ class TaxRuleCountry extends BaseI18nLoop TaxTableMap::TABLE_NAME, 'TAX_ID' ); + + $search->filterByTaxRuleId($taxRule); + $search->orderByPosition(Criteria::ASC); } - $taxRule = $this->getTax_rule(); - $search->filterByTaxRuleId($taxRule); - - $search->orderByPosition(Criteria::ASC); - /* perform search */ $taxRuleCountries = $this->search($search, $pagination); @@ -132,16 +151,23 @@ class TaxRuleCountry extends BaseI18nLoop $loopResultRow = new LoopResultRow($loopResult, $taxRuleCountry, $this->versionable, $this->timestampable, $this->countable); - if(null !== $taxes) { - $loopResultRow - ->set("TAX_RULE" , $taxRuleCountry->getTaxRuleId()) - ->set("COUNTRY" , $taxRuleCountry->getCountryId()) - ->set("COUNTRY_TITLE" , $taxRuleCountry->getVirtualColumn(CountryTableMap::TABLE_NAME . '_i18n_TITLE')) - ->set("COUNTRY_CHAPO" , $taxRuleCountry->getVirtualColumn(CountryTableMap::TABLE_NAME . '_i18n_CHAPO')) - ->set("COUNTRY_DESCRIPTION" , $taxRuleCountry->getVirtualColumn(CountryTableMap::TABLE_NAME . '_i18n_DESCRIPTION')) - ->set("COUNTRY_POSTSCRIPTUM" , $taxRuleCountry->getVirtualColumn(CountryTableMap::TABLE_NAME . '_i18n_POSTSCRIPTUM')) - ; - }elseif(null !== $country) { + if($ask === 'countries') { + if($taxCountForOriginCountry > 0) { + $loopResultRow + ->set("COUNTRY" , $taxRuleCountry->getCountryId()) + ->set("COUNTRY_TITLE" , $taxRuleCountry->getVirtualColumn(CountryTableMap::TABLE_NAME . '_i18n_TITLE')) + ->set("COUNTRY_CHAPO" , $taxRuleCountry->getVirtualColumn(CountryTableMap::TABLE_NAME . '_i18n_CHAPO')) + ->set("COUNTRY_DESCRIPTION" , $taxRuleCountry->getVirtualColumn(CountryTableMap::TABLE_NAME . '_i18n_DESCRIPTION')) + ->set("COUNTRY_POSTSCRIPTUM" , $taxRuleCountry->getVirtualColumn(CountryTableMap::TABLE_NAME . '_i18n_POSTSCRIPTUM')); + } else { + $loopResultRow + ->set("COUNTRY" , $taxRuleCountry->getId()) + ->set("COUNTRY_TITLE" , $taxRuleCountry->getVirtualColumn('i18n_TITLE')) + ->set("COUNTRY_CHAPO" , $taxRuleCountry->getVirtualColumn('i18n_CHAPO')) + ->set("COUNTRY_DESCRIPTION" , $taxRuleCountry->getVirtualColumn('i18n_DESCRIPTION')) + ->set("COUNTRY_POSTSCRIPTUM" , $taxRuleCountry->getVirtualColumn('i18n_POSTSCRIPTUM')); + } + } elseif($ask === 'taxes') { $loopResultRow ->set("TAX_RULE" , $taxRuleCountry->getTaxRuleId()) ->set("COUNTRY" , $taxRuleCountry->getCountryId()) diff --git a/templates/admin/default/tax-rule-edit.html b/templates/admin/default/tax-rule-edit.html index c236e7bc4..5ad6ab205 100644 --- a/templates/admin/default/tax-rule-edit.html +++ b/templates/admin/default/tax-rule-edit.html @@ -116,11 +116,11 @@

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

-

+

{$matchedCountries.first=$asked_country} - {loop type="tax-rule-country" name="same-country-list" tax_rule=$ID taxes="1,2,3" country=$asked_country} + {loop type="tax-rule-country" name="same-country-list" tax_rule=$ID ask="countries" country=$asked_country} {$matchedCountries[]=$COUNTRY} {$COUNTRY_TITLE} {/loop} @@ -129,6 +129,7 @@ {intl l="NONE"} {/elseloop}

+
@@ -234,11 +235,16 @@

{intl l="Tax rule taxes will be update for the following countries :"}

- +
+ + + + +
{/form_field} @@ -283,6 +289,29 @@ $('#tax_list_update_dialog').modal(); {/if} + + $('.js-collapse').each(function(k, v) { + var h = $(v).data('collapse-height'); + if( $(v).height() > h ) { + $(v).css('overflow', 'hidden').css('height', h + 'px'); + } else { + $('[data-collapse-block=' + $(v).attr('id') + ']').hide(); + } + }); + + $('.js-collapse-btn').click(function(e) { + e.preventDefault(); + var block = $(this).data('collapseBlock'); + $('#' + block).css('overflow', 'initial').css('height', 'initial'); + $(this).unbind().remove(); + }); + + $('.js-uncheck-all').click(function(e) { + e.preventDefault(); + var selectId = $(this).data('uncheckSelect'); + $('#' + selectId).selectpicker('deselectAll'); + }); + {literal} $('#country-selector').change(function(e) { $('#country-selector-form').submit(); @@ -308,7 +337,6 @@ }); }); - console.log(taxesRules); $('#tax_list').val(JSON.stringify(taxesRules)); }); From 085c2fa75cb8a0c063ba29b9d232508faff20b0c Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Mon, 14 Oct 2013 17:28:31 +0200 Subject: [PATCH 02/12] taxes management --- core/lib/Thelia/Action/Tax.php | 104 +++++++++ core/lib/Thelia/Config/Resources/action.xml | 5 + core/lib/Thelia/Config/Resources/config.xml | 4 + .../Thelia/Config/Resources/routing/admin.xml | 23 +- .../Thelia/Controller/Admin/TaxController.php | 198 ++++++++++++++++++ core/lib/Thelia/Core/Event/Tax/TaxEvent.php | 109 ++++++++++ core/lib/Thelia/Core/Event/TheliaEvents.php | 6 + core/lib/Thelia/Core/Template/Loop/Tax.php | 12 +- core/lib/Thelia/Form/TaxCreationForm.php | 67 ++++++ core/lib/Thelia/Form/TaxModificationForm.php | 66 ++++++ core/lib/Thelia/Model/Tax.php | 3 + core/lib/Thelia/TaxEngine/TaxEngine.php | 71 +++++++ .../Thelia/TaxEngine/TaxType/BaseTaxType.php | 2 + .../TaxType/FeatureFixAmountTaxType.php | 5 + .../TaxType/FeatureSlicePercentTaxType.php | 5 + .../TaxEngine/TaxType/FixAmountTaxType.php | 5 + .../TaxEngine/TaxType/PricePercentTaxType.php | 7 +- templates/admin/default/tax-edit.html | 130 ++++++++++++ templates/admin/default/taxes-rules.html | 187 ++++++++++++++++- 19 files changed, 995 insertions(+), 14 deletions(-) create mode 100644 core/lib/Thelia/Action/Tax.php create mode 100644 core/lib/Thelia/Controller/Admin/TaxController.php create mode 100644 core/lib/Thelia/Core/Event/Tax/TaxEvent.php create mode 100644 core/lib/Thelia/Form/TaxCreationForm.php create mode 100644 core/lib/Thelia/Form/TaxModificationForm.php create mode 100755 core/lib/Thelia/TaxEngine/TaxEngine.php create mode 100644 templates/admin/default/tax-edit.html diff --git a/core/lib/Thelia/Action/Tax.php b/core/lib/Thelia/Action/Tax.php new file mode 100644 index 000000000..91e51b59f --- /dev/null +++ b/core/lib/Thelia/Action/Tax.php @@ -0,0 +1,104 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Action; + +use Propel\Runtime\ActiveQuery\Criteria; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Thelia\Core\Event\Tax\TaxEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Model\Tax as TaxModel; +use Thelia\Model\TaxQuery; + +class Tax extends BaseAction implements EventSubscriberInterface +{ + /** + * @param TaxEvent $event + */ + public function create(TaxEvent $event) + { + $tax = new TaxModel(); + + $tax + ->setDispatcher($this->getDispatcher()) + ->setType($event->getType()) + ->setLocale($event->getLocale()) + ->setTitle($event->getTitle()) + ->setDescription($event->getDescription()) + ; + + $tax->save(); + + $event->setTax($tax); + } + + /** + * @param TaxEvent $event + */ + public function update(TaxEvent $event) + { + if (null !== $tax = TaxQuery::create()->findPk($event->getId())) { + + $tax + ->setDispatcher($this->getDispatcher()) + ->setType($event->getType()) + ->setLocale($event->getLocale()) + ->setTitle($event->getTitle()) + ->setDescription($event->getDescription()) + ->save() + ; + + + + $event->setTax($tax); + } + } + + /** + * @param TaxEvent $event + */ + public function delete(TaxEvent $event) + { + if (null !== $tax = TaxQuery::create()->findPk($event->getId())) { + + $tax + ->delete() + ; + + $event->setTax($tax); + } + } + + /** + * {@inheritDoc} + */ + public static function getSubscribedEvents() + { + return array( + TheliaEvents::TAX_CREATE => array("create", 128), + TheliaEvents::TAX_UPDATE => array("update", 128), + TheliaEvents::TAX_DELETE => array("delete", 128), + + ); + } +} diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index 939cc9d88..1ef84b5af 100755 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -111,6 +111,11 @@ + + + + + diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 5e2227989..19b9c97f6 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -117,6 +117,10 @@
+ + + + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 9803bc866..af05b667e 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -787,7 +787,28 @@ - + + + + Thelia\Controller\Admin\TaxController::updateAction + \d+ + + + + Thelia\Controller\Admin\TaxController::createAction + + + + Thelia\Controller\Admin\TaxController::processUpdateAction + + + + Thelia\Controller\Admin\TaxController::deleteAction + + + + + Thelia\Controller\Admin\TaxRuleController::defaultAction diff --git a/core/lib/Thelia/Controller/Admin/TaxController.php b/core/lib/Thelia/Controller/Admin/TaxController.php new file mode 100644 index 000000000..0c83aa4cb --- /dev/null +++ b/core/lib/Thelia/Controller/Admin/TaxController.php @@ -0,0 +1,198 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Controller\Admin; + +use Thelia\Core\Event\Tax\TaxEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Form\TaxCreationForm; +use Thelia\Form\TaxModificationForm; +use Thelia\Form\TaxTaxListUpdateForm; +use Thelia\Model\TaxQuery; + +class TaxController extends AbstractCrudController +{ + public function __construct() + { + parent::__construct( + 'tax', + 'manual', + 'order', + + 'admin.configuration.tax.view', + 'admin.configuration.tax.create', + 'admin.configuration.tax.update', + 'admin.configuration.tax.delete', + + TheliaEvents::TAX_CREATE, + TheliaEvents::TAX_UPDATE, + TheliaEvents::TAX_DELETE + ); + } + + protected function getCreationForm() + { + return new TaxCreationForm($this->getRequest()); + } + + protected function getUpdateForm() + { + return new TaxModificationForm($this->getRequest()); + } + + protected function getCreationEvent($formData) + { + $event = new TaxEvent(); + + $event->setLocale($formData['locale']); + $event->setTitle($formData['title']); + $event->setDescription($formData['description']); + $event->setType($formData['type']); + + return $event; + } + + protected function getUpdateEvent($formData) + { + $event = new TaxEvent(); + + $event->setLocale($formData['locale']); + $event->setId($formData['id']); + $event->setTitle($formData['title']); + $event->setDescription($formData['description']); + $event->setType($formData['type']); + + return $event; + } + + protected function getDeleteEvent() + { + $event = new TaxEvent(); + + $event->setId( + $this->getRequest()->get('tax_id', 0) + ); + + return $event; + } + + protected function eventContainsObject($event) + { + return $event->hasTax(); + } + + protected function hydrateObjectForm($object) + { + $data = array( + 'id' => $object->getId(), + 'locale' => $object->getLocale(), + 'title' => $object->getTitle(), + 'description' => $object->getDescription(), + 'type' => $object->getType(), + ); + + // Setup the object form + return new TaxModificationForm($this->getRequest(), "form", $data); + } + + protected function getObjectFromEvent($event) + { + return $event->hasTax() ? $event->getTax() : null; + } + + protected function getExistingObject() + { + return TaxQuery::create() + ->joinWithI18n($this->getCurrentEditionLocale()) + ->findOneById($this->getRequest()->get('tax_id')); + } + + protected function getObjectLabel($object) + { + return $object->getTitle(); + } + + protected function getObjectId($object) + { + return $object->getId(); + } + + protected function getViewArguments() + { + return array(); + } + + protected function getRouteArguments($tax_id = null) + { + return array( + 'tax_id' => $tax_id === null ? $this->getRequest()->get('tax_id') : $tax_id, + ); + } + + protected function renderListTemplate($currentOrder) + { + // We always return to the feature edition form + return $this->render( + 'taxes-rules', + array() + ); + } + + protected function renderEditionTemplate() + { + // We always return to the feature edition form + return $this->render('tax-edit', array_merge($this->getViewArguments(), $this->getRouteArguments())); + } + + protected function redirectToEditionTemplate($request = null, $country = null) + { + // We always return to the feature edition form + $this->redirectToRoute( + "admin.configuration.taxes.update", + $this->getViewArguments($country), + $this->getRouteArguments() + ); + } + + /** + * Put in this method post object creation processing if required. + * + * @param TaxEvent $createEvent the create event + * @return Response a response, or null to continue normal processing + */ + protected function performAdditionalCreateAction($createEvent) + { + $this->redirectToRoute( + "admin.configuration.taxes.update", + $this->getViewArguments(), + $this->getRouteArguments($createEvent->getTax()->getId()) + ); + } + + protected function redirectToListTemplate() + { + $this->redirectToRoute( + "admin.configuration.taxes-rules.list" + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/Tax/TaxEvent.php b/core/lib/Thelia/Core/Event/Tax/TaxEvent.php new file mode 100644 index 000000000..6136630ad --- /dev/null +++ b/core/lib/Thelia/Core/Event/Tax/TaxEvent.php @@ -0,0 +1,109 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Tax; +use Thelia\Core\Event\ActionEvent; +use Thelia\Model\Tax; + +class TaxEvent extends ActionEvent +{ + protected $tax = null; + + protected $locale; + protected $id; + protected $title; + protected $description; + protected $type; + + public function __construct(Tax $tax = null) + { + $this->tax = $tax; + } + + public function hasTax() + { + return ! is_null($this->tax); + } + + public function getTax() + { + return $this->tax; + } + + public function setTax(Tax $tax) + { + $this->tax = $tax; + + return $this; + } + + public function setDescription($description) + { + $this->description = $description; + } + + public function getDescription() + { + return $this->description; + } + + public function setId($id) + { + $this->id = $id; + } + + public function getId() + { + return $this->id; + } + + public function setTitle($title) + { + $this->title = $title; + } + + public function getTitle() + { + return $this->title; + } + + public function setLocale($locale) + { + $this->locale = $locale; + } + + public function getLocale() + { + return $this->locale; + } + + public function setType($type) + { + $this->type = $type; + } + + public function getType() + { + return $this->type; + } +} diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index a21e0a9c9..c2f2721b8 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -519,6 +519,12 @@ final class TheliaEvents const CHANGE_DEFAULT_CURRENCY = 'action.changeDefaultCurrency'; + // -- Tax management --------------------------------------------- + + const TAX_CREATE = "action.createTax"; + const TAX_UPDATE = "action.updateTax"; + const TAX_DELETE = "action.deleteTax"; + // -- Tax Rules management --------------------------------------------- const TAX_RULE_CREATE = "action.createTaxRule"; diff --git a/core/lib/Thelia/Core/Template/Loop/Tax.php b/core/lib/Thelia/Core/Template/Loop/Tax.php index 1ddf18824..0248e60d8 100644 --- a/core/lib/Thelia/Core/Template/Loop/Tax.php +++ b/core/lib/Thelia/Core/Template/Loop/Tax.php @@ -152,11 +152,13 @@ class Tax extends BaseI18nLoop $loopResultRow = new LoopResultRow($loopResult, $tax, $this->versionable, $this->timestampable, $this->countable); $loopResultRow - ->set("ID" , $tax->getId()) - ->set("IS_TRANSLATED" , $tax->getVirtualColumn('IS_TRANSLATED')) - ->set("LOCALE" , $locale) - ->set("TITLE" , $tax->getVirtualColumn('i18n_TITLE')) - ->set("DESCRIPTION" , $tax->getVirtualColumn('i18n_DESCRIPTION')) + ->set("ID" , $tax->getId()) + ->set("TYPE" , $tax->getType()) + ->set("SERIALIZED_REQUIREMENTS" , $tax->getSerializedRequirements()) + ->set("IS_TRANSLATED" , $tax->getVirtualColumn('IS_TRANSLATED')) + ->set("LOCALE" , $locale) + ->set("TITLE" , $tax->getVirtualColumn('i18n_TITLE')) + ->set("DESCRIPTION" , $tax->getVirtualColumn('i18n_DESCRIPTION')) ; $loopResult->addRow($loopResultRow); diff --git a/core/lib/Thelia/Form/TaxCreationForm.php b/core/lib/Thelia/Form/TaxCreationForm.php new file mode 100644 index 000000000..31b0834d4 --- /dev/null +++ b/core/lib/Thelia/Form/TaxCreationForm.php @@ -0,0 +1,67 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints; +use Symfony\Component\Validator\Constraints\NotBlank; +use Thelia\Core\Translation\Translator; +use Thelia\TaxEngine\TaxEngine; +use Thelia\TaxEngine\TaxType; + +class TaxCreationForm extends BaseForm +{ + use StandardDescriptionFieldsTrait; + + protected function buildForm($change_mode = false) + { + $types = TaxEngine::getInstance()->getTaxTypeList(); + $typeList = array(); + foreach($types as $type) { + $classPath = "\\Thelia\\TaxEngine\\TaxType\\$type"; + $instance = new $classPath(); + $typeList[$type] = $instance->getTitle(); + } + + $this->formBuilder + ->add("locale", "text", array( + "constraints" => array(new NotBlank()) + )) + ->add("type", "choice", array( + "choices" => $typeList, + "required" => true, + "constraints" => array( + new Constraints\NotBlank(), + ), + "label" => Translator::getInstance()->trans("Type"), + "label_attr" => array("for" => "type_field"), + )) + ; + + $this->addStandardDescFields(array('postscriptum', 'chapo', 'locale')); + } + + public function getName() + { + return "thelia_tax_creation"; + } +} diff --git a/core/lib/Thelia/Form/TaxModificationForm.php b/core/lib/Thelia/Form/TaxModificationForm.php new file mode 100644 index 000000000..1c496440e --- /dev/null +++ b/core/lib/Thelia/Form/TaxModificationForm.php @@ -0,0 +1,66 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints; +use Symfony\Component\Validator\ExecutionContextInterface; +use Thelia\Model\TaxQuery; + +class TaxModificationForm extends TaxCreationForm +{ + protected function buildForm() + { + parent::buildForm(true); + + $this->formBuilder + ->add("id", "hidden", array( + "required" => true, + "constraints" => array( + new Constraints\NotBlank(), + new Constraints\Callback( + array( + "methods" => array( + array($this, "verifyTaxId"), + ), + ) + ), + ) + )) + ; + } + + public function getName() + { + return "thelia_tax_modification"; + } + + public function verifyTaxId($value, ExecutionContextInterface $context) + { + $tax = TaxQuery::create() + ->findPk($value); + + if (null === $tax) { + $context->addViolation("Tax ID not found"); + } + } +} diff --git a/core/lib/Thelia/Model/Tax.php b/core/lib/Thelia/Model/Tax.php index 7b9b22b6f..6752129a2 100755 --- a/core/lib/Thelia/Model/Tax.php +++ b/core/lib/Thelia/Model/Tax.php @@ -4,10 +4,13 @@ namespace Thelia\Model; use Thelia\Exception\TaxEngineException; use Thelia\Model\Base\Tax as BaseTax; +use Thelia\Model\Tools\ModelEventDispatcherTrait; use Thelia\TaxEngine\TaxType\BaseTaxType; class Tax extends BaseTax { + use ModelEventDispatcherTrait; + public function calculateTax($amount) { if(false === filter_var($amount, FILTER_VALIDATE_FLOAT)) { diff --git a/core/lib/Thelia/TaxEngine/TaxEngine.php b/core/lib/Thelia/TaxEngine/TaxEngine.php new file mode 100755 index 000000000..8e5a5695a --- /dev/null +++ b/core/lib/Thelia/TaxEngine/TaxEngine.php @@ -0,0 +1,71 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\TaxEngine; + +/** + * Class TaxEngine + * @package Thelia\TaxEngine + * @author Etienne Roudeix + */ +class TaxEngine +{ + static public function getInstance() + { + return new TaxEngine(); + } + + private function getTaxTypeDirectory() + { + return __DIR__ . "/TaxType"; + } + + public function getTaxTypeList() + { + $typeList = array(); + + try { + $directoryBrowser = new \DirectoryIterator($this->getTaxTypeDirectory($this->getTaxTypeDirectory())); + } catch (\UnexpectedValueException $e) { + return $typeList; + } + + /* browse the directory */ + foreach ($directoryBrowser as $directoryContent) { + /* is it a file ? */ + if (!$directoryContent->isFile()) { + continue; + } + + $fileName = $directoryContent->getFilename(); + $className = substr($fileName, 0, (1+strlen($directoryContent->getExtension())) * -1); + + if($className == "BaseTaxType") { + continue; + } + + $typeList[] = $className; + } + + return $typeList; + } +} diff --git a/core/lib/Thelia/TaxEngine/TaxType/BaseTaxType.php b/core/lib/Thelia/TaxEngine/TaxType/BaseTaxType.php index 1e0a11ca7..f8bdd8647 100755 --- a/core/lib/Thelia/TaxEngine/TaxType/BaseTaxType.php +++ b/core/lib/Thelia/TaxEngine/TaxType/BaseTaxType.php @@ -41,6 +41,8 @@ abstract class BaseTaxType public abstract function getRequirementsList(); + public abstract function getTitle(); + public function calculate(Product $product, $untaxedPrice) { return $untaxedPrice * $this->pricePercentRetriever() + $this->fixAmountRetriever($product); diff --git a/core/lib/Thelia/TaxEngine/TaxType/FeatureFixAmountTaxType.php b/core/lib/Thelia/TaxEngine/TaxType/FeatureFixAmountTaxType.php index 32c78c1ac..e623528c2 100755 --- a/core/lib/Thelia/TaxEngine/TaxType/FeatureFixAmountTaxType.php +++ b/core/lib/Thelia/TaxEngine/TaxType/FeatureFixAmountTaxType.php @@ -65,4 +65,9 @@ class FeatureFixAmountTaxType extends BaseTaxType 'feature' => new ModelValidIdType('Feature'), ); } + + public function getTitle() + { + return "Fix amount Tax depending on a feature"; + } } diff --git a/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php b/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php index 311a83272..f1e95c5c7 100755 --- a/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php +++ b/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php @@ -49,4 +49,9 @@ class featureSlicePercentTaxType extends BaseTaxType 'slices' => new FloatToFloatArrayType(), ); } + + public function getTitle() + { + return "% slice Tax depending on a feature"; + } } diff --git a/core/lib/Thelia/TaxEngine/TaxType/FixAmountTaxType.php b/core/lib/Thelia/TaxEngine/TaxType/FixAmountTaxType.php index e62136d99..c93715571 100755 --- a/core/lib/Thelia/TaxEngine/TaxType/FixAmountTaxType.php +++ b/core/lib/Thelia/TaxEngine/TaxType/FixAmountTaxType.php @@ -47,4 +47,9 @@ class FixAmountTaxType extends BaseTaxType 'amount' => new FloatType(), ); } + + public function getTitle() + { + return "Fix amount Tax"; + } } diff --git a/core/lib/Thelia/TaxEngine/TaxType/PricePercentTaxType.php b/core/lib/Thelia/TaxEngine/TaxType/PricePercentTaxType.php index 342f51a6d..6881b0288 100755 --- a/core/lib/Thelia/TaxEngine/TaxType/PricePercentTaxType.php +++ b/core/lib/Thelia/TaxEngine/TaxType/PricePercentTaxType.php @@ -47,6 +47,9 @@ class PricePercentTaxType extends BaseTaxType 'percent' => new FloatType(), ); } -} -//600 / (1 + 0,10 + 0,10) =/= 600 / (1 + 0,10 ) + 600 / (1 + 0,10 ) \ No newline at end of file + public function getTitle() + { + return "Price % Tax"; + } +} diff --git a/templates/admin/default/tax-edit.html b/templates/admin/default/tax-edit.html new file mode 100644 index 000000000..435ace42b --- /dev/null +++ b/templates/admin/default/tax-edit.html @@ -0,0 +1,130 @@ +{extends file="admin-layout.tpl"} + +{block name="page-title"}{intl l='Edit a tax'}{/block} + +{block name="check-permissions"}admin.configuration.taxes.edit{/block} + +{block name="main-content"} + +
+ +
+ + + + {loop type="tax" name="tax" id=$tax_id backend_context="1" lang=$edit_language_id} + +
+
+ +
+ + {form name="thelia.admin.tax.modification"} + + + + {include + file = "includes/inner-form-toolbar.html" + hide_submit_buttons = false + + page_url = {url path="/admin/configuration/taxes/update/$tax_id"} + close_url = {url path="/admin/configuration/taxes_rules"} + } + + {* Be sure to get the product ID, even if the form could not be validated *} + + + {form_hidden_fields form=$form} + + {form_field form=$form field='success_url'} + + {/form_field} + + {form_field form=$form field='locale'} + + {/form_field} + + {if $form_error}
{$form_error_message}
{/if} + + {form_field form=$form field='title'} +
+ + +
+ {/form_field} + + {form_field form=$form field='description'} +
+ + + +
+ {/form_field} + + {form_field form=$form field='type'} +
+ + +
+ +
+
+ {/form_field} + +
+
+
+ +
+

{intl l='Tax created on %date_create. Last modification: %date_change' date_create={format_date date=$CREATE_DATE} date_change={format_date date=$UPDATE_DATE}}

+
+
+
+
+ + + {/form} +
+ +
+
+ + {/loop} + +
+ +{/block} + +{block name="javascript-initialization"} + + {javascripts file='assets/js/bootstrap-select/bootstrap-select.js'} + + {/javascripts} + + {javascripts file='assets/js/main.js'} + + {/javascripts} + + + + + +{/block} \ No newline at end of file diff --git a/templates/admin/default/taxes-rules.html b/templates/admin/default/taxes-rules.html index 67e8b414a..73eb35b40 100644 --- a/templates/admin/default/taxes-rules.html +++ b/templates/admin/default/taxes-rules.html @@ -21,6 +21,72 @@
+ +
+

{intl l="In order to manges your shop taxes you can manage"} {intl l="taxes"} {intl l="and"} {intl l="tax rules"}.

+

{intl l="Taxes define the amount of money which is add to a bought product."}

+

+ {intl l="Example :"} +

    +
  • {intl l="French 19.6% VAT is a tax which add a 19.6% tax to the product price."}
  • +
  • {intl l="Ecotax is a tax wich add a defined amount (throug a product feature) to the product price."}
  • +
+

+

{intl l="Tax rules are combination of different taxes."}

+

+ {intl l="Example :"} +

    +
  • {intl l="French 19.6% VAT with ecotax is the applicance of the ecotax (on the product price) then the applicance of the 19.6% tax (on the product price + the ecotax amount)."}
  • +
+

+

{intl l="you can combine taxes in tax rules and chose if they are applied one after the other or at the same time : it allows to apply taxes on an already taxed price or not."}

+
+ +
+
+ + + + + + + + + + + + {loop type="tax" name="taxes" backend_context="1"} + + + + + + + + {/loop} + + +
+ {intl l="Taxes"} + {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.taxes.create"} + + + + {/loop} +
{intl l="Name"}{intl l="Description"}{intl l="Actions"}
{$TITLE}{$DESCRIPTION} +
+ {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.taxes.change"} + + {/loop} + + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.taxes.change"} + + {/loop} +
+
+
+
+
@@ -41,7 +107,7 @@ - {loop type="tax-rule" name="taxes-rules"} + {loop type="tax-rule" name="taxes-rules" backend_context="1"} @@ -61,10 +127,10 @@ {/loop} - +
{$TITLE}
-
+
@@ -73,8 +139,8 @@
-{* -- Add tax rule confirmation dialog ----------------------------------- *} -{form name="thelia.admin.taxrule.add"} +{* -- Add tax confirmation dialog ----------------------------------- *} +{form name="thelia.admin.tax.add"} {if $form_error_message} {$taxCreateError = true} @@ -82,6 +148,99 @@ {$taxCreateError = false} {/if} +{* Capture the dialog body, to pass it to the generic dialog *} +{capture "tax_create_dialog"} + + {form_hidden_fields form=$form} + + {form_field form=$form field='locale'} + + {/form_field} + + {if $form_error}
{$form_error_message}
{/if} + + {form_field form=$form field='title'} +
+ + +
+ {/form_field} + + {form_field form=$form field='description'} +
+ + + +
+ {/form_field} + + {form_field form=$form field='type'} +
+ + +
+ +
+
+ {/form_field} + +{/capture} + + {include + file = "includes/generic-create-dialog.html" + + dialog_id = "tax_create_dialog" + dialog_title = {intl l="Create a new tax"} + dialog_body = {$smarty.capture.tax_create_dialog nofilter} + + dialog_ok_label = {intl l="Create"} + dialog_cancel_label = {intl l="Cancel"} + + form_action = {url path="/admin/configuration/taxes/add"} + form_enctype = {form_enctype form=$form} + form_error_message = $form_error_message + } + +{/form} + +{* -- Delete tax confirmation dialog ----------------------------------- *} + +{capture "tax_delete_dialog"} + + + {module_include location='tax_delete_form'} + +{/capture} + +{include + file = "includes/generic-confirm-dialog.html" + + dialog_id = "tax_delete_dialog" + dialog_title = {intl l="Delete tax"} + dialog_message = {intl l="Do you really want to delete this tax ?"} + + form_action = {url path='/admin/configuration/taxes/delete'} + form_content = {$smarty.capture.tax_delete_dialog nofilter} +} + +{* -- Add tax rule confirmation dialog ----------------------------------- *} +{form name="thelia.admin.taxrule.add"} + +{if $form_error_message} + {$taxRuleCreateError = true} +{else} + {$taxRuleCreateError = false} +{/if} + {* Capture the dialog body, to pass it to the generic dialog *} {capture "tax_rule_create_dialog"} @@ -154,15 +313,31 @@ {block name="javascript-initialization"} +{javascripts file='assets/js/bootstrap-select/bootstrap-select.js'} + +{/javascripts} + +{javascripts file='assets/js/main.js'} + +{/javascripts} + {/block} \ No newline at end of file From b3c761798b1c29e8549f2ce1ea65b86504bc9637 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 16 Oct 2013 11:45:18 +0200 Subject: [PATCH 03/12] fix menu when child > 0 --- .../Core/Template/Loop/CategoryTree.php | 12 ++++--- templates/default/category.html | 2 -- templates/default/includes/menu.html | 31 ++++++++++--------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Loop/CategoryTree.php b/core/lib/Thelia/Core/Template/Loop/CategoryTree.php index 009e2204f..b7c262649 100755 --- a/core/lib/Thelia/Core/Template/Loop/CategoryTree.php +++ b/core/lib/Thelia/Core/Template/Loop/CategoryTree.php @@ -84,10 +84,14 @@ class CategoryTree extends BaseI18nLoop $loopResultRow = new LoopResultRow(); $loopResultRow - ->set("ID", $result->getId())->set("TITLE", $result->getVirtualColumn('i18n_TITLE')) - ->set("PARENT", $result->getParent())->set("URL", $result->getUrl($locale)) - ->set("VISIBLE", $result->getVisible() ? "1" : "0")->set("LEVEL", $level) - ->set('CHILD_COUNT', $result->countChild())->set('PREV_LEVEL', $previousLevel) + ->set("ID", $result->getId()) + ->set("TITLE", $result->getVirtualColumn('i18n_TITLE')) + ->set("PARENT", $result->getParent()) + ->set("URL", $result->getUrl($locale)) + ->set("VISIBLE", $result->getVisible() ? "1" : "0") + ->set("LEVEL", $level) + ->set('CHILD_COUNT', $result->countChild()) + ->set('PREV_LEVEL', $previousLevel) ; $loopResult->addRow($loopResultRow); diff --git a/templates/default/category.html b/templates/default/category.html index 99db32948..419207426 100644 --- a/templates/default/category.html +++ b/templates/default/category.html @@ -46,6 +46,4 @@ - - {/block} diff --git a/templates/default/includes/menu.html b/templates/default/includes/menu.html index 083c74ef2..476e3ecd0 100644 --- a/templates/default/includes/menu.html +++ b/templates/default/includes/menu.html @@ -3,25 +3,28 @@
- \ No newline at end of file + From 9365e9ee3888ca86195378fcee8f6dab506e12ec Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Wed, 16 Oct 2013 11:46:30 +0200 Subject: [PATCH 04/12] tax management --- core/lib/Thelia/Core/Form/Type/TheliaType.php | 45 ++++++ .../Thelia/Core/Template/Element/BaseLoop.php | 2 +- .../Core/Template/Smarty/Plugins/Form.php | 135 ++++++++++++++++-- .../Template/Smarty/Plugins/TheliaLoop.php | 2 +- core/lib/Thelia/Form/TaxCreationForm.php | 23 +++ .../TaxType/FeatureSlicePercentTaxType.php | 2 +- .../Thelia/Type/AlphaNumStringListType.php | 10 ++ core/lib/Thelia/Type/AlphaNumStringType.php | 10 ++ core/lib/Thelia/Type/AnyType.php | 10 ++ core/lib/Thelia/Type/BooleanOrBothType.php | 10 ++ core/lib/Thelia/Type/BooleanType.php | 10 ++ core/lib/Thelia/Type/EnumListType.php | 10 ++ core/lib/Thelia/Type/EnumType.php | 10 ++ .../lib/Thelia/Type/FloatToFloatArrayType.php | 10 ++ core/lib/Thelia/Type/FloatType.php | 10 ++ core/lib/Thelia/Type/IntListType.php | 10 ++ .../Thelia/Type/IntToCombinedIntsListType.php | 10 ++ .../Type/IntToCombinedStringsListType.php | 10 ++ core/lib/Thelia/Type/IntType.php | 10 ++ core/lib/Thelia/Type/JsonType.php | 10 ++ core/lib/Thelia/Type/ModelType.php | 10 ++ core/lib/Thelia/Type/ModelValidIdType.php | 19 +++ core/lib/Thelia/Type/TypeInterface.php | 3 + templates/admin/default/tax-edit.html | 24 +++- 24 files changed, 393 insertions(+), 12 deletions(-) create mode 100644 core/lib/Thelia/Core/Form/Type/TheliaType.php diff --git a/core/lib/Thelia/Core/Form/Type/TheliaType.php b/core/lib/Thelia/Core/Form/Type/TheliaType.php new file mode 100644 index 000000000..4820f9b3b --- /dev/null +++ b/core/lib/Thelia/Core/Form/Type/TheliaType.php @@ -0,0 +1,45 @@ +setDefaults(array( + 'instance' => false, + 'type' => false, + 'options' => false, + )); + + $resolver->setAllowedTypes(array( + 'instance' => array('Thelia\Type\TypeInterface'), + )); + } + + /** + * {@inheritdoc} + */ + public function buildView(FormView $view, FormInterface $form, array $options) + { + $view->vars = array_replace($view->vars, array( + 'instance' => $options['instance'], + 'type' => $options['type'], + 'options' => $options['options'], + )); + } + + public function getParent() + { + return 'form'; + } + + public function getName() + { + return 'thelia_type'; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Element/BaseLoop.php b/core/lib/Thelia/Core/Template/Element/BaseLoop.php index 5ac23142d..7e803c43a 100755 --- a/core/lib/Thelia/Core/Template/Element/BaseLoop.php +++ b/core/lib/Thelia/Core/Template/Element/BaseLoop.php @@ -254,7 +254,7 @@ abstract class BaseLoop * * @param $pagination * - * @return mixed + * @return LoopResult */ abstract public function exec(&$pagination); diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php index 37be09824..7897b74a0 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -22,7 +22,11 @@ /*************************************************************************************/ namespace Thelia\Core\Template\Smarty\Plugins; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\Form\Extension\Core\Type\CollectionType; +use Symfony\Component\Form\Extension\Core\View\ChoiceView; use Symfony\Component\Form\FormView; +use Thelia\Core\Form\Type\TheliaType; use Thelia\Form\BaseForm; use Thelia\Core\Template\Element\Exception\ElementNotFoundException; use Symfony\Component\HttpFoundation\Request; @@ -56,6 +60,8 @@ use Thelia\Core\Template\ParserContext; */ class Form extends AbstractSmartyPlugin { + static private $taggedFieldsStack = null; + static private $taggedFieldsStackPosition = null; protected $request; protected $parserContext; @@ -118,11 +124,16 @@ class Form extends AbstractSmartyPlugin $template->assign("value", $fieldValue); + $template->assign("options", $formFieldView->vars); + // If Checkbox input type if ($fieldVars['checked'] !== null) { $this->renderFormFieldCheckBox($template, $formFieldView['checked']); } + //data + $template->assign("data", $fieldVars['data']); + $template->assign("label", $fieldVars["label"]); $template->assign("label_attr", $fieldVars["label_attr"]); @@ -143,18 +154,51 @@ class Form extends AbstractSmartyPlugin $template->assign("attr", implode(" ", $attr)); } + protected function assignFormTypeValues($template, $formFieldConfig, $formFieldView) + { + $formFieldType = $formFieldConfig->getType()->getInnerType(); + + /* access to choices */ + if($formFieldType instanceof ChoiceType) { + $template->assign("choices", $formFieldView->vars['choices']); + } + + /* access to collections */ + if($formFieldType instanceof CollectionType) { + if( true === $formFieldConfig->getOption('prototype') ) { + + } else { + + } + } + + /* access to thelia type */ + if($formFieldType instanceof TheliaType) { + $template->assign("formType", $formFieldView->vars['type']); + + switch($formFieldView->vars['type']) { + case "choice": + if(!isset($formFieldView->vars['options']['choices']) || !is_array($formFieldView->vars['options']['choices'])) { + //throw new + } + $choices = array(); + foreach($formFieldView->vars['options']['choices'] as $value => $choice) { + $choices[] = new ChoiceView($value, $value, $choice); + } + $template->assign("choices", $choices); + break; + } + } + } + public function renderFormField($params, $content, \Smarty_Internal_Template $template, &$repeat) { - if ($repeat) { + if ($repeat) { - $formFieldView = $this->getFormFieldView($params); + $formFieldView = $this->getFormFieldView($params); + $formFieldConfig = $this->getFormFieldConfig($params); - $template->assign("options", $formFieldView->vars); - - /* access to choices */ - if(isset($formFieldView->vars['choices'])) { - $template->assign("choices", $formFieldView->vars['choices']); - } + $this->assignFormTypeValues($template, $formFieldConfig, $formFieldView); $value = $formFieldView->vars["value"]; /* FIXME: doesnt work. We got "This form should not contain extra fields." error. @@ -185,6 +229,38 @@ $this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVar } } + public function renderTaggedFormFields($params, $content, \Smarty_Internal_Template $template, &$repeat) + { + if(null === $content) { + self::$taggedFieldsStack = $this->getFormFieldsFromTag($params); + self::$taggedFieldsStackPosition = 0; + } else { + self::$taggedFieldsStackPosition++; + } + + if(isset(self::$taggedFieldsStack[self::$taggedFieldsStackPosition])) { + $this->assignFieldValues( + $template, + self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['view']->vars["full_name"], + self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['view']->vars["value"], + self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['view']->vars + ); + + $this->assignFormTypeValues($template, self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['config'], self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['view']); + + self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['view']->setRendered(); + + $repeat = true; + } + + if (! $repeat) { + self::$taggedFieldsStack = null; + self::$taggedFieldsStackPosition = null; + } + + return $content; + } + public function renderHiddenFormField($params, \Smarty_Internal_Template $template) { $attrFormat = '%s="%s"'; @@ -266,6 +342,48 @@ $this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVar return $instance->getView()[$fieldName]; } + protected function getFormFieldsFromTag($params) + { + $instance = $this->getInstanceFromParams($params); + + $tag = $this->getParam($params, 'tag'); + + if (null == $tag) + throw new \InvalidArgumentException("'tag' parameter is missing"); + + $viewList = array(); + foreach($instance->getView() as $view) { + if(isset($view->vars['attr']['tag']) && $tag == $view->vars['attr']['tag']) { + $fieldData = $instance->getForm()->all()[$view->vars['name']]; + $viewList[] = array( + 'view' => $view, + 'config' => $fieldData->getConfig(), + ); + } + } + + return $viewList; + } + + protected function getFormFieldConfig($params) + { + $instance = $this->getInstanceFromParams($params); + + $fieldName = $this->getParam($params, 'field'); + + if (null == $fieldName) { + throw new \InvalidArgumentException("'field' parameter is missing"); + } + + $fieldData = $instance->getForm()->all()[$fieldName]; + + if (empty( $fieldData )) { + throw new \InvalidArgumentException(sprintf("Field name '%s' not found in form %s children", $fieldName, $instance->getName())); + } + + return $fieldData->getConfig(); + } + protected function getInstanceFromParams($params) { $instance = $this->getParam($params, 'form'); @@ -304,6 +422,7 @@ $this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVar return array( new SmartyPluginDescriptor("block", "form", $this, "generateForm"), new SmartyPluginDescriptor("block", "form_field", $this, "renderFormField"), + new SmartyPluginDescriptor("block", "form_tagged_fields", $this, "renderTaggedFormFields"), new SmartyPluginDescriptor("function", "form_hidden_fields", $this, "renderHiddenFormField"), new SmartyPluginDescriptor("function", "form_enctype", $this, "formEnctype"), new SmartyPluginDescriptor("block", "form_error", $this, "formError") diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php index a076c808a..f7b6fc559 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php @@ -300,7 +300,7 @@ class TheliaLoop extends AbstractSmartyPlugin /** * @param $smartyParams * - * @return object + * @return BaseLoop * @throws \Thelia\Core\Template\Element\Exception\InvalidElementException * @throws \Thelia\Core\Template\Element\Exception\ElementNotFoundException */ diff --git a/core/lib/Thelia/Form/TaxCreationForm.php b/core/lib/Thelia/Form/TaxCreationForm.php index 31b0834d4..302e55890 100644 --- a/core/lib/Thelia/Form/TaxCreationForm.php +++ b/core/lib/Thelia/Form/TaxCreationForm.php @@ -24,6 +24,7 @@ namespace Thelia\Form; use Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraints\NotBlank; +use Thelia\Core\Form\Type\TheliaType; use Thelia\Core\Translation\Translator; use Thelia\TaxEngine\TaxEngine; use Thelia\TaxEngine\TaxType; @@ -36,10 +37,12 @@ class TaxCreationForm extends BaseForm { $types = TaxEngine::getInstance()->getTaxTypeList(); $typeList = array(); + $requirementList = array(); foreach($types as $type) { $classPath = "\\Thelia\\TaxEngine\\TaxType\\$type"; $instance = new $classPath(); $typeList[$type] = $instance->getTitle(); + $requirementList[$type] = $instance->getRequirementsList(); } $this->formBuilder @@ -57,6 +60,26 @@ class TaxCreationForm extends BaseForm )) ; + foreach($requirementList as $type => $requirements) { + foreach($requirements as $name => $requirementType) { + $this->formBuilder + ->add($type . '_' . $name, new TheliaType(), array( + "instance" => $requirementType, + "constraints" => array(new NotBlank()), + "attr" => array( + "tag" => "requirements", + ), + "data" => array( + "tax_type" => $type, + ), + "label" => Translator::getInstance()->trans($name), + "type" => $requirementType->getFormType(), + "options" => $requirementType->getFormOptions(), + )) + ; + } + } + $this->addStandardDescFields(array('postscriptum', 'chapo', 'locale')); } diff --git a/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php b/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php index f1e95c5c7..8ec254843 100755 --- a/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php +++ b/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php @@ -45,7 +45,7 @@ class featureSlicePercentTaxType extends BaseTaxType public function getRequirementsList() { return array( - 'featureId' => new ModelValidIdType('Currency'), + 'featureId' => new ModelValidIdType('Feature'), 'slices' => new FloatToFloatArrayType(), ); } diff --git a/core/lib/Thelia/Type/AlphaNumStringListType.php b/core/lib/Thelia/Type/AlphaNumStringListType.php index d8e53cd95..9205373ca 100755 --- a/core/lib/Thelia/Type/AlphaNumStringListType.php +++ b/core/lib/Thelia/Type/AlphaNumStringListType.php @@ -50,4 +50,14 @@ class AlphaNumStringListType implements TypeInterface { return $this->isValid($values) ? explode(',', $values) : null; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/AlphaNumStringType.php b/core/lib/Thelia/Type/AlphaNumStringType.php index 726e6eb67..f574300cb 100755 --- a/core/lib/Thelia/Type/AlphaNumStringType.php +++ b/core/lib/Thelia/Type/AlphaNumStringType.php @@ -44,4 +44,14 @@ class AlphaNumStringType implements TypeInterface { return $this->isValid($value) ? $value : null; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/AnyType.php b/core/lib/Thelia/Type/AnyType.php index 5cdbb1272..bf5349546 100755 --- a/core/lib/Thelia/Type/AnyType.php +++ b/core/lib/Thelia/Type/AnyType.php @@ -44,4 +44,14 @@ class AnyType implements TypeInterface { return $value; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/BooleanOrBothType.php b/core/lib/Thelia/Type/BooleanOrBothType.php index 210201e26..eacd89ffc 100755 --- a/core/lib/Thelia/Type/BooleanOrBothType.php +++ b/core/lib/Thelia/Type/BooleanOrBothType.php @@ -49,4 +49,14 @@ class BooleanOrBothType implements TypeInterface if ($value === self::ANY) return $value; return $value === null ? null : filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/BooleanType.php b/core/lib/Thelia/Type/BooleanType.php index 69cba66ac..e231ce26a 100755 --- a/core/lib/Thelia/Type/BooleanType.php +++ b/core/lib/Thelia/Type/BooleanType.php @@ -44,4 +44,14 @@ class BooleanType implements TypeInterface { return $value === null ? null : filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/EnumListType.php b/core/lib/Thelia/Type/EnumListType.php index 2c37929a8..0d82e3a3e 100755 --- a/core/lib/Thelia/Type/EnumListType.php +++ b/core/lib/Thelia/Type/EnumListType.php @@ -69,4 +69,14 @@ class EnumListType implements TypeInterface { return in_array($value, $this->values); } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/EnumType.php b/core/lib/Thelia/Type/EnumType.php index 416f9714a..91f45a308 100755 --- a/core/lib/Thelia/Type/EnumType.php +++ b/core/lib/Thelia/Type/EnumType.php @@ -52,4 +52,14 @@ class EnumType implements TypeInterface { return $this->isValid($value) ? $value : null; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/FloatToFloatArrayType.php b/core/lib/Thelia/Type/FloatToFloatArrayType.php index 682ddebdd..404b7e4e4 100755 --- a/core/lib/Thelia/Type/FloatToFloatArrayType.php +++ b/core/lib/Thelia/Type/FloatToFloatArrayType.php @@ -54,4 +54,14 @@ class FloatToFloatArrayType implements TypeInterface { return $this->isValid($value) ? $value : null; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/FloatType.php b/core/lib/Thelia/Type/FloatType.php index f82f34b58..74d71adfb 100755 --- a/core/lib/Thelia/Type/FloatType.php +++ b/core/lib/Thelia/Type/FloatType.php @@ -44,4 +44,14 @@ class FloatType implements TypeInterface { return $this->isValid($value) ? $value : null; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/IntListType.php b/core/lib/Thelia/Type/IntListType.php index 28590472e..ff87bbd4e 100755 --- a/core/lib/Thelia/Type/IntListType.php +++ b/core/lib/Thelia/Type/IntListType.php @@ -50,4 +50,14 @@ class IntListType implements TypeInterface { return $this->isValid($values) ? explode(',', $values) : null; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/IntToCombinedIntsListType.php b/core/lib/Thelia/Type/IntToCombinedIntsListType.php index b2dc6b068..dfa21310d 100755 --- a/core/lib/Thelia/Type/IntToCombinedIntsListType.php +++ b/core/lib/Thelia/Type/IntToCombinedIntsListType.php @@ -124,4 +124,14 @@ class IntToCombinedIntsListType implements TypeInterface return true; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/IntToCombinedStringsListType.php b/core/lib/Thelia/Type/IntToCombinedStringsListType.php index 5863feb97..38152fdaa 100755 --- a/core/lib/Thelia/Type/IntToCombinedStringsListType.php +++ b/core/lib/Thelia/Type/IntToCombinedStringsListType.php @@ -124,4 +124,14 @@ class IntToCombinedStringsListType implements TypeInterface return true; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/IntType.php b/core/lib/Thelia/Type/IntType.php index 8e2ec4fd8..7a06a50fb 100755 --- a/core/lib/Thelia/Type/IntType.php +++ b/core/lib/Thelia/Type/IntType.php @@ -44,4 +44,14 @@ class IntType implements TypeInterface { return $this->isValid($value) ? $value : null; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/JsonType.php b/core/lib/Thelia/Type/JsonType.php index 5c92182a8..a1a1f5af6 100755 --- a/core/lib/Thelia/Type/JsonType.php +++ b/core/lib/Thelia/Type/JsonType.php @@ -46,4 +46,14 @@ class JsonType implements TypeInterface { return $this->isValid($value) ? json_decode($value, true) : null; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/ModelType.php b/core/lib/Thelia/Type/ModelType.php index 9eacef094..dadd47308 100755 --- a/core/lib/Thelia/Type/ModelType.php +++ b/core/lib/Thelia/Type/ModelType.php @@ -63,4 +63,14 @@ class ModelType implements TypeInterface { return $this->isValid($value) ? $value : null; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/ModelValidIdType.php b/core/lib/Thelia/Type/ModelValidIdType.php index 9ae94e497..16a39359e 100755 --- a/core/lib/Thelia/Type/ModelValidIdType.php +++ b/core/lib/Thelia/Type/ModelValidIdType.php @@ -67,4 +67,23 @@ class ModelValidIdType implements TypeInterface return $this->isValid($value) ? $queryClass::create()->findPk($value) : null; } + + public function getFormType() + { + return 'choice'; + } + + public function getFormOptions() + { + $queryClass = $this->expectedModelActiveRecordQuery; + + $choices = array(); + foreach($queryClass::create()->find() as $item) { + $choices[$item->getId()] = method_exists($item, "getTitle") ? $item->getTitle() : $item->getId(); + } + + return array( + "choices" => $choices, + ); + } } diff --git a/core/lib/Thelia/Type/TypeInterface.php b/core/lib/Thelia/Type/TypeInterface.php index b293b1783..642c6d935 100755 --- a/core/lib/Thelia/Type/TypeInterface.php +++ b/core/lib/Thelia/Type/TypeInterface.php @@ -35,4 +35,7 @@ interface TypeInterface public function isValid($value); public function getFormattedValue($value); + + public function getFormType(); + public function getFormOptions(); } diff --git a/templates/admin/default/tax-edit.html b/templates/admin/default/tax-edit.html index 435ace42b..173246d76 100644 --- a/templates/admin/default/tax-edit.html +++ b/templates/admin/default/tax-edit.html @@ -76,7 +76,7 @@
- {foreach $choices as $choice} {/foreach} @@ -85,6 +85,24 @@
{/form_field} + {form_tagged_fields form=$form tag='requirements'} +
+ + {if $formType == 'choice'} + + {/if} + {if $formType == 'text'} + + {/if} +
+ {/form_tagged_fields} +
@@ -123,6 +141,10 @@ From c6dbb76ebbfc0a59b0383d696488b302d4ff4044 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Wed, 16 Oct 2013 12:02:59 +0200 Subject: [PATCH 05/12] thelia type constraints --- core/lib/Thelia/Form/TaxCreationForm.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/lib/Thelia/Form/TaxCreationForm.php b/core/lib/Thelia/Form/TaxCreationForm.php index 302e55890..5448d3367 100644 --- a/core/lib/Thelia/Form/TaxCreationForm.php +++ b/core/lib/Thelia/Form/TaxCreationForm.php @@ -65,7 +65,11 @@ class TaxCreationForm extends BaseForm $this->formBuilder ->add($type . '_' . $name, new TheliaType(), array( "instance" => $requirementType, - "constraints" => array(new NotBlank()), + "constraints" => array( + "methods" => array( + array($this, "verifyTaxId"), + ), + ), "attr" => array( "tag" => "requirements", ), From 60fd54d5c3ff5b5555f876a3666a818741b32e5b Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Wed, 16 Oct 2013 16:20:21 +0200 Subject: [PATCH 06/12] restart thelia form type --- .../Admin/AbstractCrudController.php | 2 ++ .../Thelia/Controller/Admin/TaxController.php | 12 ++++++++++ core/lib/Thelia/Core/Form/Type/TheliaType.php | 10 +++++--- core/lib/Thelia/Core/Template/Loop/Tax.php | 4 +++- core/lib/Thelia/Form/TaxCreationForm.php | 23 +++++++++++++++++-- templates/admin/default/tax-edit.html | 4 ++-- 6 files changed, 47 insertions(+), 8 deletions(-) diff --git a/core/lib/Thelia/Controller/Admin/AbstractCrudController.php b/core/lib/Thelia/Controller/Admin/AbstractCrudController.php index 170c35c4f..a1be6a15d 100644 --- a/core/lib/Thelia/Controller/Admin/AbstractCrudController.php +++ b/core/lib/Thelia/Controller/Admin/AbstractCrudController.php @@ -392,6 +392,8 @@ abstract class AbstractCrudController extends BaseAdminController // Get the form field values $data = $form->getData(); + $dataType = $form->all(); + $changeEvent = $this->getUpdateEvent($data); $this->dispatch($this->updateEventIdentifier, $changeEvent); diff --git a/core/lib/Thelia/Controller/Admin/TaxController.php b/core/lib/Thelia/Controller/Admin/TaxController.php index 0c83aa4cb..bbaf075cb 100644 --- a/core/lib/Thelia/Controller/Admin/TaxController.php +++ b/core/lib/Thelia/Controller/Admin/TaxController.php @@ -76,6 +76,11 @@ class TaxController extends AbstractCrudController { $event = new TaxEvent(); + /* check the requirements */ + if(!$this->checkRequirements($formData)) { + + } + $event->setLocale($formData['locale']); $event->setId($formData['id']); $event->setTitle($formData['title']); @@ -195,4 +200,11 @@ class TaxController extends AbstractCrudController "admin.configuration.taxes-rules.list" ); } + + protected function checkRequirements($formData) + { + $type = $formData['type']; + + + } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/Form/Type/TheliaType.php b/core/lib/Thelia/Core/Form/Type/TheliaType.php index 4820f9b3b..19524ec85 100644 --- a/core/lib/Thelia/Core/Form/Type/TheliaType.php +++ b/core/lib/Thelia/Core/Form/Type/TheliaType.php @@ -12,12 +12,16 @@ class TheliaType extends AbstractType { $resolver->setDefaults(array( 'instance' => false, - 'type' => false, - 'options' => false, + 'type' => false, + 'options' => false, )); $resolver->setAllowedTypes(array( - 'instance' => array('Thelia\Type\TypeInterface'), + 'instance' => array('Thelia\Type\TypeInterface'), + )); + + $resolver->setAllowedValues(array( + 'type' => array('text', 'choice'), )); } diff --git a/core/lib/Thelia/Core/Template/Loop/Tax.php b/core/lib/Thelia/Core/Template/Loop/Tax.php index 0248e60d8..a927a0dbd 100644 --- a/core/lib/Thelia/Core/Template/Loop/Tax.php +++ b/core/lib/Thelia/Core/Template/Loop/Tax.php @@ -151,10 +151,12 @@ class Tax extends BaseI18nLoop $loopResultRow = new LoopResultRow($loopResult, $tax, $this->versionable, $this->timestampable, $this->countable); + $requirements = json_decode( base64_decode( $tax->getSerializedRequirements() ), true ); + $loopResultRow ->set("ID" , $tax->getId()) ->set("TYPE" , $tax->getType()) - ->set("SERIALIZED_REQUIREMENTS" , $tax->getSerializedRequirements()) + ->set("REQUIREMENTS" , $requirements) ->set("IS_TRANSLATED" , $tax->getVirtualColumn('IS_TRANSLATED')) ->set("LOCALE" , $locale) ->set("TITLE" , $tax->getVirtualColumn('i18n_TITLE')) diff --git a/core/lib/Thelia/Form/TaxCreationForm.php b/core/lib/Thelia/Form/TaxCreationForm.php index 5448d3367..901c459b3 100644 --- a/core/lib/Thelia/Form/TaxCreationForm.php +++ b/core/lib/Thelia/Form/TaxCreationForm.php @@ -24,6 +24,7 @@ namespace Thelia\Form; use Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraints\NotBlank; +use Symfony\Component\Validator\ExecutionContextInterface; use Thelia\Core\Form\Type\TheliaType; use Thelia\Core\Translation\Translator; use Thelia\TaxEngine\TaxEngine; @@ -54,6 +55,13 @@ class TaxCreationForm extends BaseForm "required" => true, "constraints" => array( new Constraints\NotBlank(), + new Constraints\Callback( + array( + "methods" => array( + array($this, "verifyRequirements"), + ), + ) + ), ), "label" => Translator::getInstance()->trans("Type"), "label_attr" => array("for" => "type_field"), @@ -66,8 +74,12 @@ class TaxCreationForm extends BaseForm ->add($type . '_' . $name, new TheliaType(), array( "instance" => $requirementType, "constraints" => array( - "methods" => array( - array($this, "verifyTaxId"), + new Constraints\Callback( + array( + "methods" => array( + array($this, "verifyRequirements"), + ), + ) ), ), "attr" => array( @@ -91,4 +103,11 @@ class TaxCreationForm extends BaseForm { return "thelia_tax_creation"; } + + public function verifyRequirements($value, ExecutionContextInterface $context) + { + $in = true; + + + } } diff --git a/templates/admin/default/tax-edit.html b/templates/admin/default/tax-edit.html index 173246d76..07a18a111 100644 --- a/templates/admin/default/tax-edit.html +++ b/templates/admin/default/tax-edit.html @@ -93,12 +93,12 @@ {if $formType == 'choice'} {/if} {if $formType == 'text'} - + {/if}
{/form_tagged_fields} From a2048bec240701760e9f6f0e07c083c41cac5c9b Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Wed, 16 Oct 2013 17:10:53 +0200 Subject: [PATCH 07/12] theliatype in form : types now extends bastype which implement typeinterface basetype provides verifiyForm method wich can be call in Callback constraint --- core/lib/Thelia/Core/Form/Type/TheliaType.php | 2 +- .../Core/Template/Smarty/Plugins/Form.php | 1 + core/lib/Thelia/Form/TaxCreationForm.php | 13 ++---- .../Thelia/Type/AlphaNumStringListType.php | 2 +- core/lib/Thelia/Type/AlphaNumStringType.php | 2 +- core/lib/Thelia/Type/AnyType.php | 2 +- core/lib/Thelia/Type/BaseType.php | 46 +++++++++++++++++++ core/lib/Thelia/Type/BooleanOrBothType.php | 2 +- core/lib/Thelia/Type/BooleanType.php | 2 +- core/lib/Thelia/Type/EnumListType.php | 2 +- core/lib/Thelia/Type/EnumType.php | 2 +- .../lib/Thelia/Type/FloatToFloatArrayType.php | 2 +- core/lib/Thelia/Type/FloatType.php | 2 +- core/lib/Thelia/Type/IntListType.php | 2 +- .../Thelia/Type/IntToCombinedIntsListType.php | 2 +- .../Type/IntToCombinedStringsListType.php | 2 +- core/lib/Thelia/Type/IntType.php | 2 +- core/lib/Thelia/Type/JsonType.php | 2 +- core/lib/Thelia/Type/ModelType.php | 2 +- core/lib/Thelia/Type/ModelValidIdType.php | 2 +- core/lib/Thelia/Type/TypeInterface.php | 4 +- templates/admin/default/tax-edit.html | 2 +- 22 files changed, 71 insertions(+), 29 deletions(-) create mode 100644 core/lib/Thelia/Type/BaseType.php diff --git a/core/lib/Thelia/Core/Form/Type/TheliaType.php b/core/lib/Thelia/Core/Form/Type/TheliaType.php index 19524ec85..7aeeab3e0 100644 --- a/core/lib/Thelia/Core/Form/Type/TheliaType.php +++ b/core/lib/Thelia/Core/Form/Type/TheliaType.php @@ -39,7 +39,7 @@ class TheliaType extends AbstractType public function getParent() { - return 'form'; + return 'text'; } public function getName() diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php index 7897b74a0..58fe2bf74 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -152,6 +152,7 @@ class Form extends AbstractSmartyPlugin } $template->assign("attr", implode(" ", $attr)); + $template->assign("attr_list", $fieldVars["attr"]); } protected function assignFormTypeValues($template, $formFieldConfig, $formFieldView) diff --git a/core/lib/Thelia/Form/TaxCreationForm.php b/core/lib/Thelia/Form/TaxCreationForm.php index 901c459b3..ee9ef532d 100644 --- a/core/lib/Thelia/Form/TaxCreationForm.php +++ b/core/lib/Thelia/Form/TaxCreationForm.php @@ -55,13 +55,6 @@ class TaxCreationForm extends BaseForm "required" => true, "constraints" => array( new Constraints\NotBlank(), - new Constraints\Callback( - array( - "methods" => array( - array($this, "verifyRequirements"), - ), - ) - ), ), "label" => Translator::getInstance()->trans("Type"), "label_attr" => array("for" => "type_field"), @@ -77,7 +70,7 @@ class TaxCreationForm extends BaseForm new Constraints\Callback( array( "methods" => array( - array($this, "verifyRequirements"), + array($requirementType, "verifyForm"), ), ) ), @@ -104,10 +97,10 @@ class TaxCreationForm extends BaseForm return "thelia_tax_creation"; } - public function verifyRequirements($value, ExecutionContextInterface $context) + public function verifyForm($value, ExecutionContextInterface $context) { $in = true; - + //$this->getForm()->getChildren() } } diff --git a/core/lib/Thelia/Type/AlphaNumStringListType.php b/core/lib/Thelia/Type/AlphaNumStringListType.php index 9205373ca..ccf21606d 100755 --- a/core/lib/Thelia/Type/AlphaNumStringListType.php +++ b/core/lib/Thelia/Type/AlphaNumStringListType.php @@ -28,7 +28,7 @@ namespace Thelia\Type; * */ -class AlphaNumStringListType implements TypeInterface +class AlphaNumStringListType extends BaseType { public function getType() { diff --git a/core/lib/Thelia/Type/AlphaNumStringType.php b/core/lib/Thelia/Type/AlphaNumStringType.php index f574300cb..ad9595f20 100755 --- a/core/lib/Thelia/Type/AlphaNumStringType.php +++ b/core/lib/Thelia/Type/AlphaNumStringType.php @@ -28,7 +28,7 @@ namespace Thelia\Type; * */ -class AlphaNumStringType implements TypeInterface +class AlphaNumStringType extends BaseType { public function getType() { diff --git a/core/lib/Thelia/Type/AnyType.php b/core/lib/Thelia/Type/AnyType.php index bf5349546..4e844c6e9 100755 --- a/core/lib/Thelia/Type/AnyType.php +++ b/core/lib/Thelia/Type/AnyType.php @@ -28,7 +28,7 @@ namespace Thelia\Type; * */ -class AnyType implements TypeInterface +class AnyType extends BaseType { public function getType() { diff --git a/core/lib/Thelia/Type/BaseType.php b/core/lib/Thelia/Type/BaseType.php new file mode 100644 index 000000000..7ab1a86ec --- /dev/null +++ b/core/lib/Thelia/Type/BaseType.php @@ -0,0 +1,46 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Type; + +use Symfony\Component\Validator\ExecutionContextInterface; + +/** + * + * @author Etienne Roudeix + * + */ +abstract class BaseType implements TypeInterface +{ + abstract public function getType(); + abstract public function isValid($value); + abstract public function getFormattedValue($value); + abstract public function getFormType(); + abstract public function getFormOptions(); + + public function verifyForm($value, ExecutionContextInterface $context) + { + if( ! $this->isValid($value) ) { + $context->addViolation("Thelia Type not matched"); + } + } +} diff --git a/core/lib/Thelia/Type/BooleanOrBothType.php b/core/lib/Thelia/Type/BooleanOrBothType.php index eacd89ffc..25f3d9994 100755 --- a/core/lib/Thelia/Type/BooleanOrBothType.php +++ b/core/lib/Thelia/Type/BooleanOrBothType.php @@ -29,7 +29,7 @@ namespace Thelia\Type; * */ -class BooleanOrBothType implements TypeInterface +class BooleanOrBothType extends BaseType { const ANY = '*'; diff --git a/core/lib/Thelia/Type/BooleanType.php b/core/lib/Thelia/Type/BooleanType.php index e231ce26a..5f36453de 100755 --- a/core/lib/Thelia/Type/BooleanType.php +++ b/core/lib/Thelia/Type/BooleanType.php @@ -28,7 +28,7 @@ namespace Thelia\Type; * */ -class BooleanType implements TypeInterface +class BooleanType extends BaseType { public function getType() { diff --git a/core/lib/Thelia/Type/EnumListType.php b/core/lib/Thelia/Type/EnumListType.php index 0d82e3a3e..5b54c48bf 100755 --- a/core/lib/Thelia/Type/EnumListType.php +++ b/core/lib/Thelia/Type/EnumListType.php @@ -28,7 +28,7 @@ namespace Thelia\Type; * */ -class EnumListType implements TypeInterface +class EnumListType extends BaseType { protected $values = array(); diff --git a/core/lib/Thelia/Type/EnumType.php b/core/lib/Thelia/Type/EnumType.php index 91f45a308..1283acde0 100755 --- a/core/lib/Thelia/Type/EnumType.php +++ b/core/lib/Thelia/Type/EnumType.php @@ -28,7 +28,7 @@ namespace Thelia\Type; * */ -class EnumType implements TypeInterface +class EnumType extends BaseType { protected $values = array(); diff --git a/core/lib/Thelia/Type/FloatToFloatArrayType.php b/core/lib/Thelia/Type/FloatToFloatArrayType.php index 404b7e4e4..f55997f55 100755 --- a/core/lib/Thelia/Type/FloatToFloatArrayType.php +++ b/core/lib/Thelia/Type/FloatToFloatArrayType.php @@ -28,7 +28,7 @@ namespace Thelia\Type; * */ -class FloatToFloatArrayType implements TypeInterface +class FloatToFloatArrayType extends BaseType { public function getType() { diff --git a/core/lib/Thelia/Type/FloatType.php b/core/lib/Thelia/Type/FloatType.php index 74d71adfb..830622a86 100755 --- a/core/lib/Thelia/Type/FloatType.php +++ b/core/lib/Thelia/Type/FloatType.php @@ -28,7 +28,7 @@ namespace Thelia\Type; * */ -class FloatType implements TypeInterface +class FloatType extends BaseType { public function getType() { diff --git a/core/lib/Thelia/Type/IntListType.php b/core/lib/Thelia/Type/IntListType.php index ff87bbd4e..5fe31aa3c 100755 --- a/core/lib/Thelia/Type/IntListType.php +++ b/core/lib/Thelia/Type/IntListType.php @@ -28,7 +28,7 @@ namespace Thelia\Type; * */ -class IntListType implements TypeInterface +class IntListType extends BaseType { public function getType() { diff --git a/core/lib/Thelia/Type/IntToCombinedIntsListType.php b/core/lib/Thelia/Type/IntToCombinedIntsListType.php index dfa21310d..562e160dd 100755 --- a/core/lib/Thelia/Type/IntToCombinedIntsListType.php +++ b/core/lib/Thelia/Type/IntToCombinedIntsListType.php @@ -28,7 +28,7 @@ namespace Thelia\Type; * */ -class IntToCombinedIntsListType implements TypeInterface +class IntToCombinedIntsListType extends BaseType { public function getType() { diff --git a/core/lib/Thelia/Type/IntToCombinedStringsListType.php b/core/lib/Thelia/Type/IntToCombinedStringsListType.php index 38152fdaa..5c4327dc8 100755 --- a/core/lib/Thelia/Type/IntToCombinedStringsListType.php +++ b/core/lib/Thelia/Type/IntToCombinedStringsListType.php @@ -28,7 +28,7 @@ namespace Thelia\Type; * */ -class IntToCombinedStringsListType implements TypeInterface +class IntToCombinedStringsListType extends BaseType { public function getType() { diff --git a/core/lib/Thelia/Type/IntType.php b/core/lib/Thelia/Type/IntType.php index 7a06a50fb..5aa146e60 100755 --- a/core/lib/Thelia/Type/IntType.php +++ b/core/lib/Thelia/Type/IntType.php @@ -28,7 +28,7 @@ namespace Thelia\Type; * */ -class IntType implements TypeInterface +class IntType extends BaseType { public function getType() { diff --git a/core/lib/Thelia/Type/JsonType.php b/core/lib/Thelia/Type/JsonType.php index a1a1f5af6..502a43953 100755 --- a/core/lib/Thelia/Type/JsonType.php +++ b/core/lib/Thelia/Type/JsonType.php @@ -28,7 +28,7 @@ namespace Thelia\Type; * */ -class JsonType implements TypeInterface +class JsonType extends BaseType { public function getType() { diff --git a/core/lib/Thelia/Type/ModelType.php b/core/lib/Thelia/Type/ModelType.php index dadd47308..a8ab8c553 100755 --- a/core/lib/Thelia/Type/ModelType.php +++ b/core/lib/Thelia/Type/ModelType.php @@ -30,7 +30,7 @@ use Thelia\Exception\TypeException; * @author Etienne Roudeix * */ -class ModelType implements TypeInterface +class ModelType extends BaseType { protected $expectedModelActiveRecord = null; diff --git a/core/lib/Thelia/Type/ModelValidIdType.php b/core/lib/Thelia/Type/ModelValidIdType.php index 16a39359e..a9bfec7b5 100755 --- a/core/lib/Thelia/Type/ModelValidIdType.php +++ b/core/lib/Thelia/Type/ModelValidIdType.php @@ -30,7 +30,7 @@ use Thelia\Exception\TypeException; * @author Etienne Roudeix * */ -class ModelValidIdType implements TypeInterface +class ModelValidIdType extends BaseType { protected $expectedModelActiveRecordQuery = null; diff --git a/core/lib/Thelia/Type/TypeInterface.php b/core/lib/Thelia/Type/TypeInterface.php index 642c6d935..99e2f77e0 100755 --- a/core/lib/Thelia/Type/TypeInterface.php +++ b/core/lib/Thelia/Type/TypeInterface.php @@ -22,12 +22,13 @@ /*************************************************************************************/ namespace Thelia\Type; +use Symfony\Component\Validator\ExecutionContextInterface; + /** * * @author Etienne Roudeix * */ - interface TypeInterface { public function getType(); @@ -38,4 +39,5 @@ interface TypeInterface public function getFormType(); public function getFormOptions(); + public function verifyForm($value, ExecutionContextInterface $context); } diff --git a/templates/admin/default/tax-edit.html b/templates/admin/default/tax-edit.html index 07a18a111..2bb0b260e 100644 --- a/templates/admin/default/tax-edit.html +++ b/templates/admin/default/tax-edit.html @@ -88,7 +88,7 @@ {form_tagged_fields form=$form tag='requirements'}
{if $formType == 'choice'} +
{/form_field} @@ -65,7 +65,7 @@ {intl l="The detailed description."} - +
{/form_field} @@ -78,27 +78,29 @@
+ + {$typeValue = $value} {/form_field} {form_tagged_fields form=$form tag='requirements'} -
+
{if $formType == 'choice'} - {foreach $choices as $choice} - + {/foreach} {/if} {if $formType == 'text'} - + {/if}
{/form_tagged_fields} @@ -142,7 +144,10 @@ {/block} \ No newline at end of file From 392d8a35594b60627069bc2547fc226690ab3a76 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 18 Oct 2013 11:24:19 +0200 Subject: [PATCH 10/12] decode url before searching if it's a rewritten url --- core/lib/Thelia/Rewriting/RewritingResolver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/lib/Thelia/Rewriting/RewritingResolver.php b/core/lib/Thelia/Rewriting/RewritingResolver.php index 4c8bcba40..8edd0ebba 100755 --- a/core/lib/Thelia/Rewriting/RewritingResolver.php +++ b/core/lib/Thelia/Rewriting/RewritingResolver.php @@ -59,7 +59,7 @@ class RewritingResolver public function load($rewrittenUrl) { $rewrittenUrl = ltrim($rewrittenUrl, '/'); - + $rewrittenUrl = urldecode($rewrittenUrl); $this->search = $this->rewritingUrlQuery->getResolverSearch($rewrittenUrl); if($this->search->count() == 0) { From b24546a12c7428a3aef1ed884cd7f38f8251e1aa Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 18 Oct 2013 15:45:11 +0200 Subject: [PATCH 11/12] fix product visibility comparaison parameter --- core/lib/Thelia/Core/Template/Loop/Product.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/lib/Thelia/Core/Template/Loop/Product.php b/core/lib/Thelia/Core/Template/Loop/Product.php index f0bb95249..ef47fe3b8 100755 --- a/core/lib/Thelia/Core/Template/Loop/Product.php +++ b/core/lib/Thelia/Core/Template/Loop/Product.php @@ -461,7 +461,7 @@ class Product extends BaseI18nLoop $visible = $this->getVisible(); - if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible ? 1 : 0); + if ($visible !== BooleanOrBothType::ANY) $search->filterByVisible($visible ? 1 : 0); $exclude = $this->getExclude(); From d354ed96add7450d5719de0bb8a6f487f4d8c9cf Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 18 Oct 2013 15:59:49 +0200 Subject: [PATCH 12/12] don't use alternative Logger in debugbar if debug is disabled --- .../modules/TheliaDebugBar/Listeners/DebugBarListeners.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/local/modules/TheliaDebugBar/Listeners/DebugBarListeners.php b/local/modules/TheliaDebugBar/Listeners/DebugBarListeners.php index c7b9d015c..5ea75a1df 100755 --- a/local/modules/TheliaDebugBar/Listeners/DebugBarListeners.php +++ b/local/modules/TheliaDebugBar/Listeners/DebugBarListeners.php @@ -45,13 +45,17 @@ class DebugBarListeners extends BaseAction implements EventSubscriberInterface { { $debugBar = $this->container->get("debugBar"); + $alternativelogger = null; + if($this->container->getParameter('kernel.debug')) { + $alternativelogger = \Thelia\Log\Tlog::getInstance(); + } $debugBar->addCollector(new PhpInfoCollector()); //$debugBar->addCollector(new MessagesCollector()); //$debugBar->addCollector(new RequestDataCollector()); $debugBar->addCollector(new TimeDataCollector()); $debugBar->addCollector(new MemoryCollector()); - $debugBar->addCollector(new PropelCollector(\Thelia\Log\Tlog::getInstance())); + $debugBar->addCollector(new PropelCollector($alternativelogger)); } /**