3
3
namespace CustomerFamily \LoopExtend ;
4
4
5
5
use CustomerFamily \CustomerFamily ;
6
+ use CustomerFamily \Event \CustomerFamilyEvents ;
7
+ use CustomerFamily \Event \CustomerFamilyPriceChangeEvent ;
6
8
use CustomerFamily \Model \Map \CustomerFamilyProductPriceTableMap ;
7
9
use CustomerFamily \Model \Map \ProductPurchasePriceTableMap ;
8
10
use CustomerFamily \Service \CustomerFamilyService ;
9
11
use Propel \Runtime \ActiveQuery \Criteria ;
10
12
use Propel \Runtime \ActiveQuery \Join ;
11
13
use Propel \Runtime \ActiveQuery \ModelCriteria ;
12
14
use Propel \Runtime \ActiveRecord \ActiveRecordInterface ;
15
+ use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
13
16
use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
14
17
use Thelia \Core \Event \Loop \LoopExtendsBuildModelCriteriaEvent ;
15
18
use Thelia \Core \Event \Loop \LoopExtendsParseResultsEvent ;
@@ -29,12 +32,18 @@ class CustomerFamilyPriceListener implements EventSubscriberInterface
29
32
protected $ securityContext ;
30
33
protected $ taxEngine ;
31
34
protected $ customerFamilyService ;
35
+ protected EventDispatcherInterface $ dispatcher ;
32
36
33
- public function __construct (SecurityContext $ securityContext , TaxEngine $ taxEngine , CustomerFamilyService $ customerFamilyService )
34
- {
37
+ public function __construct (
38
+ SecurityContext $ securityContext ,
39
+ TaxEngine $ taxEngine ,
40
+ CustomerFamilyService $ customerFamilyService ,
41
+ EventDispatcherInterface $ dispatcher
42
+ ) {
35
43
$ this ->securityContext = $ securityContext ;
36
44
$ this ->taxEngine = $ taxEngine ;
37
45
$ this ->customerFamilyService = $ customerFamilyService ;
46
+ $ this ->dispatcher = $ dispatcher ;
38
47
}
39
48
40
49
public static function getSubscribedEvents ()
@@ -102,6 +111,12 @@ public function extendProductModelCriteria(LoopExtendsBuildModelCriteriaEvent $e
102
111
103
112
public function extendProductParseResult (LoopExtendsParseResultsEvent $ event )
104
113
{
114
+ $ event = new CustomerFamilyPriceChangeEvent ();
115
+ $ this ->dispatcher ->dispatch ($ event , CustomerFamilyEvents::CUSTOMER_FAMILY_PRICE_CHANGE );
116
+
117
+ if (!$ event ->getAllowPriceChange ()) {
118
+ return ;
119
+ }
105
120
if ($ event ->getLoop ()->getBackendContext ()) {
106
121
return ;
107
122
}
0 commit comments