tax rule edition

This commit is contained in:
Etienne Roudeix
2013-10-11 11:09:23 +02:00
parent c1a8c27dee
commit 763026700d
11 changed files with 290 additions and 92 deletions

View File

@@ -23,9 +23,12 @@
namespace Thelia\Action;
use Propel\Runtime\ActiveQuery\Criteria;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\Tax\TaxRuleEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\TaxRuleCountry;
use Thelia\Model\TaxRuleCountryQuery;
use Thelia\Model\TaxRule as TaxRuleModel;
use Thelia\Model\TaxRuleQuery;
@@ -83,6 +86,51 @@ class TaxRule extends BaseAction implements EventSubscriberInterface
}
}
/**
* @param TaxRuleEvent $event
*/
public function updateTaxes(TaxRuleEvent $event)
{
if (null !== $taxRule = TaxRuleQuery::create()->findPk($event->getId())) {
$taxList = json_decode($event->getTaxList(), true);
/* clean the current tax rule for the countries */
TaxRuleCountryQuery::create()
->filterByTaxRule($taxRule)
->filterByCountryId($event->getCountryList(), Criteria::IN)
->delete();
/* for each country */
foreach($event->getCountryList() as $country) {
$position = 1;
/* on applique les nouvelles regles */
foreach($taxList as $tax) {
if(is_array($tax)) {
foreach($tax as $samePositionTax) {
$taxModel = new TaxRuleCountry();
$taxModel->setTaxRule($taxRule)
->setCountryId($country)
->setTaxId($samePositionTax)
->setPosition($position);
$taxModel->save();
}
} else {
$taxModel = new TaxRuleCountry();
$taxModel->setTaxRule($taxRule)
->setCountryId($country)
->setTaxId($tax)
->setPosition($position);
$taxModel->save();
}
$position++;
}
}
$event->setTaxRule($taxRule);
}
}
/**
* @param TaxRuleEvent $event
*/
@@ -106,6 +154,7 @@ class TaxRule extends BaseAction implements EventSubscriberInterface
return array(
TheliaEvents::TAX_RULE_CREATE => array("create", 128),
TheliaEvents::TAX_RULE_UPDATE => array("update", 128),
TheliaEvents::TAX_RULE_TAXES_UPDATE => array("updateTaxes", 128),
TheliaEvents::TAX_RULE_DELETE => array("delete", 128),
);