Browse Source

[Backend] Gestion des sections dans catégories / produits / Commandes

feature/module_traiteur_v1
Fab 4 years ago
parent
commit
05765b4d45
8 changed files with 117 additions and 15 deletions
  1. +9
    -0
      ShopBundle/Controller/Backend/AdminController.php
  2. +14
    -9
      ShopBundle/Form/Backend/ProductFamily/ProductFamilyCategoriesType.php
  3. +21
    -3
      ShopBundle/Model/ProductCategory.php
  4. +50
    -0
      ShopBundle/Model/Section.php
  5. +9
    -0
      ShopBundle/Resources/public/js/backend/script/productfamily/vuejs-product-family.js
  6. +1
    -0
      ShopBundle/Resources/translations/lcshop.fr.yaml
  7. +1
    -1
      ShopBundle/Resources/views/backend/productfamily/form.html.twig
  8. +12
    -2
      ShopBundle/Resources/views/backend/productfamily/panel_general.html.twig

+ 9
- 0
ShopBundle/Controller/Backend/AdminController.php View File

protected $mailUtils ; protected $mailUtils ;
protected $translator; protected $translator;
protected $utilsProcess; protected $utilsProcess;
protected $sectionUtils;
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->orderUtils = $utilsManager->getOrderUtils();; $this->orderUtils = $utilsManager->getOrderUtils();;
$this->mailUtils = $utilsManager->getMailUtils() ; $this->mailUtils = $utilsManager->getMailUtils() ;
$this->utilsProcess = $utilsManager->getUtilsProcess() ; $this->utilsProcess = $utilsManager->getUtilsProcess() ;
$this->sectionUtils = $utilsManager->getSectionUtils() ;
$this->translator = $translator; $this->translator = $translator;
} }


$dqlFilter = sprintf(str_replace('currentMerchant', $this->getUser()->getMerchant()->getId(), $dqlFilter)); $dqlFilter = sprintf(str_replace('currentMerchant', $this->getUser()->getMerchant()->getId(), $dqlFilter));
} }


if ($pos = strpos($dqlFilter, 'sectionLunch')) {
$dqlFilter = sprintf(str_replace('sectionLunch', $this->sectionUtils->getSection('lunch')->getId(), $dqlFilter));
}else if ($pos = strpos($dqlFilter, 'sectionMarket')) {
$dqlFilter = sprintf(str_replace('sectionMarket', $this->sectionUtils->getSection('market')->getId(), $dqlFilter));
}

