Browse Source

Merge branch 'develop'

master
Guillaume 4 years ago
parent
commit
e7f11bee1e
14 changed files with 383 additions and 152 deletions
  1. +17
    -21
      ShopBundle/Controller/Backend/AdminController.php
  2. +1
    -1
      ShopBundle/Controller/Backend/MerchantController.php
  3. +13
    -109
      ShopBundle/Controller/Backend/ProductFamilyController.php
  4. +1
    -0
      ShopBundle/Form/Backend/ProductFamily/ProductType.php
  5. +0
    -1
      ShopBundle/Model/AbstractEntity.php
  6. +21
    -6
      ShopBundle/Model/Product.php
  7. +36
    -4
      ShopBundle/Model/ProductFamily.php
  8. +3
    -1
      ShopBundle/Resources/public/js/backend/script/productfamily/vuejs-product-family.js
  9. +1
    -1
      ShopBundle/Resources/views/backend/productfamily/macros.html.twig
  10. +5
    -2
      ShopBundle/Resources/views/backend/productfamily/panel_products.html.twig
  11. +123
    -5
      ShopBundle/Services/ProductFamilyUtils.php
  12. +46
    -0
      ShopBundle/Services/Utils.php
  13. +9
    -1
      ShopBundle/Services/UtilsManager.php
  14. +107
    -0
      ShopBundle/Services/UtilsProcess.php

+ 17
- 21
ShopBundle/Controller/Backend/AdminController.php View File

protected $orderUtils; protected $orderUtils;
protected $mailUtils ; protected $mailUtils ;
protected $translator; protected $translator;
protected $utilsProcess;
protected $filtersForm = null; protected $filtersForm = null;


public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em,
$this->merchantUtils = $utilsManager->getMerchantUtils(); $this->merchantUtils = $utilsManager->getMerchantUtils();
$this->orderUtils = $utilsManager->getOrderUtils();; $this->orderUtils = $utilsManager->getOrderUtils();;
$this->mailUtils = $utilsManager->getMailUtils() ; $this->mailUtils = $utilsManager->getMailUtils() ;
$this->utilsProcess = $utilsManager->getUtilsProcess() ;
$this->translator = $translator; $this->translator = $translator;
} }




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


$newEntity = clone $entity ;

if($newEntity instanceof ImageInterface){
$newEntity->setImage(null);
}

$this->em->persist($newEntity) ;
$this->em->flush() ;
$newEntity = $this->utilsProcess->duplicateEntity($entity);


return $this->redirectToRoute('easyadmin', ['entity' => $easyadmin['entity']['name'], 'action' => 'edit', 'id' =>$newEntity->getId(), 'referer' =>$refererUrl ]) ; return $this->redirectToRoute('easyadmin', ['entity' => $easyadmin['entity']['name'], 'action' => 'edit', 'id' =>$newEntity->getId(), 'referer' =>$refererUrl ]) ;
} }
$entity= $this->em->getRepository($easyadmin['entity']['class'])->find($id); $entity= $this->em->getRepository($easyadmin['entity']['class'])->find($id);
$hub= $this->em->getRepository(MerchantInterface::class)->findOneByDevAlias($hubAlias); $hub= $this->em->getRepository(MerchantInterface::class)->findOneByDevAlias($hubAlias);


$newEntity = clone $entity ;
$newEntity = $this->utilsProcess->duplicateEntityToOtherHub($entity,$hub);


if($newEntity instanceof ImageInterface){
$newEntity->setImage(null);
}
$user->setMerchant($hub);
$this->em->persist($user);
$this->em->flush();


$redirectUrl = $this->generateUrl('easyadmin', ['entity' => $easyadmin['entity']['name'], 'action' => 'edit', 'id' =>$newEntity->getId(), 'referer' =>$refererUrl ]).'&hubredirection=true';


if ($hub) {
$newEntity->setMerchant($hub);
$user->setMerchant($hub);
$this->em->persist($user);
}
$this->em->persist($newEntity) ;
$this->em->flush() ;
return $this->redirectToOtherHub($hub, $redirectUrl) ;
}


