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

@@ -19,12 +19,11 @@ use Symfony\Component\Translation\TranslatorInterface;
use Thelia\Condition\ConditionEvaluator;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\Template\ParserInterface;
use Thelia\Core\Template\TemplateHelper;
use Thelia\Log\Tlog;
use Thelia\Model\AddressQuery;
use Thelia\Model\Country;
use Thelia\Model\Coupon;
use Thelia\Model\CouponQuery;
use Thelia\Cart\CartTrait;
use Thelia\Model\Currency;
use Thelia\Model\CurrencyQuery;
@@ -37,10 +36,6 @@ use Thelia\Model\CurrencyQuery;
*/
class BaseFacade implements FacadeInterface
{
use CartTrait {
CartTrait::getCart as getCartFromTrait;
}
/** @var ContainerInterface Service Container */
protected $container = null;
@@ -67,7 +62,7 @@ class BaseFacade implements FacadeInterface
*/
public function getCart()
{
return $this->getCartFromTrait($this->getDispatcher(), $this->getRequest());
return $this->getRequest()->getSession()->getSessionCart($this->getDispatcher());
}
/**
@@ -78,7 +73,9 @@ class BaseFacade implements FacadeInterface
public function getDeliveryAddress()
{
try {
return AddressQuery::create()->findPk($this->getRequest()->getSession()->getOrder()->getChoosenDeliveryAddress());
return AddressQuery::create()->findPk(
$this->getRequest()->getSession()->getOrder()->getChoosenDeliveryAddress()
);
} catch (\Exception $ex) {
throw new \LogicException("Failed to get delivery address (" . $ex->getMessage() . ")");
}
@@ -117,13 +114,15 @@ class BaseFacade implements FacadeInterface
/**
* Return Products total price
*
* @param bool $withItemsInPromo if true, the discounted items are included in the total
*
* @return float
*/
public function getCartTotalPrice($withItemsInPromo = true)
{
$total = 0;
$cartItems = $this->getRequest()->getSession()->getCart()->getCartItems();
$cartItems = $this->getRequest()->getSession()->getSessionCart($this->getDispatcher())->getCartItems();
foreach ($cartItems as $cartItem) {
if ($withItemsInPromo || ! $cartItem->getPromo()) {
@@ -137,7 +136,7 @@ class BaseFacade implements FacadeInterface
public function getCartTotalTaxPrice($withItemsInPromo = true)
{
$taxCountry = $this->getContainer()->get('thelia.taxEngine')->getDeliveryCountry();
$cartItems = $this->getRequest()->getSession()->getCart()->getCartItems();
$cartItems = $this->getRequest()->getSession()->getSessionCart($this->getDispatcher())->getCartItems();
$total = 0;
@@ -175,7 +174,19 @@ class BaseFacade implements FacadeInterface
*/
public function getNbArticlesInCart()
{
return count($this->getRequest()->getSession()->getCart()->getCartItems());
return count($this->getRequest()->getSession()->getSessionCart($this->getDispatcher())->getCartItems());
}
public function getNbArticlesInCartIncludeQuantity()
{
$cartItems = $this->getCart()->getCartItems();
$quantity = 0;
foreach ($cartItems as $cartItem) {
$quantity += $cartItem->getQuantity();
}
return $quantity;
}
/**
@@ -190,11 +201,23 @@ class BaseFacade implements FacadeInterface
if (null === $couponCodes) {
return array();
}
/** @var CouponFactory $couponFactory */
$couponFactory = $this->container->get('thelia.coupon.factory');
$coupons = array();
$coupons = [];
foreach ($couponCodes as $couponCode) {
$coupons[] = $couponFactory->buildCouponFromCode($couponCode);
// Only valid coupons are returned
try {
if (false !== $couponInterface = $couponFactory->buildCouponFromCode($couponCode)) {
$coupons[] = $couponInterface;
}
} catch (\Exception $ex) {
// Just ignore the coupon and log the problem, just in case someone realize it.
Tlog::getInstance()->warning(
sprintf("Coupon %s ignored, exception occurred: %s", $couponCode, $ex->getMessage())
);
}
}
return $coupons;
@@ -245,7 +268,9 @@ class BaseFacade implements FacadeInterface
$this->parser = $this->container->get('thelia.parser');
// Define the current back-office template that should be used
$this->parser->setTemplateDefinition(TemplateHelper::getInstance()->getActiveAdminTemplate());
$this->parser->setTemplateDefinition(
$this->parser->getTemplateHelper()->getActiveAdminTemplate()
);
}
return $this->parser;
@@ -269,7 +294,7 @@ class BaseFacade implements FacadeInterface
*/
public function getRequest()
{
return $this->container->get('request');
return $this->container->get('request_stack')->getCurrentRequest();
}
/**
@@ -303,4 +328,25 @@ class BaseFacade implements FacadeInterface
{
return $this->container->get('event_dispatcher');
}
/**
* Add a coupon in session
* @param $couponCode
* @return mixed|void
*/
public function pushCouponInSession($couponCode)
{
$consumedCoupons = $this->getRequest()->getSession()->getConsumedCoupons();
if (!isset($consumedCoupons) || !$consumedCoupons) {
$consumedCoupons = array();
}
if (!isset($consumedCoupons[$couponCode])) {
// Prevent accumulation of the same Coupon on a Checkout
$consumedCoupons[$couponCode] = $couponCode;
$this->getRequest()->getSession()->setConsumedCoupons($consumedCoupons);
}
}
}