Skip to content

Commit

Permalink
Merge pull request #7 from NVision-Commerce-Solutions/CORE-1
Browse files Browse the repository at this point in the history
Core 1
  • Loading branch information
TysvdHeuvel authored Jul 11, 2023
2 parents a081865 + 1188dd2 commit ab89a23
Show file tree
Hide file tree
Showing 14 changed files with 307 additions and 57 deletions.
4 changes: 2 additions & 2 deletions Block/Adminhtml/CustomerAttributeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function getBcCustomerBlocked()
public function getParentCustomerUrl()
{
$parent = $this->getParentCustomer->execute($this->getCustomer());
if (!$parent) {
if ($parent->getId() === $this->getCustomer()->getId()) {
return '';
}

Expand All @@ -192,7 +192,7 @@ public function getParentCustomerUrl()
public function getParentCustomerEmail()
{
$parent = $this->getParentCustomer->execute($this->getCustomer());
if (!$parent) {
if ($parent->getId() === $this->getCustomer()->getId()) {
return '';
}

Expand Down
49 changes: 49 additions & 0 deletions Block/Adminhtml/Version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Commerce365\Core\Block\Adminhtml;

use Commerce365\Core\Service\Module\VersionInterface;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\Data\Form\Element\Renderer\RendererInterface;
use Magento\Framework\Exception\ValidatorException;

class Version extends Template implements RendererInterface
{
protected $_template = 'Commerce365_Core::system/config/version.phtml';
private VersionInterface $moduleVersion;

/**
* @param Context $context
* @param VersionInterface $version
*/
public function __construct(Context $context, VersionInterface $version)
{
parent::__construct($context);
$this->moduleVersion = $version;
}

/**
* @return array[]
*/
public function getModuleVersionInfo(): array
{
return [
$this->moduleVersion->getPackageName() => [
'label' => $this->moduleVersion->getLabelName()?: $this->moduleVersion->getModuleName(),
'version' => $this->moduleVersion->getVersion()
]
];
}

/**
* @param AbstractElement $element
* @return string
* @throws ValidatorException
*/
public function render(AbstractElement $element): string
{
return $this->fetchView($this->getTemplateFile());
}
}
31 changes: 31 additions & 0 deletions Model/Command/GetCustomerEmailById.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Commerce365\Core\Model\Command;

use Magento\Framework\App\ResourceConnection;

class GetCustomerEmailById
{
private ResourceConnection $resourceConnection;

public function __construct(ResourceConnection $resourceConnection)
{
$this->resourceConnection = $resourceConnection;
}

/**
* @param $customerId
* @return string
*/
public function execute($customerId)
{
$connection = $this->resourceConnection->getConnection();
$tableName = $this->resourceConnection->getTableName('customer_entity');
$select = $connection->select()->from($tableName, ['email'])
->where('entity_id = ?', $customerId);

return $connection->fetchOne($select);
}
}
47 changes: 47 additions & 0 deletions Service/Module/Version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Commerce365\Core\Service\Module;

use Magento\Framework\Module\PackageInfoFactory;
use Magento\Framework\Module\PackageInfo;

class Version implements VersionInterface
{
private PackageInfo $packageInfo;
private string $packageName;
private string $labelName;

/**
* @param PackageInfoFactory $packageInfoFactory
* @param string $packageName
* @param string $labelName
*/
public function __construct(PackageInfoFactory $packageInfoFactory, string $packageName, string $labelName = '')
{
$this->packageInfo = $packageInfoFactory->create();
$this->packageName = $packageName;
$this->labelName = $labelName;
}

public function getVersion(): string
{
return $this->packageInfo->getVersion($this->getModuleName());
}

public function getModuleName(): ?string
{
return $this->packageInfo->getModuleName($this->packageName);
}

public function getPackageName(): string
{
return $this->packageName;
}

public function getLabelName(): ?string
{
return $this->labelName;
}
}
16 changes: 16 additions & 0 deletions Service/Module/VersionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Commerce365\Core\Service\Module;

interface VersionInterface
{
public function getVersion(): string;

public function getModuleName(): ?string;

public function getPackageName(): string;

public function getLabelName(): ?string;
}
41 changes: 41 additions & 0 deletions Setup/Patch/Data/ChangeParentCustomerAttributeLabel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Commerce365\Core\Setup\Patch\Data;

use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;

class ChangeParentCustomerAttributeLabel implements DataPatchInterface
{
private ModuleDataSetupInterface $moduleDataSetup;

public function __construct(ModuleDataSetupInterface $moduleDataSetup)
{
$this->moduleDataSetup = $moduleDataSetup;
}

public function getAliases(): array
{
return [];
}

public static function getDependencies(): array
{
return [];
}

public function apply()
{
$this->moduleDataSetup->startSetup();

$this->moduleDataSetup->getConnection()->update(
$this->moduleDataSetup->getTable('eav_attribute'),
['frontend_label' => 'Parent Customer'],
['attribute_code = ?' => 'parent_customer_id']
);

$this->moduleDataSetup->endSetup();
}
}
42 changes: 0 additions & 42 deletions Ui/Component/Listing/Column/CustomerNo.php

This file was deleted.

53 changes: 53 additions & 0 deletions Ui/Component/Listing/Column/ParentCustomer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Commerce365\Core\Ui\Component\Listing\Column;

use Commerce365\Core\Model\Command\GetCustomerEmailById;
use Magento\Backend\Model\UrlInterface;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Ui\Component\Listing\Columns\Column;

class ParentCustomer extends Column
{
private GetCustomerEmailById $getCustomerEmailById;
private UrlInterface $url;

public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
GetCustomerEmailById $getCustomerEmailById,
UrlInterface $url,
array $components = [],
array $data = []
) {
parent::__construct($context, $uiComponentFactory, $components, $data);
$this->getCustomerEmailById = $getCustomerEmailById;
$this->url = $url;
}
/**
* Prepare Data Source
*
* @param array $dataSource
* @return array
*/
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item)
{
if (empty($item['parent_customer_id'])) {
continue;
}
$email = $this->getCustomerEmailById->execute($item['parent_customer_id']);
if (!$email) {
continue;
}

$url = $this->url->getUrl('customer/index/edit', ['id' => $item['parent_customer_id']]);
$item[$this->getData('name')] = '<a href="' . $url . '">' . $email . '</a>';
}
}
return $dataSource;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "commerce365/module-core",
"version": "1.1.1",
"version": "1.2.1",
"description": "Core functionality used by all our Magento 2 extensions",
"homepage": "https://n.vision/products/commerce-365-for-magento/",
"license": [
Expand Down
8 changes: 8 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
</field>

</group>
<group id="version" translate="label" type="text" sortOrder="140" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Version</label>
<group id="coreversion" translate="label" sortOrder="1" showInDefault="1" showInWebsite="1"
showInStore="0">
<frontend_model>Commerce365CoreModuleVersionBlock</frontend_model>
<label><![CDATA[Commerce365 Core Version]]></label>
</group>
</group>
</section>
</system>
</config>
10 changes: 10 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,14 @@
</argument>
</arguments>
</type>
<virtualType name="Commerce365CoreModuleVersion" type="Commerce365\Core\Service\Module\Version">
<arguments>
<argument name="packageName" xsi:type="string">commerce365/module-core</argument>
</arguments>
</virtualType>
<virtualType name="Commerce365CoreModuleVersionBlock" type="Commerce365\Core\Block\Adminhtml\Version">
<arguments>
<argument name="version" xsi:type="object">Commerce365CoreModuleVersion</argument>
</arguments>
</virtualType>
</config>
22 changes: 22 additions & 0 deletions view/adminhtml/templates/system/config/version.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
$getList = $block->getModuleVersionInfo();
foreach ($getList as $key => $list) :?>
<?=
$label = null;
$version = null;
if (array_key_exists('label', $list)) {
$label = $list['label'];
}
if (array_key_exists('version', $list)) {
$version = $list['version'];
}
?>
<div class="version-notice">
<p>
<b><label><?= $label. ":"; ?></label></b>
<strong style="color: #ef672f; line-height:34px;"><?= $version ?><?= (isset($edition)) ? ' '. $edition : '' ?></strong>
</p>
</div>
<?php
endforeach;
?>
23 changes: 11 additions & 12 deletions view/adminhtml/templates/tab/view/customer_attribute_list.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,17 @@ $allowedAddressHtmlTags = ['b', 'br', 'em', 'i', 'li', 'ol', 'p', 'strong', 'sub
<th><?= $block->escapeHtml(__('Blocked Status:')) ?></th>
<td><?= $block->escapeHtml($block->getBcCustomerBlocked()) ?></td>
</tr>
<tr>
<th><?= $block->escapeHtml(__('Contact Number:')) ?></th>
<td><?= $block->escapeHtml($block->getBcContactNo()) ?></td>
</tr>
<tr>
<th><?= $block->escapeHtml(__('Parent Customer:')) ?></th>
<td>
<a href="<?= $this->getParentCustomerUrl()?>" target="_blank">
<?= $block->escapeHtml($block->getParentCustomerEmail()) ?>
</a>
</td>
</tr>
<?php $parentCustomerUrl = $this->getParentCustomerUrl(); ?>
<?php if($parentCustomerUrl): ?>
<tr>
<th><?= $block->escapeHtml(__('Parent Customer:')) ?></th>
<td>
<a href="<?= $parentCustomerUrl ?>" target="_blank">
<?= $block->escapeHtml($block->getParentCustomerEmail()) ?>
</a>
</td>
</tr>
<?php endif; ?>
</tbody>
</table>
<address>
Expand Down
Loading

0 comments on commit ab89a23

Please sign in to comment.