if (new $entityClass instanceof StatusInterface && strpos($dqlFilter, 'entity.status') === false) { if (new $entityClass instanceof StatusInterface && strpos($dqlFilter, 'entity.status') === false) {
if ($dqlFilter) $dqlFilter .= sprintf(' AND entity.status > = 0'); if ($dqlFilter) $dqlFilter .= sprintf(' AND entity.status > = 0');
else $dqlFilter .= sprintf(' entity.status > = 0'); else $dqlFilter .= sprintf(' entity.status > = 0');
$form->add($child->getName(), EntityType::class, array( $form->add($child->getName(), EntityType::class, array(
'class' => $this->em->getClassMetadata($passedOptions['class'])->getName(), 'class' => $this->em->getClassMetadata($passedOptions['class'])->getName(),
'label' => $passedOptions['label'], 'label' => $passedOptions['label'],
'expanded' => isset($passedOptions['expanded']) ? $passedOptions['expanded'] : false,
'multiple' => isset($passedOptions['multiple']) ? $passedOptions['multiple'] : false, 'multiple' => isset($passedOptions['multiple']) ? $passedOptions['multiple'] : false,
'placeholder' => '--', 'placeholder' => '--',
'translation_domain' => 'lcshop', 'translation_domain' => 'lcshop',

+ 14
- 9
ShopBundle/Form/Backend/ProductFamily/ProductFamilyCategoriesType.php View File

class ProductFamilyCategoriesType extends AbstractType class ProductFamilyCategoriesType extends AbstractType
{ {
protected $em; protected $em;
protected $productCategoryRepository ;
protected $productCategoryRepository;


public function __construct(EntityManagerInterface $entityManager, ProductCategoryRepository $productCategoryRepository) public function __construct(EntityManagerInterface $entityManager, ProductCategoryRepository $productCategoryRepository)
{ {
$this->em = $entityManager; $this->em = $entityManager;
$this->productCategoryRepository = $productCategoryRepository ;
$this->productCategoryRepository = $productCategoryRepository;
} }


public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)


foreach ($categories as $category) { foreach ($categories as $category) {
$builder->add('category_' . $category->getId(), CheckboxType::class, [ $builder->add('category_' . $category->getId(), CheckboxType::class, [
'label' => $category->getStatus() == 0 ? $category->getTitle() .' (hors ligne)': $category->getTitle() ,
'label' => $category->getStatus() == 0 ? $category->getTitle() . ' (hors ligne)' : $category->getTitle(),
'data' => $currentProductCategories->contains($category), 'data' => $currentProductCategories->contains($category),
'required' => false, 'required' => false,
'disabled'=>true,
'attr'=>[
'class'=>'none'
]
'disabled' => true,
'attr' => [
'class' => 'none',
'data-section' => $category->getSection()->getId()
],
]); ]);
$childrenCategories = $this->productCategoryRepository->findAllByParent($category, true); $childrenCategories = $this->productCategoryRepository->findAllByParent($category, true);
foreach ($childrenCategories as $children) { foreach ($childrenCategories as $children) {
$builder->add('category_children_' . $children->getId(), CheckboxType::class, [ $builder->add('category_children_' . $children->getId(), CheckboxType::class, [
'label' => $children->getStatus() == 0 ? $children->getTitle() .' (hors ligne)': $children->getTitle() ,
'label' => $children->getStatus() == 0 ? $children->getTitle() . ' (hors ligne)' : $children->getTitle(),
'data' => $currentProductCategories->contains($children), 'data' => $currentProductCategories->contains($children),
'required' => false
'required' => false,
'attr' => [
'data-section' => $category->getSection()->getId()
],

]); ]);
} }
} }

+ 21
- 3
ShopBundle/Model/ProductCategory.php View File



namespace Lc\ShopBundle\Model; namespace Lc\ShopBundle\Model;


use App\Entity\Hub;
use App\Entity\ProductFamily;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
protected $childrens; protected $childrens;


/** /**
* @ORM\ManyToMany(targetEntity="App\Entity\ProductFamily", mappedBy="productCategories")
* @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\ProductFamilyInterface", mappedBy="productCategories")
*/ */
protected $productFamilies; protected $productFamilies;


*/ */
protected $saleStatus; protected $saleStatus;



/**
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\SectionInterface", inversedBy="productCategories")
* @ORM\JoinColumn(nullable=false)
*/
protected $section;

public function __construct() public function __construct()
{ {
$this->childrens = new ArrayCollection(); $this->childrens = new ArrayCollection();


return $this; return $this;
} }

public function getSection(): ?Section
{
return $this->section;
}

public function setSection(?Section $section): self
{
$this->section = $section;

return $this;
}

} }

+ 50
- 0
ShopBundle/Model/Section.php View File



namespace Lc\ShopBundle\Model; namespace Lc\ShopBundle\Model;


use App\Entity\Hub;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
*/ */
protected $orderShops; protected $orderShops;



/**
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\ProductCategoryInterface", mappedBy="section")
*/
protected $productCategories;

public function __construct() public function __construct()
{ {
$this->productFamilies = new ArrayCollection(); $this->productFamilies = new ArrayCollection();
return $this->getTitle(); return $this->getTitle();
} }


public function getMerchant(): ?Hub
{
return $this->merchant;
}

public function setMerchant(?Hub $merchant): self
{
$this->merchant = $merchant;

return $this;
}

public function getCycle(): ?string public function getCycle(): ?string
{ {
return $this->cycle; return $this->cycle;


return $this; return $this;
} }

/**
* @return Collection|ProductCategory[]
*/
public function getProductCategories(): Collection
{
return $this->productCategories;
}

public function addProductCategory(ProductCategory $productCategory): self
{
if (!$this->productCategories->contains($productCategory)) {
$this->productCategories[] = $productCategory;
$productCategory->setSection($this);
}

return $this;
}

public function removeProductCategory(ProductCategory $productCategory): self
{
if ($this->productCategories->contains($productCategory)) {
$this->productCategories->removeElement($productCategory);
// set the owning side to null (unless already changed)
if ($productCategory->getSection() === $this) {
$productCategory->setSection(null);
}
}

return $this;
}
} }

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

activeProducts: false, activeProducts: false,
giftVoucherActive: false, giftVoucherActive: false,
productsQuantityAsTitle: false, productsQuantityAsTitle: false,
section: null,
formProducts: {}, formProducts: {},
currentSection: 'general', currentSection: 'general',
sectionsArray: [ sectionsArray: [
} }


} }
this.sectionHasChanged();
this.initLcSortableProductsList(); this.initLcSortableProductsList();
}); });


