tax engine model
This commit is contained in:
41
core/lib/Thelia/Exception/TaxEngineException.php
Executable file
41
core/lib/Thelia/Exception/TaxEngineException.php
Executable file
@@ -0,0 +1,41 @@
|
||||
<?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\Exception;
|
||||
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
class TaxEngineException extends \RuntimeException
|
||||
{
|
||||
const UNKNOWN_EXCEPTION = 0;
|
||||
|
||||
const UNDEFINED_PRODUCT = 501;
|
||||
const UNDEFINED_COUNTRY = 502;
|
||||
|
||||
public function __construct($message, $code = null, $previous = null) {
|
||||
if($code === null) {
|
||||
$code = self::UNKNOWN_EXCEPTION;
|
||||
}
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
65
core/lib/Thelia/TaxEngine/Calculator.php
Executable file
65
core/lib/Thelia/TaxEngine/Calculator.php
Executable 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\TaxEngine;
|
||||
|
||||
use Thelia\Exception\TaxEngineException;
|
||||
use Thelia\Model\Country;
|
||||
use Thelia\Model\Product;
|
||||
|
||||
/**
|
||||
* Class Calculator
|
||||
* @package Thelia\TaxEngine
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
class Calculator
|
||||
{
|
||||
protected $taxRulesCollection = null;
|
||||
|
||||
protected $product = null;
|
||||
protected $country = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function load(Product $product, Country $country)
|
||||
{
|
||||
if($product->getId() === null) {
|
||||
throw new TaxEngineException('Product id is empty in Calculator::load', TaxEngineException::UNDEFINED_PRODUCT);
|
||||
}
|
||||
if($country->getId() === null) {
|
||||
throw new TaxEngineException('Country id is empty in Calculator::load', TaxEngineException::UNDEFINED_COUNTRY);
|
||||
}
|
||||
|
||||
$this->product = $product;
|
||||
$this->country = $country;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTaxAmount()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -96,19 +96,19 @@
|
||||
</table>
|
||||
<table name="tax_rule" namespace="Thelia\Model">
|
||||
<column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER" />
|
||||
<column name="code" size="45" type="VARCHAR" />
|
||||
<column name="title" size="255" type="VARCHAR" />
|
||||
<column name="description" type="LONGVARCHAR" />
|
||||
<behavior name="timestampable" />
|
||||
<behavior name="i18n" />
|
||||
<behavior name="i18n">
|
||||
<parameter name="i18n_columns" value="title, description" />
|
||||
</behavior>
|
||||
</table>
|
||||
<table name="tax_rule_country" namespace="Thelia\Model">
|
||||
<column name="id" primaryKey="true" required="true" type="INTEGER" />
|
||||
<column name="tax_rule_id" type="INTEGER" />
|
||||
<column name="country_id" type="INTEGER" />
|
||||
<column name="tax_rule_id" required="true" type="INTEGER" />
|
||||
<column name="country_id" required="true" type="INTEGER" />
|
||||
<column name="tax_id" type="INTEGER" />
|
||||
<column name="none" type="TINYINT" />
|
||||
<foreign-key foreignTable="tax" name="fk_tax_rule_country_tax_id" onDelete="SET NULL" onUpdate="RESTRICT">
|
||||
<column name="position" required="true" type="INTEGER" />
|
||||
<foreign-key foreignTable="tax" name="fk_tax_rule_country_tax_id" onDelete="CASCADE" onUpdate="RESTRICT">
|
||||
<reference foreign="id" local="tax_id" />
|
||||
</foreign-key>
|
||||
<foreign-key foreignTable="tax_rule" name="fk_tax_rule_country_tax_rule_id" onDelete="CASCADE" onUpdate="RESTRICT">
|
||||
|
||||
Reference in New Issue
Block a user