Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
【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
You can’t perform that action at this time.