@@ -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) { |
@@ -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; |
@@ -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') ; | |||
} | |||
} |
@@ -32,7 +32,7 @@ class OrderUtils | |||
$this->productFamilyUtils = $productFamilyUtils ; | |||
} | |||
public function getOrderShopCurrent() | |||
public function getCartCurrent() | |||
{ | |||
$paramsSearchOrderShop = []; | |||
@@ -47,7 +47,7 @@ class OrderUtils | |||
$paramsSearchOrderShop['visitor'] = $visitor; | |||
} | |||
$orderShop = $this->orderShopRepo->findCurrent($paramsSearchOrderShop); | |||
$orderShop = $this->orderShopRepo->findCartCurrent($paramsSearchOrderShop); | |||
if (!$orderShop) { | |||
$orderShop = $this->createOrderShop([ | |||
@@ -182,7 +182,7 @@ class OrderUtils | |||
public function getOrderDatas($order = null) | |||
{ | |||
if(!$order) { | |||
$order = $this->getOrderShopCurrent() ; | |||
$order = $this->getCartCurrent() ; | |||
} | |||
$data = [] ; |