Skip to content

Commit

Permalink
Merge pull request #3 from NVision-Commerce-Solutions/CORE-1
Browse files Browse the repository at this point in the history
Core
  • Loading branch information
TysvdHeuvel authored Apr 6, 2023
2 parents a79859f + 5c959c1 commit a8c42e9
Show file tree
Hide file tree
Showing 12 changed files with 307 additions and 168 deletions.
2 changes: 2 additions & 0 deletions Block/AbstractList.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public function getSortDirection()
*/
protected function addSortingToQuery(array $query): array
{
$query['sortColumn'] = 'Document Date';
$query['sortDirection'] = 'DESC';
if ($this->getSortColumn() && $this->getSortDirection()) {
$query['sortColumn'] = $this->getSortColumn();
$query['sortDirection'] = $this->getSortDirection();
Expand Down
38 changes: 28 additions & 10 deletions Block/Adminhtml/CustomerAttributeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Commerce365\Core\Block\Adminhtml;

use Commerce365\Core\Service\Customer\GetParentCustomer;
use Magento\Backend\Model\Url;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
use Magento\Framework\Api\DataObjectHelper;
Expand All @@ -11,17 +13,23 @@ class CustomerAttributeList extends \Magento\Backend\Block\Template
private $customer;
private CustomerInterfaceFactory $customerDataFactory;
private DataObjectHelper $dataObjectHelper;
private GetParentCustomer $getParentCustomer;
private Url $urlBuilder;

public function __construct(
\Magento\Backend\Block\Template\Context $context,
CustomerInterfaceFactory $customerDataFactory,
DataObjectHelper $dataObjectHelper,
GetParentCustomer $getParentCustomer,
Url $urlBuilder,
array $data = []
) {
$this->customerDataFactory = $customerDataFactory;
$this->dataObjectHelper = $dataObjectHelper;

parent::__construct($context, $data);
$this->getParentCustomer = $getParentCustomer;
$this->urlBuilder = $urlBuilder;
}

public function getCustomer()
Expand Down Expand Up @@ -58,16 +66,6 @@ public function getBcContactNo()
return '';
}

public function getParentCustomerId()
{
$customer = $this->getCustomer();
if ($customer->getCustomAttribute('parent_customer_id')) {
return $customer->getCustomAttribute('parent_customer_id')->getValue();
}

return '';
}

public function getBcCustomerName()
{
$customer = $this->getCustomer();
Expand Down Expand Up @@ -180,4 +178,24 @@ public function getBcCustomerBlocked()
return "Unknown";
}
}

public function getParentCustomerUrl()
{
$parent = $this->getParentCustomer->execute($this->getCustomer());
if (!$parent) {
return '';
}

return $this->urlBuilder->getUrl('*/*/edit', ['id' => $parent->getId()]);
}

public function getParentCustomerEmail()
{
$parent = $this->getParentCustomer->execute($this->getCustomer());
if (!$parent) {
return '';
}

return $parent->getEmail();
}
}
34 changes: 12 additions & 22 deletions Block/Adminhtml/Edit/Tab/CustomerAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace Commerce365\Core\Block\Adminhtml\Edit\Tab;

use Commerce365\Core\Block\Adminhtml\CustomerAttributeList;
use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Customer\Controller\RegistryConstants;
use Magento\Framework\Phrase;
use Magento\Ui\Component\Layout\Tabs\TabInterface;

