Sfoglia il codice sorgente

[Frontend] Paiements partiels : première version

develop
Guillaume 3 anni fa
parent
commit
55ac4e22d4
6 ha cambiato i file con 59 aggiunte e 44 eliminazioni
  1. +1
    -3
      ShopBundle/Controller/Backend/OrderController.php
  2. +6
    -1
      ShopBundle/Manager/EntityManager.php
  3. +4
    -6
      ShopBundle/Model/OrderStatus.php
  4. +2
    -1
      ShopBundle/Resources/translations/lcshop.fr.yaml
  5. +20
    -10
      ShopBundle/Services/Order/OrderUtils.php
  6. +26
    -23
      ShopBundle/Services/Order/OrderUtilsPaymentTrait.php

+ 1
- 3
ShopBundle/Controller/Backend/OrderController.php Vedi File

@@ -459,7 +459,6 @@ class OrderController extends AdminController
$parameters['form_order_send_payment_link'] = $this->createCustomForm(OrderSendPaymentLink::class, 'orderSendPaymentLink', $parameters)->createView();
break;
case OrderStatus::ALIAS_ERROR_PAYMENT_ONLINE :
case OrderStatus::ALIAS_WAITING_PAYMENT_CREDIT :
case OrderStatus::ALIAS_WAITING_PAYMENT_ONLINE :
$parameters['form_order_send_payment_link'] = $this->createCustomForm(OrderSendPaymentLink::class, 'orderSendPaymentLink', $parameters)->createView();
$parameters['form_order_payment'] = $this->createCustomForm(OrderPaymentType::class, 'orderPayment', $parameters, false)->createView();
@@ -467,8 +466,7 @@ class OrderController extends AdminController
$parameters['form_order_status'] = $this->createCustomForm(OrderStatusType::class, 'orderStatus', $parameters)->createView();
$parameters['form_order_invoice_address'] = $this->createCustomForm(OrderInvoiceAddressType::class, 'orderInvoiceAddress', $parameters)->createView();
break;
case OrderStatus::ALIAS_PAID_BY_CREDIT :
case OrderStatus::ALIAS_PAID_ONLINE :
case OrderStatus::ALIAS_PAID :
case OrderStatus::ALIAS_WAITING_DELIVERY :
case OrderStatus::ALIAS_WAITING_BANK_RETURN :
$parameters['form_order_payment'] = $this->createCustomForm(OrderPaymentType::class, 'orderPayment', $parameters, false)->createView();

+ 6
- 1
ShopBundle/Manager/EntityManager.php Vedi File

@@ -93,11 +93,16 @@ class EntityManager
return $this;
}

protected function persist($entity)
public function persist($entity)
{
$this->entityManager->persist($entity);
}

public function refresh($entity)
{
$this->entityManager->refresh($entity);
}

