protected $merchant; | protected $merchant; | ||||
/** | /** | ||||
* @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\ProductCategoryInterface", inversedBy="productFamilies", fetch="EAGER") | |||||
* @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\ProductCategoryInterface", inversedBy="productFamilies") | |||||
*/ | */ | ||||
protected $productCategories; | protected $productCategories; | ||||
protected $productsType; | protected $productsType; | ||||
/** | /** | ||||
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\ProductInterface", mappedBy="productFamily", orphanRemoval=true, cascade={"persist"}, fetch="EAGER") | |||||
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\ProductInterface", mappedBy="productFamily", orphanRemoval=true, cascade={"persist"}) | |||||
*/ | */ | ||||
protected $products; | protected $products; | ||||
/** | /** | ||||
* @method ProductFamilyInterface|null find($id, $lockMode = null, $lockVersion = null) | * @method ProductFamilyInterface|null find($id, $lockMode = null, $lockVersion = null) | ||||
* @method ProductFamilyInterface|null findOneBy(array $criteria, array $orderBy = null) | * @method ProductFamilyInterface|null findOneBy(array $criteria, array $orderBy = null) | ||||
* @method ProductFamilyInterface[] findAll() | |||||
* @method ProductFamilyInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | * @method ProductFamilyInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | ||||
*/ | */ | ||||
class ProductFamilyRepository extends BaseRepository implements DefaultRepositoryInterface | class ProductFamilyRepository extends BaseRepository implements DefaultRepositoryInterface | ||||
$query->innerJoin('e.products', 'pfp'); | $query->innerJoin('e.products', 'pfp'); | ||||
$query->addSelect('pfp') ; | $query->addSelect('pfp') ; | ||||
$query->innerJoin('e.supplier', 'pfs'); | |||||
$query->addSelect('pfs') ; | |||||
return $query ; | return $query ; | ||||
} | } | ||||
public function findAll() | |||||
{ | |||||
$query = $this->findByMerchantQuery() ; | |||||
$query = $this->joinRelations($query) ; | |||||
return $query->getQuery()->getResult() ; | |||||
} | |||||
public function getProductFamiliesByCategory($category){ | public function getProductFamiliesByCategory($category){ | ||||
$query = $this->findByMerchantQuery() ; | $query = $this->findByMerchantQuery() ; | ||||
$query = $this->joinRelations($query) ; | $query = $this->joinRelations($query) ; |
public function getReductionCatalogByProductFamily($productFamily, $user) | public function getReductionCatalogByProductFamily($productFamily, $user) | ||||
{ | { | ||||
$query = $this->findByMerchantQuery(); | $query = $this->findByMerchantQuery(); | ||||
$query->andWhere('e.status = 1'); | $query->andWhere('e.status = 1'); | ||||
$query->andWhere(':user MEMBER OF e.users OR e.users is empty'); | $query->andWhere(':user MEMBER OF e.users OR e.users is empty'); | ||||
$query->setParameter('productCategory', $productFamily->getProductCategories()); | $query->setParameter('productCategory', $productFamily->getProductCategories()); | ||||
$query->setParameter('supplier', $productFamily->getSupplier()); | $query->setParameter('supplier', $productFamily->getSupplier()); | ||||
return $query->getQuery()->getResult(); | return $query->getQuery()->getResult(); | ||||
} | } | ||||
public function getReductionCatalogByProductFamilyConditions($productFamilyIds, $user) | public function getReductionCatalogByProductFamilyConditions($productFamilyIds, $user) | ||||
{ | { | ||||
$query = $this->findByMerchantQuery(); | $query = $this->findByMerchantQuery(); | ||||
$query->andWhere('e.status = 1'); | $query->andWhere('e.status = 1'); | ||||
$query->andWhere('e.permanent = 1 OR (e.dateStart <= :now AND e.dateEnd >= :now)'); | $query->andWhere('e.permanent = 1 OR (e.dateStart <= :now AND e.dateEnd >= :now)'); | ||||
$query->leftJoin('e.productFamilies', 'pfs') ; | |||||
$query->addSelect('pfs') ; | |||||
$query->leftJoin('e.productFamily', 'pf') ; | |||||
$query->addSelect('pf') ; | |||||
$query->leftJoin('e.productCategories', 'pc') ; | |||||
$query->addSelect('pc') ; | |||||
if($user){ | if($user){ | ||||
$query->andWhere(':user MEMBER OF e.users OR e.users is empty'); | $query->andWhere(':user MEMBER OF e.users OR e.users is empty'); | ||||
$query->andWhere(':groupUser MEMBER OF e.groupUsers OR e.groupUsers is empty'); | $query->andWhere(':groupUser MEMBER OF e.groupUsers OR e.groupUsers is empty'); | ||||
$query->setParameter(':now', new \DateTime()); | $query->setParameter(':now', new \DateTime()); | ||||
return $query->getQuery()->getResult(); | return $query->getQuery()->getResult(); | ||||
} | } | ||||
} | } |