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\Entity\Producer; |
17
|
|
|
use WellCommerce\Bundle\CatalogBundle\Entity\ProducerTranslation; |
18
|
|
|
use WellCommerce\Bundle\CatalogBundle\Entity\Product; |
19
|
|
|
use WellCommerce\Bundle\CoreBundle\DataSet\AbstractDataSet; |
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 AbstractDataSet |
29
|
|
|
{ |
30
|
|
|
public function getIdentifier(): string |
31
|
|
|
{ |
32
|
|
|
return 'front.producer_collection'; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function configureOptions(DataSetConfiguratorInterface $configurator) |
36
|
|
|
{ |
37
|
|
|
$configurator->setColumns([ |
38
|
|
|
'id' => 'producer_collection.id', |
39
|
|
|
'name' => 'producer_collection_translation.name', |
40
|
|
|
'route' => 'IDENTITY(producer_collection_translation.route)', |
41
|
|
|
'shop' => 'producer_collection_shops.id', |
42
|
|
|
'producerId' => 'producer_collection_producers.id', |
43
|
|
|
'photo' => 'photos.path', |
44
|
|
|
'products' => 'COUNT(producer_collection_products.id)', |
45
|
|
|
]); |
46
|
|
|
|
47
|
|
|
$configurator->setColumnTransformers([ |
48
|
|
|
'route' => $this->manager->createTransformer('route'), |
49
|
|
|
]); |
50
|
|
|
|
51
|
|
|
$configurator->setCacheOptions(new CacheOptions(true, 3600, [ |
52
|
|
|
Product::class, |
53
|
|
|
Producer::class, |
54
|
|
|
ProducerTranslation::class, |
55
|
|
|
])); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected function createQueryBuilder(): QueryBuilder |
59
|
|
|
{ |
60
|
|
|
$queryBuilder = $this->repository->getQueryBuilder(); |
61
|
|
|
$queryBuilder->groupBy('producer_collection.id'); |
62
|
|
|
$queryBuilder->leftJoin('producer_collection.translations', 'producer_collection_translation'); |
63
|
|
|
$queryBuilder->leftJoin('producer_collection.producer', 'producer_collection_producers'); |
64
|
|
|
$queryBuilder->leftJoin('producer_collection.products', 'producer_collection_products'); |
65
|
|
|
$queryBuilder->leftJoin('producer_collection.shops', 'producer_collection_shops'); |
66
|
|
|
$queryBuilder->leftJoin('producer_collection.photo', 'photos'); |
67
|
|
|
|
68
|
|
|
$queryBuilder->where($queryBuilder->expr()->eq('producer_collection_shops.id', |
69
|
|
|
$this->getShopStorage()->getCurrentShopIdentifier())); |
70
|
|
|
|
71
|
|
|
return $queryBuilder; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|