@@ -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; | |||
@@ -234,7 +235,8 @@ class ProductFamilyController extends AdminController | |||
} | |||
} | |||
protected function processProducts($entity, $clone = false) | |||
/*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) { | |||
@@ -244,6 +246,7 @@ class ProductFamilyController extends AdminController | |||
$entity->addProduct($product); | |||
} else { | |||
foreach ($entity->getProducts() as $i => $product) { | |||
dump($product); | |||
if ($clone) { | |||
$newProduct = clone $product; | |||
$newProduct->setProductFamily($entity); | |||
@@ -255,8 +258,70 @@ class ProductFamilyController extends AdminController | |||
$entity->addProduct($product); | |||
} | |||
} | |||
die(); | |||
} | |||
}*/ | |||
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 { | |||
dump('blop'); | |||
foreach ($entity->getProducts() as $product) { | |||
dump($product); | |||
} | |||
//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 { | |||
foreach ($entity->getProducts() as $product) { | |||
$product->setStatus(0); | |||
} | |||
$originProduct->setStatus(1); | |||
} | |||
//Enregistrement | |||
$originProduct->setProductFamily($entity); | |||
$this->em->persist($originProduct); | |||
$entity->addProduct($originProduct); | |||
foreach ($entity->getProducts() as $product) { | |||
$product->setProductFamily($entity); | |||
$this->em->persist($product); | |||
$entity->addProduct($product); | |||
dump($product); | |||
} | |||
//die(); | |||
} | |||
} | |||
protected function processCategories(ProductFamilyInterface $entity) | |||
@@ -288,7 +353,9 @@ class ProductFamilyController extends AdminController | |||
$id = $this->request->query->get('id'); | |||
$easyadmin = $this->request->attributes->get('easyadmin'); | |||
$entity = $easyadmin['item']; | |||
foreach ($entity->getProducts() as $product){ | |||
dump($product); | |||
} | |||
if ($this->request->isXmlHttpRequest() && $property = $this->request->query->get('property')) { | |||
$newValue = 'true' === mb_strtolower($this->request->query->get('newValue')); | |||
$fieldsMetadata = $this->entity['list']['fields']; | |||
@@ -310,11 +377,17 @@ 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; | |||
} | |||
} | |||
} | |||
dump($sortableProductsField); | |||
ksort($sortableProductsField); | |||
$editForm->handleRequest($this->request); |
@@ -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 |
@@ -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; | |||
} | |||
} |
@@ -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,10 +268,11 @@ $(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); | |||
}); | |||
});*/ | |||
} | |||
}, |
@@ -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 }} |
@@ -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> |