<commit_before><?php

/*
 * This file is part of the Sonata package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Sonata\ProductBundle\Repository;

use Doctrine\ORM\EntityRepository;

/**
 * @author <NAME> <<EMAIL>>
 */
class BaseProductRepository extends EntityRepository
{
    /**
     * Returns an array of last products.
     *
     * @param int $limit Number max of required results
     *
     * @return array
     */
    public function findLastActiveProducts($limit = 5)
    {
        $rootEnabledProducts = $this->createQueryBuilder('pr')
            ->select('pr.id')
            ->where('pr.parent is null and pr.enabled = :enabled')
            ->andWhere('pr.stock is not null and pr.stock != 0')
            ->andWhere('pr.price is not null and pr.price != 0');

        $enabledChildren = $this->createQueryBuilder('pc')
            ->select('pc.id')
            ->innerJoin('pc.parent', 'pa')
            ->where('pa.enabled = :enabled')
            ->andWhere('pc.enabled = :enabled')
            ->andWhere('pc.stock is not null and pc.stock != 0')
            ->andWhere('pc.price is not null and pc.price != 0');

        $eb = $this->getEntityManager()->getExpressionBuilder();

        return $this->createQueryBuilder('p')
            ->select('p', 'i', 'g')
            ->distinct()
            ->leftJoin('p.image', 'i')
            ->leftJoin('p.gallery', 'g')
            ->where(
                $eb->orX(
                    $eb->in('p.id', $rootEnabledProducts->getDQL()),
                    $eb->in('p.id', $enabledChildren->getDQL())
                )
            )
            ->orderBy('p.createdAt', 'DESC')
            ->setMaxResults($limit)
            ->setParameters(array(
                'enabled' => true
            ))
            ->getQuery()
            ->execute();
    }
}<commit_msg>Updated new products block service query<commit_after><?php

/*
 * This file is part of the Sonata package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Sonata\ProductBundle\Repository;

use Doctrine\ORM\EntityRepository;

/**
 * @author <NAME> <<EMAIL>>
 */
class BaseProductRepository extends EntityRepository
{
    /**
     * Returns an array of last products.
     *
     * @param int $limit 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')      // Limit to master products or products without variations
            ->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();
    }
}
{'fraction_non_alphanumeric': 0.15084599942644106, 'fraction_numerical': 0.0028677946659019216, 'mean_word_length': 1.945945945945946, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '416095', 'n_tokens_mistral': 990, 'n_tokens_neox': 964, 'n_words': 256}