Browse Source

Merge duplication supplier & productOrigin

feature/export_comptable
Fab 4 years ago
parent
commit
0802eff415
8 changed files with 124 additions and 61 deletions
  1. +9
    -26
      ShopBundle/Controller/Backend/ProductFamilyController.php
  2. +1
    -0
      ShopBundle/Form/Backend/ProductFamily/ProductType.php
  3. +21
    -6
      ShopBundle/Model/Product.php
  4. +36
    -4
      ShopBundle/Model/ProductFamily.php
  5. +3
    -1
      ShopBundle/Resources/public/js/backend/script/productfamily/vuejs-product-family.js
  6. +1
    -1
      ShopBundle/Resources/views/backend/productfamily/macros.html.twig
  7. +5
    -2
      ShopBundle/Resources/views/backend/productfamily/panel_products.html.twig
  8. +48
    -21
      ShopBundle/Services/ProductFamilyUtils.php

+ 9
- 26
ShopBundle/Controller/Backend/ProductFamilyController.php View File

@@ -10,6 +10,7 @@ use Lc\ShopBundle\Context\ImageInterface;
use Lc\ShopBundle\Context\OrderShopInterface;
use Lc\ShopBundle\Context\ProductCategoryInterface;
use Lc\ShopBundle\Context\ProductFamilyInterface;
use Lc\ShopBundle\Context\ProductInterface;
use Lc\ShopBundle\Context\ReductionCatalogInterface;
use Lc\ShopBundle\Context\TaxRateInterface;
use Lc\ShopBundle\Form\Backend\Common\AbstractEditPositionType;
@@ -206,8 +207,6 @@ class ProductFamilyController extends AdminController
$this->em->flush();
}



protected function editAction()
{

@@ -238,11 +237,16 @@ class ProductFamilyController extends AdminController
$deleteForm = $this->createDeleteForm($this->entity['name'], $id);

$sortableProductsField = array();

foreach ($editForm->get('products')->getData() as $k => $product) {
$sortableProductsField[$product->getPosition()] = $k;
if($product->getOriginProduct() == false) {
$sortableProductsField[$product->getPosition()] = $k;
}else{
$sortableProductsField[-1] = $k;
}

}

}
ksort($sortableProductsField);

$editForm->handleRequest($this->request);
@@ -333,33 +337,12 @@ class ProductFamilyController extends AdminController
'entity' => $entity,
'categories' => $categories,
'sortableProductsField' => array(),
'totalProductOrdered' => array()
'totalProductOrdered' => array('total'=>0)
];

return $this->executeDynamicMethod('render<EntityName>Template', ['new', $this->entity['templates']['new'], $parameters]);
}

/*public function duplicateAction()
{
$id = $this->request->query->get('id');
$refererUrl = $this->request->query->get('referer', '');

$easyadmin = $this->request->attributes->get('easyadmin');

$entity = $this->em->getRepository($easyadmin['entity']['class'])->find($id);

$newProductFamily = clone $entity;
if ($easyadmin['entity']['name'] == "ProductFamily") {

}

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

return $this->redirectToRoute('easyadmin', ['entity' => $easyadmin['entity']['name'], 'action' => 'edit', 'id' => $newProductFamily->getId(), 'referer' => $refererUrl]);
}*/



//hack utilisé pour filter sur les catégories lors du tri des produits par sous cat
//A améliorer à l'occas

+ 1
- 0
ShopBundle/Form/Backend/ProductFamily/ProductType.php View File

