Inital commit

This commit is contained in:
2020-11-19 15:36:28 +01:00
parent 71f32f83d3
commit 66ce4ee218
18077 changed files with 2166122 additions and 35184 deletions

View File

@@ -12,10 +12,13 @@
namespace Thelia\TaxEngine;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\RequestStack;
use Thelia\Core\HttpFoundation\Session\Session;
use Thelia\Model\AddressQuery;
use Thelia\Model\Country;
use Thelia\Model\CountryQuery;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Model\Customer;
use Thelia\Model\State;
/**
* Class TaxEngine
@@ -26,18 +29,17 @@ use Thelia\Core\HttpFoundation\Request;
class TaxEngine
{
protected $taxCountry = null;
protected $taxState = null;
protected $typeList = null;
protected $taxTypesDirectories = array();
/**
* @var Session $session
*/
protected $session = null;
/** @var RequestStack */
protected $requestStack;
public function __construct(Request $request)
public function __construct(RequestStack $requestStack)
{
$this->session = $request->getSession();
$this->requestStack = $requestStack;
// Intialize the defaults Tax Types
$this->taxTypesDirectories['Thelia\\TaxEngine\\TaxType'] = __DIR__ . DS . "TaxType";
@@ -69,20 +71,19 @@ class TaxEngine
public function getTaxTypeList()
{
if ($this->typeList === null) {
$this->typeList = array();
foreach ($this->taxTypesDirectories as $namespace => $directory) {
try {
$directoryIterator = new \DirectoryIterator($directory);
foreach ($directoryIterator as $fileinfo) {
if ($fileinfo->isFile()) {
$fileName = $fileinfo->getFilename();
$className = substr($fileName, 0, (1+strlen($fileinfo->getExtension())) * -1);
$extension = $fileinfo->getExtension();
if (strtolower($extension) !== 'php') {
continue;
}
$className = $fileinfo->getBaseName('.php');
try {
$fullyQualifiedClassName = "$namespace\\$className";
@@ -112,29 +113,60 @@ class TaxEngine
* Then look at the current customer default address country
* Else look at the default website country
* @return null|TaxEngine
* @return null|Country
*/
public function getDeliveryCountry()
{
if (null === $this->taxCountry) {
/* is there a logged in customer ? */
if (null !== $customer = $this->session->getCustomerUser()) {
if (null !== $this->session->getOrder()
&& null !== $this->session->getOrder()->getChoosenDeliveryAddress()
&& null !== $currentDeliveryAddress = AddressQuery::create()->findPk($this->session->getOrder()->getChoosenDeliveryAddress())) {
/** @var Customer $customer */
if (null !== $customer = $this->getSession()->getCustomerUser()) {
if (null !== $this->getSession()->getOrder()
&& null !== $this->getSession()->getOrder()->getChoosenDeliveryAddress()
&& null !== $currentDeliveryAddress = AddressQuery::create()->findPk($this->getSession()->getOrder()->getChoosenDeliveryAddress())) {
$this->taxCountry = $currentDeliveryAddress->getCountry();
$this->taxState = $currentDeliveryAddress->getState();
} else {
$customerDefaultAddress = $customer->getDefaultAddress();
$this->taxCountry = $customerDefaultAddress->getCountry();
$this->taxState = $customerDefaultAddress->getState();
}
}
if (null == $this->taxCountry) {
$this->taxCountry = CountryQuery::create()->findOneByByDefault(1);
$this->taxState = null;
}
}
return $this->taxCountry;
}
/**
* Find Tax State Id
*
* First look for a picked delivery address state
* Then look at the current customer default address state
* Else null
* @return null|State
* @since 2.3.0-alpha1
*/
public function getDeliveryState()
{
if (null === $this->taxCountry) {
/* is there a logged in customer ? */
$this->getDeliveryCountry();
}
return $this->taxState;
}
/**
* @return Session
*/
protected function getSession()
{
return $this->requestStack->getCurrentRequest()->getSession();
}
}