File tree Expand file tree Collapse file tree 4 files changed +80
-0
lines changed
Model/VaryData/Applicator Expand file tree Collapse file tree 4 files changed +80
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace Firegento \CacheWarmup \Model \VaryData \Applicator ;
5+
6+ use Magento \Customer \Model \CustomerFactory ;
7+ use Magento \Customer \Model \Session ;
8+
9+ class CustomerGroupApplicator implements VaryDataApplicatorInterface
10+ {
11+ private const VARY_DATA_KEY = 'customer_group ' ;
12+
13+ /**
14+ * @var Session
15+ */
16+ private $ customerSession ;
17+ /**
18+ * @var CustomerFactory
19+ */
20+ private $ customerFactory ;
21+
22+ public function __construct (Session $ customerSession , CustomerFactory $ customerFactory )
23+ {
24+ $ this ->customerSession = $ customerSession ;
25+ $ this ->customerFactory = $ customerFactory ;
26+ }
27+
28+ public function apply (array $ varyData ): void
29+ {
30+ $ this ->customerSession ->clearStorage ();
31+ $ customerGroupId = $ varyData [self ::VARY_DATA_KEY ];
32+ $ customer = $ this ->customerFactory ->create ()->setGroupId ($ customerGroupId );
33+ $ this ->customerSession ->setCustomerGroupId ($ customerGroupId );
34+ $ this ->customerSession ->setCustomer ($ customer );
35+ }
36+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace Firegento \CacheWarmup \Model \VaryData \Applicator ;
5+
6+ interface VaryDataApplicatorInterface
7+ {
8+ public function apply (array $ varyData ): void ;
9+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace Firegento \CacheWarmup \Model \VaryData \Applicator ;
5+
6+ class VaryDataApplicatorList
7+ {
8+ /**
9+ * @var VaryDataApplicatorInterface[]
10+ */
11+ private $ varyDataApplicators ;
12+
13+ /**
14+ * VaryDataApplicatorList constructor.
15+ * @param VaryDataApplicatorInterface[] $varyDataApplicators
16+ */
17+ public function __construct (array $ varyDataApplicators = [])
18+ {
19+ $ this ->varyDataApplicators = $ varyDataApplicators ;
20+ }
21+
22+ public function applyAll (array $ varyData ): void
23+ {
24+ foreach ($ this ->varyDataApplicators as $ varyDataApplicator ) {
25+ $ varyDataApplicator ->apply ($ varyData );
26+ }
27+ }
28+ }
Original file line number Diff line number Diff line change 33 <type name =" Magento\Framework\App\PageCache\Identifier" >
44 <plugin name =" saveVaryData" type =" \Firegento\CacheWarmup\Plugin\CacheIdentifier\SaveVaryData" />
55 </type >
6+ <type name =" Firegento\CacheWarmup\Model\VaryData\Applicator\VaryDataApplicatorList" >
7+ <arguments >
8+ <argument name =" varyDataApplicators" xsi : type =" array" >
9+ <item name =" customer_group" xsi : type =" object" >Firegento\CacheWarmup\Model\VaryData\Applicator\CustomerGroupApplicator</item >
10+ </argument >
11+ </arguments >
12+ </type >
613</config >
You can’t perform that action at this time.
0 commit comments