$redirectUrl = $hub->getMerchantConfig('url').substr($this->generateUrl('easyadmin', ['entity' => $easyadmin['entity']['name'], 'action' => 'edit', 'id' =>$newEntity->getId(), 'referer' =>$refererUrl ]),1).'&hubredirection=true';
public function redirectToOtherHub($hub, $url){
if(strpos($_SERVER['HTTP_HOST'], 'localhost')!==false){
return $this->redirect($url);
}else{
return $this->redirect($hub->getMerchantConfig('url').substr($url,1));
}


return $this->redirect($redirectUrl) ;
} }



} }



+ 1
- 1
ShopBundle/Controller/Backend/MerchantController.php View File

$em->persist($user); $em->persist($user);
$em->flush(); $em->flush();


return $this->redirect($merchant->getMerchantConfig('url').'admin/dashboard?hubredirection=true') ;
return $this->redirectToOtherHub($merchant, '/admin/dashboard?hubredirection=true') ;
} }
} }



+ 13
- 109
ShopBundle/Controller/Backend/ProductFamilyController.php View File

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;
private $choicesTaxRateParam; private $choicesTaxRateParam;
private $choicesSupplierTaxRateParam; private $choicesSupplierTaxRateParam;
private $parameterBag ; private $parameterBag ;
private $productFamilyUtils ;


public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em,
MailjetTransport $mailjetTransport, UtilsManager $utilsManager, TranslatorInterface $translator, MailjetTransport $mailjetTransport, UtilsManager $utilsManager, TranslatorInterface $translator,
{ {
parent::__construct($security, $userManager, $em, $mailjetTransport, $utilsManager, $translator); parent::__construct($security, $userManager, $em, $mailjetTransport, $utilsManager, $translator);
$this->parameterBag = $parameterBag ; $this->parameterBag = $parameterBag ;
$this->productFamilyUtils = $utilsManager->getProductFamilyUtils() ;
} }


public function createEntityFormBuilder($entity, $view, $override = true) public function createEntityFormBuilder($entity, $view, $override = true)
public function updateProductFamilyEntity($entity, $editForm = false) public function updateProductFamilyEntity($entity, $editForm = false)
{ {
if ($editForm) { if ($editForm) {
$this->processReductionCatalog($entity, $editForm);
$this->processCategories($entity);
$this->processProducts($entity);
$this->processPrice($entity);
$entity = $this->productFamilyUtils->processBeforePersistProductFamily($entity, $editForm);
} }


parent::updateEntity($entity); parent::updateEntity($entity);


public function persistProductFamilyEntity($entity, $newForm) public function persistProductFamilyEntity($entity, $newForm)
{ {
$this->processReductionCatalog($entity, $newForm);
$this->processCategories($entity);
$this->processProducts($entity);
$this->processPrice($entity);
$entity = $this->productFamilyUtils->processBeforePersistProductFamily($entity, $newForm);


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


protected function processReductionCatalog($entity, $editForm)
{
$reductionCatalog = $editForm->get('reductionCatalog')->getData();
if ($reductionCatalog instanceof ReductionCatalogInterface) {
if ($reductionCatalog->getValue() && $reductionCatalog->getBehaviorTaxRate() && $reductionCatalog->getUnit()) {
$reductionCatalog->setMerchant($entity->getMerchant());
$reductionCatalog->setStatus($editForm->get('activeReductionCatalog')->getData());
$reductionCatalog->setProductFamily($entity);
$this->em->persist($reductionCatalog);
}
}
}

protected function processPrice($entity)
{
if ($entity->getBehaviorPrice() == 'by-piece') {
$entity->setPriceByRefUnit(null);
$entity->setBuyingPriceByRefUnit(null);
} else if ($entity->getBehaviorPrice() == 'by-reference-unit') {
$entity->setPrice(null);
$entity->setBuyingPrice(null);
}
}

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 {
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);
}
}
}

}

protected function processCategories(ProductFamilyInterface $entity)
{
$productCategoryRepository = $this->getDoctrine()->getRepository(ProductCategoryInterface::class);
$productCategories = $entity->getProductCategories();

$entity->initProductCategories();

foreach ($productCategories as $key => $bool) {
if (is_bool($bool) && $bool) {
if (strpos($key, 'category_children_') !== false) {
$idCategory = (int)str_replace('category_children_', '', $key);
} else {
$idCategory = (int)str_replace('category_', '', $key);
}

$category = $productCategoryRepository->find($idCategory);
$entity->addProductCategory($category);
}
}
}

protected function editAction() protected function editAction()
{ {


$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;
}


}


}
ksort($sortableProductsField); ksort($sortableProductsField);


$editForm->handleRequest($this->request); $editForm->handleRequest($this->request);
'entity' => $entity, 'entity' => $entity,
'categories' => $categories, 'categories' => $categories,
'sortableProductsField' => array(), 'sortableProductsField' => array(),
'totalProductOrdered' => array()
'totalProductOrdered' => array('total'=>0)
]; ];


return $this->executeDynamicMethod('render<EntityName>Template', ['new', $this->entity['templates']['new'], $parameters]); 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->processProducts($newProductFamily, true);
}

if($newProductFamily instanceof ImageInterface) {
$basePath = $this->parameterBag->get('kernel.project_dir').'/public/uploads/images/' ;
$imageProductFamily = 'produits/'.md5(time()).'.jpg' ;
copy($basePath.$entity->getImage(), $basePath.$imageProductFamily) ;
$newProductFamily->setImage($imageProductFamily);
}

$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 //hack utilisé pour filter sur les catégories lors du tri des produits par sous cat
//A améliorer à l'occas //A améliorer à l'occas

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

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

+ 0
- 1
ShopBundle/Model/AbstractEntity.php View File

*/ */
protected $updatedBy; protected $updatedBy;



public function getCreatedAt(): ?\DateTimeInterface public function getCreatedAt(): ?\DateTimeInterface
{ {
return $this->createdAt; return $this->createdAt;

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

*/ */
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;
}
} }

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



case self::BEHAVIOR_COUNT_STOCK_BY_PRODUCT : case self::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :


foreach($this->getProducts() as $product) {
foreach($this->getProductsOnline() as $product) {
$availableQuantity += $product->getAvailableQuantityInherited() ; $availableQuantity += $product->getAvailableQuantityInherited() ;
} }
break ; break ;
$productsOnlineArray = new ArrayCollection() ; $productsOnlineArray = new ArrayCollection() ;


foreach($products as $product) { foreach($products as $product) {
if($product->getStatus() == 1) {
if($product->getStatus() == 1 && $product->getOriginProduct() !=true) {
$productsOnlineArray[] = $product ; $productsOnlineArray[] = $product ;
} }
} }
{ {
if ($this->getActiveProducts()) { if ($this->getActiveProducts()) {
$arrayCountProducts = []; $arrayCountProducts = [];
$products = $this->getProducts();
$products = $this->getProductsOnline();


foreach ($products as $product) { foreach ($products as $product) {
$titleProduct = $product->getTitleInherited(); $titleProduct = $product->getTitleInherited();
public function getProductsGroupByTitle() public function getProductsGroupByTitle()
{ {
$arrayProductsGroupByTitle = []; $arrayProductsGroupByTitle = [];
$products = $this->getProducts();
$products = $this->getProductsOnline();


foreach ($products as $product) { foreach ($products as $product) {
if($product->getStatus() == 1) { if($product->getStatus() == 1) {


return $arrayProductsGroupByTitle; 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

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);
}); });

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



{% 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 }}

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

</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>

+ 123
- 5
ShopBundle/Services/ProductFamilyUtils.php View File



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


use App\Entity\Product;
use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\PriceUtilsInterface; use Lc\ShopBundle\Context\PriceUtilsInterface;
use Lc\ShopBundle\Context\ProductCategoryInterface;
use Lc\ShopBundle\Context\ProductFamilyInterface;
use Lc\ShopBundle\Context\ProductInterface;
use Lc\ShopBundle\Context\ReductionCatalogInterface;
use Lc\ShopBundle\Model\ProductFamily; use Lc\ShopBundle\Model\ProductFamily;


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


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


public function getCheapestProduct($productFamily) public function getCheapestProduct($productFamily)


private function getCheapestOrMostExpensiveProduct($productFamily, $comparisonFunction, $returnSelfIfNotActiveProducts) 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) { if ($returnSelfIfNotActiveProducts) {
return $productFamily; return $productFamily;
} }
} }




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

return $productFamily;
}

protected function processReductionCatalog($entity, $editForm)
{
$reductionCatalog = $editForm->get('reductionCatalog')->getData();
if ($reductionCatalog instanceof ReductionCatalogInterface) {
if ($reductionCatalog->getValue() && $reductionCatalog->getBehaviorTaxRate() && $reductionCatalog->getUnit()) {
$reductionCatalog->setMerchant($entity->getMerchant());
$reductionCatalog->setStatus($editForm->get('activeReductionCatalog')->getData());
$reductionCatalog->setProductFamily($entity);
$this->em->persist($reductionCatalog);
}
}
}

protected function processPrice($entity)
{
if ($entity->getBehaviorPrice() == 'by-piece') {
$entity->setPriceByRefUnit(null);
$entity->setBuyingPriceByRefUnit(null);
} else if ($entity->getBehaviorPrice() == 'by-reference-unit') {
$entity->setPrice(null);
$entity->setBuyingPrice(null);
}
}

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 {
//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);
}
}

}