if (typeof this.$refs.productUnitPrice !== 'undefined') { if (typeof this.$refs.productUnitPrice !== 'undefined') {
return this.$refs.productUnitPrice.behaviorPrice; return this.$refs.productUnitPrice.behaviorPrice;
} }
},
sectionHasChanged: function (){
$('.product-categories').find('.form-check-input:not(.none)').prop('disabled', true);
$('.product-categories').find('.form-check-input[data-section="'+this.section+'"]:not(.none)').prop('disabled', false);
} }
}, },
watch: { watch: {
title: function () { title: function () {
this.updateChild() this.updateChild()
}, },
section: function (){
this.sectionHasChanged()
},
propertyNoveltyExpirationDateActive: function () { propertyNoveltyExpirationDateActive: function () {
if(!this.propertyNoveltyExpirationDateActive){ if(!this.propertyNoveltyExpirationDateActive){
this.propertyNoveltyExpirationDate = null; this.propertyNoveltyExpirationDate = null;

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

editStockNoQuantityDefault: "Le stock n'a pas été modifié pour le produit #%id% (Aucune quantité par défaut)" editStockNoQuantityDefault: "Le stock n'a pas été modifié pour le produit #%id% (Aucune quantité par défaut)"
field: field:
default: default:
section: Espace
unit: Unité unit: Unité
placeholder: Choisissez une option placeholder: Choisissez une option
deliveryPointSale: Lieu de livraison deliveryPointSale: Lieu de livraison

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

{% import '@LcShop/backend/productfamily/macros.html.twig' as product_family_macros %} {% import '@LcShop/backend/productfamily/macros.html.twig' as product_family_macros %}


{% set formValues = form.vars.value %} {% set formValues = form.vars.value %}

<div id="lc-product-family-edit"> <div id="lc-product-family-edit">
<div class="card card-light"> <div class="card card-light">
<div class="lc-vue-js-container card-header p-0 border-bottom-0"> <div class="lc-vue-js-container card-header p-0 border-bottom-0">
{% if formValues.activeProducts %}activeProducts: "{{ formValues.activeProducts }}",{% endif %} {% if formValues.activeProducts %}activeProducts: "{{ formValues.activeProducts }}",{% endif %}
{% if formValues.giftVoucherActive %}giftVoucherActive: "{{ formValues.giftVoucherActive }}",{% endif %} {% if formValues.giftVoucherActive %}giftVoucherActive: "{{ formValues.giftVoucherActive }}",{% endif %}
{% if formValues.productsQuantityAsTitle %}productsQuantityAsTitle: {{ formValues.productsQuantityAsTitle }},{% endif %} {% if formValues.productsQuantityAsTitle %}productsQuantityAsTitle: {{ formValues.productsQuantityAsTitle }},{% endif %}
{% if form.sections.vars.value %}section: {{ form.sections.vars.value[0] }},{% endif %}


}; };
multiplyingFactor = "{{ form.multiplyingFactor.vars.value }}" multiplyingFactor = "{{ form.multiplyingFactor.vars.value }}"

+ 12
- 2
ShopBundle/Resources/views/backend/productfamily/panel_general.html.twig View File

</div> </div>


<div class="col-12"> <div class="col-12">
{{ form_row(form.sections) }}
{{ form_label(form.sections) }}
{% for section in form.sections %}
<div class="form-check">
<label class="form-check-label" for="{{ section.vars.id }}">
<input v-model="section" type="radio" id="{{ section.vars.id }}" name="{{ section.vars.full_name }}" class="form-check-input" value="{{ section.vars.value }}" {{ section.vars.checked == true ? 'checked="checked"' : '' }}>
<span class="checkmark"></span>
{{ section.vars.label }}
</label>
</div>
{% endfor %}
{% do form.sections.setRendered %}
</div> </div>
{{ macros.endCard() }} {{ macros.endCard() }}


<div class="col-12 product-categories"> <div class="col-12 product-categories">
{% for category in form.productCategories %} {% for category in form.productCategories %}


<div class="field {{ category.vars.disabled ? 'parent' }}">
<div class="field {{ category.vars.disabled ? 'parent' }}">
{{ form_row(category) }} {{ form_row(category) }}
</div> </div>



Loading…
Cancel
Save