44
55use JustBetter \CustomerPricing \Actions \CustomerPrice ;
66use Magento \Authorization \Model \UserContextInterface ;
7+ use Magento \Backend \Model \Session \Quote ;
78use Magento \Catalog \Model \Product ;
9+ use Magento \Customer \Api \CustomerRepositoryInterface ;
810use Magento \Customer \Model \Session ;
9- use Magento \Framework \Api \AttributeValue ;
11+ use Magento \Framework \App \Area ;
12+ use Magento \Framework \App \State ;
1013use Magento \Framework \Event \Observer ;
1114use Magento \Framework \Event \ObserverInterface ;
1215use Psr \Log \LoggerInterface ;
@@ -16,14 +19,24 @@ class FinalPrice implements ObserverInterface
1619 public function __construct (
1720 protected Session $ customerSession ,
1821 protected UserContextInterface $ userContext ,
22+ protected CustomerRepositoryInterface $ customerRepositoryInterface ,
1923 protected LoggerInterface $ logger ,
24+ protected State $ state ,
25+ protected Quote $ quote ,
2026 protected CustomerPrice $ customerPrice
2127 ) {
2228 }
2329
2430 public function execute (Observer $ observer ): void
2531 {
26- $ customerId = $ this ->userContext ->getUserType () === UserContextInterface::USER_TYPE_CUSTOMER ? (int ) $ this ->userContext ->getUserId () : null ;
32+ $ customerId = $ this ->customerSession ->getCustomerId ();
33+ $ isAdmin = $ this ->state ->getAreaCode () === Area::AREA_ADMINHTML ;
34+
35+ if ($ isAdmin ) {
36+ $ customerId = $ this ->quote ->getCustomerId ();
37+ } elseif ($ customerId === null && ! $ isAdmin ) {
38+ $ customerId = $ this ->userContext ->getUserType () === UserContextInterface::USER_TYPE_CUSTOMER ? (int ) $ this ->userContext ->getUserId () : null ;
39+ }
2740
2841 if ($ customerId === null ) {
2942 return ;
0 commit comments