protected function processCategories(ProductFamilyInterface $entity)
{
$productCategoryRepository = $this->em->getRepository(ProductCategoryInterface::class);
$productCategories = $entity->getProductCategories();

$entity->initProductCategories();

foreach ($productCategories as $key => $bool) {
if (is_bool($bool) && $bool) {
if (strpos($key, 'category_children_') !== false) {
$idCategory = (int)str_replace('category_children_', '', $key);
} else {
$idCategory = (int)str_replace('category_', '', $key);
}

$category = $productCategoryRepository->find($idCategory);
$entity->addProductCategory($category);
}
}
}

} }

+ 46
- 0
ShopBundle/Services/Utils.php View File

use Geocoder\Provider\Addok\Addok; use Geocoder\Provider\Addok\Addok;
use Geocoder\Query\GeocodeQuery; use Geocoder\Query\GeocodeQuery;
use Geocoder\Query\ReverseQuery; use Geocoder\Query\ReverseQuery;
use Lc\ShopBundle\Context\ImageInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface; use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\PageInterface; use Lc\ShopBundle\Context\PageInterface;
use Lc\ShopBundle\Context\PointSaleInterface; use Lc\ShopBundle\Context\PointSaleInterface;
use Lc\ShopBundle\Context\ProductFamilyInterface;
use Lc\ShopBundle\Context\ProductFamilyUtilsInterface;
use Lc\ShopBundle\Context\ReminderInterface; use Lc\ShopBundle\Context\ReminderInterface;
use Lc\ShopBundle\Context\TaxRateInterface; use Lc\ShopBundle\Context\TaxRateInterface;
use Lc\ShopBundle\Context\UnitInterface; use Lc\ShopBundle\Context\UnitInterface;
return $this->parameterBag->get('app.path.images'); return $this->parameterBag->get('app.path.images');
} }



public function duplicateEntity($entity){
$newEntity = clone $entity ;

if($newEntity instanceof ImageInterface){
$this->duplicateImage($entity);
$newEntity->setImage(null);
}

if($newEntity instanceof ProductFamilyInterface){
$this->productFamilyUtils->processBeforePersistProductFamily($newEntity);
}

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

return $newEntity;
}

public function duplicateImage($entity, $folder = false){
$basePath = $this->parameterBag->get('kernel.project_dir').'/public/uploads/images/' ;


if($entity->getImage() && file_exists($basePath.$entity->getImage())) {
dump(pathinfo($basePath.$entity->getImage()));
}
die();


$newImage = md5(uniqid()).'.jpg';
if($folder) $newImage = $folder.'/'.$newImage;

if($entity->getImage() && file_exists($basePath.$entity->getImage())) {
copy($basePath.$entity->getImage(), $basePath . $newImage);
$entity->setImage($newImage);
}else{
$entity->setImage(null);
}
return $entity;
}



} }

+ 9
- 1
ShopBundle/Services/UtilsManager.php View File

use Lc\ShopBundle\Context\PriceUtilsInterface; use Lc\ShopBundle\Context\PriceUtilsInterface;
use Lc\ShopBundle\Context\ProductFamilyUtilsInterface; use Lc\ShopBundle\Context\ProductFamilyUtilsInterface;
use Lc\ShopBundle\Context\Services\StatisticsUtilsInterface; use Lc\ShopBundle\Context\Services\StatisticsUtilsInterface;
use League\Flysystem\Util;