public function getEntityName($className)
{
if (substr($className, -9) === 'Interface') {

+ 4
- 6
ShopBundle/Model/OrderStatus.php Vedi File

@@ -14,11 +14,10 @@ abstract class OrderStatus
const ALIAS_CART = 'cart' ;
const ALIAS_CART_CANCELED = 'cart-canceled' ;
const ALIAS_WAITING_PAYMENT_ONLINE = 'waiting-payment-online' ;
const ALIAS_WAITING_PAYMENT_CREDIT = 'waiting-payment-credit' ;
const ALIAS_WAITING_BANK_RETURN = 'waiting-bank-return' ;
const ALIAS_PAID_ONLINE = 'paid-online' ;
const ALIAS_PARTIAL_PAYMENT = 'partial-payment' ;
const ALIAS_PAID = 'paid' ;
const ALIAS_ERROR_PAYMENT_ONLINE = 'error-payment-online' ;
const ALIAS_PAID_BY_CREDIT = 'paid-by-credit' ;
const ALIAS_WAITING_DELIVERY = 'waiting-delivery' ;
const ALIAS_WAITING_DELIVERY_WITH_PAYMENT = 'waiting-delivery-with-payment' ;
const ALIAS_DELIVERED_WITHOUT_PAYMENT = 'delivered-without-payment' ;
@@ -30,8 +29,7 @@ abstract class OrderStatus

//TODO : AJOUTER un champ valid ds orderSTATUS
static $statusAliasAsValid = [
self::ALIAS_PAID_ONLINE,
self::ALIAS_PAID_BY_CREDIT,
self::ALIAS_PAID,
self::ALIAS_WAITING_DELIVERY,
self::ALIAS_WAITING_BANK_RETURN,
self::ALIAS_WAITING_DELIVERY_WITH_PAYMENT,
@@ -46,8 +44,8 @@ abstract class OrderStatus

static $statusAliasAsCart = [
self::ALIAS_CART,
self::ALIAS_PARTIAL_PAYMENT,
self::ALIAS_WAITING_PAYMENT_ONLINE,
self::ALIAS_WAITING_PAYMENT_CREDIT,
self::ALIAS_ERROR_PAYMENT_ONLINE
];


+ 2
- 1
ShopBundle/Resources/translations/lcshop.fr.yaml Vedi File

@@ -141,10 +141,11 @@ error:
deliverySlotMissing: Vous n'avez pas de créneau de livraison
productUnavailable: Certains produits ne sont plus disponibles
nextStatusNotAllow: La commande ne peut passer à ce statut
noPayment: Le montant de la commande n'a pas été règlé dans sa totalité
incompletePayment: Le montant de la commande n'a pas été règlé dans sa totalité
otherOrderAlreadyExist: Une autre commande existe déjà pour cet utilisateur, vous avez été redirigé.
minimumAmountZone: Montant minimum de commande non respecté pour cette zone
minimumAmountPointSale: Montant minimum de commande non respecté pour ce point de vente
noPayment: Aucun paiement n'a été enregistré pour cette commande
reductionCart:
conditionsError: Cette réduction ne peut pas être appliqué sur cette commande
date: La réduction n'est plus active

+ 20
- 10
ShopBundle/Services/Order/OrderUtils.php Vedi File

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

use App\Entity\OrderProductReductionCatalog;
use App\Entity\OrderShop;
use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\DocumentInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\OrderReductionCreditInterface;
@@ -16,6 +15,7 @@ use Lc\ShopBundle\Context\ReductionCreditInterface;
use Lc\ShopBundle\Context\SectionInterface;
use Lc\ShopBundle\Context\SectionUtilsInterface;
use Lc\ShopBundle\Context\UserUtilsInterface;
use Lc\ShopBundle\Manager\EntityManager;
use Lc\ShopBundle\Model\ProductFamily;
use Lc\ShopBundle\Services\CreditUtils;
use Lc\ShopBundle\Services\DocumentUtils;
@@ -50,18 +50,28 @@ class OrderUtils
protected $router;
protected $sectionUtils ;

public function __construct(EntityManagerInterface $em, Security $security, RouterInterface $router, UserUtilsInterface $userUtils,
MerchantUtilsInterface $merchantUtils, PriceUtilsInterface $priceUtils, ProductFamilyUtilsInterface $productFamilyUtils,
DocumentUtils $documentUtils, Utils $utils, CreditUtils $creditUtils, SectionUtilsInterface $sectionUtils)
public function __construct(
EntityManager $em,
Security $security,
RouterInterface $router,
UserUtilsInterface $userUtils,
MerchantUtilsInterface $merchantUtils,
PriceUtilsInterface $priceUtils,
ProductFamilyUtilsInterface $productFamilyUtils,
DocumentUtils $documentUtils,
Utils $utils,
CreditUtils $creditUtils,
SectionUtilsInterface $sectionUtils
)
{
$this->em = $em;
$this->security = $security;
$this->userUtils = $userUtils;
$this->merchantUtils = $merchantUtils;
$this->orderShopRepo = $this->em->getRepository($this->em->getClassMetadata(OrderShopInterface::class)->getName());
$this->reductionCreditRepo = $this->em->getRepository($this->em->getClassMetadata(ReductionCreditInterface::class)->getName());
$this->orderReductionCreditRepo = $this->em->getRepository($this->em->getClassMetadata(OrderReductionCreditInterface::class)->getName());
$this->documentRepo = $this->em->getRepository($this->em->getClassMetadata(DocumentInterface::class)->getName());
$this->orderShopRepo = $this->em->getRepository($this->em->getEntityName(OrderShopInterface::class));
$this->reductionCreditRepo = $this->em->getRepository($this->em->getEntityName(ReductionCreditInterface::class));
$this->orderReductionCreditRepo = $this->em->getRepository($this->em->getEntityName(OrderReductionCreditInterface::class));
$this->documentRepo = $this->em->getRepository($this->em->getEntityName(DocumentInterface::class));
$this->priceUtils = $priceUtils;
$this->productFamilyUtils = $productFamilyUtils;
$this->documentUtils = $documentUtils;
@@ -296,8 +306,8 @@ class OrderUtils

public function newOrderStatusHistory($order, $status, $origin = 'user')
{
$orderStatusHistoryClass = $this->em->getClassMetadata(OrderStatusHistoryInterface::class);
$orderStatusHistory = new $orderStatusHistoryClass->name;
$orderStatusHistoryClass = $this->em->getEntityName(OrderStatusHistoryInterface::class);
$orderStatusHistory = new $orderStatusHistoryClass;
$orderStatusHistory->setOrderShop($order);
$orderStatusHistory->setOrderStatus($status);
$orderStatusHistory->setOrigin($origin);

+ 26
- 23
ShopBundle/Services/Order/OrderUtilsPaymentTrait.php Vedi File

@@ -3,46 +3,44 @@
namespace Lc\ShopBundle\Services\Order;


use App\Entity\CreditHistory;
use App\Factory\Order\OrderPaymentFactory;
use Lc\ShopBundle\Context\OrderPaymentInterface;
use Lc\ShopBundle\Services\Utils;

trait OrderUtilsPaymentTrait
{
public function createOrderPayment($orderShop, $meanPayment, $amount, $reference = null, $comment = null, $paidAt = null)
{
$classOrderPayment = $this->em->getClassMetadata(OrderPaymentInterface::class)->getName();
$orderPayment = new $classOrderPayment;

$orderPayment->setOrderShop($orderShop);
$orderPayment->setMeanPayment($meanPayment);
$orderPayment->setAmount($amount);
$orderPayment->setReference($reference);
$orderPayment->setComment($comment);
$orderPayment->setEditable(false);
$orderPayment->setCreatedBy($orderShop->getUser());
$orderPayment->setUpdatedBy($orderShop->getUser());
public function createOrderPayment($params = [])
{
$orderPayment = $this->factoryManager->createEntity(OrderPaymentFactory::class, $params);

if ($paidAt) {
$orderPayment->setPaidAt($paidAt);
} else {
$orderPayment->setPaidAt(new \DateTime('now'));
if(isset($params['meanPayment']) && $params['meanPayment'] == Utils::MEAN_PAYMENT_CREDIT) {
$this->creditUtils->createCreditHistory(CreditHistory::TYPE_DEBIT, $this->security->getUser(), [
'orderPayment' => $orderPayment
]);
}

$this->em->persist($orderPayment);
$this->em->flush();
$this->em->create($orderPayment) ;
$this->em->flush() ;

return $orderPayment;
return $orderPayment ;
}

public function isOrderPaid($order, $mergeComplementaryOrderShop = false)
{
$totalOrderPayments = $this->getTotalOrderPayments($order, $mergeComplementaryOrderShop) ;
$totalOrder = $this->priceUtils->getTotalWithTax($order) ;

if ( (abs($totalOrderPayments - $totalOrder) < 0.00001
|| $totalOrderPayments >= $totalOrder)
&& $totalOrder > 0) {

if ($this->getTotalOrderPayments($order, $mergeComplementaryOrderShop) >= $this->priceUtils->getTotalWithTax($order) && $this->priceUtils->getTotalWithTax($order) > 0) {
return true;
} else {
}
else {
return false;
}


}

public function getTotalOrderPayments($order, $mergeComplementaryOrderShop = false): float
@@ -61,4 +59,9 @@ trait OrderUtilsPaymentTrait
return $totalAmount;
}

public function getTotalRemainingToBePaid($order)
{
return $this->priceUtils->getTotalWithTax($order) - $this->getTotalOrderPayments($order) ;
}

}

Loading…
Annulla
Salva