-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add public method to retrieve active design from customer session (#4)
- Loading branch information
Rob Aimes
authored
Mar 2, 2022
1 parent
7705a9a
commit 8638356
Showing
2 changed files
with
59 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* Copyright © Rob Aimes - https://aimes.dev/ | ||
* https://github.com/robaimes | ||
*/ | ||
|
||
namespace Aimes\CheckoutDesigns\Scope; | ||
|
||
use Aimes\CheckoutDesigns\Api\CheckoutDesignInterface; | ||
use Aimes\CheckoutDesigns\Model\Config\Source\CheckoutDesigns; | ||
use Magento\Customer\Model\Session as CustomerSession; | ||
|
||
class Customer | ||
{ | ||
/** @var Config */ | ||
private $config; | ||
|
||
/** @var CustomerSession */ | ||
private $customerSession; | ||
|
||
/** | ||
* @param Config $config | ||
* @param CustomerSession $customerSession | ||
*/ | ||
public function __construct( | ||
Config $config, | ||
CustomerSession $customerSession | ||
) { | ||
$this->config = $config; | ||
$this->customerSession = $customerSession; | ||
} | ||
|
||
/** | ||
* @return CheckoutDesignInterface|null | ||
* @throws LocalizedException | ||
* @throws NoSuchEntityException | ||
*/ | ||
public function getActiveDesign(): ?CheckoutDesignInterface | ||
{ | ||
$groupMapping = $this->config->getCustomerGroupMapping(); | ||
|
||
if ($groupMapping !== null) { | ||
$currentCustomerGroup = $this->customerSession->getCustomerGroupId(); | ||
|
||
if (isset($groupMapping[$currentCustomerGroup])) { | ||
return $this->config->getDesign($groupMapping[$currentCustomerGroup]); | ||
} | ||
} | ||
|
||
return $this->config->getDesign(); | ||
} | ||
} |