Browse Source

Processus de commande

feature/export_comptable
Fab 4 years ago
parent
commit
98869f9129
8 changed files with 184 additions and 107 deletions
  1. +13
    -16
      ShopBundle/Controller/Backend/OrderController.php
  2. +5
    -4
      ShopBundle/Controller/Backend/ProductFamilyController.php
  3. +5
    -0
      ShopBundle/Model/ProductFamily.php
  4. +4
    -4
      ShopBundle/Resources/views/backend/order/panel_cart.html.twig
  5. +1
    -1
      ShopBundle/Resources/views/backend/productfamily/panel_products.html.twig
  6. +3
    -3
      ShopBundle/Resources/views/backend/productfamily/panel_stock.html.twig
  7. +37
    -79
      ShopBundle/Services/OrderUtils.php
  8. +116
    -0
      ShopBundle/Services/OrderUtilsReductionTrait.php

+ 13
- 16
ShopBundle/Controller/Backend/OrderController.php View File

$filterOrderStatus = false; $filterOrderStatus = false;




if ($dqlFilter['orderStatus'])$filterOrderStatus = $dqlFilter['orderStatus'];
if ($dqlFilter['orderStatus']) $filterOrderStatus = $dqlFilter['orderStatus'];
$dqlFilter = $dqlFilter['filter']; $dqlFilter = $dqlFilter['filter'];


$queryBuilder = parent::createListQueryBuilder($entityClass, $sortDirection, $sortField, $dqlFilter); $queryBuilder = parent::createListQueryBuilder($entityClass, $sortDirection, $sortField, $dqlFilter);


$queryBuilder->leftJoin('entity.orderStatus','orderStatus');
$queryBuilder->leftJoin('entity.orderStatus', 'orderStatus');


dump($filterOrderStatus); dump($filterOrderStatus);
if ($filterOrderStatus) { if ($filterOrderStatus) {
} }





public function updateEntity($entity) public function updateEntity($entity)
{ {


} }





public function getUserViaFirstStepForm($entity) public function getUserViaFirstStepForm($entity)
{ {
$userClass = $this->em->getClassMetadata(UserInterface::class); $userClass = $this->em->getClassMetadata(UserInterface::class);


if ($formOrderStatus->isSubmitted() && $formOrderStatus->isValid()) { if ($formOrderStatus->isSubmitted() && $formOrderStatus->isValid()) {


if($orderShop = $this->orderUtils->changeOrderStatus($formOrderStatus->get('orderStatus')->getData(), $orderShop)){
if ($orderShop = $this->orderUtils->changeOrderStatus($formOrderStatus->get('orderStatus')->getData(), $orderShop)) {
$this->addFlash('success', 'La commande a bien été modifié.'); $this->addFlash('success', 'La commande a bien été modifié.');
} }
}else{
} else {
$this->addFlash('error', 'Une erreur s\'est produite'); $this->addFlash('error', 'Une erreur s\'est produite');
} }


$easyadmin = $this->request->attributes->get('easyadmin'); $easyadmin = $this->request->attributes->get('easyadmin');
$orderShop = $easyadmin['item']; $orderShop = $easyadmin['item'];


$orderPaymentClass =$this->em->getClassMetadata(OrderPaymentInterface::class);
$orderPaymentClass = $this->em->getClassMetadata(OrderPaymentInterface::class);


$orderPayment = new $orderPaymentClass->name; $orderPayment = new $orderPaymentClass->name;


} }





