1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* WellCommerce Open-Source E-Commerce Platform |
4
|
|
|
* |
5
|
|
|
* This file is part of the WellCommerce package. |
6
|
|
|
* |
7
|
|
|
* (c) Adam Piotrowski <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, |
10
|
|
|
* please view the LICENSE file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace WellCommerce\Bundle\CatalogBundle\DataSet\Front; |
14
|
|
|
|
15
|
|
|
use Doctrine\ORM\QueryBuilder; |
16
|
|
|
use WellCommerce\Bundle\CatalogBundle\DataSet\Admin\ProducerDataSet as BaseDataSet; |
17
|
|
|
use WellCommerce\Bundle\CatalogBundle\Entity\Producer; |
18
|
|
|
use WellCommerce\Bundle\CatalogBundle\Entity\ProducerTranslation; |
19
|
|
|
use WellCommerce\Bundle\CatalogBundle\Entity\Product; |
20
|
|
|
use WellCommerce\Component\DataSet\Cache\CacheOptions; |
21
|
|
|
use WellCommerce\Component\DataSet\Configurator\DataSetConfiguratorInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class ProducerCollectionDataSet |
25
|
|
|
* |
26
|
|
|
* @author Rafał Martonik <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class ProducerCollectionDataSet extends BaseDataSet |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
public function configureOptions(DataSetConfiguratorInterface $configurator) |
34
|
|
|
{ |
35
|
|
|
$configurator->setColumns([ |
36
|
|
|
'id' => 'producer_collection.id', |
37
|
|
|
'name' => 'producer_collection_translation.name', |
38
|
|
|
'route' => 'IDENTITY(producer_collection_translation.route)', |
39
|
|
|
'shop' => 'producer_collection_shops.id', |
40
|
|
|
'producerId' => 'producer_collection_producers.id', |
41
|
|
|
'photo' => 'photos.path', |
42
|
|
|
'products' => 'COUNT(producer_collection_products.id)', |
43
|
|
|
]); |
44
|
|
|
|
45
|
|
|
$configurator->setColumnTransformers([ |
46
|
|
|
'route' => $this->manager->createTransformer('route'), |
47
|
|
|
]); |
48
|
|
|
|
49
|
|
|
$configurator->setCacheOptions(new CacheOptions(true, 3600, [ |
50
|
|
|
Product::class, |
51
|
|
|
Producer::class, |
52
|
|
|
ProducerTranslation::class, |
53
|
|
|
])); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
protected function createQueryBuilder(): QueryBuilder |
57
|
|
|
{ |
58
|
|
|
$queryBuilder = $this->repository->getQueryBuilder(); |
59
|
|
|
$queryBuilder->groupBy('producer_collection.id'); |
60
|
|
|
$queryBuilder->leftJoin('producer_collection.translations', 'producer_collection_translation'); |
61
|
|
|
$queryBuilder->leftJoin('producer_collection.producer', 'producer_collection_producers'); |
62
|
|
|
$queryBuilder->leftJoin('producer_collection.products', 'producer_collection_products'); |
63
|
|
|
$queryBuilder->leftJoin('producer_collection.shops', 'producer_collection_shops'); |
64
|
|
|
$queryBuilder->leftJoin('producer_collection.photo', 'photos'); |
65
|
|
|
|
66
|
|
|
$queryBuilder->where($queryBuilder->expr()->eq('producer_collection_shops.id', |
67
|
|
|
$this->getShopStorage()->getCurrentShopIdentifier())); |
68
|
|
|
|
69
|
|
|
return $queryBuilder; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|