Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active April 23, 2016 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurozumi/97676bdb5a35039b478202cb22c2bfe2 to your computer and use it in GitHub Desktop.
Save kurozumi/97676bdb5a35039b478202cb22c2bfe2 to your computer and use it in GitHub Desktop.
【EC-CUBE3】指定した商品の過去一ヶ月の注文数を集計する方法
<?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