<?php
namespace App\Services;
use App\Entity\Cart;
use App\Entity\CartProduct;
use App\Entity\CartProductEquipment;
use App\Entity\CartProductParameterValue;
use App\Entity\Currency;
use App\Entity\Language;
use App\Entity\Product;
use App\Entity\ProductLangParam;
use App\Entity\ProductPriceVariants;
use App\Entity\RebateCode;
use App\Repository\CartRepository;
use App\Repository\DeliveryCountryRepository;
use App\Repository\DeliveryMethodRepository;
use App\Repository\PaymentMethodRepository;
use App\Exception\CartException;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class PasswordProtectedService
{
private $em;
private $translator;
private $cartRepository;
private $tokenStorage;
private $session;
private $productManager;
/**
* CartService constructor.
* @param EntityManagerInterface $em
* @param TranslatorInterface $translator
* @param CartRepository $cartRepository
*/
public function __construct(EntityManagerInterface $em, TranslatorInterface $translator, CartRepository $cartRepository, TokenStorageInterface $tokenStorage, SessionInterface $session, ProductManager $productManager) {
$this->em = $em;
$this->translator = $translator;
$this->cartRepository = $cartRepository;
$this->tokenStorage = $tokenStorage;
$this->session = $session;
$this->productManager = $productManager;
}
/**
* Get cart session
* @return mixed
*/
public function getCartSession() {
return $this->session->get('cart_session');
}
/**
* @return string locale
*/
public function getLocale() {
return $this->session->get('_locale');
}
public function isPasswordProtected() {
if ($this->session->get('password_provided')) {
return false;
}
/** @var $language Language */
$language = $this->em->getRepository(Language::class)->findOneBy(['locale'=>$this->getLocale(), 'deletedBy'=>null]);
if ($language and $language->getPasswordProtected()) {
return true;
}
return false;
}
public function getSitePassword() {
/** @var $language Language */
$language = $this->em->getRepository(Language::class)->findOneBy(['locale'=>$this->getLocale(), 'deletedBy'=>null]);
return $language->getPassword();
}
}