Bladeren bron

Frontend : intégration menu principal / ajout Merchant à ProductCategory

reduction
Guillaume 4 jaren geleden
bovenliggende
commit
2b9a57eab0
4 gewijzigde bestanden met toevoegingen van 109 en 45 verwijderingen
  1. +38
    -0
      ShopBundle/Model/Merchant.php
  2. +58
    -6
      ShopBundle/Model/ProductCategory.php
  3. +10
    -3
      ShopBundle/Repository/BaseRepository.php
  4. +3
    -36
      ShopBundle/Repository/ProductCategoryRepository.php

+ 38
- 0
ShopBundle/Model/Merchant.php Bestand weergeven

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

namespace Lc\ShopBundle\Model;

use App\Entity\ProductCategory;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
@@ -44,11 +45,17 @@ abstract class Merchant extends AbstractDocumentEntity
*/
protected $address;

/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductCategory", mappedBy="merchant", orphanRemoval=true)
*/
private $productCategories;

public function __construct()
{
$this->pointSales = new ArrayCollection();
$this->productFamilies = new ArrayCollection();
$this->merchantConfigs = new ArrayCollection();
$this->productCategories = new ArrayCollection();
}

public function getCreditConfig(): ?CreditConfig
@@ -189,4 +196,35 @@ abstract class Merchant extends AbstractDocumentEntity

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->setMerchant($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->getMerchant() === $this) {
$productCategory->setMerchant(null);
}
}

return $this;
}
}

+ 58
- 6
ShopBundle/Model/ProductCategory.php Bestand weergeven

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

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;
@@ -13,6 +15,12 @@ use Lc\ShopBundle\Context\TreeInterface;
abstract class ProductCategory extends AbstractDocumentEntity implements TreeInterface
{

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

/**
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\ProductCategoryInterface", inversedBy="childrens")
*/
@@ -23,18 +31,22 @@ abstract class ProductCategory extends AbstractDocumentEntity implements TreeInt
*/
protected $childrens;

public function __toString()
{
// TODO: Implement __toString() method.
return $this->getTitle();
}
/**
* @ORM\ManyToMany(targetEntity="App\Entity\ProductFamily", mappedBy="productCategory")
*/
protected $productFamilies;

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


public function __toString()
{
// TODO: Implement __toString() method.
return $this->getTitle();
}

public function getParent(): ?self
{
@@ -78,4 +90,44 @@ abstract class ProductCategory extends AbstractDocumentEntity implements TreeInt

return $this;
}

/**
* @return Collection|ProductFamily[]
*/
public function getProductFamilies(): Collection
{
return $this->productFamilies;
}

public function addProductFamily(ProductFamily $productFamily): self
{
if (!$this->productFamilies->contains($productFamily)) {
$this->productFamilies[] = $productFamily;
$productFamily->addProductCategory($this);
}

return $this;
}

public function removeProductFamily(ProductFamily $productFamily): self
{
if ($this->productFamilies->contains($productFamily)) {
$this->productFamilies->removeElement($productFamily);
$productFamily->removeProductCategory($this);
}

return $this;
}

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

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

return $this;
}
}

+ 10
- 3
ShopBundle/Repository/BaseRepository.php Bestand weergeven

@@ -5,6 +5,7 @@ namespace Lc\ShopBundle\Repository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Security\Core\Security;

class BaseRepository extends EntityRepository implements ServiceEntityRepositoryInterface
{
@@ -33,14 +34,20 @@ class BaseRepository extends EntityRepository implements ServiceEntityRepository
->setParameter('currentMerchant', $merchant->getId())
->getQuery()
->getResult();

}

public function findOneByDevAlias($devAlias)
public function findByMerchantQuery($merchant)
{
return $this->createQueryBuilder('e')
->where('e.merchant = :currentMerchant')
->setParameter('currentMerchant', $merchant->getId()) ;
}

public function findOneByDevAlias($devAlias, $merchant)
{
return $this->findByMerchantQuery($merchant)
->where('e.devAlias = :devAlias')
->andWhere('object.status = 1')
->andWhere('e.status = 1')
->setParameter('devAlias', $devAlias)
->getQuery()
->getResult();

+ 3
- 36
ShopBundle/Repository/ProductCategoryRepository.php Bestand weergeven

@@ -17,57 +17,24 @@ class ProductCategoryRepository extends BaseRepository
{
public function __construct(EntityManager $entityManager)
{

parent::__construct($entityManager, ProductCategoryInterface::class);
}


public static function adminQueryBuilderForTree(BaseRepository $e): QueryBuilder
{

return $e->createQueryBuilder('e')
->where('e.parent is NULL')
->andWhere('e.status >= 0')
->orderBy('e.position', 'ASC');
}

public function findAllParents()
public function findAllParents($merchant)
{
return $this->createQueryBuilder('e')
->where('e.parent is NULL')
return $this->findByMerchantQuery($merchant)
->andWhere('e.parent is NULL')
->andWhere('e.status >= 0')
->orderBy('e.position', 'ASC')
->getQuery()
->getResult();
}


// /**
// * @return ProductCategory[] Returns an array of ProductCategory objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('p')
->andWhere('p.exampleField = :val')
->setParameter('val', $value)
->orderBy('p.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/

/*
public function findOneBySomeField($value): ?ProductCategory
{
return $this->createQueryBuilder('p')
->andWhere('p.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}

Laden…
Annuleren
Opslaan