$form->handleRequest($request); | $form->handleRequest($request); | ||||
if ($form->isSubmitted() && $form->isValid()) { | if ($form->isSubmitted() && $form->isValid()) { | ||||
$orderShop = $this->orderUtils->getOrderShopCurrent() ; | |||||
$orderShop = $this->orderUtils->getCartCurrent() ; | |||||
$data = $form->getData() ; | $data = $form->getData() ; | ||||
foreach($data as $orderProduct) { | foreach($data as $orderProduct) { | ||||
if($orderProduct instanceof OrderProductInterface) { | if($orderProduct instanceof OrderProductInterface) { |
$this->creditHistories = new ArrayCollection(); | $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 | public function getMerchant(): ?Merchant | ||||
{ | { | ||||
return $this->merchant; | return $this->merchant; |
return OrderShopInterface::class; | return OrderShopInterface::class; | ||||
} | } | ||||
public function findCurrent($params) | |||||
public function findCartCurrent($params) | |||||
{ | { | ||||
$query = $this->createQueryBuilder('e') ; | $query = $this->createQueryBuilder('e') ; | ||||
return $query->getQuery()->getOneOrNullResult() ; | 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) | public function findAllByDateStartEnd($dateStart, $dateEnd) | ||||
{ | { | ||||
$query = $this->findByMerchantQuery() | $query = $this->findByMerchantQuery() | ||||
->andWhere('e.createdAt >= :dateStart') | ->andWhere('e.createdAt >= :dateStart') | ||||
->setParameter('dateStart', $dateStart) | ->setParameter('dateStart', $dateStart) | ||||
->andWhere('e.createdAt <= :dateEnd') | ->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() ; | return $query->getQuery()->getResult() ; | ||||
} | } | ||||
public function filterOrderCart($query, $isCart = false) | |||||
{ | |||||
$operator = $isCart ? '=' : '>' ; | |||||
return $query->leftJoin('e.orderStatusHistories', 'orderStatusHistories') | |||||
->andWhere('SIZE(e.orderStatusHistories) '.$operator.' 0') ; | |||||
} | |||||
} | } |
$this->productFamilyUtils = $productFamilyUtils ; | $this->productFamilyUtils = $productFamilyUtils ; | ||||
} | } | ||||
public function getOrderShopCurrent() | |||||
public function getCartCurrent() | |||||
{ | { | ||||
$paramsSearchOrderShop = []; | $paramsSearchOrderShop = []; | ||||
$paramsSearchOrderShop['visitor'] = $visitor; | $paramsSearchOrderShop['visitor'] = $visitor; | ||||
} | } | ||||
$orderShop = $this->orderShopRepo->findCurrent($paramsSearchOrderShop); | |||||
$orderShop = $this->orderShopRepo->findCartCurrent($paramsSearchOrderShop); | |||||
if (!$orderShop) { | if (!$orderShop) { | ||||
$orderShop = $this->createOrderShop([ | $orderShop = $this->createOrderShop([ | ||||
public function getOrderDatas($order = null) | public function getOrderDatas($order = null) | ||||
{ | { | ||||
if(!$order) { | if(!$order) { | ||||
$order = $this->getOrderShopCurrent() ; | |||||
$order = $this->getCartCurrent() ; | |||||
} | } | ||||
$data = [] ; | $data = [] ; |