tax engine

This commit is contained in:
Etienne Roudeix
2013-09-09 14:24:50 +02:00
parent a178835f6b
commit 0ddf88e46e
9 changed files with 117 additions and 21 deletions

View File

@@ -4,7 +4,8 @@ namespace Thelia\Model;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Model\Base\TaxRuleQuery as BaseTaxRuleQuery;
use Thelia\Model\Map\TaxRuleCountryTableMap;
use Thelia\Model\Map\TaxTableMap;
/**
* Skeleton subclass for performing query and update operations on the 'tax_rule' table.
@@ -18,14 +19,26 @@ use Thelia\Model\Base\TaxRuleQuery as BaseTaxRuleQuery;
*/
class TaxRuleQuery extends BaseTaxRuleQuery
{
public function getTaxCalculatorCollection(Product $product, Country $country)
{
$search = TaxRuleCountryQuery::create()
->filterByCountry($country, Criteria::EQUAL)
->filterByTaxRuleId($product->getTaxRuleId())
->orderByPosition()
->find();
const ALIAS_FOR_TAX_RULE_COUNTRY_POSITION = 'taxRuleCountryPosition';
const ALIAS_FOR_TAX_RATE_SUM = 'taxRateSum';
return $search;
public function getTaxCalculatorGroupedCollection(Product $product, Country $country)
{
$search = TaxQuery::create()
->filterByTaxRuleCountry(
TaxRuleCountryQuery::create()
->filterByCountry($country, Criteria::EQUAL)
->filterByTaxRuleId($product->getTaxRuleId())
->groupByPosition()
->orderByPosition()
->find()
)
->withColumn(TaxRuleCountryTableMap::POSITION, self::ALIAS_FOR_TAX_RULE_COUNTRY_POSITION)
->withColumn('ROUND(SUM(' . TaxTableMap::RATE . '), 2)', self::ALIAS_FOR_TAX_RATE_SUM)
;
//var_dump($search->toString());
return $search->find();
}
} // TaxRuleQuery