public function orderReductionCartAction() public function orderReductionCartAction()
{ {


if ($formOrderReductionCart->isSubmitted() && $formOrderReductionCart->isValid()) { if ($formOrderReductionCart->isSubmitted() && $formOrderReductionCart->isValid()) {
$reductionCart = $formOrderReductionCart->get('reductionCart')->getData(); $reductionCart = $formOrderReductionCart->get('reductionCart')->getData();
$orderShop->reductionError = array(); $orderShop->reductionError = array();
if($this->orderUtils->isReductionCartAllowToBeAddToOrder($orderShop, $reductionCart)){
if ($this->orderUtils->isReductionCartAllowToBeAddToOrder($orderShop, $reductionCart)) {
$orderReductionCart = $this->orderUtils->createOrderReductionCart($orderShop, $reductionCart); $orderReductionCart = $this->orderUtils->createOrderReductionCart($orderShop, $reductionCart);
$this->em->persist($orderReductionCart); $this->em->persist($orderReductionCart);
$this->em->flush(); $this->em->flush();
$response['status'] = 'success'; $response['status'] = 'success';
$response['message'] = 'La réduction a bien été ajouté'; $response['message'] = 'La réduction a bien été ajouté';


}else{
} else {
$response['status'] = 'error'; $response['status'] = 'error';
$response['message'] = 'Cette réduction ne peut pas être appliqué sur cette commande'; $response['message'] = 'Cette réduction ne peut pas être appliqué sur cette commande';


$response['message'] .= '<ul>'; $response['message'] .= '<ul>';
foreach ($orderShop->reductionError as $error) { foreach ($orderShop->reductionError as $error) {
$response['message'] .= '<li> <i>'.$this->translator->trans($error, array(), 'lcshop'). '</i></li>';
$response['message'] .= '<li> <i>' . $this->translator->trans($error, array(), 'lcshop') . '</i></li>';
} }
$response['message'] .= '</ul>'; $response['message'] .= '</ul>';
} }
if ($formOrderReductionCredit->isSubmitted() && $formOrderReductionCredit->isValid()) { if ($formOrderReductionCredit->isSubmitted() && $formOrderReductionCredit->isValid()) {
$reductionCredit = $formOrderReductionCredit->get('reductionCredit')->getData(); $reductionCredit = $formOrderReductionCredit->get('reductionCredit')->getData();
$orderShop->reductionError = array(); $orderShop->reductionError = array();
if($this->orderUtils->isReductionCreditAllowToBeAddToOrder($orderShop, $reductionCredit)){
if ($this->orderUtils->isReductionCreditAllowToBeAddToOrder($orderShop, $reductionCredit)) {
$orderReductionCredit = $this->orderUtils->createOrderReductionCredit($orderShop, $reductionCredit); $orderReductionCredit = $this->orderUtils->createOrderReductionCredit($orderShop, $reductionCredit);
$this->em->persist($orderReductionCredit); $this->em->persist($orderReductionCredit);
$this->em->flush(); $this->em->flush();
$response['status'] = 'success'; $response['status'] = 'success';
$response['message'] = 'L\'avoir a bien été ajouté'; $response['message'] = 'L\'avoir a bien été ajouté';


}else{
} else {
$response['status'] = 'error'; $response['status'] = 'error';
$response['message'] = 'Cet avoir ne peut pas être appliqué sur cette commande'; $response['message'] = 'Cet avoir ne peut pas être appliqué sur cette commande';


$response['message'] .= '<ul>'; $response['message'] .= '<ul>';
foreach ($orderShop->reductionError as $error) { foreach ($orderShop->reductionError as $error) {
$response['message'] .= '<li> <i>'.$this->translator->trans($error, array(), 'lcshop'). '</i></li>';
$response['message'] .= '<li> <i>' . $this->translator->trans($error, array(), 'lcshop') . '</i></li>';
} }
$response['message'] .= '</ul>'; $response['message'] .= '</ul>';
} }
]) ])
)); ));


