namespace Lc\ShopBundle\Controller\Backend; | namespace Lc\ShopBundle\Controller\Backend; | ||||
use App\Entity\OrderShop; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents; | use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents; | ||||
use Lc\ShopBundle\Context\OrderProductInterface; | use Lc\ShopBundle\Context\OrderProductInterface; | ||||
use Lc\ShopBundle\Context\UserInterface; | use Lc\ShopBundle\Context\UserInterface; | ||||
} | } | ||||
public function orderReductionCreditAction() | |||||
{ | |||||
$id = $this->request->query->get('id'); | |||||
$easyadmin = $this->request->attributes->get('easyadmin'); | |||||
$orderShop = $easyadmin['item']; | |||||
$formOrderReductionCredit = $this->createForm(OrderReductionCreditType::class, $orderShop); | |||||
$formOrderReductionCredit->handleRequest($this->request); | |||||
if ($formOrderReductionCredit->isSubmitted() && $formOrderReductionCredit->isValid()) { | |||||
$reductionCredit = $formOrderReductionCredit->get('reductionCredit')->getData(); | |||||
$orderShop->reductionError = array(); | |||||
if($this->orderUtils->isReductionCreditAllowToBeAddToOrder($orderShop, $reductionCredit)){ | |||||
$orderReductionCredit = $this->orderUtils->createOrderReductionCredit($orderShop, $reductionCredit); | |||||
$this->em->persist($orderReductionCredit); | |||||
$this->em->flush(); | |||||
$response['status'] = 'success'; | |||||
$response['message'] = 'L\'avoir a bien été ajouté'; | |||||
}else{ | |||||
$response['status'] = 'error'; | |||||
$response['message'] = 'Cet avoir ne peut pas être appliqué sur cette commande'; | |||||
$response['message'] .= '<ul>'; | |||||
foreach ($orderShop->reductionError as $error) { | |||||
$response['message'] .= '<li> <i>'.$this->translator->trans($error, array(), 'lcshop'). '</i></li>'; | |||||
} | |||||
$response['message'] .= '</ul>'; | |||||
} | |||||
} else { | |||||
$response['status'] = 'error'; | |||||
$response['message'] = 'Une erreur est survenue'; | |||||
} | |||||
$response['data'] = $this->orderUtils->getOrderAsJsonObject($orderShop);; | |||||
return new Response(json_encode($response)); | |||||
} | |||||
public function renderOrderShopTemplate($actionName, $templatePath, array $parameters = []) | public function renderOrderShopTemplate($actionName, $templatePath, array $parameters = []) | ||||
{ | { | ||||
//dump($this->em->getRepository(OrderShop::class)->getValidOrder()); | |||||
if ($actionName == 'show') { | if ($actionName == 'show') { | ||||
$formAddProductToOrder = $this->createForm(AddPoductToOrderType::class, null, array( | $formAddProductToOrder = $this->createForm(AddPoductToOrderType::class, null, array( | ||||
'action' => $this->generateUrl('easyadmin', [ | 'action' => $this->generateUrl('easyadmin', [ |
*/ | */ | ||||
protected $title; | protected $title; | ||||
/** | /** | ||||
* @ORM\Column(type="text", nullable=true) | * @ORM\Column(type="text", nullable=true) | ||||
*/ | */ | ||||
*/ | */ | ||||
protected $devAlias; | protected $devAlias; | ||||
/** | |||||
* @ORM\Column(type="text", nullable=true) | |||||
*/ | |||||
protected $metaDescription; | |||||
/** | |||||
* @var array | |||||
* @ORM\Column(name="old_url", type="array", nullable=true) | |||||
*/ | |||||
private $oldUrl; | |||||
public function setImageFile(File $image = null) | public function setImageFile(File $image = null) | ||||
{ | { | ||||
{ | { | ||||
return $this->imageFile; | return $this->imageFile; | ||||
} | } | ||||
public function getTitle(): ?string | public function getTitle(): ?string | ||||
{ | { | ||||
return $this->title; | return $this->title; | ||||
} | } | ||||
public function getDescription(): ?string | public function getDescription(): ?string | ||||
{ | { | ||||
return $this->description; | return $this->description; | ||||
return $this; | return $this; | ||||
} | } | ||||
/** | |||||
* Set oldUrl | |||||
* | |||||
* @param array $oldUrl | |||||
* | |||||
* @return AbstractEntity | |||||
*/ | |||||
public function setOldUrl($oldUrl) | |||||
{ | |||||
$this->oldUrl = $oldUrl; | |||||
return $this; | |||||
} | |||||
/** | |||||
* Get oldUrl | |||||
* | |||||
* @return array | |||||
*/ | |||||
public function getOldUrl() | |||||
{ | |||||
return $this->oldUrl; | |||||
} | |||||
public function getMetaDescription(): ?string | |||||
{ | |||||
return $this->metaDescription; | |||||
} | |||||
public function setMetaDescription(?string $metaDescription): self | |||||
{ | |||||
$this->metaDescription = $metaDescription; | |||||
return $this; | |||||
} | |||||
public function getImage(): ?string | public function getImage(): ?string | ||||
{ | { | ||||
return $this->image; | return $this->image; |
*/ | */ | ||||
protected $title; | protected $title; | ||||
/** | |||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\OrderShopInterface", inversedBy="orderReductionCredits") | |||||
* @ORM\JoinColumn(nullable=false) | |||||
*/ | |||||
protected $orderShop; | |||||
/** | |||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\ReductionCreditInterface") | |||||
* @ORM\JoinColumn(nullable=false) | |||||
*/ | |||||
protected $reductionCredit; | |||||
public function __toString() | |||||
{ | |||||
return $this->title; | |||||
} | |||||
public function getTitle(): ?string | public function getTitle(): ?string | ||||
{ | { | ||||
return $this->title; | return $this->title; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getOrderShop(): ?OrderShop | |||||
{ | |||||
return $this->orderShop; | |||||
} | |||||
public function setOrderShop(?OrderShop $orderShop): self | |||||
{ | |||||
$this->orderShop = $orderShop; | |||||
return $this; | |||||
} | |||||
public function getReductionCredit(): ?ReductionCredit | |||||
{ | |||||
return $this->reductionCredit; | |||||
} | |||||
public function setReductionCredit(?ReductionCredit $reductionCredit): self | |||||
{ | |||||
$this->reductionCredit = $reductionCredit; | |||||
return $this; | |||||
} | |||||
} | } |
*/ | */ | ||||
class OrderShopRepository extends BaseRepository implements DefaultRepositoryInterface | class OrderShopRepository extends BaseRepository implements DefaultRepositoryInterface | ||||
{ | { | ||||
public function getInterfaceClass() | public function getInterfaceClass() | ||||
{ | { | ||||
return OrderShopInterface::class; | return OrderShopInterface::class; | ||||
} | } | ||||
protected $statusAliasAsValid = array('paid-online', 'paid-by-credit', 'waiting-delivery', 'waiting-delivery-with-payment', 'delivered-without-payment', 'done'); | |||||
public function getValidOrderWithReductionCredit($reductionCredit, $user){ | |||||
$query = $this->findValidOrderQuery(); | |||||
$query->andWhere('e.user = :user'); | |||||
$query->leftJoin('e.orderReductionCredits', 'orc'); | |||||
$query->andWhere('orc.reductionCredit = :reductionCredit'); | |||||
$query->setParameter('reductionCredit', $reductionCredit); | |||||
$query->setParameter('user', $user); | |||||
return $query->getQuery()->getResult(); | |||||
} | |||||
public function findValidOrderQuery(){ | |||||
$query = $this->findByMerchantQuery(); | |||||
$query->leftJoin('e.orderStatus', 'os'); | |||||
$query->andWhere('os.alias IN (:alias)'); | |||||
$query->setParameter('alias', $this->statusAliasAsValid); | |||||
return $query; | |||||
} | |||||
public function findCartCurrent($params) | public function findCartCurrent($params) | ||||
{ | { | ||||
$query = $this->findByMerchantQuery() ; | $query = $this->findByMerchantQuery() ; | ||||
->andWhere('SIZE(e.orderStatusHistories) '.$operator.' 0') ; | ->andWhere('SIZE(e.orderStatusHistories) '.$operator.' 0') ; | ||||
} | } | ||||
//getValidOrders() | |||||
//getValidOrders() | |||||
} | } |
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\OrderProductInterface; | ||||
use Lc\ShopBundle\Context\OrderReductionCreditInterface; | |||||
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 Lc\ShopBundle\Form\Backend\Order\OrderReductionCreditType; | |||||
use Symfony\Component\HttpFoundation\Session\SessionInterface; | use Symfony\Component\HttpFoundation\Session\SessionInterface; | ||||
use Symfony\Component\Security\Core\Security; | use Symfony\Component\Security\Core\Security; | ||||
return $orderReductionCart; | return $orderReductionCart; | ||||
} | } | ||||
public function isReductionCreditAllowToBeAddToOrder($orderShop, $reductionCredit){ | |||||
if($this->orderShopRepo->getValidOrderWithReductionCredit($reductionCredit, $orderShop->getUser())>0){ | |||||
return false; | |||||
}else{ | |||||
return true; | |||||
} | |||||
} | |||||
public function createOrderReductionCredit(OrderShopInterface $orderShop, ReductionCreditInterface $reductionCredit) | |||||
{ | |||||
$orderReductionCreditClass = $this->em->getClassMetadata(OrderReductionCreditInterface::class); | |||||
$orderReductionCredit = new $orderReductionCreditClass->name; | |||||
$orderReductionCredit->setOrderShop($orderShop); | |||||
$orderReductionCredit->setReductionCredit($reductionCredit); | |||||
$orderReductionCredit->setTitle($reductionCredit->getTitle()); | |||||
$orderReductionCredit->setValue($reductionCredit->getValue()); | |||||
$orderReductionCredit->setUnit($reductionCredit->getUnit()); | |||||
$orderReductionCredit->setBehaviorTaxRate($reductionCredit->getBehaviorTaxRate()); | |||||
return $orderReductionCredit; | |||||
} | |||||
/*public function getReductionCreditsAvailable($order) | /*public function getReductionCreditsAvailable($order) | ||||
{ | { | ||||
$reductionCreditRepo = $this->em->getRepository(ReductionCreditInterface::class); | $reductionCreditRepo = $this->em->getRepository(ReductionCreditInterface::class); |