Преглед изворни кода

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

feature/module_traiteur_v1
Fab пре 3 година
родитељ
комит
05765b4d45
8 измењених фајлова са 117 додато и 15 уклоњено
  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 Прегледај датотеку

@@ -44,6 +44,7 @@ class AdminController extends EasyAdminController
protected $mailUtils ;
protected $translator;
protected $utilsProcess;
protected $sectionUtils;
protected $filtersForm = null;

public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em,
@@ -58,6 +59,7 @@ class AdminController extends EasyAdminController
$this->orderUtils = $utilsManager->getOrderUtils();;
$this->mailUtils = $utilsManager->getMailUtils() ;
$this->utilsProcess = $utilsManager->getUtilsProcess() ;
$this->sectionUtils = $utilsManager->getSectionUtils() ;
$this->translator = $translator;
}

@@ -131,6 +133,12 @@ class AdminController extends EasyAdminController
$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 ($dqlFilter) $dqlFilter .= sprintf(' AND entity.status > = 0');
else $dqlFilter .= sprintf(' entity.status > = 0');
@@ -477,6 +485,7 @@ class AdminController extends EasyAdminController
$form->add($child->getName(), EntityType::class, array(
'class' => $this->em->getClassMetadata($passedOptions['class'])->getName(),
'label' => $passedOptions['label'],
'expanded' => isset($passedOptions['expanded']) ? $passedOptions['expanded'] : false,
'multiple' => isset($passedOptions['multiple']) ? $passedOptions['multiple'] : false,
'placeholder' => '--',
'translation_domain' => 'lcshop',

+ 14
- 9
ShopBundle/Form/Backend/ProductFamily/ProductFamilyCategoriesType.php Прегледај датотеку

@@ -16,12 +16,12 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
class ProductFamilyCategoriesType extends AbstractType
{
protected $em;
protected $productCategoryRepository ;
protected $productCategoryRepository;

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

public function buildForm(FormBuilderInterface $builder, array $options)
@@ -34,20 +34,25 @@ class ProductFamilyCategoriesType extends AbstractType

foreach ($categories as $category) {
$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),
'required' => false,
'disabled'=>true,
'attr'=>[
'class'=>'none'
]
'disabled' => true,
'attr' => [
'class' => 'none',
'data-section' => $category->getSection()->getId()
],
]);
$childrenCategories = $this->productCategoryRepository->findAllByParent($category, true);
foreach ($childrenCategories as $children) {
$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),
'required' => false
'required' => false,
'attr' => [
'data-section' => $category->getSection()->getId()
],

]);
}
}

+ 21
- 3
ShopBundle/Model/ProductCategory.php Прегледај датотеку

@@ -2,8 +2,6 @@

namespace Lc\ShopBundle\Model;

use App\Entity\Hub;
use App\Entity\ProductFamily;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
@@ -34,7 +32,7 @@ abstract class ProductCategory extends AbstractDocumentEntity implements TreeInt
protected $childrens;

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

@@ -43,6 +41,13 @@ abstract class ProductCategory extends AbstractDocumentEntity implements TreeInt
*/
protected $saleStatus;


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

public function __construct()
{
$this->childrens = new ArrayCollection();
@@ -171,4 +176,17 @@ abstract class ProductCategory extends AbstractDocumentEntity implements TreeInt

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 Прегледај датотеку

@@ -2,6 +2,7 @@

namespace Lc\ShopBundle\Model;

use App\Entity\Hub;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
@@ -38,6 +39,12 @@ abstract class Section extends AbstractDocumentEntity implements FilterMerchantI
*/
protected $orderShops;


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

public function __construct()
{
$this->productFamilies = new ArrayCollection();
@@ -49,6 +56,18 @@ abstract class Section extends AbstractDocumentEntity implements FilterMerchantI
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
{
return $this->cycle;
@@ -119,4 +138,35 @@ abstract class Section extends AbstractDocumentEntity implements FilterMerchantI

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 Прегледај датотеку

@@ -426,6 +426,7 @@ $(window).on('load', function () {
activeProducts: false,
giftVoucherActive: false,
productsQuantityAsTitle: false,
section: null,
formProducts: {},
currentSection: 'general',
sectionsArray: [
@@ -487,6 +488,7 @@ $(window).on('load', function () {
}

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

@@ -583,12 +585,19 @@ $(window).on('load', function () {
if (typeof this.$refs.productUnitPrice !== 'undefined') {
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: {
title: function () {
this.updateChild()
},
section: function (){
this.sectionHasChanged()
},
propertyNoveltyExpirationDateActive: function () {
if(!this.propertyNoveltyExpirationDateActive){
this.propertyNoveltyExpirationDate = null;

+ 1
- 0
ShopBundle/Resources/translations/lcshop.fr.yaml Прегледај датотеку

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

+ 1
- 1
ShopBundle/Resources/views/backend/productfamily/form.html.twig Прегледај датотеку

@@ -3,7 +3,6 @@
{% import '@LcShop/backend/productfamily/macros.html.twig' as product_family_macros %}

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

<div id="lc-product-family-edit">
<div class="card card-light">
<div class="lc-vue-js-container card-header p-0 border-bottom-0">
@@ -50,6 +49,7 @@
{% if formValues.activeProducts %}activeProducts: "{{ formValues.activeProducts }}",{% endif %}
{% if formValues.giftVoucherActive %}giftVoucherActive: "{{ formValues.giftVoucherActive }}",{% 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 }}"

+ 12
- 2
ShopBundle/Resources/views/backend/productfamily/panel_general.html.twig Прегледај датотеку

@@ -13,7 +13,17 @@
</div>

<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>
{{ macros.endCard() }}

@@ -50,7 +60,7 @@
<div class="col-12 product-categories">
{% for category in form.productCategories %}

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


Loading…
Откажи
Сачувај