Sfoglia il codice sorgente

Ajout des ReductionCredit sur commandes

feature/export_comptable
Fab 4 anni fa
parent
commit
ff4e0b8f44
5 ha cambiato i file con 190 aggiunte e 3 eliminazioni
  1. +46
    -0
      ShopBundle/Controller/Backend/OrderController.php
  2. +50
    -2
      ShopBundle/Model/AbstractDocumentEntity.php
  3. +42
    -0
      ShopBundle/Model/OrderReductionCredit.php
  4. +26
    -1
      ShopBundle/Repository/OrderShopRepository.php
  5. +26
    -0
      ShopBundle/Services/OrderUtils.php

+ 46
- 0
ShopBundle/Controller/Backend/OrderController.php Vedi File

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

namespace Lc\ShopBundle\Controller\Backend;

use App\Entity\OrderShop;
use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents;
use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Context\UserInterface;
@@ -266,8 +267,53 @@ class OrderController extends AdminController
}


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 = [])
{
//dump($this->em->getRepository(OrderShop::class)->getValidOrder());

if ($actionName == 'show') {
$formAddProductToOrder = $this->createForm(AddPoductToOrderType::class, null, array(
'action' => $this->generateUrl('easyadmin', [

+ 50
- 2
ShopBundle/Model/AbstractDocumentEntity.php Vedi File

@@ -27,7 +27,6 @@ abstract class AbstractDocumentEntity extends AbstractEntity implements StatusIn
*/
protected $title;


/**
* @ORM\Column(type="text", nullable=true)
*/
@@ -49,6 +48,17 @@ abstract class AbstractDocumentEntity extends AbstractEntity implements StatusIn
*/
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)
{
@@ -67,6 +77,7 @@ abstract class AbstractDocumentEntity extends AbstractEntity implements StatusIn
{
return $this->imageFile;
}

public function getTitle(): ?string
{
return $this->title;
@@ -80,7 +91,6 @@ abstract class AbstractDocumentEntity extends AbstractEntity implements StatusIn
}



public function getDescription(): ?string
{
return $this->description;
@@ -93,6 +103,44 @@ abstract class AbstractDocumentEntity extends AbstractEntity implements StatusIn
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
{
return $this->image;

+ 42
- 0
ShopBundle/Model/OrderReductionCredit.php Vedi File

@@ -17,6 +17,24 @@ abstract class OrderReductionCredit implements ReductionInterface
*/
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
{
return $this->title;
@@ -28,4 +46,28 @@ abstract class OrderReductionCredit implements ReductionInterface

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

+ 26
- 1
ShopBundle/Repository/OrderShopRepository.php Vedi File

@@ -13,11 +13,36 @@ use Lc\ShopBundle\Context\OrderShopInterface;
*/
class OrderShopRepository extends BaseRepository implements DefaultRepositoryInterface
{

public function getInterfaceClass()
{
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)
{
$query = $this->findByMerchantQuery() ;
@@ -87,5 +112,5 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt
->andWhere('SIZE(e.orderStatusHistories) '.$operator.' 0') ;
}

//getValidOrders()
//getValidOrders()
}

+ 26
- 0
ShopBundle/Services/OrderUtils.php Vedi File

@@ -8,6 +8,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\OrderReductionCartInterface;
use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Context\OrderReductionCreditInterface;
use Lc\ShopBundle\Context\OrderShopInterface;
use Lc\ShopBundle\Context\OrderStatusHistoryInterface;
use Lc\ShopBundle\Context\OrderStatusInterface;
@@ -15,6 +16,7 @@ use Lc\ShopBundle\Context\ProductFamilyUtilsInterface;
use Lc\ShopBundle\Context\ReductionCartInterface;
use Lc\ShopBundle\Context\ReductionCreditInterface;
use Lc\ShopBundle\Context\UserInterface;
use Lc\ShopBundle\Form\Backend\Order\OrderReductionCreditType;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Security;

@@ -339,6 +341,30 @@ class OrderUtils
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)
{
$reductionCreditRepo = $this->em->getRepository(ReductionCreditInterface::class);

Loading…
Annulla
Salva