if(!isset($parameters['form_order_delivery_address'])) {
if (!isset($parameters['form_order_delivery_address'])) {
$formOrderDeliveryAddress = $this->createForm(OrderDeliveryAddressType::class, null, array( $formOrderDeliveryAddress = $this->createForm(OrderDeliveryAddressType::class, null, array(
'data' => $parameters['entity'], 'data' => $parameters['entity'],
'action' => $this->generateUrl('easyadmin', [ 'action' => $this->generateUrl('easyadmin', [
$id = $this->request->query->get('id'); $id = $this->request->query->get('id');
$easyadmin = $this->request->attributes->get('easyadmin'); $easyadmin = $this->request->attributes->get('easyadmin');
$entity = $easyadmin['item']; $entity = $easyadmin['item'];
$easyadmin['entity']['name'] = 'OrderShop';
$easyadmin['entity']['name'] = 'OrderShop';
$fields = $this->entity['show']['fields']; $fields = $this->entity['show']['fields'];
$deleteForm = $this->createDeleteForm($this->entity['name'], $id); $deleteForm = $this->createDeleteForm($this->entity['name'], $id);



+ 5
- 4
ShopBundle/Controller/Backend/ProductFamilyController.php View File

use Lc\ShopBundle\Context\TaxRateInterface; use Lc\ShopBundle\Context\TaxRateInterface;
use Lc\ShopBundle\Form\Backend\Common\ReductionCatalogType; use Lc\ShopBundle\Form\Backend\Common\ReductionCatalogType;
use Lc\ShopBundle\Form\Backend\ProductFamily\ProductType; use Lc\ShopBundle\Form\Backend\ProductFamily\ProductType;
use Lc\ShopBundle\Model\ProductFamily;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\NumberType; use Symfony\Component\Form\Extension\Core\Type\NumberType;
)); ));


$formBuilder->add('behaviorCountStock', ChoiceType::class, array( $formBuilder->add('behaviorCountStock', ChoiceType::class, array(
'empty_data' => 'by-product-family',
'empty_data' => ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY,
'choices' => array( 'choices' => array(
'field.ProductFamily.behaviorCountStockOptions.byQuantity' => 'by-quantity',
'field.ProductFamily.behaviorCountStockOptions.byProductFamily' => 'by-product-family',
'field.ProductFamily.behaviorCountStockOptions.byProduct' => 'by-product'
'field.ProductFamily.behaviorCountStockOptions.' . ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE => ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE,
'field.ProductFamily.behaviorCountStockOptions.' . ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY => ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY,
'field.ProductFamily.behaviorCountStockOptions.' . ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT => ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT
), ),
'translation_domain' => 'lcshop', 'translation_domain' => 'lcshop',
'multiple' => false, 'multiple' => false,

+ 5
- 0
ShopBundle/Model/ProductFamily.php View File



abstract class ProductFamily extends AbstractDocumentEntity implements ProductPropertyInterface, PriceInterface, FilterMerchantInterface abstract class ProductFamily extends AbstractDocumentEntity implements ProductPropertyInterface, PriceInterface, FilterMerchantInterface
{ {
const BEHAVIOR_COUNT_STOCK_BY_MEASURE = 'by-measure' ;
const BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY = 'by-product-family' ;
const BEHAVIOR_COUNT_STOCK_BY_PRODUCT = 'by-product' ;
const TYPE_CREDIT = 'credit' ;

use ProductPropertyTrait; use ProductPropertyTrait;





+ 4
- 4
ShopBundle/Resources/views/backend/order/panel_cart.html.twig View File

{% endfor %} {% endfor %}
</div> </div>
<div class="col"> <div class="col">
<div v-show="behaviorCountStock == 'by-product-family' || behaviorCountStock == 'by-quantity'"
<div v-show="behaviorCountStock == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY') }}' || behaviorCountStock == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE') }}'"
class="form-group"> class="form-group">
{{ form_label(form.availableQuantity) }} {{ form_label(form.availableQuantity) }}
<div class="form-widget"> <div class="form-widget">
<div class="input-group"> <div class="input-group">
{{ form_widget(form.availableQuantity) }} {{ form_widget(form.availableQuantity) }}
<div v-show="behaviorCountStock == 'by-quantity'" class="input-group-append">
<div v-show="behaviorCountStock == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE') }}'" class="input-group-append">
<span class="input-group-text">${ getUnitReference() }</span> <span class="input-group-text">${ getUnitReference() }</span>
</div> </div>
</div> </div>
<div class="form-widget"> <div class="form-widget">
<div class="input-group"> <div class="input-group">
{{ form_widget(form.availableQuantityDefault) }} {{ form_widget(form.availableQuantityDefault) }}
<div v-show="behaviorCountStock == 'by-quantity'" class="input-group-append">
<div v-show="behaviorCountStock == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE') }}'" class="input-group-append">
<span class="input-group-text">${ getUnitReference() }</span> <span class="input-group-text">${ getUnitReference() }</span>
</div> </div>
</div> </div>
</div> </div>
</fieldset> </fieldset>
</div> </div>
</div>
</div>

+ 1
- 1
ShopBundle/Resources/views/backend/productfamily/panel_products.html.twig View File

{{ macros.productField(2, product.price, 'price', false, '€', 'v-show="productFamily.behaviorPrice == \'by-piece\'"') }} {{ macros.productField(2, product.price, 'price', false, '€', 'v-show="productFamily.behaviorPrice == \'by-piece\'"') }}
{{ macros.productField(2, product.priceWithTax, 'priceWithTax', false, '€', 'v-show="productFamily.behaviorPrice == \'by-piece\'"') }} {{ macros.productField(2, product.priceWithTax, 'priceWithTax', false, '€', 'v-show="productFamily.behaviorPrice == \'by-piece\'"') }}


{{ macros.productField(1, product.availableQuantity, 'availableQuantity',false, '', 'v-show="productFamily.behaviorCountStock== \'by-product\'"') }}
{{ macros.productField(1, product.availableQuantity, 'availableQuantity',false, '', 'v-show="productFamily.behaviorCountStock== \' '~ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT') ~' \'"') }}
{{ macros.productField(1, product.availableQuantityDefault, 'availableQuantityDefault',false, '', 'v-show="productFamily.behaviorCountStock== \'by-product\'"') }} {{ macros.productField(1, product.availableQuantityDefault, 'availableQuantityDefault',false, '', 'v-show="productFamily.behaviorCountStock== \'by-product\'"') }}


{{ macros.productField(2, product.propertyExpirationDate, 'propertyExpirationDate','propertyExpirationDateValue', '', 'v-show="productFamily.behaviorExpirationDate== \'by-product\'"') }} {{ macros.productField(2, product.propertyExpirationDate, 'propertyExpirationDate','propertyExpirationDateValue', '', 'v-show="productFamily.behaviorExpirationDate== \'by-product\'"') }}

+ 3
- 3
ShopBundle/Resources/views/backend/productfamily/panel_stock.html.twig View File

{% endfor %} {% endfor %}
</div> </div>
<div class="col"> <div class="col">
<div v-show="behaviorCountStock == 'by-product-family' || behaviorCountStock == 'by-quantity'"
<div v-show="behaviorCountStock == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY') }}' || behaviorCountStock == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE') }}'"
class="form-group"> class="form-group">
{{ form_label(form.availableQuantity) }} {{ form_label(form.availableQuantity) }}
<div class="form-widget"> <div class="form-widget">
<div class="input-group"> <div class="input-group">
{{ form_widget(form.availableQuantity) }} {{ form_widget(form.availableQuantity) }}
<div v-show="behaviorCountStock == 'by-quantity'" class="input-group-append">
<div v-show="behaviorCountStock == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE') }}'" class="input-group-append">
<span class="input-group-text">${ getUnitReference() }</span> <span class="input-group-text">${ getUnitReference() }</span>
</div> </div>
</div> </div>
<div class="form-widget"> <div class="form-widget">
<div class="input-group"> <div class="input-group">
{{ form_widget(form.availableQuantityDefault) }} {{ form_widget(form.availableQuantityDefault) }}
<div v-show="behaviorCountStock == 'by-quantity'" class="input-group-append">
<div v-show="behaviorCountStock == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE') }}'" class="input-group-append">
<span class="input-group-text">${ getUnitReference() }</span> <span class="input-group-text">${ getUnitReference() }</span>
</div> </div>
</div> </div>

+ 37
- 79
ShopBundle/Services/OrderUtils.php View File

use Lc\ShopBundle\Context\UserInterface; use Lc\ShopBundle\Context\UserInterface;
use Lc\ShopBundle\Model\Document; use Lc\ShopBundle\Model\Document;
use Lc\ShopBundle\Form\Backend\Order\OrderReductionCreditType; use Lc\ShopBundle\Form\Backend\Order\OrderReductionCreditType;
use Lc\ShopBundle\Model\ProductFamily;
use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;


class OrderUtils class OrderUtils
{ {
use OrderUtilsReductionTrait;

protected $em; protected $em;
protected $security; protected $security;
protected $userUtils; protected $userUtils;


public function getCartCurrent() public function getCartCurrent()
{ {

$paramsSearchOrderShop = []; $paramsSearchOrderShop = [];


$user = $this->security->getUser(); $user = $this->security->getUser();
$return = true ; $return = true ;
} }
} }
return $return ; return $return ;
} }


public function compareOrderProductReductionCatalog($orderProductReductionCatalog1, $orderProductReductionCatalog2)
{
return (!$orderProductReductionCatalog1 && !$orderProductReductionCatalog2)
|| ($orderProductReductionCatalog1
&& $orderProductReductionCatalog2
&& $orderProductReductionCatalog1->getUnit() == $orderProductReductionCatalog2->getUnit()
&& (string) $orderProductReductionCatalog1->getValue() == (string) $orderProductReductionCatalog2->getValue()
&& $orderProductReductionCatalog1->getBehaviorTaxRate() == $orderProductReductionCatalog2->getBehaviorTaxRate()) ;
}



public function countQuantities($orderShop) public function countQuantities($orderShop)
{ {
return $data; return $data;
} }


public function getSummaryOrderProductReductionCatalog($orderProductReductionCatalog)
{
$text = '';

if ($orderProductReductionCatalog) {
if ($orderProductReductionCatalog->getUnit() == 'amount') {
$text .= '- ' . $orderProductReductionCatalog->getValue() . '&nbsp;€';
}

if ($orderProductReductionCatalog->getUnit() == 'percent') {
$text .= '- ' . $orderProductReductionCatalog->getValue() . '&nbsp;%';
}
}

return $text;
}


public function newOrderStatusHistory($order, $status, $origin = 'user') public function newOrderStatusHistory($order, $status, $origin = 'user')
{ {
$this->em->persist($orderStatusHistory); $this->em->persist($orderStatusHistory);
} }


public function createOrderReductionCart(OrderShopInterface $orderShop, ReductionCartInterface $reductionCart)
{
$orderReductionCartClass = $this->em->getClassMetadata(OrderReductionCartInterface::class);
$orderReductionCart = new $orderReductionCartClass->name;

$orderReductionCart->setOrderShop($orderShop);
$orderReductionCart->setReductionCart($reductionCart);


$orderReductionCart->setTitle($reductionCart->getTitle());
$orderReductionCart->setValue($reductionCart->getValue());
$orderReductionCart->setUnit($reductionCart->getUnit());
$orderReductionCart->setBehaviorTaxRate($reductionCart->getBehaviorTaxRate());
$orderReductionCart->setFreeShipping($reductionCart->getFreeShipping());
$orderReductionCart->setAppliedTo($reductionCart->getAppliedTo());
$orderReductionCart->setType($reductionCart->getType());


$this->em->persist($orderReductionCart) ;
$this->em->flush() ;


return $orderReductionCart;
}

public function isReductionCreditAllowToBeAddToOrder($orderShop, $reductionCredit){

if($this->orderShopRepo->findValidOrderWithReductionCredit($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);

$reductionCredits = $reductionCreditRepo->getReductionCreditByUser($order->getUser());
foreach ($reductionCredits as $reductionCredit){

}
}*/


public function mergeOrderShops($orderShop1, $orderShop2) public function mergeOrderShops($orderShop1, $orderShop2)
{ {
} }
return $totalAmount; return $totalAmount;
} }

public function deductAvailabilityProduct(\Lc\ShopBundle\Model\OrderShop $orderShop){
foreach ($orderShop->getOrderProducts() as $orderProduct){
switch ($orderProduct->getProduct()->getProductFamily()->getBehaviorCountStock()) {
case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE :



break;
case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :

$oldAvailability = $orderProduct->getProduct()->getProductFamily()->getAvailableQuantity();
$newAvailability = $oldAvailability - $orderProduct->getQuantityOrder();
$orderProduct->getProduct()->getProductFamily()->setAvailableQuantity($newAvailability);

$this->em->persist($orderProduct->getProduct()->getProductFamily());

break;
case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantity();
$newAvailability = $oldAvailability - $orderProduct->getQuantityOrder();
$orderProduct->getProduct()->setAvailableQuantity($newAvailability);

$this->em->persist($orderProduct->getProduct());

break;
}

$this->em->flush();
}
}
} }

+ 116
- 0
ShopBundle/Services/OrderUtilsReductionTrait.php View File

<?php

namespace Lc\ShopBundle\Services;

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\OrderPaymentInterface;
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;
use Lc\ShopBundle\Context\ProductFamilyUtilsInterface;
use Lc\ShopBundle\Context\ReductionCartInterface;
use Lc\ShopBundle\Context\ReductionCreditInterface;
use Lc\ShopBundle\Context\UserInterface;
use Lc\ShopBundle\Model\Document;
use Lc\ShopBundle\Form\Backend\Order\OrderReductionCreditType;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Security;

trait OrderUtilsReductionTrait
{
public function compareOrderProductReductionCatalog($orderProductReductionCatalog1, $orderProductReductionCatalog2)
{
return (!$orderProductReductionCatalog1 && !$orderProductReductionCatalog2)
|| ($orderProductReductionCatalog1
&& $orderProductReductionCatalog2
&& $orderProductReductionCatalog1->getUnit() == $orderProductReductionCatalog2->getUnit()
&& (string) $orderProductReductionCatalog1->getValue() == (string) $orderProductReductionCatalog2->getValue()
&& $orderProductReductionCatalog1->getBehaviorTaxRate() == $orderProductReductionCatalog2->getBehaviorTaxRate()) ;
}


public function getSummaryOrderProductReductionCatalog($orderProductReductionCatalog)
{
$text = '';

if ($orderProductReductionCatalog) {
if ($orderProductReductionCatalog->getUnit() == 'amount') {
$text .= '- ' . $orderProductReductionCatalog->getValue() . '&nbsp;€';
}

if ($orderProductReductionCatalog->getUnit() == 'percent') {
$text .= '- ' . $orderProductReductionCatalog->getValue() . '&nbsp;%';
}
}

return $text;
}


public function createOrderReductionCart(OrderShopInterface $orderShop, ReductionCartInterface $reductionCart)
{
$orderReductionCartClass = $this->em->getClassMetadata(OrderReductionCartInterface::class);
$orderReductionCart = new $orderReductionCartClass->name;

$orderReductionCart->setOrderShop($orderShop);
$orderReductionCart->setReductionCart($reductionCart);

$orderReductionCart->setTitle($reductionCart->getTitle());
$orderReductionCart->setValue($reductionCart->getValue());
$orderReductionCart->setUnit($reductionCart->getUnit());
$orderReductionCart->setBehaviorTaxRate($reductionCart->getBehaviorTaxRate());
$orderReductionCart->setFreeShipping($reductionCart->getFreeShipping());
$orderReductionCart->setAppliedTo($reductionCart->getAppliedTo());
$orderReductionCart->setType($reductionCart->getType());

$this->em->persist($orderReductionCart) ;
$this->em->flush() ;

return $orderReductionCart;
}

public function isReductionCreditAllowToBeAddToOrder($orderShop, $reductionCredit){

if($this->orderShopRepo->findValidOrderWithReductionCredit($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);

$reductionCredits = $reductionCreditRepo->getReductionCreditByUser($order->getUser());
foreach ($reductionCredits as $reductionCredit){

}
}*/



}

Loading…
Cancel
Save