class CustomerAttributes extends Generic implements TabInterface
{
protected $_coreRegistry;
protected $_systemStore;

public function __construct(
\Magento\Backend\Block\Template\Context $context,
Expand All @@ -19,7 +20,6 @@ public function __construct(
array $data = []
) {
$this->_coreRegistry = $registry;
$this->_systemStore = $systemStore;
parent::__construct($context, $registry, $formFactory, $data);
}

Expand All @@ -30,24 +30,18 @@ public function getCustomerId()
{
return $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
}
/**
* @return \Magento\Framework\Phrase
*/
public function getTabLabel()

public function getTabLabel(): Phrase
{
return __('Commerce 365 label');
}
/**
* @return \Magento\Framework\Phrase
*/
public function getTabTitle()

public function getTabTitle(): Phrase
{
return __('Commerce 365');
}
/**
* @return bool
*/
public function canShowTab()

public function canShowTab(): bool
{
if ($this->getCustomerId()) {
return true;
Expand All @@ -58,7 +52,7 @@ public function canShowTab()
/**
* @return bool
*/
public function isHidden()
public function isHidden(): bool
{
if ($this->getCustomerId()) {
return false;
Expand All @@ -70,7 +64,7 @@ public function isHidden()
*
* @return string
*/
public function getTabClass()
public function getTabClass(): string
{
return '';
}
Expand All @@ -81,9 +75,7 @@ public function getTabClass()
*/
public function getTabUrl()
{
//replace the tab with the url you want
return '';
//return $this->getUrl('test/*/test', ['_current' => true]);
}
/**
* Tab should be loaded trough Ajax call
Expand All @@ -106,11 +98,9 @@ protected function _toHtml()

public function getFormHtml()
{
$html = $this->getLayout()
->createBlock('Commerce365\Core\Block\Adminhtml\CustomerAttributeList')
return $this->getLayout()
->createBlock(CustomerAttributeList::class)
->setTemplate('Commerce365_Core::tab/view/customer_attribute_list.phtml')
->toHtml();

return $html;
}
}
44 changes: 44 additions & 0 deletions Service/Customer/GetParentCustomer.php
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);
}
}
85 changes: 85 additions & 0 deletions Service/Customer/ParentResolveCustomerSession.php
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();
}
}
9 changes: 2 additions & 7 deletions Service/PrepareSalesRequestQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@
namespace Commerce365\Core\Service;

use Commerce365\Core\Model\MainConfig;
use Commerce365\Core\Service\Customer\ParentResolveCustomerSession;
use Magento\Customer\Model\Session;

class PrepareSalesRequestQuery
{
private MainConfig $mainConfig;
private Session $customerSession;

/**
* @param MainConfig $mainConfig
* @param Session $customerSession
*/
public function __construct(MainConfig $mainConfig, Session $customerSession)
public function __construct(MainConfig $mainConfig, ParentResolveCustomerSession $customerSession)
{
$this->mainConfig = $mainConfig;
$this->customerSession = $customerSession;
Expand All @@ -25,8 +22,6 @@ public function execute(array $query)
{
$query['customerId'] = $this->customerSession->getCustomer()->getId();

// $this->c365Helper->LogDebug('Retrieving sales documents for customer: ' . $query['customerId']);

//config returns 0 or 1, but we need false or true for our querystring parameter
$query['webOrdersOnly'] = true;
if ($this->mainConfig->getIncludeNonWebOrders()) {
Expand Down
45 changes: 0 additions & 45 deletions Setup/InstallData.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,10 @@
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Customer\Model\Customer;
use Magento\Customer\Setup\CustomerSetupFactory;

use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;

class InstallData implements InstallDataInterface
{
private $customerSetupFactory;
private $c365Helper;
private $eavSetupFactory;

public function __construct(CustomerSetupFactory $customerSetupFactory, \Commerce365\Core\Helper\Data $helper, EavSetupFactory $eavSetupFactory)
{
$this->customerSetupFactory = $customerSetupFactory;
$this->c365Helper = $helper;
$this->eavSetupFactory = $eavSetupFactory;
}

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$this->c365Helper->LogInfo('Commerce 365 Configuration Module - Install data (intial)');
//$this->cleanup($setup);

$this->c365Helper->LogEmergency('Testing the logging mechanism: Emergency');
$this->c365Helper->LogCritical('Testing the logging mechanism: Critical');
$this->c365Helper->LogError('Testing the logging mechanism: Error', ['param1' => 'value1']);
$this->c365Helper->LogWarning('Testing the logging mechanism: Warning');
$this->c365Helper->LogInfo('Testing the logging mechanism: Info');
$this->c365Helper->LogDebug('Testing the logging mechanism: Debug');
}

private function cleanup(ModuleDataSetupInterface $setup)
{
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'bc_customer_no');
$eavSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'bc_contact_no');
$eavSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'parent_customer_id');
$eavSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'bc_company_name');
$eavSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'bc_customer_price_group');
$eavSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'bc_customer_discount_group');
$eavSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'bc_payment_terms_code');
$eavSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'bc_payment_method_code');
$eavSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'bc_shipment_method_code');
$eavSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'bc_shipment_agent_code');
$eavSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'bc_shipment_agent_service_code');
$eavSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'bc_location_code');
$eavSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'bc_blocked_code');

$this->c365Helper->LogInfo('Removed existing customer custom attributes');
}
}
Loading

0 comments on commit a8c42e9

Please sign in to comment.