瀏覽代碼

Merge branch 'develop' of https://gitea.laclic.fr/Laclic/LcShopBundle into develop

feature/export_comptable
Fab 4 年之前
父節點
當前提交
27bb74240a
共有 5 個檔案被更改,包括 86 行新增11 行删除
  1. +1
    -1
      ShopBundle/Controller/Frontend/CartController.php
  2. +24
    -0
      ShopBundle/Model/OrderShop.php
  3. +35
    -5
      ShopBundle/Repository/OrderShopRepository.php
  4. +3
    -4
      ShopBundle/Services/OrderUtils.php
  5. +23
    -1
      ShopBundle/Services/UserUtils.php

+ 1
- 1
ShopBundle/Controller/Frontend/CartController.php 查看文件

@@ -42,7 +42,7 @@ class CartController extends BaseController
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$orderShop = $this->orderUtils->getOrderShopCurrent() ;
$orderShop = $this->orderUtils->getCartCurrent() ;
$data = $form->getData() ;
foreach($data as $orderProduct) {
if($orderProduct instanceof OrderProductInterface) {

+ 24
- 0
ShopBundle/Model/OrderShop.php 查看文件

@@ -97,6 +97,30 @@ abstract class OrderShop extends AbstractEntity implements FilterMerchantInterfa
$this->creditHistories = new ArrayCollection();
}

public function getDateCreated()
{
$orderStatusHistory = $this->getOrderStatusHistory('new') ;
if($orderStatusHistory) {
return $orderStatusHistory->getCreatedAt() ;
}

return null ;
}

public function getOrderStatusHistory($status)
{
$orderStatusHistories = $this->getOrderStatusHistories() ;
if(count($orderStatusHistories) > 0) {
foreach($orderStatusHistories as $orderStatusHistory) {
if($orderStatusHistory->getOrderStatus() == $status) {
return $orderStatusHistory ;
}
}
}

return null ;
}

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

+ 35
- 5
ShopBundle/Repository/OrderShopRepository.php 查看文件

@@ -18,7 +18,7 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt
return OrderShopInterface::class;
}

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

@@ -36,19 +36,49 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt
return $query->getQuery()->getOneOrNullResult() ;
}

public function findAllBy($params = [])
{
$query = $this->findByMerchantQuery() ;

if(isset($params['dateStart'])) {
$query->andWhere('e.createdAt >= :dateStart')->setParameter('dateStart', $params['dateStart']) ;
}

if(isset($params['dateEnd'])) {
$query->andWhere('e.createdAt <= :dateEnd')->setParameter('dateEnd', $params['dateEnd']) ;
}

if(!isset($params['isCart'])) {
$query = $this->filterOrderCart($query) ;
}

if(isset($params['user'])) {
$query->andWhere('e.user = :user')->setParameter('user', $params['user']) ;
}

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

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

public function findAllByDateStartEnd($dateStart, $dateEnd)
{
$query = $this->findByMerchantQuery()
->andWhere('e.createdAt >= :dateStart')
->setParameter('dateStart', $dateStart)
->andWhere('e.createdAt <= :dateEnd')
->setParameter('dateEnd', $dateEnd)
;
->setParameter('dateEnd', $dateEnd);

$query->leftJoin('e.orderStatusHistories', 'orderStatusHistories')
->andWhere('SIZE(e.orderStatusHistories) > 0') ;
$this->filterOrderCart($query) ;

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

public function filterOrderCart($query, $isCart = false)
{
$operator = $isCart ? '=' : '>' ;
return $query->leftJoin('e.orderStatusHistories', 'orderStatusHistories')
->andWhere('SIZE(e.orderStatusHistories) '.$operator.' 0') ;
}

}

+ 3
- 4
ShopBundle/Services/OrderUtils.php 查看文件

@@ -32,8 +32,7 @@ class OrderUtils
$this->productFamilyUtils = $productFamilyUtils ;
}


public function getOrderShopCurrent()
public function getCartCurrent()
{
$paramsSearchOrderShop = [];

@@ -48,7 +47,7 @@ class OrderUtils
$paramsSearchOrderShop['visitor'] = $visitor;
}

$orderShop = $this->orderShopRepo->findCurrent($paramsSearchOrderShop);
$orderShop = $this->orderShopRepo->findCartCurrent($paramsSearchOrderShop);

if (!$orderShop) {
$orderShop = $this->createOrderShop([
@@ -184,7 +183,7 @@ class OrderUtils
public function getOrderDatas($order = null)
{
if(!$order) {
$order = $this->getOrderShopCurrent() ;
$order = $this->getCartCurrent() ;
}

$data = [] ;

+ 23
- 1
ShopBundle/Services/UserUtils.php 查看文件

@@ -3,6 +3,7 @@
namespace Lc\ShopBundle\Services ;

use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Symfony\Component\HttpFoundation\Cookie ;
use Lc\ShopBundle\Context\VisitorInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
@@ -15,14 +16,17 @@ class UserUtils
protected $utils ;
protected $requestStack ;
protected $visitorRepository ;
protected $merchantUtils ;

public function __construct(ParameterBagInterface $parameterBag, EntityManagerInterface $em, Utils $utils, RequestStack $requestStack)
public function __construct(ParameterBagInterface $parameterBag, EntityManagerInterface $em, Utils $utils,
RequestStack $requestStack, MerchantUtilsInterface $merchantUtils)
{
$this->em = $em ;
$this->parameterBag = $parameterBag ;
$this->utils = $utils ;
$this->requestStack = $requestStack ;
$this->visitorRepository = $this->em->getRepository($this->em->getClassMetadata(VisitorInterface::class)->getName()) ;
$this->merchantUtils = $merchantUtils ;
}

public function getCookieNameVisitor()
@@ -80,4 +84,22 @@ class UserUtils
$this->em->flush() ;
}

public function setNewsletter($user, $subscribeNewsletter)
{
$currentMerchant = $this->merchantUtils->getMerchantCurrent() ;
$newsletters = $currentMerchant->getNewsletters() ;

if(isset($newsletters[0]) && $newsletters[0]) {
if($subscribeNewsletter) {
$user->addNewsletter($newsletters[0]) ;
}
else {
$user->removeNewsletter($newsletters[0]) ;
}
}

$this->em->persist($user) ;
$this->em->flush() ;
}

}

Loading…
取消
儲存