Преглед изворни кода

Merge branch 'develop'

master
Guillaume пре 4 година
родитељ
комит
a71bdafc76
9 измењених фајлова са 175 додато и 48 уклоњено
  1. +16
    -0
      ShopBundle/Model/Address.php
  2. +36
    -0
      ShopBundle/Model/Merchant.php
  3. +5
    -5
      ShopBundle/Model/OrderShop.php
  4. +21
    -1
      ShopBundle/Model/Page.php
  5. +2
    -2
      ShopBundle/Repository/OrderShopRepository.php
  6. +1
    -0
      ShopBundle/Resources/translations/lcshop.fr.yaml
  7. +87
    -29
      ShopBundle/Services/OrderUtils.php
  8. +0
    -9
      ShopBundle/Services/PriceUtils.php
  9. +7
    -2
      ShopBundle/Services/UserUtils.php

+ 16
- 0
ShopBundle/Model/Address.php Прегледај датотеку

@@ -95,6 +95,10 @@ abstract class Address extends AbstractEntity
*/
protected $merchant;

/**
* @ORM\Column(type="text", nullable=true)
*/
protected $deliveryInfos;

public function __toString()
{
@@ -347,4 +351,16 @@ abstract class Address extends AbstractEntity

return $this;
}

public function getDeliveryInfos(): ?string
{
return $this->deliveryInfos;
}

public function setDeliveryInfos(?string $deliveryInfos): self
{
$this->deliveryInfos = $deliveryInfos;

return $this;
}
}

+ 36
- 0
ShopBundle/Model/Merchant.php Прегледај датотеку

@@ -56,6 +56,11 @@ abstract class Merchant extends AbstractDocumentEntity
*/
protected $news;

/**
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\PageInterface", mappedBy="merchant", orphanRemoval=true)
*/
protected $pages;

/**
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\NewsletterInterface", mappedBy="merchant")
*/
@@ -279,6 +284,37 @@ abstract class Merchant extends AbstractDocumentEntity
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[]
*/

+ 5
- 5
ShopBundle/Model/OrderShop.php Прегледај датотеку

@@ -83,7 +83,7 @@ abstract class OrderShop extends AbstractEntity implements FilterMerchantInterfa
/**
* @ORM\Column(type="text", nullable=true)
*/
protected $infosDelivery;
protected $deliveryInfos;

public function __construct()
{
@@ -329,14 +329,14 @@ abstract class OrderShop extends AbstractEntity implements FilterMerchantInterfa
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;
}

+ 21
- 1
ShopBundle/Model/Page.php Прегледај датотеку

@@ -2,18 +2,26 @@

namespace Lc\ShopBundle\Model;

use App\Entity\Hub;
use Doctrine\ORM\Mapping as ORM;
use Lc\ShopBundle\Context\FilterMerchantInterface;

/**
* @ORM\MappedSuperclass()
*/
abstract class Page extends AbstractDocumentEntity
abstract class Page extends AbstractDocumentEntity implements FilterMerchantInterface
{
/**
* @ORM\Column(type="text", nullable=true)
*/
protected $content;

/**
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface", inversedBy="pages")
* @ORM\JoinColumn(nullable=false)
*/
protected $merchant;

public function __toString()
{
return $this->getTitle() ;
@@ -30,4 +38,16 @@ abstract class Page extends AbstractDocumentEntity

return $this;
}

public function getMerchant(): ?Hub
{
return $this->merchant;
}

public function setMerchant(?Hub $merchant): self
{
$this->merchant = $merchant;

return $this;
}
}

+ 2
- 2
ShopBundle/Repository/OrderShopRepository.php Прегледај датотеку

@@ -20,7 +20,7 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt

public function findCartCurrent($params)
{
$query = $this->createQueryBuilder('e') ;
$query = $this->findByMerchantQuery() ;

if(isset($params['user'])) {
$query->andWhere('e.user = :user')->setParameter('user', $params['user']) ;
@@ -62,7 +62,7 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt
$query->andWhere('e.user = :user')->setParameter('user', $params['user']) ;
}

$query->orderBy('e.createdAt', 'DESC') ;
$query->orderBy('e.id', 'DESC') ;

return $query->getQuery()->getResult() ;
}

+ 1
- 0
ShopBundle/Resources/translations/lcshop.fr.yaml Прегледај датотеку

@@ -124,6 +124,7 @@ field:
devAlias: Alias
merchantConfigs: Configuration
taxRate: Règle de taxe
deliveryTaxRate: Règle de taxe (livraison)
value: Valeur
behaviorAddToCart: Ajout au panier
taxIncluded: TVA incluse

+ 87
- 29
ShopBundle/Services/OrderUtils.php Прегледај датотеку

@@ -6,9 +6,11 @@ use App\Entity\OrderProductReductionCatalog;
use App\Entity\OrderShop;
use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Context\OrderShopInterface;
use Lc\ShopBundle\Context\ProductFamilyUtilsInterface;
use Lc\ShopBundle\Context\UserInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Security;

