Merge branch 'master' of https://github.com/thelia/thelia
This commit is contained in:
@@ -22,10 +22,14 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Action;
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Propel\Runtime\Propel;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\AddressCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\AddressEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Model\Address as AddressModel;
|
||||
use Thelia\Model\Map\AddressTableMap;
|
||||
|
||||
/**
|
||||
* Class Address
|
||||
@@ -49,31 +53,51 @@ class Address extends BaseAction implements EventSubscriberInterface
|
||||
$this->createOrUpdate($addressModel, $event);
|
||||
}
|
||||
|
||||
public function delete(AddressEvent $event)
|
||||
{
|
||||
$address = $event->getAddress();
|
||||
|
||||
$address->delete();
|
||||
}
|
||||
|
||||
protected function createOrUpdate(AddressModel $addressModel, AddressCreateOrUpdateEvent $event)
|
||||
{
|
||||
$addressModel->setDispatcher($this->getDispatcher());
|
||||
$con = Propel::getWriteConnection(AddressTableMap::DATABASE_NAME);
|
||||
$con->beginTransaction();
|
||||
try {
|
||||
if ($addressModel->isNew()) {
|
||||
$addressModel->setLabel($event->getLabel());
|
||||
}
|
||||
|
||||
if ($addressModel->isNew()) {
|
||||
$addressModel->setLabel($event->getLabel());
|
||||
$addressModel
|
||||
->setTitleId($event->getTitle())
|
||||
->setFirstname($event->getFirstname())
|
||||
->setLastname($event->getLastname())
|
||||
->setAddress1($event->getAddress1())
|
||||
->setAddress2($event->getAddress2())
|
||||
->setAddress3($event->getAddress3())
|
||||
->setZipcode($event->getZipcode())
|
||||
->setCity($event->getCity())
|
||||
->setCountryId($event->getCountry())
|
||||
->setCellphone($event->getCellphone())
|
||||
->setPhone($event->getPhone())
|
||||
->setCompany($event->getCompany())
|
||||
->save()
|
||||
;
|
||||
|
||||
if($event->getIsDefault()) {
|
||||
$addressModel->makeItDefault();
|
||||
}
|
||||
|
||||
$event->setAddress($addressModel);
|
||||
$con->commit();
|
||||
|
||||
} catch(PropelException $e) {
|
||||
$con->rollback();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$addressModel
|
||||
->setTitleId($event->getTitle())
|
||||
->setFirstname($event->getFirstname())
|
||||
->setLastname($event->getLastname())
|
||||
->setAddress1($event->getAddress1())
|
||||
->setAddress2($event->getAddress2())
|
||||
->setAddress3($event->getAddress3())
|
||||
->setZipcode($event->getZipcode())
|
||||
->setCity($event->getCity())
|
||||
->setCountryId($event->getCountry())
|
||||
->setCellphone($event->getCellphone())
|
||||
->setPhone($event->getPhone())
|
||||
->setCompany($event->getCompany())
|
||||
->save()
|
||||
;
|
||||
|
||||
$event->setAddress($addressModel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,7 +124,8 @@ class Address extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
return array(
|
||||
TheliaEvents::ADDRESS_CREATE => array("create", 128),
|
||||
TheliaEvents::ADDRESS_UPDATE => array("update", 128)
|
||||
TheliaEvents::ADDRESS_UPDATE => array("update", 128),
|
||||
TheliaEvents::ADDRESS_DELETE => array("delete", 128)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,18 +59,29 @@
|
||||
<!-- end customer routes -->
|
||||
|
||||
<!-- customer address routes -->
|
||||
<route id="address.create" path="/address/create" >
|
||||
<route id="address.create.view" path="/address/create" methods="get">
|
||||
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
||||
<default key="_view">address</default>
|
||||
</route>
|
||||
|
||||
<route id="address.create" path="/address/create" methods="post" >
|
||||
<default key="_controller">Thelia\Controller\Front\AddressController::createAction</default>
|
||||
<default key="_view">address</default>
|
||||
</route>
|
||||
|
||||
<route id="address.edit" path="/address/edit/{address_id}">
|
||||
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
||||
<default key="_view">address-edit</default>
|
||||
<route id="address.edit" path="/address/update/{address_id}" methods="get">
|
||||
<default key="_controller">Thelia\Controller\Front\AddressController::updateViewAction</default>
|
||||
<default key="_view">address-update</default>
|
||||
</route>
|
||||
|
||||
<route id="address.update" path="/address/update" >
|
||||
<default key="_controller">Thelia\Controller\Front\AddressController::updateAction</default>
|
||||
<route id="address.update" path="/address/update/{address_id}" methods="post" >
|
||||
<default key="_controller">Thelia\Controller\Front\AddressController::processUpdateAction</default>
|
||||
<default key="_view">address-update</default>
|
||||
</route>
|
||||
|
||||
<route id="address.delete" path="/address/delete/{address_id}">
|
||||
<default key="_controller">Thelia\Controller\Front\AddressController::deleteAction</default>
|
||||
<default key="_view">account</default>
|
||||
</route>
|
||||
|
||||
<route id="address.generateModal" path="/address/modal/{address_id}" methods="get">
|
||||
|
||||
@@ -4,12 +4,28 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||
|
||||
<route id="home" path="/install" >
|
||||
<route id="install.step1" path="/install" >
|
||||
<default key="_controller">Thelia\Controller\Install\InstallController::index</default>
|
||||
</route>
|
||||
|
||||
<route id="home" path="/install/step/2" >
|
||||
<route id="install.step2" path="/install/step/2" >
|
||||
<default key="_controller">Thelia\Controller\Install\InstallController::checkPermission</default>
|
||||
</route>
|
||||
|
||||
<route id="install.step3" path="/install/step/3" >
|
||||
<default key="_controller">Thelia\Controller\Install\InstallController::databaseConnection</default>
|
||||
</route>
|
||||
|
||||
<route id="install.step4" path="/install/step/4" >
|
||||
<default key="_controller">Thelia\Controller\Install\InstallController::databaseSelection</default>
|
||||
</route>
|
||||
|
||||
<route id="install.step5" path="/install/step/5" >
|
||||
<default key="_controller">Thelia\Controller\Install\InstallController::generalInformation</default>
|
||||
</route>
|
||||
|
||||
<route id="install.step6" path="/install/thanks" >
|
||||
<default key="_controller">Thelia\Controller\Install\InstallController::thanks</default>
|
||||
</route>
|
||||
|
||||
</routes>
|
||||
|
||||
@@ -23,11 +23,12 @@
|
||||
|
||||
namespace Thelia\Controller\Front;
|
||||
use Thelia\Core\Event\AddressCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\AddressEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Form\AddressCreateForm;
|
||||
use Thelia\Form\AddressUpdateForm;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Model\Base\AddressQuery;
|
||||
use Thelia\Model\AddressQuery;
|
||||
use Thelia\Model\Customer;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
@@ -46,14 +47,13 @@ class AddressController extends BaseFrontController
|
||||
*/
|
||||
public function generateModalAction($address_id)
|
||||
{
|
||||
if ($this->getSecurityContext()->hasCustomerUser() === false) {
|
||||
$this->accessDenied();
|
||||
}
|
||||
|
||||
$this->checkAuth();
|
||||
$this->checkXmlHttpRequest();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create controller.
|
||||
* Check if customer is logged in
|
||||
@@ -62,9 +62,7 @@ class AddressController extends BaseFrontController
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
if ($this->getSecurityContext()->hasCustomerUser() === false) {
|
||||
$this->accessDenied()
|
||||
}
|
||||
$this->checkAuth();
|
||||
|
||||
$addressCreate = new AddressCreateForm($this->getRequest());
|
||||
|
||||
@@ -96,20 +94,28 @@ class AddressController extends BaseFrontController
|
||||
}
|
||||
}
|
||||
|
||||
public function updateAction()
|
||||
public function updateViewAction($address_id)
|
||||
{
|
||||
$this->checkAuth();
|
||||
|
||||
$customer = $this->getSecurityContext()->getCustomerUser();
|
||||
$address = AddressQuery::create()->findPk($address_id);
|
||||
|
||||
if(!$address || $customer->getId() != $address->getCustomerId()) {
|
||||
$this->redirectToRoute("home");
|
||||
}
|
||||
|
||||
$this->getParserContext()->set("address_id", $address_id);
|
||||
}
|
||||
|
||||
public function processUpdateAction($address_id)
|
||||
{
|
||||
$this->checkAuth();
|
||||
$request = $this->getRequest();
|
||||
|
||||
if ($this->getSecurityContext()->hasCustomerUser() === false) {
|
||||
$this->redirectToRoute("home");
|
||||
}
|
||||
|
||||
if (null === $address_id = $request->get("address_id")) {
|
||||
$this->redirectToRoute("home");
|
||||
}
|
||||
|
||||
$addressUpdate = new AddressUpdateForm($request);
|
||||
|
||||
|
||||
try {
|
||||
$customer = $this->getSecurityContext()->getCustomerUser();
|
||||
|
||||
@@ -136,7 +142,7 @@ class AddressController extends BaseFrontController
|
||||
} catch (\Exception $e) {
|
||||
$message = sprintf("Sorry, an error occured: %s", $e->getMessage());
|
||||
}
|
||||
|
||||
$this->getParserContext()->set("address_id", $address_id);
|
||||
if ($message !== false) {
|
||||
\Thelia\Log\Tlog::getInstance()->error(sprintf("Error during address creation process : %s", $message));
|
||||
|
||||
@@ -149,6 +155,22 @@ class AddressController extends BaseFrontController
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteAction($address_id)
|
||||
{
|
||||
$this->checkAuth();
|
||||
|
||||
$customer = $this->getSecurityContext()->getCustomerUser();
|
||||
$address = AddressQuery::create()->findPk($address_id);
|
||||
|
||||
if(!$address || $customer->getId() != $address->getCustomerId()) {
|
||||
$this->redirectToRoute("home");
|
||||
}
|
||||
|
||||
$this->dispatch(TheliaEvents::ADDRESS_DELETE, new AddressEvent($address));
|
||||
|
||||
$this->redirectToRoute("customer.account.view");
|
||||
}
|
||||
|
||||
protected function createAddressEvent($form)
|
||||
{
|
||||
return new AddressCreateOrUpdateEvent(
|
||||
@@ -164,7 +186,8 @@ class AddressController extends BaseFrontController
|
||||
$form->get("country")->getData(),
|
||||
$form->get("cellphone")->getData(),
|
||||
$form->get("phone")->getData(),
|
||||
$form->get("company")->getData()
|
||||
$form->get("company")->getData(),
|
||||
$form->get("is_default")->getData()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,4 +50,11 @@ class BaseFrontController extends BaseController
|
||||
{
|
||||
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId, array(), $referenceType), $urlParameters));
|
||||
}
|
||||
|
||||
public function checkAuth()
|
||||
{
|
||||
if($this->getSecurityContext()->hasCustomerUser() === false) {
|
||||
$this->redirectToRoute("customer.login.view");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class BaseInstallController extends BaseController
|
||||
{
|
||||
$parser = $this->container->get("thelia.parser");
|
||||
|
||||
// Define the template thant shoud be used
|
||||
// Define the template that shoud be used
|
||||
$parser->setTemplate("install");
|
||||
|
||||
return $parser;
|
||||
|
||||
@@ -33,18 +33,61 @@ class InstallController extends BaseInstallController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$this->verifyStep(1);
|
||||
//$this->verifyStep(1);
|
||||
|
||||
$this->getSession()->set("step", 1);
|
||||
|
||||
$this->render("index.html");
|
||||
return $this->render("index.html");
|
||||
}
|
||||
|
||||
public function checkPermission()
|
||||
{
|
||||
$this->verifyStep(2);
|
||||
//$this->verifyStep(2);
|
||||
|
||||
$permission = new CheckPermission();
|
||||
//$permission = new CheckPermission();
|
||||
|
||||
$this->getSession()->set("step", 2);
|
||||
return $this->render("step-2.html");
|
||||
}
|
||||
|
||||
public function databaseConnection()
|
||||
{
|
||||
//$this->verifyStep(2);
|
||||
|
||||
//$permission = new CheckPermission();
|
||||
|
||||
$this->getSession()->set("step", 3);
|
||||
return $this->render("step-3.html");
|
||||
}
|
||||
|
||||
public function databaseSelection()
|
||||
{
|
||||
//$this->verifyStep(2);
|
||||
|
||||
//$permission = new CheckPermission();
|
||||
|
||||
$this->getSession()->set("step", 4);
|
||||
return $this->render("step-4.html");
|
||||
}
|
||||
|
||||
public function generalInformation()
|
||||
{
|
||||
//$this->verifyStep(2);
|
||||
|
||||
//$permission = new CheckPermission();
|
||||
|
||||
$this->getSession()->set("step", 5);
|
||||
return $this->render("step-5.html");
|
||||
}
|
||||
|
||||
public function thanks()
|
||||
{
|
||||
//$this->verifyStep(2);
|
||||
|
||||
//$permission = new CheckPermission();
|
||||
|
||||
$this->getSession()->set("step", 6);
|
||||
return $this->render("thanks.html");
|
||||
}
|
||||
|
||||
protected function verifyStep($step)
|
||||
|
||||
@@ -108,7 +108,12 @@ class AddressCreateOrUpdateEvent extends ActionEvent
|
||||
*/
|
||||
protected $address;
|
||||
|
||||
public function __construct($label, $title, $firstname, $lastname, $address1, $address2, $address3, $zipcode, $city, $country, $cellphone, $phone, $company)
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $isDefault;
|
||||
|
||||
public function __construct($label, $title, $firstname, $lastname, $address1, $address2, $address3, $zipcode, $city, $country, $cellphone, $phone, $company, $isDefault = 0)
|
||||
{
|
||||
$this->address1 = $address1;
|
||||
$this->address2 = $address2;
|
||||
@@ -123,6 +128,7 @@ class AddressCreateOrUpdateEvent extends ActionEvent
|
||||
$this->phone = $phone;
|
||||
$this->title = $title;
|
||||
$this->zipcode = $zipcode;
|
||||
$this->isDefault = $isDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -229,6 +235,16 @@ class AddressCreateOrUpdateEvent extends ActionEvent
|
||||
return $this->zipcode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getIsDefault()
|
||||
{
|
||||
return $this->isDefault;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param \Thelia\Model\Customer $customer
|
||||
*/
|
||||
|
||||
@@ -129,6 +129,11 @@ final class TheliaEvents
|
||||
*/
|
||||
const ADDRESS_UPDATE = "action.updateAddress";
|
||||
|
||||
/**
|
||||
* sent on address removal
|
||||
*/
|
||||
const ADDRESS_DELETE = "action.deleteAddress";
|
||||
|
||||
const BEFORE_CREATEADDRESS = "action.before_createAddress";
|
||||
const AFTER_CREATEADDRESS = "action.after_createAddress";
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ class AddressCreateForm extends BaseForm
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Address label *"),
|
||||
"label" => Translator::getInstance()->trans("Address label"),
|
||||
"label_attr" => array(
|
||||
"for" => "label_create"
|
||||
),
|
||||
@@ -154,11 +154,17 @@ class AddressCreateForm extends BaseForm
|
||||
)
|
||||
))
|
||||
->add("company", "text", array(
|
||||
"label" => Translator::getInstance()->trans("Compagny"),
|
||||
"label" => Translator::getInstance()->trans("Company"),
|
||||
"label_attr" => array(
|
||||
"for" => "company_create"
|
||||
)
|
||||
))
|
||||
->add("is_default", "integer", array(
|
||||
"label" => Translator::getInstance()->trans("Make this address has my primary address"),
|
||||
"label_attr" => array(
|
||||
"for" => "default_address"
|
||||
)
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,9 +34,10 @@ abstract class BaseInstall
|
||||
*/
|
||||
public function __construct($verifyInstall = true)
|
||||
{
|
||||
/* TODO : activate this part
|
||||
if (file_exists(THELIA_ROOT . '/local/config/database.yml') && $verifyInstall) {
|
||||
throw new AlreadyInstallException("Thelia is already installed");
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
$this->exec();
|
||||
|
||||
@@ -7,10 +7,24 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Core\Event\AddressEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Model\Base\Address as BaseAddress;
|
||||
use Thelia\Model\AddressQuery;
|
||||
|
||||
class Address extends BaseAddress {
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
|
||||
/**
|
||||
* put the the current address as default one
|
||||
*/
|
||||
public function makeItDefault()
|
||||
{
|
||||
|
||||
AddressQuery::create()->filterByCustomerId($this->getCustomerId())
|
||||
->update(array('IsDefault' => '0'));
|
||||
|
||||
$this->setIsDefault(1);
|
||||
$this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Code to be run before inserting to database
|
||||
* @param ConnectionInterface $con
|
||||
|
||||
@@ -73,11 +73,16 @@ class Calculator
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTaxAmount($untaxedPrice)
|
||||
public function getTaxAmountFromUntaxedPrice($untaxedPrice)
|
||||
{
|
||||
return $this->getTaxedPrice($untaxedPrice) - $untaxedPrice;
|
||||
}
|
||||
|
||||
public function getTaxAmountFromTaxedPrice($taxedPrice)
|
||||
{
|
||||
return $taxedPrice - $this->getUntaxedPrice($taxedPrice);
|
||||
}
|
||||
|
||||
public function getTaxedPrice($untaxedPrice)
|
||||
{
|
||||
if(null === $this->taxRulesCollection) {
|
||||
@@ -111,4 +116,72 @@ class Calculator
|
||||
|
||||
return $taxedPrice;
|
||||
}
|
||||
|
||||
public function getUntaxedPrice($taxedPrice)
|
||||
{
|
||||
if(null === $this->taxRulesCollection) {
|
||||
throw new TaxEngineException('Tax rules collection is empty in Calculator::getTaxAmount', TaxEngineException::UNDEFINED_TAX_RULES_COLLECTION);
|
||||
}
|
||||
|
||||
if(false === filter_var($taxedPrice, FILTER_VALIDATE_FLOAT)) {
|
||||
throw new TaxEngineException('BAD AMOUNT FORMAT', TaxEngineException::BAD_AMOUNT_FORMAT);
|
||||
}
|
||||
|
||||
$taxRule = $this->taxRulesCollection->getLast();
|
||||
|
||||
$untaxedPrice = $taxedPrice;
|
||||
$currentPosition = (int)$taxRule->getTaxRuleCountryPosition();
|
||||
$currentFixTax = 0;
|
||||
$currentTaxFactor = 0;
|
||||
|
||||
do {
|
||||
$position = (int)$taxRule->getTaxRuleCountryPosition();
|
||||
|
||||
$taxType = $taxRule->getTypeInstance();
|
||||
$taxType->loadRequirements( $taxRule->getRequirements() );
|
||||
|
||||
if($currentPosition !== $position) {
|
||||
$untaxedPrice -= $currentFixTax;
|
||||
$untaxedPrice = $untaxedPrice / (1+$currentTaxFactor);
|
||||
$currentFixTax = 0;
|
||||
$currentTaxFactor = 0;
|
||||
$currentPosition = $position;
|
||||
}
|
||||
|
||||
$currentFixTax += $taxType->fixAmountRetriever();
|
||||
$currentTaxFactor += $taxType->pricePercentRetriever();
|
||||
|
||||
|
||||
} while($taxRule = $this->taxRulesCollection->getPrevious());
|
||||
|
||||
$untaxedPrice -= $currentFixTax;
|
||||
$untaxedPrice = $untaxedPrice / (1+$currentTaxFactor);
|
||||
|
||||
/*do {
|
||||
|
||||
$taxType = $taxRule->getTypeInstance();
|
||||
$taxType->loadRequirements( $taxRule->getRequirements() );
|
||||
|
||||
$untaxedPrice -= $taxType->fixAmountRetriever();
|
||||
|
||||
} while($taxRule = $this->taxRulesCollection->getPrevious());
|
||||
|
||||
$taxRule = $this->taxRulesCollection->getLast();
|
||||
|
||||
$currentTaxFactor = 0;
|
||||
do {
|
||||
|
||||
$taxType = $taxRule->getTypeInstance();
|
||||
$taxType->loadRequirements( $taxRule->getRequirements() );
|
||||
|
||||
$currentTaxFactor += $taxType->pricePercentRetriever($untaxedPrice);
|
||||
|
||||
$toto = true;
|
||||
|
||||
} while($taxRule = $this->taxRulesCollection->getPrevious());
|
||||
|
||||
$untaxedPrice = $untaxedPrice / (1+$currentTaxFactor);*/
|
||||
|
||||
return $untaxedPrice;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,10 @@ abstract class BaseTaxType
|
||||
|
||||
public abstract function calculate($untaxedPrice);
|
||||
|
||||
public abstract function pricePercentRetriever();
|
||||
|
||||
public abstract function fixAmountRetriever();
|
||||
|
||||
public abstract function getRequirementsList();
|
||||
|
||||
public function loadRequirements($requirementsValues)
|
||||
|
||||
@@ -37,6 +37,16 @@ class featureSlicePercentTaxType extends BaseTaxType
|
||||
|
||||
}
|
||||
|
||||
public function pricePercentRetriever()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function fixAmountRetriever()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function getRequirementsList()
|
||||
{
|
||||
return array(
|
||||
|
||||
@@ -36,6 +36,16 @@ class FixAmountTaxType extends BaseTaxType
|
||||
return $this->getRequirement("amount");
|
||||
}
|
||||
|
||||
public function pricePercentRetriever()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function fixAmountRetriever()
|
||||
{
|
||||
return $this->getRequirement("amount");
|
||||
}
|
||||
|
||||
public function getRequirementsList()
|
||||
{
|
||||
return array(
|
||||
|
||||
@@ -36,6 +36,16 @@ class PricePercentTaxType extends BaseTaxType
|
||||
return $untaxedPrice * $this->getRequirement("percent") * 0.01;
|
||||
}
|
||||
|
||||
public function pricePercentRetriever()
|
||||
{
|
||||
return ($this->getRequirement("percent") * 0.01);
|
||||
}
|
||||
|
||||
public function fixAmountRetriever()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getRequirementsList()
|
||||
{
|
||||
return array(
|
||||
@@ -43,3 +53,5 @@ class PricePercentTaxType extends BaseTaxType
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//600 / (1 + 0,10 + 0,10) =/= 600 / (1 + 0,10 ) + 600 / (1 + 0,10 )
|
||||
@@ -112,17 +112,17 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase
|
||||
* @expectedException \Thelia\Exception\TaxEngineException
|
||||
* @expectedExceptionCode 503
|
||||
*/
|
||||
public function testGetTaxAmountBadTaxRulesCollection()
|
||||
public function testGetTaxedPriceBadTaxRulesCollection()
|
||||
{
|
||||
$calculator = new Calculator();
|
||||
$calculator->getTaxAmount(500);
|
||||
$calculator->getTaxedPrice(500);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Thelia\Exception\TaxEngineException
|
||||
* @expectedExceptionCode 601
|
||||
*/
|
||||
public function testGetTaxAmountBadAmount()
|
||||
public function testGetTaxedPriceBadAmount()
|
||||
{
|
||||
$taxRulesCollection = new ObjectCollection();
|
||||
|
||||
@@ -131,12 +131,11 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase
|
||||
$rewritingUrlQuery = $this->getProperty('taxRulesCollection');
|
||||
$rewritingUrlQuery->setValue($calculator, $taxRulesCollection);
|
||||
|
||||
$calculator->getTaxAmount('foo');
|
||||
$calculator->getTaxedPrice('foo');
|
||||
}
|
||||
|
||||
public function testGetTaxAmountAndGetTaxedPrice()
|
||||
public function testGetTaxedPriceAndGetTaxAmountFromUntaxedPrice()
|
||||
{
|
||||
/* consecutives taxes */
|
||||
$taxRulesCollection = new ObjectCollection();
|
||||
$taxRulesCollection->setModel('\Thelia\Model\Tax');
|
||||
|
||||
@@ -144,14 +143,24 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase
|
||||
$tax->setType('PricePercentTaxType')
|
||||
->setRequirements(array('percent' => 10))
|
||||
->setVirtualColumn('taxRuleCountryPosition', 1);
|
||||
|
||||
$taxRulesCollection->append($tax);
|
||||
|
||||
$tax = new Tax();
|
||||
$tax->setType('PricePercentTaxType')
|
||||
->setRequirements(array('percent' => 8))
|
||||
->setVirtualColumn('taxRuleCountryPosition', 1);
|
||||
$taxRulesCollection->append($tax);
|
||||
|
||||
$tax = new Tax();
|
||||
$tax->setType('FixAmountTaxType')
|
||||
->setRequirements(array('amount' => 5))
|
||||
->setVirtualColumn('taxRuleCountryPosition', 2);
|
||||
$taxRulesCollection->append($tax);
|
||||
|
||||
$tax = new Tax();
|
||||
$tax->setType('PricePercentTaxType')
|
||||
->setRequirements(array('percent' => 1))
|
||||
->setVirtualColumn('taxRuleCountryPosition', 3);
|
||||
$taxRulesCollection->append($tax);
|
||||
|
||||
$calculator = new Calculator();
|
||||
@@ -159,19 +168,22 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase
|
||||
$rewritingUrlQuery = $this->getProperty('taxRulesCollection');
|
||||
$rewritingUrlQuery->setValue($calculator, $taxRulesCollection);
|
||||
|
||||
$taxAmount = $calculator->getTaxAmount(500);
|
||||
$taxAmount = $calculator->getTaxAmountFromUntaxedPrice(500);
|
||||
$taxedPrice = $calculator->getTaxedPrice(500);
|
||||
|
||||
/*
|
||||
* expect :
|
||||
* tax 1 = 500*0.10 = 50 // amout with tax 1 : 550
|
||||
* tax 2 = 550*0.08 = 44 // amout with tax 2 : 594
|
||||
* total tax amount = 94
|
||||
* tax 1 = 500*0.10 = 50 + 500*0.08 = 40 // amount with tax 1 : 590
|
||||
* tax 2 = 5 // amount with tax 2 : 595
|
||||
* tax 3 = 595 * 0.01 = 5.95 // amount with tax 3 : 600.95
|
||||
* total tax amount = 100.95
|
||||
*/
|
||||
$this->assertEquals(94, $taxAmount);
|
||||
$this->assertEquals(594, $taxedPrice);
|
||||
$this->assertEquals(100.95, $taxAmount);
|
||||
$this->assertEquals(600.95, $taxedPrice);
|
||||
}
|
||||
|
||||
/* same position taxes */
|
||||
public function testGetUntaxedPriceAndGetTaxAmountFromTaxedPrice()
|
||||
{
|
||||
$taxRulesCollection = new ObjectCollection();
|
||||
$taxRulesCollection->setModel('\Thelia\Model\Tax');
|
||||
|
||||
@@ -179,14 +191,24 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase
|
||||
$tax->setType('PricePercentTaxType')
|
||||
->setRequirements(array('percent' => 10))
|
||||
->setVirtualColumn('taxRuleCountryPosition', 1);
|
||||
|
||||
$taxRulesCollection->append($tax);
|
||||
|
||||
$tax = new Tax();
|
||||
$tax->setType('PricePercentTaxType')
|
||||
->setRequirements(array('percent' => 8))
|
||||
->setVirtualColumn('taxRuleCountryPosition', 1);
|
||||
$taxRulesCollection->append($tax);
|
||||
|
||||
$tax = new Tax();
|
||||
$tax->setType('FixAmountTaxType')
|
||||
->setRequirements(array('amount' => 5))
|
||||
->setVirtualColumn('taxRuleCountryPosition', 2);
|
||||
$taxRulesCollection->append($tax);
|
||||
|
||||
$tax = new Tax();
|
||||
$tax->setType('PricePercentTaxType')
|
||||
->setRequirements(array('percent' => 1))
|
||||
->setVirtualColumn('taxRuleCountryPosition', 3);
|
||||
$taxRulesCollection->append($tax);
|
||||
|
||||
$calculator = new Calculator();
|
||||
@@ -194,16 +216,17 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase
|
||||
$rewritingUrlQuery = $this->getProperty('taxRulesCollection');
|
||||
$rewritingUrlQuery->setValue($calculator, $taxRulesCollection);
|
||||
|
||||
$taxAmount = $calculator->getTaxAmount(500);
|
||||
$taxedPrice = $calculator->getTaxedPrice(500);
|
||||
$taxAmount = $calculator->getTaxAmountFromTaxedPrice(600.95);
|
||||
$untaxedPrice = $calculator->getUntaxedPrice(600.95);
|
||||
|
||||
/*
|
||||
* expect :
|
||||
* tax 1 = 500*0.10 = 50 // amout with tax 1 : 550
|
||||
* tax 2 = 500*0.08 = 40 // amout with tax 2 : 590
|
||||
* total tax amount = 90
|
||||
* tax 3 = 600.95 - 600.95 / (1 + 0.01) = 5,95 // amount without tax 3 : 595
|
||||
* tax 2 = 5 // amount without tax 2 : 590
|
||||
* tax 1 = 590 - 590 / (1 + 0.08 + 0.10) = 90 // amount without tax 1 : 500
|
||||
* total tax amount = 100.95
|
||||
*/
|
||||
$this->assertEquals(90, $taxAmount);
|
||||
$this->assertEquals(590, $taxedPrice);
|
||||
$this->assertEquals(100.95, $taxAmount);
|
||||
$this->assertEquals(500, $untaxedPrice);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user