@@ -29,6 +29,7 @@ class ProductType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{

//dump($builder);

$builder->add('title', TextType::class, array(
"required" => false

+ 21
- 6
ShopBundle/Model/Product.php View File

@@ -47,6 +47,10 @@ abstract class Product extends AbstractEntity implements SortableInterface, Prod
*/
protected $title;

/**
* @ORM\Column(type="boolean", nullable=true)
*/
protected $originProduct;

public function __construct()
{
@@ -56,13 +60,13 @@ abstract class Product extends AbstractEntity implements SortableInterface, Prod

public function __toString()
{
$title = $this->getProductFamily()->getTitle() ;
$title = $this->getProductFamily()->getTitle();

if($this->getTitle() && strlen($this->getTitle())) {
$title .= ' - '. $this->getTitle() ;
if ($this->getTitle() && strlen($this->getTitle())) {
$title .= ' - ' . $this->getTitle();
}

return $title ;
return $title;
}

public function getBuyingPriceInherited()
@@ -133,8 +137,7 @@ abstract class Product extends AbstractEntity implements SortableInterface, Prod
{
if ($this->getQuantity()) {
return $this->getQuantity();
}
else {
} else {
return $this->getProductFamily()->getQuantity();
}
}
@@ -199,4 +202,16 @@ abstract class Product extends AbstractEntity implements SortableInterface, Prod

return $this;
}

public function getOriginProduct(): ?bool
{
return $this->originProduct;
}

public function setOriginProduct(?bool $originProduct): self
{
$this->originProduct = $originProduct;

return $this;
}
}

+ 36
- 4
ShopBundle/Model/ProductFamily.php View File

@@ -243,7 +243,7 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr

case self::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :

foreach($this->getProducts() as $product) {
foreach($this->getProductsOnline() as $product) {
$availableQuantity += $product->getAvailableQuantityInherited() ;
}
break ;
@@ -327,7 +327,7 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr
$productsOnlineArray = new ArrayCollection() ;

foreach($products as $product) {
if($product->getStatus() == 1) {
if($product->getStatus() == 1 && $product->getOriginProduct() !=true) {
$productsOnlineArray[] = $product ;
}
}
@@ -753,7 +753,7 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr
{
if ($this->getActiveProducts()) {
$arrayCountProducts = [];
$products = $this->getProducts();
$products = $this->getProductsOnline();

foreach ($products as $product) {
$titleProduct = $product->getTitleInherited();
@@ -777,7 +777,7 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr
public function getProductsGroupByTitle()
{
$arrayProductsGroupByTitle = [];
$products = $this->getProducts();
$products = $this->getProductsOnline();

foreach ($products as $product) {
if($product->getStatus() == 1) {
@@ -791,4 +791,36 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr

return $arrayProductsGroupByTitle;
}

public function getOriginProduct()
{
$products = $this->getProducts() ;

foreach($products as $product) {
if($product->getOriginProduct()) {
return $product ;
}
}
}

public function getOriginProductOnline()
{
$originProduct = $this->getOriginProduct() ;

if($originProduct->getStatus()==1){
return $originProduct;
}else{
return false;
}
}

public function hasOneProductOnline()
{
if( ($this->getActiveProducts() && count($this->getProductsOnline()) > 0)
|| (!$this->getActiveProducts() && $this->getOriginProduct())){
return true ;
}

return false ;
}
}

+ 3
- 1
ShopBundle/Resources/public/js/backend/script/productfamily/vuejs-product-family.js View File

@@ -167,6 +167,7 @@ $(window).on('load', function () {
title: null,
position: 0,
status:1,
originProduct: false,
fieldToUpdate: ['title', 'unit', 'quantity', 'price'],
price: null,
priceWithTax: null,
@@ -267,7 +268,8 @@ $(window).on('load', function () {
},
deleteProductForm: function () {
if (confirm('Êtes-vous sur de cette action ?')) {
Vue.delete(this.$parent.formProducts, this.keyForm);
this.status = -1;
//Vue.delete(this.$parent.formProducts, this.keyForm);
this.$nextTick(function () {
this.$parent.updateSortableProducts(true);
});

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

@@ -60,7 +60,7 @@

{% macro product_row(product, totalProductOrdered) %}

<tr class="lc-draggable">
<tr class="lc-draggable" v-show="originProduct != true && status >= 0 ">
<td>
{% if product.vars.value is not null %}
#{{ product.vars.value.id }}

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

@@ -53,7 +53,7 @@
</th>

<th colspan="3" class="price">
{# v-show="getBehaviorPrice() =='{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_PIECE') }}'">#}
{# v-show="getBehaviorPrice() =='{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_PIECE') }}'">#}
PV HT
</th>
<th colspan="3" class="price main-info">
@@ -137,7 +137,7 @@
</th>

<th colspan="3" class="price">
{# v-show="getBehaviorPrice() =='{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_PIECE') }}'">#}
{# v-show="getBehaviorPrice() =='{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_PIECE') }}'">#}
${productFamily.price}
</th>
<th colspan="3" class="price main-info">
@@ -195,7 +195,9 @@
{% for keyForm,i in sortableProductsField %}
{% set product = form.products[i] %}

{#{% if product.vars.value.status >= 0 and (product.vars.value.originProduct is null or product.vars.value.originProduct == false) %}#}
window.productForm[{{ keyForm }}] = {
{% if product.vars.value.originProduct is defined %}originProduct: parseInt({{ product.vars.value.originProduct }}),{% endif %}
{% if product.vars.value.status is defined %}status: parseInt({{ product.vars.value.status }}),{% endif %}
{% if product.vars.value.position %}position: "{{ product.vars.value.position }}",{% endif %}
{% if product.vars.value.title %}title: "{{ product.vars.value.title }}",{% endif %}
@@ -211,6 +213,7 @@
{#{% if product.vars.value.expirationDate %}expirationDate: "{{ product.vars.value.expirationDate|date('d/m/Y') }}"{% endif %}#}
};
window.formProductTemplate[{{ keyForm }}] = '{{ product_family_macros.product_row(product, totalProductOrdered[product.vars.value.id])|replace({"\n":' ', "\r":' ', "'" : "\\'"})|raw }}';
{#{% endif %}#}
{% endfor %}

</script>

+ 48
- 21
ShopBundle/Services/ProductFamilyUtils.php View File

@@ -47,10 +47,14 @@ class ProductFamilyUtils

private function getCheapestOrMostExpensiveProduct($productFamily, $comparisonFunction, $returnSelfIfNotActiveProducts)
{
$products = $productFamily->getProductsOnline()->getValues() ;
if (count($products) > 0) {
usort($products, $comparisonFunction);
return $products[0];
if($productFamily->getActiveProducts()) {
$products = $productFamily->getProductsOnline()->getValues();
if (count($products) > 0) {
usort($products, $comparisonFunction);
return $products[0];
}
}else{
return $productFamily->getOriginProduct();
}
if ($returnSelfIfNotActiveProducts) {
return $productFamily;
@@ -99,24 +103,47 @@ class ProductFamilyUtils

protected function processProducts($entity, $clone = false)
{
//si il existe un et un seul produit pour ce product family n'ajoute rien supprime rien
if (count($entity->getProducts()) == 0) {
$product = new Product();
$product->setProductFamily($entity);
$this->em->persist($product);
$entity->addProduct($product);
} else {
if($clone) {
foreach ($entity->getProducts() as $i => $product) {
if ($clone) {
$newProduct = clone $product;
$newProduct->setProductFamily($entity);
$this->em->persist($newProduct);
$entity->addProduct($newProduct);
} else {
$product->setProductFamily($entity);
$this->em->persist($product);
$entity->addProduct($product);
}
$newProduct = clone $product;
$newProduct->setProductFamily($entity);
$this->em->persist($newProduct);
$entity->addProduct($newProduct);
}
}else {
//Récupère le product origin
$originProducts = $this->em->getRepository(ProductInterface::class)->findBy(array(
'productFamily' => $entity->getId(),
'originProduct' => true
));


if (count($originProducts) > 1) {
throw new \ErrorException('Plusieurs OriginProduct pour un même produit... Contacter fab');

// Case Nouveau product family
} else if (count($originProducts) == 0) {
$originProduct = new Product();
$originProduct->setProductFamily($entity);
$originProduct->setOriginProduct(true);
$entity->addProduct($originProduct);
} else {
$originProduct = $originProducts[0];
}

if ($entity->getActiveProducts()) {
$originProduct->setStatus(-1);
} else {
$originProduct->setStatus(1);
}

//Enregistrement
$entity->addProduct($originProduct);

foreach ($entity->getProducts() as $product) {
$product->setProductFamily($entity);
$this->em->persist($product);
$entity->addProduct($product);
}
}


Loading…
Cancel
Save