class OrderUtils
@@ -20,9 +22,11 @@ class OrderUtils
protected $orderShopRepo;
protected $priceUtils ;
protected $productFamilyUtils ;
protected $session ;

public function __construct(EntityManagerInterface $em, Security $security, UserUtils $userUtils,
MerchantUtilsInterface $merchantUtils, PriceUtils $priceUtils, ProductFamilyUtilsInterface $productFamilyUtils)
MerchantUtilsInterface $merchantUtils, PriceUtils $priceUtils, ProductFamilyUtilsInterface $productFamilyUtils,
SessionInterface $session)
{
$this->em = $em;
$this->security = $security;
@@ -31,6 +35,7 @@ class OrderUtils
$this->orderShopRepo = $this->em->getRepository($this->em->getClassMetadata(OrderShopInterface::class)->getName());
$this->priceUtils = $priceUtils ;
$this->productFamilyUtils = $productFamilyUtils ;
$this->session = $session ;
}

public function getCartCurrent()
@@ -40,22 +45,44 @@ class OrderUtils
$user = $this->security->getUser();
$visitor = $this->userUtils->getVisitorCurrent();

$orderShop = null ;
$orderShopUser = null ;
$orderShopVisitor = null ;

if ($user) {
$paramsSearchOrderShop['user'] = $user;
$orderShopUser = $this->orderShopRepo->findCartCurrent([
'user' => $user
]);
}

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;
@@ -103,7 +130,7 @@ class OrderUtils
return $orderShop;
}

public function addOrderProduct($orderShop, $orderProductAdd)
public function addOrderProduct($orderShop, $orderProductAdd, $persist = true)
{
if ($orderProductAdd->getQuantityOrder() > 0) {
$updated = false;
@@ -128,37 +155,49 @@ class OrderUtils

foreach($orderShop->getOrderProducts() as $orderProduct) {
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())) {

$updated = true;
$orderProduct->setQuantityOrder($orderProduct->getQuantityOrder() + $orderProductAdd->getQuantityOrder());
$this->em->persist($orderProduct);

if($persist) {
$this->em->persist($orderProduct);
}

$updated = true;

break ;
}
}

if (!$updated) {
$orderShop->addOrderProduct($orderProductAdd);

if(isset($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);
}

$this->em->flush();
if($persist) {
$this->em->flush();
}
}

}

public function compareOrderProductReductionCatalog($orderProductReductionCatalog1, $orderProductReductionCatalog2)
{
return $orderProductReductionCatalog1 && $orderProductReductionCatalog2
&& $orderProductReductionCatalog1->getUnit() == $orderProductReductionCatalog2->getUnit()
&& $orderProductReductionCatalog1->getValue() == $orderProductReductionCatalog2->getValue()
&& $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)
@@ -195,15 +234,17 @@ class OrderUtils

public function getOrderDatas($order = null)
{
$data = [] ;
if(!$order) {
$order = $this->getCartCurrent() ;
}

$data = [] ;
$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 ;
}
@@ -256,4 +297,21 @@ class OrderUtils
return $text ;
}

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 ;
}
}

}

+ 0
- 9
ShopBundle/Services/PriceUtils.php Прегледај датотеку

@@ -50,15 +50,6 @@ class PriceUtils
);
}

/*public function getPriceUnitWithTaxAndReduction($entity)
{
if($entity instanceof ProductInterface) {
return $this->getPriceWithTaxAndReduction($entity) / $entity->getQuantity() ;
}

return null ;
}*/

public function getPriceByRefUnit($entity)
{
if($entity instanceof ProductPropertyInterface) {

+ 7
- 2
ShopBundle/Services/UserUtils.php Прегледај датотеку

@@ -2,6 +2,7 @@

namespace Lc\ShopBundle\Services ;

use ConnectHolland\CookieConsentBundle\Cookie\CookieChecker;
use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Symfony\Component\HttpFoundation\Cookie ;
@@ -17,9 +18,10 @@ class UserUtils
protected $requestStack ;
protected $visitorRepository ;
protected $merchantUtils ;
protected $cookieChecker ;

public function __construct(ParameterBagInterface $parameterBag, EntityManagerInterface $em, Utils $utils,
RequestStack $requestStack, MerchantUtilsInterface $merchantUtils)
RequestStack $requestStack, MerchantUtilsInterface $merchantUtils, CookieChecker $cookieChecker)
{
$this->em = $em ;
$this->parameterBag = $parameterBag ;
@@ -27,6 +29,7 @@ class UserUtils
$this->requestStack = $requestStack ;
$this->visitorRepository = $this->em->getRepository($this->em->getClassMetadata(VisitorInterface::class)->getName()) ;
$this->merchantUtils = $merchantUtils ;
$this->cookieChecker = $cookieChecker ;
}

public function getCookieNameVisitor()
@@ -46,7 +49,9 @@ class UserUtils

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)

Loading…
Откажи
Сачувај