Merge branch 'master' into module_management
Conflicts: core/lib/Thelia/Core/Template/Loop/TaxRuleCountry.php core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php
This commit is contained in:
104
core/lib/Thelia/Action/Tax.php
Normal file
104
core/lib/Thelia/Action/Tax.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
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())
|
||||
->setRequirements($event->getRequirements())
|
||||
->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())
|
||||
->setRequirements($event->getRequirements())
|
||||
->setType($event->getType())
|
||||
->setLocale($event->getLocale())
|
||||
->setTitle($event->getTitle())
|
||||
->setDescription($event->getDescription())
|
||||
;
|
||||
|
||||
$tax->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),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\Tax\TaxRuleEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Model\Map\TaxRuleTableMap;
|
||||
use Thelia\Model\TaxRuleCountry;
|
||||
use Thelia\Model\TaxRuleCountryQuery;
|
||||
use Thelia\Model\TaxRule as TaxRuleModel;
|
||||
@@ -132,6 +133,23 @@ class TaxRule extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TaxRuleEvent $event
|
||||
*/
|
||||
public function setDefault(TaxRuleEvent $event)
|
||||
{
|
||||
if (null !== $taxRule = TaxRuleQuery::create()->findPk($event->getId())) {
|
||||
|
||||
TaxRuleQuery::create()->update(array(
|
||||
"IsDefault" => 0
|
||||
));
|
||||
|
||||
$taxRule->setIsDefault(1)->save();
|
||||
|
||||
$event->setTaxRule($taxRule);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -142,7 +160,7 @@ class TaxRule extends BaseAction implements EventSubscriberInterface
|
||||
TheliaEvents::TAX_RULE_UPDATE => array("update", 128),
|
||||
TheliaEvents::TAX_RULE_TAXES_UPDATE => array("updateTaxes", 128),
|
||||
TheliaEvents::TAX_RULE_DELETE => array("delete", 128),
|
||||
|
||||
TheliaEvents::TAX_RULE_SET_DEFAULT => array("setDefault", 128),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +111,11 @@
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
|
||||
<service id="thelia.action.tax" class="Thelia\Action\Tax">
|
||||
<argument type="service" id="service_container"/>
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
|
||||
<service id="thelia.action.content" class="Thelia\Action\Content">
|
||||
<argument type="service" id="service_container"/>
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
<form name="thelia.install.step3" class="Thelia\Form\InstallStep3Form"/>
|
||||
|
||||
<form name="thelia.customer.creation" class="Thelia\Form\CustomerCreation"/>
|
||||
<form name="thelia.customer.update" class="Thelia\Form\CustomerUpdateForm"/>
|
||||
<form name="thelia.customer.modification" class="Thelia\Form\CustomerModification"/>
|
||||
<form name="thelia.customer.lostpassword" class="Thelia\Form\CustomerLostPasswordForm"/>
|
||||
|
||||
@@ -118,6 +119,10 @@
|
||||
<form name="thelia.admin.taxrule.taxlistupdate" class="Thelia\Form\TaxRuleTaxListUpdateForm"/>
|
||||
<form name="thelia.admin.taxrule.add" class="Thelia\Form\TaxRuleCreationForm"/>
|
||||
|
||||
<form name="thelia.admin.tax.modification" class="Thelia\Form\TaxModificationForm"/>
|
||||
<form name="thelia.admin.tax.taxlistupdate" class="Thelia\Form\TaxTaxListUpdateForm"/>
|
||||
<form name="thelia.admin.tax.add" class="Thelia\Form\TaxCreationForm"/>
|
||||
|
||||
<form name="thelia.admin.template.creation" class="Thelia\Form\TemplateCreationForm"/>
|
||||
<form name="thelia.admin.template.modification" class="Thelia\Form\TemplateModificationForm"/>
|
||||
|
||||
@@ -125,6 +130,10 @@
|
||||
<form name="thelia.admin.country.modification" class="Thelia\Form\CountryModificationForm"/>
|
||||
|
||||
<form name="thelia.admin.profile.modification" class="Thelia\Form\ProfileModificationForm"/>
|
||||
|
||||
<form name="thelia.admin.language.creation" class="Thelia\Form\LanguageCreationForm"/>
|
||||
|
||||
<form name="thelia.admin.admin-profile.creation" class="Thelia\Form\AdminProfileCreationForm"/>
|
||||
|
||||
<form name="thelia.admin.area.create" class="Thelia\Form\Area\AreaCreateForm"/>
|
||||
<form name="thelia.admin.area.modification" class="Thelia\Form\Area\AreaModificationForm"/>
|
||||
|
||||
@@ -4,22 +4,22 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||
|
||||
<!-- Route to administration base -->
|
||||
<!-- Route to administration base -->
|
||||
<route id="admin" path="/admin">
|
||||
<default key="_controller">Thelia\Controller\Admin\AdminController::indexAction</default>
|
||||
</route>
|
||||
|
||||
<!-- Route to the administration login page -->
|
||||
<!-- Route to the administration login page -->
|
||||
<route id="admin.login" path="/admin/login">
|
||||
<default key="_controller">Thelia\Controller\Admin\SessionController::showLoginAction</default>
|
||||
</route>
|
||||
|
||||
<!-- Route to the administration logout page -->
|
||||
<!-- Route to the administration logout page -->
|
||||
<route id="admin.logout" path="/admin/logout">
|
||||
<default key="_controller">Thelia\Controller\Admin\SessionController::checkLogoutAction</default>
|
||||
</route>
|
||||
|
||||
<!-- Route to the login check controller -->
|
||||
<!-- Route to the login check controller -->
|
||||
<route id="admin.checklogin" path="/admin/checklogin">
|
||||
<default key="_controller">Thelia\Controller\Admin\SessionController::checkLoginAction</default>
|
||||
</route>
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
|
||||
|
||||
<!-- Route to the catalog controller -->
|
||||
<!-- Route to the catalog controller -->
|
||||
|
||||
<route id="admin.catalog" path="/admin/catalog">
|
||||
<default key="_controller">Thelia\Controller\Admin\CategoryController::defaultAction</default>
|
||||
@@ -827,7 +827,28 @@
|
||||
|
||||
<!-- end Modules rule management -->
|
||||
|
||||
<!-- taxe rules management -->
|
||||
<!-- tax management -->
|
||||
|
||||
<route id="admin.configuration.taxes.update" path="/admin/configuration/taxes/update/{tax_id}">
|
||||
<default key="_controller">Thelia\Controller\Admin\TaxController::updateAction</default>
|
||||
<requirement key="tax_id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.taxes.add" path="/admin/configuration/taxes/add">
|
||||
<default key="_controller">Thelia\Controller\Admin\TaxController::createAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.taxes.save" path="/admin/configuration/taxes/save">
|
||||
<default key="_controller">Thelia\Controller\Admin\TaxController::processUpdateAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.taxes.delete" path="/admin/configuration/taxes/delete">
|
||||
<default key="_controller">Thelia\Controller\Admin\TaxController::deleteAction</default>
|
||||
</route>
|
||||
|
||||
<!-- end tax management -->
|
||||
|
||||
<!-- tax rules management -->
|
||||
|
||||
<route id="admin.configuration.taxes-rules.list" path="/admin/configuration/taxes_rules">
|
||||
<default key="_controller">Thelia\Controller\Admin\TaxRuleController::defaultAction</default>
|
||||
@@ -854,10 +875,15 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\TaxRuleController::deleteAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.taxes-rules.set-default" path="/admin/configuration/taxes_rules/update/set_default/{tax_rule_id}">
|
||||
<default key="_controller">Thelia\Controller\Admin\TaxRuleController::setDefaultAction</default>
|
||||
<requirement key="tax_rule_id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<!-- end tax rules management -->
|
||||
|
||||
|
||||
<!-- The default route, to display a template -->
|
||||
<!-- The default route, to display a template -->
|
||||
|
||||
<route id="admin.processTemplate" path="/admin/{template}">
|
||||
<default key="_controller">Thelia\Controller\Admin\AdminController::processTemplateAction</default>
|
||||
|
||||
@@ -4,56 +4,75 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||
|
||||
<route id="home" path="/" >
|
||||
<route id="home" path="/">
|
||||
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
||||
<default key="_view">index</default>
|
||||
</route>
|
||||
|
||||
<!-- Customer routes -->
|
||||
|
||||
<!-- Search routes -->
|
||||
<route id="search" path="/search">
|
||||
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
||||
<default key="_view">search</default>
|
||||
</route>
|
||||
|
||||
<route id="view_all" path="/view_all" methods="get">
|
||||
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
||||
<default key="_view">view_all</default>
|
||||
</route>
|
||||
|
||||
<!-- Customer routes : Register -->
|
||||
<route id="customer.create.process" path="/register" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Front\CustomerController::createAction</default>
|
||||
<default key="_view">register</default>
|
||||
</route>
|
||||
|
||||
<route id="customer.create.view" path="/register">
|
||||
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
||||
<default key="_view">register</default>
|
||||
</route>
|
||||
|
||||
<!-- Customer routes : Login -->
|
||||
<route id="customer.login.process" path="/login" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Front\CustomerController::loginAction</default>
|
||||
<default key="_view">login</default>
|
||||
</route>
|
||||
|
||||
<route id="customer.login.view" path="/login">
|
||||
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
||||
<default key="_view">login</default>
|
||||
</route>
|
||||
|
||||
<!-- Customer routes : Logout -->
|
||||
<route id="customer.logout.process" path="/logout">
|
||||
<default key="_controller">Thelia\Controller\Front\CustomerController::logoutAction</default>
|
||||
</route>
|
||||
|
||||
<route id="customer.account.view" path="/customer/account">
|
||||
<!-- Customer routes : Account -->
|
||||
<route id="customer.account.view" path="/account">
|
||||
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
||||
<default key="_view">account</default>
|
||||
</route>
|
||||
|
||||
<route id="customer.create.process" path="/customer/create" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Front\CustomerController::createAction</default>
|
||||
<default key="_view">register</default>
|
||||
<route id="customer.update.view" path="/account/update" methods="get">
|
||||
<default key="_controller">Thelia\Controller\Front\CustomerController::viewAction</default>
|
||||
<default key="_view">account-update</default>
|
||||
</route>
|
||||
|
||||
|
||||
<route id="customer.update.process" path="/customer/update" methods="post">
|
||||
<route id="customer.update.process" path="/account/update" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Front\CustomerController::updateAction</default>
|
||||
</route>
|
||||
|
||||
<route id="customer.login.process" path="/customer/login" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Front\CustomerController::loginAction</default>
|
||||
<default key="_view">login</default>
|
||||
<default key="_view">account-update</default>
|
||||
</route>
|
||||
|
||||
|
||||
<route id="customer.password.retrieve.view" path="/password" methods="get">
|
||||
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
||||
<default key="_view">password</default>
|
||||
</route>
|
||||
|
||||
<route id="customer.password.retrieve.process" path="/password" methods="post">
|
||||
<route id="customer.password.retrieve.process" path="/account/password" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Front\CustomerController::newPasswordAction</default>
|
||||
<default key="_view">password</default>
|
||||
<default key="_view">account-password</default>
|
||||
</route>
|
||||
|
||||
<route id="customer.password.retrieve.view" path="account/password" methods="get">
|
||||
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
||||
<default key="_view">account-password</default>
|
||||
</route>
|
||||
|
||||
<!-- end customer routes -->
|
||||
|
||||
33
core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php → core/lib/Thelia/Controller/Admin/AdminProfileController.php
Executable file → Normal file
33
core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php → core/lib/Thelia/Controller/Admin/AdminProfileController.php
Executable file → Normal file
@@ -20,33 +20,20 @@
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\TaxEngine\TaxType;
|
||||
|
||||
use Thelia\Type\FloatToFloatArrayType;
|
||||
use Thelia\Type\ModelValidIdType;
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
* Class AdminProfileController
|
||||
* @package Thelia\Controller\Admin
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class featureSlicePercentTaxType extends BaseTaxType
|
||||
class AdminProfileController extends BaseAdminController
|
||||
{
|
||||
public function pricePercentRetriever()
|
||||
public function defaultAction()
|
||||
{
|
||||
|
||||
if (null !== $response = $this->checkAuth("admin.admin-profile.view")) return $response;
|
||||
return $this->render("admin-profiles", array("display_admin_profile" => 20));
|
||||
}
|
||||
|
||||
public function fixAmountRetriever(\Thelia\Model\Product $product)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function getRequirementsList()
|
||||
{
|
||||
return array(
|
||||
'featureId' => new ModelValidIdType('Currency'),
|
||||
'slices' => new FloatToFloatArrayType(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
39
core/lib/Thelia/Controller/Admin/LanguageController.php
Normal file
39
core/lib/Thelia/Controller/Admin/LanguageController.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
/**
|
||||
* Class LanguageController
|
||||
* @package Thelia\Controller\Admin
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class LanguageController extends BaseAdminController
|
||||
{
|
||||
public function defaultAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.languages.view")) return $response;
|
||||
return $this->render("languages");
|
||||
}
|
||||
|
||||
}
|
||||
39
core/lib/Thelia/Controller/Admin/MailingSystemController.php
Normal file
39
core/lib/Thelia/Controller/Admin/MailingSystemController.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
/**
|
||||
* Class MailingSystemController
|
||||
* @package Thelia\Controller\Admin
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class MailingSystemController extends BaseAdminController
|
||||
{
|
||||
public function defaultAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.mailing-system.view")) return $response;
|
||||
return $this->render("mailing-system");
|
||||
}
|
||||
|
||||
}
|
||||
227
core/lib/Thelia/Controller/Admin/TaxController.php
Normal file
227
core/lib/Thelia/Controller/Admin/TaxController.php
Normal file
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
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']);
|
||||
$event->setRequirements($this->getRequirements($formData['type'], $formData));
|
||||
|
||||
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']);
|
||||
$event->setRequirements($this->getRequirements($formData['type'], $formData));
|
||||
|
||||
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"
|
||||
);
|
||||
}
|
||||
|
||||
protected function checkRequirements($formData)
|
||||
{
|
||||
$type = $formData['type'];
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function getRequirements($type, $formData)
|
||||
{
|
||||
$requirements = array();
|
||||
foreach($formData as $data => $value) {
|
||||
if(!strstr($data, ':')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$couple = explode(':', $data);
|
||||
|
||||
if(count($couple) != 2 || $couple[0] != $type) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$requirements[$couple[1]] = $value;
|
||||
}
|
||||
|
||||
return $requirements;
|
||||
}
|
||||
}
|
||||
@@ -236,6 +236,23 @@ class TaxRuleController extends AbstractCrudController
|
||||
return parent::updateAction();
|
||||
}
|
||||
|
||||
public function setDefaultAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response;
|
||||
|
||||
$setDefaultEvent = new TaxRuleEvent();
|
||||
|
||||
$taxRuleId = $this->getRequest()->attributes->get('tax_rule_id');
|
||||
|
||||
$setDefaultEvent->setId(
|
||||
$taxRuleId
|
||||
);
|
||||
|
||||
$this->dispatch(TheliaEvents::TAX_RULE_SET_DEFAULT, $setDefaultEvent);
|
||||
|
||||
$this->redirectToListTemplate();
|
||||
}
|
||||
|
||||
public function processUpdateTaxesAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
|
||||
@@ -31,10 +31,11 @@ use Thelia\Core\Security\Exception\UsernameNotFoundException;
|
||||
use Thelia\Form\CustomerCreation;
|
||||
use Thelia\Form\CustomerLogin;
|
||||
use Thelia\Form\CustomerLostPasswordForm;
|
||||
use Thelia\Form\CustomerModification;
|
||||
use Thelia\Form\CustomerUpdateForm;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Model\Customer;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Core\Security\Exception\WrongPasswordException;
|
||||
@@ -128,32 +129,56 @@ class CustomerController extends BaseFrontController
|
||||
}
|
||||
}
|
||||
|
||||
protected function getExistingCustomer($customer_id)
|
||||
{
|
||||
return CustomerQuery::create()
|
||||
->findOneById($customer_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update customer data. On success, redirect to success_url if exists.
|
||||
* Otherwise, display the same view again.
|
||||
*/
|
||||
public function viewAction()
|
||||
{
|
||||
$this->checkAuth();
|
||||
|
||||
$customer = $this->getSecurityContext()->getCustomerUser();
|
||||
$data = array(
|
||||
'id' => $customer->getId(),
|
||||
'title' => $customer->getTitleId(),
|
||||
'firstname' => $customer->getFirstName(),
|
||||
'lastname' => $customer->getLastName(),
|
||||
'email' => $customer->getEmail(),
|
||||
);
|
||||
|
||||
$customerUpdateForm = new CustomerUpdateForm($this->getRequest(), 'form', $data);
|
||||
|
||||
// Pass it to the parser
|
||||
$this->getParserContext()->addForm($customerUpdateForm);
|
||||
}
|
||||
|
||||
public function updateAction()
|
||||
{
|
||||
if ($this->getSecurityContext()->hasCustomerUser()) {
|
||||
|
||||
$message = false;
|
||||
|
||||
$customerModification = new CustomerModification($this->getRequest());
|
||||
$customerUpdateForm = new CustomerUpdateForm($this->getRequest());
|
||||
|
||||
try {
|
||||
|
||||
$customer = $this->getSecurityContext()->getCustomerUser();
|
||||
|
||||
$form = $this->validateForm($customerModification, "post");
|
||||
$form = $this->validateForm($customerUpdateForm, "post");
|
||||
|
||||
$customerChangeEvent = $this->createEventInstance($form->getData());
|
||||
$customerChangeEvent->setCustomer($customer);
|
||||
|
||||
$this->dispatch(TheliaEvents::CUSTOMER_UPDATEACCOUNT, $customerChangeEvent);
|
||||
|
||||
$this->processLogin($customerChangeEvent->getCustomer());
|
||||
|
||||
$this->redirectSuccess($customerModification);
|
||||
$this->redirectSuccess($customerUpdateForm);
|
||||
|
||||
} catch (FormValidationException $e) {
|
||||
$message = sprintf("Please check your input: %s", $e->getMessage());
|
||||
@@ -164,10 +189,10 @@ class CustomerController extends BaseFrontController
|
||||
if ($message !== false) {
|
||||
Tlog::getInstance()->error(sprintf("Error during customer modification process : %s.", $message));
|
||||
|
||||
$customerModification->setErrorMessage($message);
|
||||
$customerUpdateForm->setErrorMessage($message);
|
||||
|
||||
$this->getParserContext()
|
||||
->addForm($customerModification)
|
||||
->addForm($customerUpdateForm)
|
||||
->setGeneralError($message)
|
||||
;
|
||||
}
|
||||
@@ -193,31 +218,33 @@ class CustomerController extends BaseFrontController
|
||||
|
||||
$form = $this->validateForm($customerLoginForm, "post");
|
||||
|
||||
$authenticator = new CustomerUsernamePasswordFormAuthenticator($request, $customerLoginForm);
|
||||
// If User is a new customer
|
||||
if ($form->get('account')->getData() == 0 && !$form->get("email")->getErrors()) {
|
||||
$this->redirectToRoute("customer.create.view", array("email" => $form->get("email")->getData()));
|
||||
} else {
|
||||
|
||||
$customer = $authenticator->getAuthentifiedUser();
|
||||
try {
|
||||
|
||||
$this->processLogin($customer);
|
||||
$authenticator = new CustomerUsernamePasswordFormAuthenticator($request, $customerLoginForm);
|
||||
|
||||
$this->redirectSuccess($customerLoginForm);
|
||||
$customer = $authenticator->getAuthentifiedUser();
|
||||
|
||||
} catch (FormValidationException $e) {
|
||||
$this->processLogin($customer);
|
||||
|
||||
if ($request->request->has("account")) {
|
||||
$account = $request->request->get("account");
|
||||
$form = $customerLoginForm->getForm();
|
||||
if ($account == 0 && $form->get("email")->getData() !== null) {
|
||||
$this->redirectToRoute("customer.create.view", array("email" => $form->get("email")->getData()));
|
||||
$this->redirectSuccess($customerLoginForm);
|
||||
|
||||
} catch (UsernameNotFoundException $e) {
|
||||
$message = "Wrong email or password. Please try again";
|
||||
} catch (WrongPasswordException $e) {
|
||||
$message = "Wrong email or password. Please try again";
|
||||
} catch (AuthenticationException $e) {
|
||||
$message = "Wrong email or password. Please try again";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (FormValidationException $e) {
|
||||
$message = sprintf("Please check your input: %s", $e->getMessage());
|
||||
} catch (UsernameNotFoundException $e) {
|
||||
$message = "Wrong email or password. Please try again";
|
||||
} catch (WrongPasswordException $e) {
|
||||
$message = "Wrong email or password. Please try again";
|
||||
} catch (AuthenticationException $e) {
|
||||
$message = "Wrong email or password. Please try again";
|
||||
} catch (\Exception $e) {
|
||||
$message = sprintf("Sorry, an error occured: %s", $e->getMessage());
|
||||
}
|
||||
@@ -265,14 +292,14 @@ class CustomerController extends BaseFrontController
|
||||
$data["title"],
|
||||
$data["firstname"],
|
||||
$data["lastname"],
|
||||
$data["address1"],
|
||||
$data["address2"],
|
||||
$data["address3"],
|
||||
$data["phone"],
|
||||
$data["cellphone"],
|
||||
$data["zipcode"],
|
||||
$data["city"],
|
||||
$data["country"],
|
||||
isset($data["address1"])?$data["address1"]:null,
|
||||
isset($data["address2"])?$data["address2"]:null,
|
||||
isset($data["address3"])?$data["address3"]:null,
|
||||
isset($data["phone"])?$data["phone"]:null,
|
||||
isset($data["cellphone"])?$data["cellphone"]:null,
|
||||
isset($data["zipcode"])?$data["zipcode"]:null,
|
||||
isset($data["city"])?$data["city"]:null,
|
||||
isset($data["country"])?$data["country"]:null,
|
||||
isset($data["email"])?$data["email"]:null,
|
||||
isset($data["password"]) ? $data["password"]:null,
|
||||
$this->getRequest()->getSession()->getLang()->getId(),
|
||||
|
||||
120
core/lib/Thelia/Core/Event/Tax/TaxEvent.php
Normal file
120
core/lib/Thelia/Core/Event/Tax/TaxEvent.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
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;
|
||||
protected $requirements;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public function setRequirements($requirements)
|
||||
{
|
||||
$this->requirements = $requirements;
|
||||
}
|
||||
|
||||
public function getRequirements()
|
||||
{
|
||||
return $this->requirements;
|
||||
}
|
||||
}
|
||||
@@ -540,6 +540,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";
|
||||
|
||||
49
core/lib/Thelia/Core/Form/Type/TheliaType.php
Normal file
49
core/lib/Thelia/Core/Form/Type/TheliaType.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace Thelia\Core\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||
|
||||
class TheliaType extends AbstractType
|
||||
{
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
//'instance' => false,
|
||||
'type' => false,
|
||||
'options' => false,
|
||||
));
|
||||
|
||||
$resolver->setAllowedTypes(array(
|
||||
//'instance' => array('Thelia\Type\TypeInterface'),
|
||||
));
|
||||
|
||||
$resolver->setAllowedValues(array(
|
||||
'type' => array('text', 'choice'),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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 'text';
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'thelia_type';
|
||||
}
|
||||
}
|
||||
@@ -254,7 +254,7 @@ abstract class BaseLoop
|
||||
*
|
||||
* @param $pagination
|
||||
*
|
||||
* @return mixed
|
||||
* @return LoopResult
|
||||
*/
|
||||
abstract public function exec(&$pagination);
|
||||
|
||||
|
||||
@@ -102,6 +102,7 @@ class Cart extends BaseLoop
|
||||
->set("TAXED_PRICE", $cartItem->getTaxedPrice($taxCountry))
|
||||
->set("PROMO_TAXED_PRICE", $cartItem->getTaxedPromoPrice($taxCountry))
|
||||
->set("IS_PROMO", $cartItem->getPromo() === 1 ? 1 : 0);
|
||||
$loopResultRow->set("PRODUCT_SALE_ELEMENTS_ID", $productSaleElement->getId());
|
||||
$result->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -86,6 +86,7 @@ class Content extends BaseI18nLoop
|
||||
*/
|
||||
public function exec(&$pagination)
|
||||
{
|
||||
|
||||
$search = ContentQuery::create();
|
||||
|
||||
/* manage translations */
|
||||
@@ -138,27 +139,15 @@ class Content extends BaseI18nLoop
|
||||
$current_folder = $this->getCurrent_folder();
|
||||
|
||||
if ($current_folder === true) {
|
||||
$search->filterByFolder(
|
||||
FolderQuery::create()->filterByContent(
|
||||
ContentFolderQuery::create()->filterByContentId(
|
||||
$this->request->get("content_id"),
|
||||
Criteria::EQUAL
|
||||
)->find(),
|
||||
Criteria::IN
|
||||
)->find(),
|
||||
Criteria::IN
|
||||
);
|
||||
$current = ContentQuery::create()->findPk($this->request->get("content_id"));
|
||||
|
||||
$search->filterByFolder($current->getFolders(), Criteria::IN);
|
||||
|
||||
} elseif ($current_folder === false) {
|
||||
$search->filterByFolder(
|
||||
FolderQuery::create()->filterByContent(
|
||||
ContentFolderQuery::create()->filterByContentId(
|
||||
$this->request->get("content_id"),
|
||||
Criteria::EQUAL
|
||||
)->find(),
|
||||
Criteria::IN
|
||||
)->find(),
|
||||
Criteria::NOT_IN
|
||||
);
|
||||
|
||||
$current = ContentQuery::create()->findPk($this->request->get("content_id"));
|
||||
|
||||
$search->filterByFolder($current->getFolders(), Criteria::NOT_IN);
|
||||
}
|
||||
|
||||
$visible = $this->getVisible();
|
||||
|
||||
@@ -87,6 +87,7 @@ class Product extends BaseI18nLoop
|
||||
Argument::createIntTypeArgument('depth', 1),
|
||||
Argument::createBooleanOrBothTypeArgument('visible', 1),
|
||||
Argument::createIntTypeArgument('currency'),
|
||||
Argument::createAnyTypeArgument('title'),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
@@ -171,6 +172,17 @@ class Product extends BaseI18nLoop
|
||||
$search->filterByRef($ref, Criteria::IN);
|
||||
}
|
||||
|
||||
|
||||
$title = $this->getTitle();
|
||||
|
||||
if(!is_null($title)){
|
||||
|
||||
$search->where(" CASE WHEN NOT ISNULL(`requested_locale_i18n`.ID) THEN `requested_locale_i18n`.`TITLE` ELSE `default_locale_i18n`.`TITLE` END ".Criteria::LIKE." ?", "%".$title."%", \PDO::PARAM_STR);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$category = $this->getCategory();
|
||||
$categoryDefault = $this->getCategoryDefault();
|
||||
|
||||
@@ -461,7 +473,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();
|
||||
|
||||
|
||||
@@ -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("REQUIREMENTS" , $tax->getRequirements())
|
||||
->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);
|
||||
|
||||
@@ -32,9 +32,12 @@ 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;
|
||||
use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type;
|
||||
use Thelia\Model\TaxRuleCountryQuery;
|
||||
|
||||
/**
|
||||
@@ -56,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)
|
||||
);
|
||||
}
|
||||
@@ -71,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 */
|
||||
@@ -114,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);
|
||||
|
||||
@@ -130,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())
|
||||
@@ -150,6 +178,8 @@ class TaxRuleCountry extends BaseI18nLoop
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
|
||||
@@ -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,14 +124,17 @@ class Form extends AbstractSmartyPlugin
|
||||
|
||||
$template->assign("value", $fieldValue);
|
||||
|
||||
// If Checkbox input type
|
||||
if ($fieldVars['checked'] !== null) {
|
||||
$this->renderFormFieldCheckBox($template, $formFieldView['checked']);
|
||||
}
|
||||
$template->assign("checked", isset($fieldVars['checked']) ? $fieldVars['checked'] : false);
|
||||
|
||||
|
||||
//data
|
||||
$template->assign("data", $fieldVars['data']);
|
||||
|
||||
$template->assign("label", $fieldVars["label"]);
|
||||
$template->assign("label_attr", $fieldVars["label_attr"]);
|
||||
|
||||
$template->assign('required', isset($fieldVars['required']) ? $fieldVars['required'] : false);
|
||||
|
||||
$errors = $fieldVars["errors"];
|
||||
|
||||
$template->assign("error", empty($errors) ? false : true);
|
||||
@@ -141,20 +150,59 @@ class Form extends AbstractSmartyPlugin
|
||||
}
|
||||
|
||||
$template->assign("attr", implode(" ", $attr));
|
||||
$template->assign("attr_list", $fieldVars["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 choices */
|
||||
if (isset($formFieldView->vars['choices'])) {
|
||||
$template->assign("choices", $formFieldView->vars['choices']);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 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 +233,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 +346,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,22 +426,10 @@ $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")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Smarty_Internal_Template $template
|
||||
* @param $formFieldView
|
||||
*/
|
||||
public function renderFormFieldCheckBox(\Smarty_Internal_Template $template, $isChecked)
|
||||
{
|
||||
$template->assign("value", 0);
|
||||
if ($isChecked) {
|
||||
$template->assign("value", 1);
|
||||
}
|
||||
$template->assign("value", $isChecked);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
65
core/lib/Thelia/Form/AdminProfileCreationForm.php
Normal file
65
core/lib/Thelia/Form/AdminProfileCreationForm.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Form;
|
||||
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
class AdminProfileCreationForm extends BaseForm
|
||||
{
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
->add("wording" , "text" , array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Wording *"),
|
||||
"label_attr" => array(
|
||||
"for" => "wording"
|
||||
))
|
||||
)
|
||||
->add("name" , "text" , array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Name *"),
|
||||
"label_attr" => array(
|
||||
"for" => "name"
|
||||
))
|
||||
)
|
||||
->add("description" , "text" , array(
|
||||
"label" => Translator::getInstance()->trans("Description"),
|
||||
"label_attr" => array(
|
||||
"for" => "description"
|
||||
))
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return "thelia_admin_profile_creation";
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,16 @@ class CustomerCreation extends BaseForm
|
||||
{
|
||||
$this->formBuilder
|
||||
->add("auto_login", "integer")
|
||||
// Personal Informations
|
||||
->add("title", "text", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank()
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Title"),
|
||||
"label_attr" => array(
|
||||
"for" => "title"
|
||||
)
|
||||
))
|
||||
->add("firstname", "text", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank()
|
||||
@@ -58,84 +68,6 @@ class CustomerCreation extends BaseForm
|
||||
"for" => "lastname"
|
||||
)
|
||||
))
|
||||
->add("address1", "text", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank()
|
||||
),
|
||||
"label_attr" => array(
|
||||
"for" => "address"
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Street Address"),
|
||||
"label_attr" => array(
|
||||
"for" => "address1"
|
||||
)
|
||||
))
|
||||
->add("address2", "text", array(
|
||||
"label" => Translator::getInstance()->trans("Address Line 2"),
|
||||
"label_attr" => array(
|
||||
"for" => "address2"
|
||||
)
|
||||
))
|
||||
->add("address3", "text", array(
|
||||
"label" => Translator::getInstance()->trans("Address Line 3"),
|
||||
"label_attr" => array(
|
||||
"for" => "address3"
|
||||
)
|
||||
))
|
||||
->add("company", "text", array(
|
||||
"label" => Translator::getInstance()->trans("Company Name"),
|
||||
"label_attr" => array(
|
||||
"for" => "company"
|
||||
)
|
||||
))
|
||||
->add("phone", "text", array(
|
||||
"label" => Translator::getInstance()->trans("Phone"),
|
||||
"label_attr" => array(
|
||||
"for" => "phone"
|
||||
)
|
||||
))
|
||||
->add("cellphone", "text", array(
|
||||
"label" => Translator::getInstance()->trans("Cellphone"),
|
||||
"label_attr" => array(
|
||||
"for" => "cellphone"
|
||||
)
|
||||
))
|
||||
->add("zipcode", "text", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank()
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Zip code"),
|
||||
"label_attr" => array(
|
||||
"for" => "zipcode"
|
||||
)
|
||||
))
|
||||
->add("city", "text", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank()
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("City"),
|
||||
"label_attr" => array(
|
||||
"for" => "city"
|
||||
)
|
||||
))
|
||||
->add("country", "text", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank()
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Country"),
|
||||
"label_attr" => array(
|
||||
"for" => "country"
|
||||
)
|
||||
))
|
||||
->add("title", "text", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank()
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Title"),
|
||||
"label_attr" => array(
|
||||
"for" => "title"
|
||||
)
|
||||
))
|
||||
->add("email", "email", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank(),
|
||||
@@ -143,7 +75,7 @@ class CustomerCreation extends BaseForm
|
||||
new Constraints\Callback(array(
|
||||
"methods" => array(
|
||||
array($this,
|
||||
"verifyExistingEmail")
|
||||
"verifyExistingEmail")
|
||||
)
|
||||
))
|
||||
),
|
||||
@@ -163,6 +95,79 @@ class CustomerCreation extends BaseForm
|
||||
),
|
||||
"label" => "email confirmation"
|
||||
))*/
|
||||
->add("phone", "text", array(
|
||||
"label" => Translator::getInstance()->trans("Phone"),
|
||||
"label_attr" => array(
|
||||
"for" => "phone"
|
||||
),
|
||||
"required" => false
|
||||
))
|
||||
->add("cellphone", "text", array(
|
||||
"label" => Translator::getInstance()->trans("Cellphone"),
|
||||
"label_attr" => array(
|
||||
"for" => "cellphone"
|
||||
),
|
||||
"required" => false
|
||||
))
|
||||
// Delivery Informations
|
||||
->add("company", "text", array(
|
||||
"label" => Translator::getInstance()->trans("Company Name"),
|
||||
"label_attr" => array(
|
||||
"for" => "company"
|
||||
),
|
||||
"required" => false
|
||||
))
|
||||
->add("address1", "text", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank()
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Street Address"),
|
||||
"label_attr" => array(
|
||||
"for" => "address1"
|
||||
)
|
||||
))
|
||||
->add("address2", "text", array(
|
||||
"label" => Translator::getInstance()->trans("Address Line 2"),
|
||||
"label_attr" => array(
|
||||
"for" => "address2"
|
||||
),
|
||||
"required" => false
|
||||
))
|
||||
->add("address3", "text", array(
|
||||
"label" => Translator::getInstance()->trans("Address Line 3"),
|
||||
"label_attr" => array(
|
||||
"for" => "address3"
|
||||
),
|
||||
"required" => false
|
||||
))
|
||||
->add("city", "text", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank()
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("City"),
|
||||
"label_attr" => array(
|
||||
"for" => "city"
|
||||
)
|
||||
))
|
||||
->add("zipcode", "text", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank()
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Zip code"),
|
||||
"label_attr" => array(
|
||||
"for" => "zipcode"
|
||||
)
|
||||
))
|
||||
->add("country", "text", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank()
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Country"),
|
||||
"label_attr" => array(
|
||||
"for" => "country"
|
||||
)
|
||||
))
|
||||
// Login Information
|
||||
->add("password", "password", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank(),
|
||||
@@ -186,8 +191,14 @@ class CustomerCreation extends BaseForm
|
||||
"for" => "password_confirmation"
|
||||
)
|
||||
))
|
||||
|
||||
;
|
||||
->add("agreed", "checkbox", array(
|
||||
"constraints" => array(
|
||||
new Constraints\True(array("message" => "Please accept the Terms and conditions in order to register."))
|
||||
),
|
||||
"label_attr" => array(
|
||||
"for" => "agreed"
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
public function verifyPasswordField($value, ExecutionContextInterface $context)
|
||||
|
||||
@@ -22,10 +22,19 @@
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Form;
|
||||
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\Constraints\Email;
|
||||
use Symfony\Component\Validator\ConstraintViolation;
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Model\Base\CustomerQuery;
|
||||
|
||||
/**
|
||||
* Class CustomerLogin
|
||||
* @package Thelia\Form
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class CustomerLogin extends BaseForm
|
||||
{
|
||||
protected function buildForm()
|
||||
@@ -33,27 +42,82 @@ class CustomerLogin extends BaseForm
|
||||
$this->formBuilder
|
||||
->add("email", "email", array(
|
||||
"constraints" => array(
|
||||
new NotBlank(),
|
||||
new Email()
|
||||
new Constraints\NotBlank(),
|
||||
new Constraints\Email(),
|
||||
new Constraints\Callback(array(
|
||||
"methods" => array(
|
||||
array($this, "verifyExistingEmail")
|
||||
)
|
||||
))
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Please enter your email address"),
|
||||
"label_attr" => array(
|
||||
"for" => "email"
|
||||
)
|
||||
))
|
||||
->add("account", "choice", array(
|
||||
"constraints" => array(
|
||||
new Constraints\Callback(array(
|
||||
"methods" => array(
|
||||
array($this, "verifyAccount")
|
||||
)
|
||||
))
|
||||
),
|
||||
"required" => true
|
||||
"choices" => array(
|
||||
0 => Translator::getInstance()->trans("No, I am a new customer."),
|
||||
1 => Translator::getInstance()->trans("Yes, I have a password :")
|
||||
),
|
||||
"label_attr" => array(
|
||||
"for" => "account"
|
||||
),
|
||||
"data" => 0
|
||||
))
|
||||
->add("password", "password", array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
),
|
||||
/*"constraints" => array(
|
||||
new Constraints\NotBlank()
|
||||
),*/
|
||||
"label" => Translator::getInstance()->trans("Please enter your password"),
|
||||
"label_attr" => array(
|
||||
"for" => "password"
|
||||
),
|
||||
"required" => true
|
||||
))
|
||||
->add("remember_me", "checkbox")
|
||||
;
|
||||
"required" => false
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* If the user select "Yes, I have a password", we check the password.
|
||||
*/
|
||||
public function verifyAccount($value, ExecutionContextInterface $context)
|
||||
{
|
||||
if ($value == 1) {
|
||||
$data = $context->getRoot()->getData();
|
||||
if (false === $data['password'] || (empty($data['password']) && '0' != $data['password'])) {
|
||||
|
||||
$context->getViolations()->add(new ConstraintViolation(
|
||||
'This value should not be blank.',
|
||||
'account_password',
|
||||
array(),
|
||||
$context->getRoot(),
|
||||
'children[password].data',
|
||||
'propertyPath'
|
||||
));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the user select "I'am a new customer", we make sure is email address does not exit in the database.
|
||||
*/
|
||||
public function verifyExistingEmail($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$data = $context->getRoot()->getData();
|
||||
if ($data["account"] == 0) {
|
||||
$customer = CustomerQuery::create()->findOneByEmail($value);
|
||||
if ($customer) {
|
||||
$context->addViolation("A user already exists with this email address. Please login or if you've forgotten your password, go to Reset Your Password.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getName()
|
||||
|
||||
@@ -82,7 +82,7 @@ class CustomerLostPasswordForm extends BaseForm
|
||||
{
|
||||
$customer = CustomerQuery::create()->findOneByEmail($value);
|
||||
if (null === $customer) {
|
||||
$context->addViolation("This email does not exists exists");
|
||||
$context->addViolation("This email does not exists");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
75
core/lib/Thelia/Form/CustomerUpdateForm.php
Executable file
75
core/lib/Thelia/Form/CustomerUpdateForm.php
Executable file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Form;
|
||||
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
/**
|
||||
* Class CustomerUpdateForm
|
||||
* @package Thelia\Form
|
||||
* @author Christophe Laffont <claffont@openstudio.fr>
|
||||
*/
|
||||
class CustomerUpdateForm extends CustomerCreation
|
||||
{
|
||||
|
||||
protected function buildForm()
|
||||
{
|
||||
parent::buildForm();
|
||||
|
||||
|
||||
$this->formBuilder
|
||||
->remove("auto_login")
|
||||
// Remove From Personal Informations
|
||||
->remove("phone")
|
||||
->remove("cellphone")
|
||||
// Remove Delivery Informations
|
||||
->remove("company")
|
||||
->remove("address1")
|
||||
->remove("address2")
|
||||
->remove("address3")
|
||||
->remove("city")
|
||||
->remove("zipcode")
|
||||
->remove("country")
|
||||
// Remove Login Information
|
||||
->remove("password")
|
||||
->remove("password_confirm")
|
||||
// Remove Terms & conditions
|
||||
->remove("agreed")
|
||||
|
||||
// Add Newsletter
|
||||
->add("newsletter", "checkbox", array(
|
||||
"label" => "I would like to receive the newsletter our the latest news.",
|
||||
"label_attr" => array(
|
||||
"for" => "newsletter"
|
||||
),
|
||||
"required" => false
|
||||
));
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return "thelia_customer_update";
|
||||
}
|
||||
}
|
||||
58
core/lib/Thelia/Form/LanguageCreationForm.php
Normal file
58
core/lib/Thelia/Form/LanguageCreationForm.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Form;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
class LanguageCreationForm extends BaseForm
|
||||
{
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
->add("title", "text", array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Language title *"),
|
||||
"label_attr" => array(
|
||||
"for" => "title"
|
||||
)
|
||||
))
|
||||
->add("isocode", "text", array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("ISO Code *"),
|
||||
"label_attr" => array(
|
||||
"for" => "isocode"
|
||||
)
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return "thelia_language_creation";
|
||||
}
|
||||
}
|
||||
97
core/lib/Thelia/Form/TaxCreationForm.php
Normal file
97
core/lib/Thelia/Form/TaxCreationForm.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
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;
|
||||
use Thelia\TaxEngine\TaxType;
|
||||
|
||||
class TaxCreationForm extends BaseForm
|
||||
{
|
||||
use StandardDescriptionFieldsTrait;
|
||||
|
||||
protected function buildForm($change_mode = false)
|
||||
{
|
||||
$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
|
||||
->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"),
|
||||
))
|
||||
;
|
||||
|
||||
foreach($requirementList as $type => $requirements) {
|
||||
foreach($requirements as $name => $requirementType) {
|
||||
$this->formBuilder
|
||||
->add($type . ':' . $name, new TheliaType(), array(
|
||||
//"instance" => $requirementType,
|
||||
"constraints" => array(
|
||||
new Constraints\Callback(
|
||||
array(
|
||||
"methods" => array(
|
||||
array($requirementType, "verifyForm"),
|
||||
),
|
||||
)
|
||||
),
|
||||
),
|
||||
"attr" => array(
|
||||
"tag" => "requirements",
|
||||
"tax_type" => $type,
|
||||
),
|
||||
"label" => Translator::getInstance()->trans($name),
|
||||
"type" => $requirementType->getFormType(),
|
||||
"options" => $requirementType->getFormOptions(),
|
||||
))
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
$this->addStandardDescFields(array('postscriptum', 'chapo', 'locale'));
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return "thelia_tax_creation";
|
||||
}
|
||||
}
|
||||
66
core/lib/Thelia/Form/TaxModificationForm.php
Normal file
66
core/lib/Thelia/Form/TaxModificationForm.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)) {
|
||||
|
||||
@@ -36,7 +36,11 @@ trait ModelEventDispatcherTrait {
|
||||
*/
|
||||
protected $dispatcher = null;
|
||||
|
||||
|
||||
/**
|
||||
* @param EventDispatcherInterface $dispatcher
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDispatcher(EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$this->dispatcher = $dispatcher;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
71
core/lib/Thelia/TaxEngine/TaxEngine.php
Executable file
71
core/lib/Thelia/TaxEngine/TaxEngine.php
Executable file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\TaxEngine;
|
||||
|
||||
/**
|
||||
* Class TaxEngine
|
||||
* @package Thelia\TaxEngine
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -65,4 +65,9 @@ class FeatureFixAmountTaxType extends BaseTaxType
|
||||
'feature' => new ModelValidIdType('Feature'),
|
||||
);
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return "Fix amount Tax depending on a feature";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,4 +47,9 @@ class FixAmountTaxType extends BaseTaxType
|
||||
'amount' => new FloatType(),
|
||||
);
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return "Fix amount Tax";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 )
|
||||
public function getTitle()
|
||||
{
|
||||
return "Price % Tax";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
||||
*
|
||||
*/
|
||||
|
||||
class AlphaNumStringListType implements TypeInterface
|
||||
class AlphaNumStringListType extends BaseType
|
||||
{
|
||||
public function getType()
|
||||
{
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
||||
*
|
||||
*/
|
||||
|
||||
class AlphaNumStringType implements TypeInterface
|
||||
class AlphaNumStringType extends BaseType
|
||||
{
|
||||
public function getType()
|
||||
{
|
||||
@@ -44,4 +44,14 @@ class AlphaNumStringType implements TypeInterface
|
||||
{
|
||||
return $this->isValid($value) ? $value : null;
|
||||
}
|
||||
|
||||
public function getFormType()
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
public function getFormOptions()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
||||
*
|
||||
*/
|
||||
|
||||
class AnyType implements TypeInterface
|
||||
class AnyType extends BaseType
|
||||
{
|
||||
public function getType()
|
||||
{
|
||||
@@ -44,4 +44,14 @@ class AnyType implements TypeInterface
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function getFormType()
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
public function getFormOptions()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
46
core/lib/Thelia/Type/BaseType.php
Normal file
46
core/lib/Thelia/Type/BaseType.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Type;
|
||||
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
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(sprintf("received value `%s` does not match `%s` type", $value, $this->getType()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ namespace Thelia\Type;
|
||||
*
|
||||
*/
|
||||
|
||||
class BooleanOrBothType implements TypeInterface
|
||||
class BooleanOrBothType extends BaseType
|
||||
{
|
||||
|
||||
const ANY = '*';
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
||||
*
|
||||
*/
|
||||
|
||||
class BooleanType implements TypeInterface
|
||||
class BooleanType extends BaseType
|
||||
{
|
||||
public function getType()
|
||||
{
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
||||
*
|
||||
*/
|
||||
|
||||
class EnumListType implements TypeInterface
|
||||
class EnumListType extends BaseType
|
||||
{
|
||||
protected $values = array();
|
||||
|
||||
@@ -69,4 +69,14 @@ class EnumListType implements TypeInterface
|
||||
{
|
||||
return in_array($value, $this->values);
|
||||
}
|
||||
|
||||
public function getFormType()
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
public function getFormOptions()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
||||
*
|
||||
*/
|
||||
|
||||
class EnumType implements TypeInterface
|
||||
class EnumType extends BaseType
|
||||
{
|
||||
protected $values = array();
|
||||
|
||||
@@ -52,4 +52,14 @@ class EnumType implements TypeInterface
|
||||
{
|
||||
return $this->isValid($value) ? $value : null;
|
||||
}
|
||||
|
||||
public function getFormType()
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
public function getFormOptions()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
||||
*
|
||||
*/
|
||||
|
||||
class FloatToFloatArrayType implements TypeInterface
|
||||
class FloatToFloatArrayType extends BaseType
|
||||
{
|
||||
public function getType()
|
||||
{
|
||||
@@ -54,4 +54,14 @@ class FloatToFloatArrayType implements TypeInterface
|
||||
{
|
||||
return $this->isValid($value) ? $value : null;
|
||||
}
|
||||
|
||||
public function getFormType()
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
public function getFormOptions()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
||||
*
|
||||
*/
|
||||
|
||||
class FloatType implements TypeInterface
|
||||
class FloatType extends BaseType
|
||||
{
|
||||
public function getType()
|
||||
{
|
||||
@@ -44,4 +44,14 @@ class FloatType implements TypeInterface
|
||||
{
|
||||
return $this->isValid($value) ? $value : null;
|
||||
}
|
||||
|
||||
public function getFormType()
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
public function getFormOptions()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
||||
*
|
||||
*/
|
||||
|
||||
class IntListType implements TypeInterface
|
||||
class IntListType extends BaseType
|
||||
{
|
||||
public function getType()
|
||||
{
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
||||
*
|
||||
*/
|
||||
|
||||
class IntToCombinedIntsListType implements TypeInterface
|
||||
class IntToCombinedIntsListType extends BaseType
|
||||
{
|
||||
public function getType()
|
||||
{
|
||||
@@ -124,4 +124,14 @@ class IntToCombinedIntsListType implements TypeInterface
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getFormType()
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
public function getFormOptions()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
||||
*
|
||||
*/
|
||||
|
||||
class IntToCombinedStringsListType implements TypeInterface
|
||||
class IntToCombinedStringsListType extends BaseType
|
||||
{
|
||||
public function getType()
|
||||
{
|
||||
@@ -124,4 +124,14 @@ class IntToCombinedStringsListType implements TypeInterface
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getFormType()
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
public function getFormOptions()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
||||
*
|
||||
*/
|
||||
|
||||
class IntType implements TypeInterface
|
||||
class IntType extends BaseType
|
||||
{
|
||||
public function getType()
|
||||
{
|
||||
@@ -44,4 +44,14 @@ class IntType implements TypeInterface
|
||||
{
|
||||
return $this->isValid($value) ? $value : null;
|
||||
}
|
||||
|
||||
public function getFormType()
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
public function getFormOptions()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
||||
*
|
||||
*/
|
||||
|
||||
class JsonType implements TypeInterface
|
||||
class JsonType extends BaseType
|
||||
{
|
||||
public function getType()
|
||||
{
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ use Thelia\Exception\TypeException;
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ModelType implements TypeInterface
|
||||
class ModelType extends BaseType
|
||||
{
|
||||
protected $expectedModelActiveRecord = null;
|
||||
|
||||
@@ -63,4 +63,14 @@ class ModelType implements TypeInterface
|
||||
{
|
||||
return $this->isValid($value) ? $value : null;
|
||||
}
|
||||
|
||||
public function getFormType()
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
public function getFormOptions()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ use Thelia\Exception\TypeException;
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ModelValidIdType implements TypeInterface
|
||||
class ModelValidIdType extends BaseType
|
||||
{
|
||||
protected $expectedModelActiveRecordQuery = null;
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,12 +22,13 @@
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Type;
|
||||
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
|
||||
interface TypeInterface
|
||||
{
|
||||
public function getType();
|
||||
@@ -35,4 +36,8 @@ interface TypeInterface
|
||||
public function isValid($value);
|
||||
|
||||
public function getFormattedValue($value);
|
||||
|
||||
public function getFormType();
|
||||
public function getFormOptions();
|
||||
public function verifyForm($value, ExecutionContextInterface $context);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user