Skip to content

Commit f246db4

Browse files
authored
Merge pull request #2 from justbetter/feature/admin-prices
Support customer prices in admin
2 parents 3897498 + a919c94 commit f246db4

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/Observer/FinalPrice.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44

55
use JustBetter\CustomerPricing\Actions\CustomerPrice;
66
use Magento\Authorization\Model\UserContextInterface;
7+
use Magento\Backend\Model\Session\Quote;
78
use Magento\Catalog\Model\Product;
9+
use Magento\Customer\Api\CustomerRepositoryInterface;
810
use Magento\Customer\Model\Session;
9-
use Magento\Framework\Api\AttributeValue;
11+
use Magento\Framework\App\Area;
12+
use Magento\Framework\App\State;
1013
use Magento\Framework\Event\Observer;
1114
use Magento\Framework\Event\ObserverInterface;
1215
use 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

Comments
 (0)