change the way product is created

This commit is contained in:
Manuel Raynaud
2014-03-13 09:56:11 +01:00
parent d8e1f24fda
commit e4ba7d8d11
13 changed files with 259 additions and 107 deletions

View File

@@ -100,6 +100,27 @@ class Calculator
return $this;
}
public function loadTaxRuleWithoutProduct(TaxRule $taxRule, Country $country)
{
$this->product = null;
$this->country = null;
$this->taxRulesCollection = null;
if ($taxRule->getId() === null) {
throw new TaxEngineException('TaxRule id is empty in Calculator::loadTaxRule', TaxEngineException::UNDEFINED_TAX_RULE);
}
if ($country->getId() === null) {
throw new TaxEngineException('Country id is empty in Calculator::loadTaxRule', TaxEngineException::UNDEFINED_COUNTRY);
}
$this->country = $country;
$this->product = new Product();
$this->taxRulesCollection = $this->taxRuleQuery->getTaxCalculatorCollection($taxRule, $country);
return $this;
}
public function getTaxAmountFromUntaxedPrice($untaxedPrice, &$taxCollection = null)
{
return $this->getTaxedPrice($untaxedPrice, $taxCollection) - $untaxedPrice;

View File

@@ -47,6 +47,7 @@ class FeatureFixAmountTaxType extends BaseTaxType
public function fixAmountRetriever(Product $product)
{
$taxAmount = 0;
$featureId = $this->getRequirement("feature");
$query = FeatureProductQuery::create()
@@ -54,14 +55,17 @@ class FeatureFixAmountTaxType extends BaseTaxType
->filterByFeatureId($featureId)
->findOne();
$taxAmount = $query->getFreeTextValue();
if (null !== $query) {
$taxAmount = $query->getFreeTextValue();
$testInt = new FloatType();
if (!$testInt->isValid($taxAmount)) {
throw new TaxEngineException(
$testInt = new FloatType();
if (!$testInt->isValid($taxAmount)) {
throw new TaxEngineException(
Translator::getInstance()->trans('Feature value does not match FLOAT format'),
TaxEngineException::FEATURE_BAD_EXPECTED_VALUE
);
);
}
}
return $taxAmount;