class UtilsManager class UtilsManager
{ {
DocumentUtils $documentUtils, DocumentUtils $documentUtils,
MailUtils $mailUtils, MailUtils $mailUtils,
TicketUtils $ticketUtils, TicketUtils $ticketUtils,
PointLocationUtils $pointLocationUtils
PointLocationUtils $pointLocationUtils,
UtilsProcess $utilsProcess
) )
{ {
$this->utils = $utils ; $this->utils = $utils ;
$this->mailUtils = $mailUtils ; $this->mailUtils = $mailUtils ;
$this->ticketUtils = $ticketUtils ; $this->ticketUtils = $ticketUtils ;
$this->pointLocationUtils = $pointLocationUtils ; $this->pointLocationUtils = $pointLocationUtils ;
$this->utilsProcess = $utilsProcess ;
} }


public function getUtils(): Utils public function getUtils(): Utils
return $this->pointLocationUtils ; return $this->pointLocationUtils ;
} }


public function getUtilsProcess(): UtilsProcess
{
return $this->utilsProcess ;
}

} }

+ 107
- 0
ShopBundle/Services/UtilsProcess.php View File

<?php

namespace Lc\ShopBundle\Services;

use Cocur\Slugify\Slugify;
use Doctrine\ORM\EntityManagerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Configuration\ConfigManager;
use Geocoder\Model\Coordinates;
use Geocoder\Provider\Addok\Addok;
use Geocoder\Query\GeocodeQuery;
use Geocoder\Query\ReverseQuery;
use Lc\ShopBundle\Context\ImageInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\PageInterface;
use Lc\ShopBundle\Context\PointSaleInterface;
use Lc\ShopBundle\Context\ProductFamilyInterface;
use Lc\ShopBundle\Context\ProductFamilyUtilsInterface;
use Lc\ShopBundle\Context\ReminderInterface;
use Lc\ShopBundle\Context\TaxRateInterface;
use Lc\ShopBundle\Context\UnitInterface;
use Lc\ShopBundle\Context\UserInterface;
use Lc\ShopBundle\Context\UserPointSaleInterface;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpClient\HttplugClient;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class UtilsProcess
{
protected $em;
protected $parameterBag;
protected $merchantUtils;
protected $productFamilyUtils;


public function __construct(EntityManagerInterface $em, ParameterBagInterface $parameterBag, ProductFamilyUtilsInterface $productFamilyUtils)
{
$this->em = $em;
$this->parameterBag = $parameterBag;
$this->productFamilyUtils = $productFamilyUtils;
}


public function duplicateEntity($entity, $flush = true)
{
$newEntity = clone $entity;

if ($newEntity instanceof ImageInterface) {
$newEntity = $this->duplicateImage($newEntity);
}

if ($newEntity instanceof ProductFamilyInterface) {
$newEntity = $this->productFamilyUtils->processBeforePersistProductFamily($newEntity, false, true);
}

if(method_exists($newEntity, 'getAddress') && is_object($newEntity->getAddress())){
$address = $newEntity->getAddress();
$newAddress = $this->duplicateEntity($address);
$newEntity->setAddress($newAddress);
$this->em->persist($newAddress);
}

$this->em->persist($newEntity);
if($flush){
$this->em->flush();
}


return $newEntity;
}

public function duplicateEntityToOtherHub($entity, $hub){
$newEntity = $this->duplicateEntity($entity);

if ($hub) {
$newEntity->setMerchant($hub);
}
$this->em->persist($newEntity) ;
$this->em->flush() ;

return $newEntity;
}

public function duplicateImage($entity, $folder = false)
{
$basePath = $this->parameterBag->get('kernel.project_dir') . '/public/uploads/images/';


if ($entity->getImage() && file_exists($basePath . $entity->getImage())) {
$extension = (pathinfo($basePath . $entity->getImage(), PATHINFO_EXTENSION));

if ($extension == "jpg" || $extension == "png" || $extension == "gif") {
$newImage = md5(uniqid()) . '.' . $extension;
if ($folder) $newImage = $folder . '/' . $newImage;
copy($basePath . $entity->getImage(), $basePath . $newImage);
$entity->setImage($newImage);
}
} else {
$entity->setImage(null);
}
return $entity;
}


}

Loading…
Cancel
Save