Browse Source

[Backend] Correctifs multiples

feature/module_traiteur_v1
Fab 4 years ago
parent
commit
2c20981820
7 changed files with 40 additions and 30 deletions
  1. +2
    -0
      ShopBundle/Controller/Backend/OrderController.php
  2. +1
    -0
      ShopBundle/Resources/public/js/backend/script/default/utils.js
  3. +2
    -1
      ShopBundle/Resources/translations/lcshop.fr.yaml
  4. +0
    -1
      ShopBundle/Resources/views/backend/default/block/actions.html.twig
  5. +1
    -0
      ShopBundle/Resources/views/backend/default/block/flash_messages.html.twig
  6. +2
    -1
      ShopBundle/Resources/views/backend/default/list.html.twig
  7. +32
    -27
      ShopBundle/Services/ProductFamilyUtils.php

+ 2
- 0
ShopBundle/Controller/Backend/OrderController.php View File

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


//SI PAS DE problème après le 23/05/2021 à supprimer
die('Une erreur est survenue, merci de contacter FAB : Erreur ligne 80 LC =>OrderController ');
foreach ($entity->getOrderProducts() as $orderProduct) { foreach ($entity->getOrderProducts() as $orderProduct) {
//dump($orderProduct); //dump($orderProduct);
$orderProduct->setCreatedBy($this->getUser()); $orderProduct->setCreatedBy($this->getUser());

+ 1
- 0
ShopBundle/Resources/public/js/backend/script/default/utils.js View File



function generateNotice(type, text) { function generateNotice(type, text) {
toastr.options.timeOut = 30000; toastr.options.timeOut = 30000;
toastr.options.preventDuplicates = true;
toastr[type](text); toastr[type](text);


/*var n = noty({ /*var n = noty({

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

common: common:
fieldChange: Le champ a bien été modifié fieldChange: Le champ a bien été modifié
productFamily: productFamily:
editStock: Le stock a bien été modifié
editStock: "Stocks renouveler pour : %count% produits"
error: error:
form: form:
submitted: Une erreur est survenue à la soumission du formulaire submitted: Une erreur est survenue à la soumission du formulaire
notAdded: Le crédit n'a pas été ajouté notAdded: Le crédit n'a pas été ajouté
productFamily: productFamily:
editStock: Le stock n'a pas été modifié, une erreur est survenue editStock: Le stock n'a pas été modifié, une erreur est survenue
editStockNoQuantityDefault: "Le stock n'a pas été modifié pour le produit #%id% (Aucune quantité par défaut)"
field: field:
default: default:
placeholder: Choisissez une option placeholder: Choisissez une option

+ 0
- 1
ShopBundle/Resources/views/backend/default/block/actions.html.twig View File

{% set dropdownAction ={} %} {% set dropdownAction ={} %}
{% for action in actions %} {% for action in actions %}



{% if action.group is defined and action.group==true %} {% if action.group is defined and action.group==true %}
{% set dropdownAction = dropdownAction|merge({(loop.index0): action}) %} {% set dropdownAction = dropdownAction|merge({(loop.index0): action}) %}
{% else %} {% else %}

+ 1
- 0
ShopBundle/Resources/views/backend/default/block/flash_messages.html.twig View File

{% endif %} {% endif %}
{% if _flash_messages|length > 0 %} {% if _flash_messages|length > 0 %}
<div id="lc-flash-messages"> <div id="lc-flash-messages">

{% for label, messages in _flash_messages %} {% for label, messages in _flash_messages %}
{% if label != 'alert' %} {% if label != 'alert' %}
{% for message in messages %} {% for message in messages %}

+ 2
- 1
ShopBundle/Resources/views/backend/default/list.html.twig View File



<td class="{{ isSortingField ? 'sorted' }} {{ metadata.dataType|lower }} {{ metadata.css_class }}" {{ easyadmin_config('design.rtl') ? 'dir="rtl"' }}> <td class="{{ isSortingField ? 'sorted' }} {{ metadata.dataType|lower }} {{ metadata.css_class }}" {{ easyadmin_config('design.rtl') ? 'dir="rtl"' }}>
{% if (field == 'title' or field== 'id') and (metadata.dataType=="string" or metadata.dataType=="integer") %} {% if (field == 'title' or field== 'id') and (metadata.dataType=="string" or metadata.dataType=="integer") %}

<a class="link-as-text" <a class="link-as-text"
href="{{ path('easyadmin', {'action':'edit', 'entity':_entity_config.name, 'id': item.id}) }}">
href="{{ path('easyadmin', _request_parameters|merge({ action: 'edit', id: item.id })) }}">
{{ easyadmin_render_field_for_list_view(_entity_config.name, item, metadata) }} {{ easyadmin_render_field_for_list_view(_entity_config.name, item, metadata) }}
</a> </a>
{% else %} {% else %}

+ 32
- 27
ShopBundle/Services/ProductFamilyUtils.php View File

<?php <?php


namespace Lc\ShopBundle\Services ;
namespace Lc\ShopBundle\Services;


use App\Entity\Product; use App\Entity\Product;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;


class ProductFamilyUtils class ProductFamilyUtils
{ {
protected $priceUtils ;
protected $em ;
protected $priceUtils;
protected $em;



public function __construct(PriceUtilsInterface $priceUtils, EntityManagerInterface $em) public function __construct(PriceUtilsInterface $priceUtils, EntityManagerInterface $em)
{ {
$this->priceUtils = $priceUtils ;
$this->priceUtils = $priceUtils;
$this->em = $em; $this->em = $em;
} }


public function getCheapestProduct($productFamily) public function getCheapestProduct($productFamily)
{ {
$priceUtils = $this->priceUtils ;
$priceUtils = $this->priceUtils;
return $this->getCheapestOrMostExpensiveProduct($productFamily, function ($a, $b) use ($priceUtils) { return $this->getCheapestOrMostExpensiveProduct($productFamily, function ($a, $b) use ($priceUtils) {
return $priceUtils->getPriceWithTaxAndReduction($a) > $priceUtils->getPriceWithTaxAndReduction($b) ;
return $priceUtils->getPriceWithTaxAndReduction($a) > $priceUtils->getPriceWithTaxAndReduction($b);
}, true); }, true);
} }


public function getCheapestProductByRefUnit($productFamily) public function getCheapestProductByRefUnit($productFamily)
{ {
$priceUtils = $this->priceUtils ;
$priceUtils = $this->priceUtils;
return $this->getCheapestOrMostExpensiveProduct($productFamily, function ($a, $b) use ($priceUtils) { return $this->getCheapestOrMostExpensiveProduct($productFamily, function ($a, $b) use ($priceUtils) {
return $priceUtils->getPriceByRefUnitWithTaxAndReduction($a) > $priceUtils->getPriceByRefUnitWithTaxAndReduction($b) ;
return $priceUtils->getPriceByRefUnitWithTaxAndReduction($a) > $priceUtils->getPriceByRefUnitWithTaxAndReduction($b);
}, false); }, false);
} }


public function getMostExpensiveProductByRefUnit($productFamily) public function getMostExpensiveProductByRefUnit($productFamily)
{ {
$priceUtils = $this->priceUtils ;
$priceUtils = $this->priceUtils;
return $this->getCheapestOrMostExpensiveProduct($productFamily, function ($a, $b) use ($priceUtils) { return $this->getCheapestOrMostExpensiveProduct($productFamily, function ($a, $b) use ($priceUtils) {
return $priceUtils->getPriceByRefUnitWithTaxAndReduction($a) < $priceUtils->getPriceByRefUnitWithTaxAndReduction($b) ;
return $priceUtils->getPriceByRefUnitWithTaxAndReduction($a) < $priceUtils->getPriceByRefUnitWithTaxAndReduction($b);
}, false); }, false);
} }


private function getCheapestOrMostExpensiveProduct($productFamily, $comparisonFunction, $returnSelfIfNotActiveProducts) private function getCheapestOrMostExpensiveProduct($productFamily, $comparisonFunction, $returnSelfIfNotActiveProducts)
{ {
if($productFamily->getActiveProducts()) {
if ($productFamily->getActiveProducts()) {
$products = $productFamily->getProductsOnline()->getValues(); $products = $productFamily->getProductsOnline()->getValues();
if (count($products) > 0) { if (count($products) > 0) {
usort($products, $comparisonFunction); usort($products, $comparisonFunction);
return $products[0]; return $products[0];
} }
}else{
} else {
return $productFamily->getOriginProduct(); return $productFamily->getOriginProduct();
} }
if ($returnSelfIfNotActiveProducts) { if ($returnSelfIfNotActiveProducts) {
return $productFamily; return $productFamily;
}
else {
} else {
return false; return false;
} }
} }




public function processBeforePersistProductFamily($productFamily, $editForm=false, $clone =false){
if($editForm){
public function processBeforePersistProductFamily($productFamily, $editForm = false, $clone = false)
{
if ($editForm) {
$this->processReductionCatalog($productFamily, $editForm); $this->processReductionCatalog($productFamily, $editForm);
$this->processCategories($productFamily); $this->processCategories($productFamily);
} }
} }
} }


protected function processCloneProduct($productFamily)
{
foreach ($productFamily->getProducts() as $i => $product) {
$newProduct = clone $product;
$newProduct->setProductFamily($productFamily);
$this->em->persist($newProduct);
$productFamily->addProduct($newProduct);
}
}

protected function processProducts($entity, $clone = false) protected function processProducts($entity, $clone = false)
{ {
if($clone) {
foreach ($entity->getProducts() as $i => $product) {
$newProduct = clone $product;
$newProduct->setProductFamily($entity);
$this->em->persist($newProduct);
$entity->addProduct($newProduct);
}
}else {
if ($clone) {
$this->processCloneProduct($entity);
} else {
//Récupère le product origin //Récupère le product origin
$originProducts = $this->em->getRepository(ProductInterface::class)->findBy(array( $originProducts = $this->em->getRepository(ProductInterface::class)->findBy(array(
'productFamily' => $entity->getId(), 'productFamily' => $entity->getId(),
foreach ($entity->getProducts() as $product) { foreach ($entity->getProducts() as $product) {
$product->setProductFamily($entity); $product->setProductFamily($entity);


if($entity->getProductsQuantityAsTitle() && $product->getStatus()>=1){
$product->setTitle(str_replace('.', ',',$product->getQuantityInherited()).$product->getUnitInherited()->getWording());
if ($entity->getProductsQuantityAsTitle() && $product->getStatus() >= 1) {
$product->setTitle(str_replace('.', ',', $product->getQuantityInherited()) . $product->getUnitInherited()->getWording());
} }


$this->em->persist($product); $this->em->persist($product);

Loading…
Cancel
Save