Last active
April 23, 2016 17:02
-
-
Save kurozumi/97676bdb5a35039b478202cb22c2bfe2 to your computer and use it in GitHub Desktop.
【EC-CUBE3】指定した商品の過去一ヶ月の注文数を集計する方法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Plugin\Sample\Controller; | |
| use Eccube\Application; | |
| use Eccube\Common\Constant; | |
| use Symfony\Component\HttpFoundation\Request; | |
| class SampleController | |
| { | |
| public function index(Application $app, Request $request) | |
| { | |
| $qb = $app['orm.em']->getRepository('Eccube\Entity\OrderDetail') | |
| ->createQueryBuilder('od') | |
| ->innerJoin('od.Product', 'p') | |
| ->innerJoin('Eccube\Entity\Order', 'o', 'WITH', 'o.id = od.Order') | |
| ->select('COUNT(p.id) AS orders') | |
| ->groupBy('p.id') | |
| ->where('o.order_date >= :now') | |
| ->andWhere('p.id = :product_id') | |
| ->setParameter('product_id', $app['request']->get('id')) | |
| ->setParameter('now', new \DateTime('-1 month')); | |
| $result = $qb | |
| ->getQuery() | |
| ->getSingleResult(); | |
| dump($result); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment