-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from NVision-Commerce-Solutions/CORE-1
Core
- Loading branch information
Showing
12 changed files
with
307 additions
and
168 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
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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Commerce365\Core\Service\Customer; | ||
|
||
use Magento\Customer\Api\CustomerRepositoryInterface; | ||
use Magento\Customer\Api\Data\CustomerInterface; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
|
||
class GetParentCustomer | ||
{ | ||
private CustomerRepositoryInterface $customerRepository; | ||
|
||
public function __construct(CustomerRepositoryInterface $customerRepository) | ||
{ | ||
$this->customerRepository = $customerRepository; | ||
} | ||
|
||
public function execute(CustomerInterface $customer): CustomerInterface | ||
{ | ||
if (!$customer->getCustomAttribute('parent_customer_id')) { | ||
return $customer; | ||
} | ||
|
||
$parentId = $customer->getCustomAttribute('parent_customer_id')->getValue(); | ||
try { | ||
return $this->customerRepository->getById($parentId); | ||
} catch (NoSuchEntityException $e) { | ||
return $customer; | ||
} | ||
} | ||
|
||
public function getByCustomerId($customerId) | ||
{ | ||
try { | ||
$customer = $this->customerRepository->getById($customerId); | ||
} catch (NoSuchEntityException $e) { | ||
return null; | ||
} | ||
|
||
return $this->execute($customer); | ||
} | ||
} |
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,85 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Commerce365\Core\Service\Customer; | ||
|
||
use Magento\Customer\Api\CustomerRepositoryInterface; | ||
use Magento\Customer\Api\GroupManagementInterface; | ||
use Magento\Customer\Model\AccountConfirmation; | ||
use Magento\Customer\Model\Config\Share; | ||
use Magento\Customer\Model\CustomerFactory; | ||
use Magento\Customer\Model\ResourceModel\Customer as ResourceCustomer; | ||
use Magento\Customer\Model\Session; | ||
use Magento\Framework\Session\Generic; | ||
|
||
class ParentResolveCustomerSession extends Session | ||
{ | ||
private GetParentCustomer $getParentCustomer; | ||
|
||
public function __construct( | ||
\Magento\Framework\App\Request\Http $request, | ||
\Magento\Framework\Session\SidResolverInterface $sidResolver, | ||
\Magento\Framework\Session\Config\ConfigInterface $sessionConfig, | ||
\Magento\Framework\Session\SaveHandlerInterface $saveHandler, | ||
\Magento\Framework\Session\ValidatorInterface $validator, | ||
\Magento\Framework\Session\StorageInterface $storage, | ||
\Magento\Framework\Stdlib\CookieManagerInterface $cookieManager, | ||
\Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory, | ||
\Magento\Framework\App\State $appState, | ||
Share $configShare, | ||
\Magento\Framework\Url\Helper\Data $coreUrl, | ||
\Magento\Customer\Model\Url $customerUrl, | ||
ResourceCustomer $customerResource, | ||
CustomerFactory $customerFactory, | ||
\Magento\Framework\UrlFactory $urlFactory, | ||
Generic $session, | ||
\Magento\Framework\Event\ManagerInterface $eventManager, | ||
\Magento\Framework\App\Http\Context $httpContext, | ||
CustomerRepositoryInterface $customerRepository, | ||
GroupManagementInterface $groupManagement, | ||
\Magento\Framework\App\Response\Http $response, | ||
GetParentCustomer $getParentCustomer, | ||
AccountConfirmation $accountConfirmation = null | ||
) { | ||
parent::__construct( | ||
$request, | ||
$sidResolver, | ||
$sessionConfig, | ||
$saveHandler, | ||
$validator, | ||
$storage, | ||
$cookieManager, | ||
$cookieMetadataFactory, | ||
$appState, | ||
$configShare, | ||
$coreUrl, | ||
$customerUrl, | ||
$customerResource, | ||
$customerFactory, | ||
$urlFactory, | ||
$session, | ||
$eventManager, | ||
$httpContext, | ||
$customerRepository, | ||
$groupManagement, | ||
$response, | ||
$accountConfirmation | ||
); | ||
$this->getParentCustomer = $getParentCustomer; | ||
} | ||
|
||
public function getCustomer() | ||
{ | ||
$customer = parent::getCustomer(); | ||
|
||
return $this->getParentCustomer->execute($customer); | ||
} | ||
|
||
public function getCustomerId() | ||
{ | ||
$customer = parent::getCustomer(); | ||
|
||
return $this->getParentCustomer->execute($customer)->getId(); | ||
} | ||
} |
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
Oops, something went wrong.