tax types

This commit is contained in:
Etienne Roudeix
2013-10-07 11:57:43 +02:00
parent 0efb01220c
commit fe3aea4ab7
9 changed files with 120 additions and 14 deletions

View File

@@ -777,6 +777,19 @@
<!-- end Modules rule management -->
<!-- taxe rules management -->
<route id="admin.configuration.taxes-rules.default" path="/admin/configuration/taxes_rules">
<default key="_controller">Thelia\Controller\Admin\TaxRuleController::defaultAction</default>
</route>
<route id="admin.configuration.taxes-rules.update" path="/admin/configuration/taxes_rules/update/{tax_rule_id}" methods="get">
<default key="_controller">Thelia\Controller\Admin\TaxRuleController::updateAction</default>
<requirement key="tax_rule_id">\d+</requirement>
</route>
<!-- end tax rules management -->
<!-- The default route, to display a template -->

View File

@@ -43,6 +43,8 @@ class TaxEngineException extends \RuntimeException
const BAD_AMOUNT_FORMAT = 601;
const FEATURE_BAD_EXPECTED_VALUE = 701;
public function __construct($message, $code = null, $previous = null)
{
if ($code === null) {

View File

@@ -23,6 +23,7 @@
namespace Thelia\TaxEngine\TaxType;
use Thelia\Exception\TaxEngineException;
use Thelia\Model\Product;
use Thelia\Type\TypeInterface;
/**
@@ -38,7 +39,7 @@ abstract class BaseTaxType
public abstract function pricePercentRetriever();
public abstract function fixAmountRetriever();
public abstract function fixAmountRetriever(Product $product);
public abstract function getRequirementsList();

View File

@@ -0,0 +1,72 @@
<?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\TaxType;
use Thelia\Exception\TaxEngineException;
use Thelia\Model\FeatureProductQuery;
use Thelia\Model\Product;
use Thelia\Type\FloatType;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class FeatureFixAmountTaxType extends BaseTaxType
{
public function calculate($untaxedPrice)
{
return $this->getRequirement("amount");
}
public function pricePercentRetriever()
{
return 0;
}
public function fixAmountRetriever(Product $product)
{
$featureId = $this->getRequirement("featureId");
$query = FeatureProductQuery::create()
->filterByProduct($product)
->filterByFeatureId($featureId)
->findOne();
$taxAmount = $query->getFreeTextValue();
$testInt = new FloatType();
if(!$testInt->isValid($taxAmount)) {
throw new TaxEngineException('Feature value does not match FLOAT format', TaxEngineException::FEATURE_BAD_EXPECTED_VALUE);
}
return $taxAmount;
}
public function getRequirementsList()
{
return array(
'featureId' => new ModelType('Feature'),
);
}
}

View File

@@ -42,7 +42,7 @@ class featureSlicePercentTaxType extends BaseTaxType
}
public function fixAmountRetriever()
public function fixAmountRetriever(\Thelia\Model\Product $product)
{
}

View File

@@ -41,7 +41,7 @@ class FixAmountTaxType extends BaseTaxType
return 0;
}
public function fixAmountRetriever()
public function fixAmountRetriever(\Thelia\Model\Product $product)
{
return $this->getRequirement("amount");
}

View File

@@ -41,7 +41,7 @@ class PricePercentTaxType extends BaseTaxType
return ($this->getRequirement("percent") * 0.01);
}
public function fixAmountRetriever()
public function fixAmountRetriever(\Thelia\Model\Product $product)
{
return 0;
}