Sonata\ProductBundle\Repository\BaseProductRepository::findLastActiveProducts PHP Method

findLastActiveProducts() public method

Returns an array of last products.
public findLastActiveProducts ( integer $limit = 5 ) : array
$limit integer Number max of required results
return array
    public function findLastActiveProducts($limit = 5)
    {
        return $this->createQueryBuilder('p')->select('p', 'i', 'g')->distinct()->leftJoin('p.image', 'i')->leftJoin('p.gallery', 'g')->leftJoin('p.variations', 'pv')->andWhere('p.parent IS NULL')->andWhere('p.enabled = :enabled')->andWhere('pv.enabled = :enabled or pv.enabled IS NULL')->andWhere('p.stock != 0')->andWhere('p.price != 0')->andWhere('pv.stock != 0 or pv.stock IS NULL')->andWhere('pv.price != 0 or pv.price IS NULL')->orderBy('p.createdAt', 'DESC')->setMaxResults($limit)->setParameters(array('enabled' => true))->getQuery()->execute();
    }
BaseProductRepository