use Lc\ShopBundle\Context\OrderShopInterface; | use Lc\ShopBundle\Context\OrderShopInterface; | ||||
use Lc\ShopBundle\Context\ProductCategoryInterface; | use Lc\ShopBundle\Context\ProductCategoryInterface; | ||||
use Lc\ShopBundle\Context\ProductFamilyInterface; | use Lc\ShopBundle\Context\ProductFamilyInterface; | ||||
use Lc\ShopBundle\Context\ProductInterface; | |||||
use Lc\ShopBundle\Context\ReductionCatalogInterface; | use Lc\ShopBundle\Context\ReductionCatalogInterface; | ||||
use Lc\ShopBundle\Context\TaxRateInterface; | use Lc\ShopBundle\Context\TaxRateInterface; | ||||
use Lc\ShopBundle\Form\Backend\Common\AbstractEditPositionType; | use Lc\ShopBundle\Form\Backend\Common\AbstractEditPositionType; | ||||
} | } | ||||
} | } | ||||
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 | //si il existe un et un seul produit pour ce product family n'ajoute rien supprime rien | ||||
if (count($entity->getProducts()) == 0) { | if (count($entity->getProducts()) == 0) { | ||||
$entity->addProduct($product); | $entity->addProduct($product); | ||||
} else { | } else { | ||||
foreach ($entity->getProducts() as $i => $product) { | foreach ($entity->getProducts() as $i => $product) { | ||||
dump($product); | |||||
if ($clone) { | if ($clone) { | ||||
$newProduct = clone $product; | $newProduct = clone $product; | ||||
$newProduct->setProductFamily($entity); | $newProduct->setProductFamily($entity); | ||||
$entity->addProduct($product); | $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) | protected function processCategories(ProductFamilyInterface $entity) | ||||
$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']; | ||||
foreach ($entity->getProducts() as $product){ | |||||
dump($product); | |||||
} | |||||
if ($this->request->isXmlHttpRequest() && $property = $this->request->query->get('property')) { | if ($this->request->isXmlHttpRequest() && $property = $this->request->query->get('property')) { | ||||
$newValue = 'true' === mb_strtolower($this->request->query->get('newValue')); | $newValue = 'true' === mb_strtolower($this->request->query->get('newValue')); | ||||
$fieldsMetadata = $this->entity['list']['fields']; | $fieldsMetadata = $this->entity['list']['fields']; | ||||
$deleteForm = $this->createDeleteForm($this->entity['name'], $id); | $deleteForm = $this->createDeleteForm($this->entity['name'], $id); | ||||
$sortableProductsField = array(); | $sortableProductsField = array(); | ||||
foreach ($editForm->get('products')->getData() as $k => $product) { | 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); | ksort($sortableProductsField); | ||||
$editForm->handleRequest($this->request); | $editForm->handleRequest($this->request); |
public function buildForm(FormBuilderInterface $builder, array $options) | public function buildForm(FormBuilderInterface $builder, array $options) | ||||
{ | { | ||||
//dump($builder); | |||||
$builder->add('title', TextType::class, array( | $builder->add('title', TextType::class, array( | ||||
"required" => false | "required" => false |
*/ | */ | ||||
protected $title; | protected $title; | ||||
/** | |||||
* @ORM\Column(type="boolean", nullable=true) | |||||
*/ | |||||
protected $originProduct; | |||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
public function __toString() | 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() | public function getBuyingPriceInherited() | ||||
{ | { | ||||
if ($this->getQuantity()) { | if ($this->getQuantity()) { | ||||
return $this->getQuantity(); | return $this->getQuantity(); | ||||
} | |||||
else { | |||||
} else { | |||||
return $this->getProductFamily()->getQuantity(); | return $this->getProductFamily()->getQuantity(); | ||||
} | } | ||||
} | } | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getOriginProduct(): ?bool | |||||
{ | |||||
return $this->originProduct; | |||||
} | |||||
public function setOriginProduct(?bool $originProduct): self | |||||
{ | |||||
$this->originProduct = $originProduct; | |||||
return $this; | |||||
} | |||||
} | } |
title: null, | title: null, | ||||
position: 0, | position: 0, | ||||
status:1, | status:1, | ||||
originProduct: false, | |||||
fieldToUpdate: ['title', 'unit', 'quantity', 'price'], | fieldToUpdate: ['title', 'unit', 'quantity', 'price'], | ||||
price: null, | price: null, | ||||
priceWithTax: null, | priceWithTax: null, | ||||
}, | }, | ||||
deleteProductForm: function () { | deleteProductForm: function () { | ||||
if (confirm('Êtes-vous sur de cette action ?')) { | 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.$nextTick(function () { | ||||
this.$parent.updateSortableProducts(true); | this.$parent.updateSortableProducts(true); | ||||
}); | |||||
});*/ | |||||
} | } | ||||
}, | }, |
{% macro product_row(product, totalProductOrdered) %} | {% macro product_row(product, totalProductOrdered) %} | ||||
<tr class="lc-draggable"> | |||||
<tr class="lc-draggable" v-show="originProduct != true && status >= 0 "> | |||||
<td> | <td> | ||||
{% if product.vars.value is not null %} | {% if product.vars.value is not null %} | ||||
#{{ product.vars.value.id }} | #{{ product.vars.value.id }} |
</th> | </th> | ||||
<th colspan="3" class="price"> | <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 | PV HT | ||||
</th> | </th> | ||||
<th colspan="3" class="price main-info"> | <th colspan="3" class="price main-info"> | ||||
</th> | </th> | ||||
<th colspan="3" class="price"> | <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} | ${productFamily.price} | ||||
</th> | </th> | ||||
<th colspan="3" class="price main-info"> | <th colspan="3" class="price main-info"> | ||||
{% for keyForm,i in sortableProductsField %} | {% for keyForm,i in sortableProductsField %} | ||||
{% set product = form.products[i] %} | {% 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 }}] = { | 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.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.position %}position: "{{ product.vars.value.position }}",{% endif %} | ||||
{% if product.vars.value.title %}title: "{{ product.vars.value.title }}",{% endif %} | {% if product.vars.value.title %}title: "{{ product.vars.value.title }}",{% endif %} | ||||
{#{% if product.vars.value.expirationDate %}expirationDate: "{{ product.vars.value.expirationDate|date('d/m/Y') }}"{% endif %}#} | {#{% 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 }}'; | window.formProductTemplate[{{ keyForm }}] = '{{ product_family_macros.product_row(product, totalProductOrdered[product.vars.value.id])|replace({"\n":' ', "\r":' ', "'" : "\\'"})|raw }}'; | ||||
{#{% endif %}#} | |||||
{% endfor %} | {% endfor %} | ||||
</script> | </script> |