$builder | $builder | ||||
->add('reductionCredit', EntityType::class, array( | ->add('reductionCredit', EntityType::class, array( | ||||
'class' => $reductionCreditClass->getName(), | 'class' => $reductionCreditClass->getName(), | ||||
'choices' => $this->orderUtils->getReductionCreditByUser($entity->getUser()), | |||||
'choices' => $reductionCreditRepo->getReductionCreditByUser($entity->getUser()), | |||||
//'choices' => $this->orderUtils->getReductionCreditsAvailable($entity), | //'choices' => $this->orderUtils->getReductionCreditsAvailable($entity), | ||||
'required' => true, | 'required' => true, |
public function buildForm(FormBuilderInterface $builder, array $options) | public function buildForm(FormBuilderInterface $builder, array $options) | ||||
{ | { | ||||
$reductionCartRepo = $this->em->getRepository(ReductionCartInterface::class); | $reductionCartRepo = $this->em->getRepository(ReductionCartInterface::class); | ||||
$types = array(); | |||||
foreach ($reductionCartRepo->getValuesOfFieldType() as $type){ | foreach ($reductionCartRepo->getValuesOfFieldType() as $type){ | ||||
$types['field.ReductionCart.typeOptions.'.$type['type']] = $type['type']; | $types['field.ReductionCart.typeOptions.'.$type['type']] = $type['type']; | ||||
} | } |
*/ | */ | ||||
protected $merchant; | protected $merchant; | ||||
/** | |||||
* @ORM\Column(type="text", nullable=true) | |||||
*/ | |||||
protected $deliveryInfos; | |||||
public function __toString() | public function __toString() | ||||
{ | { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getDeliveryInfos(): ?string | |||||
{ | |||||
return $this->deliveryInfos; | |||||
} | |||||
public function setDeliveryInfos(?string $deliveryInfos): self | |||||
{ | |||||
$this->deliveryInfos = $deliveryInfos; | |||||
return $this; | |||||
} | |||||
} | } |
*/ | */ | ||||
protected $news; | protected $news; | ||||
/** | |||||
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\PageInterface", mappedBy="merchant", orphanRemoval=true) | |||||
*/ | |||||
protected $pages; | |||||
/** | /** | ||||
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\NewsletterInterface", mappedBy="merchant") | * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\NewsletterInterface", mappedBy="merchant") | ||||
*/ | */ | ||||
return $this; | return $this; | ||||
} | } | ||||
/** | |||||
* @return Collection|Page[] | |||||
*/ | |||||
public function getPages(): Collection | |||||
{ | |||||
return $this->pages; | |||||
} | |||||
public function addPage(Page $page): self | |||||
{ | |||||
if (!$this->pages->contains($page)) { | |||||
$this->pages[] = $page; | |||||
$page->setMerchant($this); | |||||
} | |||||
return $this; | |||||
} | |||||
public function removePage(Page $page): self | |||||
{ | |||||
if ($this->pages->contains($page)) { | |||||
$this->pages->removeElement($page); | |||||
// set the owning side to null (unless already changed) | |||||
if ($page->getMerchant() === $this) { | |||||
$page->setMerchant(null); | |||||
} | |||||
} | |||||
return $this; | |||||
} | |||||
/** | /** | ||||
* @return Collection|Newsletter[] | * @return Collection|Newsletter[] | ||||
*/ | */ |
/** | /** | ||||
* @ORM\Column(type="text", nullable=true) | * @ORM\Column(type="text", nullable=true) | ||||
*/ | */ | ||||
protected $infosDelivery; | |||||
protected $deliveryInfos; | |||||
/** | /** | ||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\OrderStatusInterface") | * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\OrderStatusInterface") | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getInfosDelivery(): ?string | |||||
public function getDeliveryInfos(): ?string | |||||
{ | { | ||||
return $this->infosDelivery; | |||||
return $this->deliveryInfos; | |||||
} | } | ||||
public function setInfosDelivery(?string $infosDelivery): self | |||||
public function setDeliveryInfos(?string $deliveryInfos): self | |||||
{ | { | ||||
$this->infosDelivery = $infosDelivery; | |||||
$this->deliveryInfos = $deliveryInfos; | |||||
return $this; | return $this; | ||||
} | } |
namespace Lc\ShopBundle\Model; | namespace Lc\ShopBundle\Model; | ||||
use App\Entity\Hub; | |||||
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
use Lc\ShopBundle\Context\FilterMerchantInterface; | |||||
/** | /** | ||||
* @ORM\MappedSuperclass() | * @ORM\MappedSuperclass() | ||||
*/ | */ | ||||
abstract class Page extends AbstractDocumentEntity | |||||
abstract class Page extends AbstractDocumentEntity implements FilterMerchantInterface | |||||
{ | { | ||||
/** | /** | ||||
* @ORM\Column(type="text", nullable=true) | * @ORM\Column(type="text", nullable=true) | ||||
*/ | */ | ||||
protected $content; | protected $content; | ||||
/** | |||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface", inversedBy="pages") | |||||
* @ORM\JoinColumn(nullable=false) | |||||
*/ | |||||
protected $merchant; | |||||
public function __toString() | public function __toString() | ||||
{ | { | ||||
return $this->getTitle() ; | return $this->getTitle() ; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getMerchant(): ?Hub | |||||
{ | |||||
return $this->merchant; | |||||
} | |||||
public function setMerchant(?Hub $merchant): self | |||||
{ | |||||
$this->merchant = $merchant; | |||||
return $this; | |||||
} | |||||
} | } |
public function findCartCurrent($params) | public function findCartCurrent($params) | ||||
{ | { | ||||
$query = $this->createQueryBuilder('e') ; | |||||
$query = $this->findByMerchantQuery() ; | |||||
if(isset($params['user'])) { | if(isset($params['user'])) { | ||||
$query->andWhere('e.user = :user')->setParameter('user', $params['user']) ; | $query->andWhere('e.user = :user')->setParameter('user', $params['user']) ; | ||||
$query->leftJoin('e.orderStatusHistories', 'orderStatusHistories') | $query->leftJoin('e.orderStatusHistories', 'orderStatusHistories') | ||||
->andWhere('SIZE(e.orderStatusHistories) = 0') ; | ->andWhere('SIZE(e.orderStatusHistories) = 0') ; | ||||
return $query->getQuery()->getOneOrNullResult() ; | |||||
$results = $query->getQuery()->getResult() ; | |||||
if($results) { | |||||
return $results[0] ; | |||||
} | |||||
return null ; | |||||
} | } | ||||
public function findAllBy($params = []) | public function findAllBy($params = []) | ||||
$query->andWhere('e.user = :user')->setParameter('user', $params['user']) ; | $query->andWhere('e.user = :user')->setParameter('user', $params['user']) ; | ||||
} | } | ||||
$query->orderBy('e.createdAt', 'DESC') ; | |||||
$query->orderBy('e.id', 'DESC') ; | |||||
return $query->getQuery()->getResult() ; | return $query->getQuery()->getResult() ; | ||||
} | } |
warningMessageType: Type de message d'avertissement | warningMessageType: Type de message d'avertissement | ||||
warningMessageTypeOptions: | warningMessageTypeOptions: | ||||
warning: Attention (jaune) | warning: Attention (jaune) | ||||
info: Information (bleu) | |||||
info: Information (gris) | |||||
error: Erreur (rouge) | error: Erreur (rouge) | ||||
success: Succès (vert) | success: Succès (vert) | ||||
warningMessage: Contenu du message d'avertissement | warningMessage: Contenu du message d'avertissement | ||||
devAlias: Alias | devAlias: Alias | ||||
merchantConfigs: Configuration | merchantConfigs: Configuration | ||||
taxRate: Règle de taxe | taxRate: Règle de taxe | ||||
deliveryTaxRate: Règle de taxe (livraison) | |||||
value: Valeur | value: Valeur | ||||
behaviorAddToCart: Ajout au panier | behaviorAddToCart: Ajout au panier | ||||
taxIncluded: TVA incluse | taxIncluded: TVA incluse |
use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | use Lc\ShopBundle\Context\MerchantUtilsInterface; | ||||
use Lc\ShopBundle\Context\OrderReductionCartInterface; | use Lc\ShopBundle\Context\OrderReductionCartInterface; | ||||
use Lc\ShopBundle\Context\OrderProductInterface; | |||||
use Lc\ShopBundle\Context\OrderShopInterface; | use Lc\ShopBundle\Context\OrderShopInterface; | ||||
use Lc\ShopBundle\Context\OrderStatusHistoryInterface; | use Lc\ShopBundle\Context\OrderStatusHistoryInterface; | ||||
use Lc\ShopBundle\Context\OrderStatusInterface; | use Lc\ShopBundle\Context\OrderStatusInterface; | ||||
use Lc\ShopBundle\Context\ReductionCartInterface; | use Lc\ShopBundle\Context\ReductionCartInterface; | ||||
use Lc\ShopBundle\Context\ReductionCreditInterface; | use Lc\ShopBundle\Context\ReductionCreditInterface; | ||||
use Lc\ShopBundle\Context\UserInterface; | use Lc\ShopBundle\Context\UserInterface; | ||||
use Symfony\Component\HttpFoundation\Session\SessionInterface; | |||||
use Symfony\Component\Security\Core\Security; | use Symfony\Component\Security\Core\Security; | ||||
class OrderUtils | class OrderUtils | ||||
$this->productFamilyUtils = $productFamilyUtils; | $this->productFamilyUtils = $productFamilyUtils; | ||||
} | } | ||||
public function getCartCurrent() | public function getCartCurrent() | ||||
{ | { | ||||
$paramsSearchOrderShop = []; | $paramsSearchOrderShop = []; | ||||
$user = $this->security->getUser(); | $user = $this->security->getUser(); | ||||
$visitor = $this->userUtils->getVisitorCurrent(); | $visitor = $this->userUtils->getVisitorCurrent(); | ||||
$orderShop = null; | |||||
$orderShopUser = null; | |||||
$orderShopVisitor = null; | |||||
if ($user) { | if ($user) { | ||||
$paramsSearchOrderShop['user'] = $user; | |||||
$orderShopUser = $this->orderShopRepo->findCartCurrent([ | |||||
'user' => $user | |||||
]); | |||||
} | } | ||||
if ($visitor) { | if ($visitor) { | ||||
$paramsSearchOrderShop['visitor'] = $visitor; | |||||
$orderShopVisitor = $this->orderShopRepo->findCartCurrent([ | |||||
'visitor' => $visitor | |||||
]); | |||||
} | } | ||||
$orderShop = $this->orderShopRepo->findCartCurrent($paramsSearchOrderShop); | |||||
if ($orderShopUser || $orderShopVisitor) { | |||||
if ($orderShopUser && $orderShopVisitor && $orderShopUser != $orderShopVisitor && $orderShopVisitor->getOrderProducts() && count($orderShopVisitor->getOrderProducts())) { | |||||
$orderShop = $this->mergeOrderShops($orderShopUser, $orderShopVisitor); | |||||
$this->session->getFlashBag()->add('success', "Votre panier visiteur vient d'être fusionné avec votre panier client."); | |||||
} else { | |||||
$orderShop = ($orderShopUser) ? $orderShopUser : $orderShopVisitor; | |||||
} | |||||
} | |||||
if (!$orderShop) { | |||||
$orderShop = $this->createOrderShop([ | |||||
'user' => $user, | |||||
'visitor' => $visitor, | |||||
'merchant' => $this->merchantUtils->getMerchantCurrent() | |||||
]); | |||||
if (!$user && !$visitor) { | |||||
$this->session->getFlashBag()->add('error', 'Vous devez accepter les cookies ou vous connecter pour créer un panier.'); | |||||
} else { | |||||
if (!$orderShop) { | |||||
$orderShop = $this->createOrderShop([ | |||||
'user' => $user, | |||||
'visitor' => $visitor, | |||||
'merchant' => $this->merchantUtils->getMerchantCurrent() | |||||
]); | |||||
} | |||||
} | } | ||||
return $orderShop; | return $orderShop; | ||||
return $orderShop; | return $orderShop; | ||||
} | } | ||||
public function addOrderProduct($orderShop, $orderProductAdd) | |||||
public function addOrderProduct($orderShop, $orderProductAdd, $persist = true) | |||||
{ | { | ||||
if ($orderProductAdd->getQuantityOrder() > 0) { | if ($orderProductAdd->getQuantityOrder() > 0) { | ||||
$updated = false; | $updated = false; | ||||
foreach ($orderShop->getOrderProducts() as $orderProduct) { | foreach ($orderShop->getOrderProducts() as $orderProduct) { | ||||
if ($orderProduct->getProduct()->getId() == $orderProductAdd->getProduct()->getId() | if ($orderProduct->getProduct()->getId() == $orderProductAdd->getProduct()->getId() | ||||
&& $this->priceUtils->getPrice($orderProduct) == $this->priceUtils->getPrice($orderProductAdd) | |||||
&& (string)$this->priceUtils->getPrice($orderProduct) == (string)$this->priceUtils->getPrice($orderProductAdd) | |||||
&& $this->compareOrderProductReductionCatalog($orderProduct->getOrderProductReductionCatalog(), $orderProductAdd->getOrderProductReductionCatalog())) { | && $this->compareOrderProductReductionCatalog($orderProduct->getOrderProductReductionCatalog(), $orderProductAdd->getOrderProductReductionCatalog())) { | ||||
$updated = true; | |||||
$orderProduct->setQuantityOrder($orderProduct->getQuantityOrder() + $orderProductAdd->getQuantityOrder()); | $orderProduct->setQuantityOrder($orderProduct->getQuantityOrder() + $orderProductAdd->getQuantityOrder()); | ||||
$this->em->persist($orderProduct); | |||||
if ($persist) { | |||||
$this->em->persist($orderProduct); | |||||
} | |||||
$updated = true; | |||||
break; | |||||
} | } | ||||
} | } | ||||
if (isset($orderProductReductionCatalog)) { | if (isset($orderProductReductionCatalog)) { | ||||
$this->em->persist($orderProductReductionCatalog); | $this->em->persist($orderProductReductionCatalog); | ||||
if ($persist) { | |||||
if (isset($orderProductReductionCatalog)) { | |||||
$this->em->persist($orderProductReductionCatalog); | |||||
} | |||||
$this->em->persist($orderProductAdd); | |||||
$this->em->persist($orderShop); | |||||
} | |||||
} | } | ||||
$this->em->persist($orderProductAdd); | |||||
$this->em->persist($orderShop); | |||||
if ($persist) { | |||||
$this->em->flush(); | |||||
} | |||||
} | } | ||||
$this->em->flush(); | |||||
} | } | ||||
} | } | ||||
public function compareOrderProductReductionCatalog($orderProductReductionCatalog1, $orderProductReductionCatalog2) | public function compareOrderProductReductionCatalog($orderProductReductionCatalog1, $orderProductReductionCatalog2) | ||||
{ | { | ||||
return $orderProductReductionCatalog1 && $orderProductReductionCatalog2 | return $orderProductReductionCatalog1 && $orderProductReductionCatalog2 | ||||
&& $orderProductReductionCatalog1->getUnit() == $orderProductReductionCatalog2->getUnit() | && $orderProductReductionCatalog1->getUnit() == $orderProductReductionCatalog2->getUnit() | ||||
&& $orderProductReductionCatalog1->getValue() == $orderProductReductionCatalog2->getValue() | && $orderProductReductionCatalog1->getValue() == $orderProductReductionCatalog2->getValue() | ||||
&& $orderProductReductionCatalog1->getBehaviorTaxRate() == $orderProductReductionCatalog2->getBehaviorTaxRate(); | && $orderProductReductionCatalog1->getBehaviorTaxRate() == $orderProductReductionCatalog2->getBehaviorTaxRate(); | ||||
/*return (!$orderProductReductionCatalog1 && !$orderProductReductionCatalog2) | |||||
|| ($orderProductReductionCatalog1 | |||||
&& $orderProductReductionCatalog2 | |||||
&& $orderProductReductionCatalog1->getUnit() == $orderProductReductionCatalog2->getUnit() | |||||
&& (string) $orderProductReductionCatalog1->getValue() == (string) $orderProductReductionCatalog2->getValue() | |||||
&& $orderProductReductionCatalog1->getBehaviorTaxRate() == $orderProductReductionCatalog2->getBehaviorTaxRate()) ;*/ | |||||
} | } | ||||
public function countQuantities($orderShop) | public function countQuantities($orderShop) | ||||
public function getOrderDatas($order = null) | public function getOrderDatas($order = null) | ||||
{ | { | ||||
$data = []; | |||||
if (!$order) { | if (!$order) { | ||||
$order = $this->getCartCurrent(); | $order = $this->getCartCurrent(); | ||||
} | } | ||||
$data = []; | |||||
$data['order'] = $order; | $data['order'] = $order; | ||||
$data['count'] = $this->countQuantities($order); | |||||
$data['total_with_tax'] = $this->priceUtils->getTotalWithTaxAndReduction($order); | |||||
$data['order_products_by_category'] = $this->getOrderProductsByParentCategory($order); | |||||
if ($order) { | |||||
$data['count'] = $this->countQuantities($order); | |||||
$data['total_with_tax'] = $this->priceUtils->getTotalWithTaxAndReduction($order); | |||||
$data['order_products_by_category'] = $this->getOrderProductsByParentCategory($order); | |||||
} | |||||
return $data; | return $data; | ||||
} | } | ||||
$this->em->persist($orderStatusHistory); | $this->em->persist($orderStatusHistory); | ||||
} | } | ||||
public function createOrderReductionCart(OrderShopInterface $orderShop, ReductionCartInterface $reductionCart) | public function createOrderReductionCart(OrderShopInterface $orderShop, ReductionCartInterface $reductionCart) | ||||
{ | { | ||||
$orderReductionCartClass = $this->em->getClassMetadata(OrderReductionCartInterface::class); | $orderReductionCartClass = $this->em->getClassMetadata(OrderReductionCartInterface::class); | ||||
} | } | ||||
}*/ | }*/ | ||||
public function mergeOrderShops($orderShop1, $orderShop2) | |||||
{ | |||||
if ($orderShop1 && $orderShop2) { | |||||
foreach ($orderShop2->getOrderProducts() as $orderProduct) { | |||||
$this->addOrderProduct($orderShop1, $orderProduct); | |||||
$this->em->remove($orderProduct); | |||||
} | |||||
$this->em->remove($orderShop2); | |||||
$this->em->persist($orderShop1); | |||||
$this->em->flush(); | |||||
return $orderShop1; | |||||
} | |||||
} | |||||
} | } |
if(isset($reductionCatalogValue) && isset($reductionCatalogUnit) && isset($reductionCatalogBehaviorTaxRate)) { | if(isset($reductionCatalogValue) && isset($reductionCatalogUnit) && isset($reductionCatalogBehaviorTaxRate)) { | ||||
if ($reductionCatalogUnit == 'percent') { | if ($reductionCatalogUnit == 'percent') { | ||||
return $this->applyReductionPercent( | |||||
$priceWithTax = $this->applyReductionPercent( | |||||
$priceWithTax, | $priceWithTax, | ||||
$reductionCatalogValue | $reductionCatalogValue | ||||
); | ); | ||||
} | } | ||||
elseif ($reductionCatalogUnit == 'amount') { | elseif ($reductionCatalogUnit == 'amount') { | ||||
if($reductionCatalogBehaviorTaxRate == 'tax-excluded') { | if($reductionCatalogBehaviorTaxRate == 'tax-excluded') { | ||||
return $this->applyTax( | |||||
$priceWithTax = $this->applyTax( | |||||
$this->applyReductionAmount( | $this->applyReductionAmount( | ||||
$price, | $price, | ||||
$reductionCatalogValue | $reductionCatalogValue | ||||
); | ); | ||||
} | } | ||||
elseif($reductionCatalogBehaviorTaxRate == 'tax-included') { | elseif($reductionCatalogBehaviorTaxRate == 'tax-included') { | ||||
return $this->applyReductionAmount( | |||||
$priceWithTax = $this->applyReductionAmount( | |||||
$priceWithTax, | $priceWithTax, | ||||
$reductionCatalogValue | $reductionCatalogValue | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
return $priceWithTax ; | |||||
return $this->round($priceWithTax) ; | |||||
} | } | ||||
public function applyTax($price, $taxRateValue) | public function applyTax($price, $taxRateValue) |
namespace Lc\ShopBundle\Services ; | namespace Lc\ShopBundle\Services ; | ||||
use ConnectHolland\CookieConsentBundle\Cookie\CookieChecker; | |||||
use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | use Lc\ShopBundle\Context\MerchantUtilsInterface; | ||||
use Symfony\Component\HttpFoundation\Cookie ; | use Symfony\Component\HttpFoundation\Cookie ; | ||||
protected $requestStack ; | protected $requestStack ; | ||||
protected $visitorRepository ; | protected $visitorRepository ; | ||||
protected $merchantUtils ; | protected $merchantUtils ; | ||||
protected $cookieChecker ; | |||||
public function __construct(ParameterBagInterface $parameterBag, EntityManagerInterface $em, Utils $utils, | public function __construct(ParameterBagInterface $parameterBag, EntityManagerInterface $em, Utils $utils, | ||||
RequestStack $requestStack, MerchantUtilsInterface $merchantUtils) | |||||
RequestStack $requestStack, MerchantUtilsInterface $merchantUtils, CookieChecker $cookieChecker) | |||||
{ | { | ||||
$this->em = $em ; | $this->em = $em ; | ||||
$this->parameterBag = $parameterBag ; | $this->parameterBag = $parameterBag ; | ||||
$this->requestStack = $requestStack ; | $this->requestStack = $requestStack ; | ||||
$this->visitorRepository = $this->em->getRepository($this->em->getClassMetadata(VisitorInterface::class)->getName()) ; | $this->visitorRepository = $this->em->getRepository($this->em->getClassMetadata(VisitorInterface::class)->getName()) ; | ||||
$this->merchantUtils = $merchantUtils ; | $this->merchantUtils = $merchantUtils ; | ||||
$this->cookieChecker = $cookieChecker ; | |||||
} | } | ||||
public function getCookieNameVisitor() | public function getCookieNameVisitor() | ||||
public function setCookieVisitor($response, $cookie) | public function setCookieVisitor($response, $cookie) | ||||
{ | { | ||||
$response->headers->setCookie(Cookie::create($this->getCookieNameVisitor(), $this->cryptCookie($cookie), 0, '/', $this->utils->getCookieDomain())); | |||||
if($this->cookieChecker->isCategoryAllowedByUser('site')) { | |||||
$response->headers->setCookie(Cookie::create($this->getCookieNameVisitor(), $this->cryptCookie($cookie), 0, '/', $this->utils->getCookieDomain())); | |||||
} | |||||
} | } | ||||
public function getVisitor($cookie) | public function getVisitor($cookie) |