<?php
namespace Customize\Repository;
use Eccube\Entity\Product;
use Eccube\Repository\ProductRepository;
use Doctrine\Persistence\ManagerRegistry as RegistryInterface;
use Eccube\Common\EccubeConfig;
use Eccube\Doctrine\Query\Queries;
use Eccube\Repository\Master\ProductStatusRepository;
class ProductRepositoryCustomize extends ProductRepository{
/** @var ProductSalesRepository */
protected $productSalesRepository;
/** @var ProductStatusRepository */
protected $productStatusRepository; // 追加
/**
* ProductRepository constructor.
*
* @param RegistryInterface $registry
* @param Queries $queries
* @param EccubeConfig $eccubeConfig
* @param ProductStatusRepository $productStatusRepository
*/
public function __construct(
RegistryInterface $registry,
Queries $queries,
EccubeConfig $eccubeConfig,
ProductSalesRepository $productSalesRepository,
ProductStatusRepository $productStatusRepository
) {
parent::__construct($registry, $queries,$eccubeConfig);
$this->productSalesRepository = $productSalesRepository;
$this->productStatusRepository = $productStatusRepository;
}
/**
* 指定カラムの並び順で全データを取得
*
* @param string $column
* @param string $type
* @return void
*/
public function getOrderBy(string $column = 'id',string $type = 'DESC'){
$status = $this->productStatusRepository->findOneBy(['id' => 1]);
$qb = $this->createQueryBuilder('p');
$qb->innerJoin('p.ProductClasses', 'pc');
$qb->andWhere('p.Status = :Status')->setParameter('Status',$status);
$qb->andWhere('pc.visible = :visible')->setParameter('visible', 1);
$qb->orderBy('p.' . $column,$type);
return $qb->getQuery()->getResult();
}
/**
* 指定の販売IDの商品を取得する
*
* @param integer $id
* @param string $column
* @param string $type
* @return void
*/
public function getProductSales(int $id,string $column = 'id',string $type = 'DESC'){
$productSales = $this->productSalesRepository->find($id);
$qb = $this->createQueryBuilder('p');
$qb->where('p.ProductSales = :sales')->setParameter('sales',$productSales);
$qb->orderBy('p.' . $column,$type);
return $qb->getQuery()->getResult();
}
}