Skip to content

Commit

Permalink
Add composer support for Magento 2.3.x / code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
srenon committed Apr 4, 2019
1 parent a527780 commit 865af1e
Show file tree
Hide file tree
Showing 20 changed files with 267 additions and 147 deletions.
37 changes: 26 additions & 11 deletions Block/Adminhtml/Order/View/GuestToCustomerButtonList.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
<?php

/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* https://www.magepal.com | [email protected]
*/

namespace MagePal\GuestToCustomer\Block\Adminhtml\Order\View;

class GuestToCustomerButtonList extends \Magento\Backend\Block\Widget\Button\ButtonList
use Magento\Backend\Block\Widget\Button\ButtonList;
use Magento\Backend\Block\Widget\Button\ItemFactory;
use Magento\Framework\Registry;
use Magento\Framework\UrlInterface;
use Magento\Sales\Api\Data\OrderInterface;
use MagePal\GuestToCustomer\Helper\Data;

/**
* Class GuestToCustomerButtonList
* @package MagePal\GuestToCustomer\Block\Adminhtml\Order\View
*/
class GuestToCustomerButtonList extends ButtonList
{
/**
* GuestToCustomerButtonList constructor.
* @param \Magento\Backend\Block\Widget\Button\ItemFactory $itemFactory
* @param \Magento\Framework\Registry $coreRegistry
* @param \Magento\Framework\UrlInterface $urlBuilder
* @param \MagePal\GuestToCustomer\Helper\Data $helperData
* @param ItemFactory $itemFactory
* @param Registry $coreRegistry
* @param UrlInterface $urlBuilder
* @param Data $helperData
*/
public function __construct(
\Magento\Backend\Block\Widget\Button\ItemFactory $itemFactory,
\Magento\Framework\Registry $coreRegistry,
\Magento\Framework\UrlInterface $urlBuilder,
\MagePal\GuestToCustomer\Helper\Data $helperData
ItemFactory $itemFactory,
Registry $coreRegistry,
UrlInterface $urlBuilder,
Data $helperData
) {
parent::__construct($itemFactory);

/** @var \Magento\Sales\Api\Data\OrderInterface $order */
/** @var OrderInterface $order */
$order = $coreRegistry->registry('current_order');

if ($helperData->isEnabled() && $order && !$order->getCustomerId()) {
Expand Down
59 changes: 38 additions & 21 deletions Block/Adminhtml/System/Config/Form/Composer/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,56 @@
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | [email protected]
*/
* https://www.magepal.com | [email protected]
*/

namespace MagePal\GuestToCustomer\Block\Adminhtml\System\Config\Form\Composer;

class Version extends \Magento\Config\Block\System\Config\Form\Field
use Exception;
use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Component\ComponentRegistrarInterface;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Filesystem\Directory\ReadFactory;
use Magento\Framework\Phrase;

/**
* Class Version
* @package MagePal\GuestToCustomer\Block\Adminhtml\System\Config\Form\Composer
*/
class Version extends Field
{

/**
* @var \Magento\Framework\App\DeploymentConfig
* @var DeploymentConfig
*/
protected $deploymentConfig;

/**
* @var \Magento\Framework\Component\ComponentRegistrarInterface
* @var ComponentRegistrarInterface
*/
protected $componentRegistrar;

/**
* @var \Magento\Framework\Filesystem\Directory\ReadFactory
* @var ReadFactory
*/
protected $readFactory;

/**
* @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
* @param \Magento\Framework\Component\ComponentRegistrarInterface $componentRegistrar
* @param \Magento\Framework\Filesystem\Directory\ReadFactory $readFactory
* @param Context $context
* @param DeploymentConfig $deploymentConfig
* @param ComponentRegistrarInterface $componentRegistrar
* @param ReadFactory $readFactory
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\App\DeploymentConfig $deploymentConfig,
\Magento\Framework\Component\ComponentRegistrarInterface $componentRegistrar,
\Magento\Framework\Filesystem\Directory\ReadFactory $readFactory,
Context $context,
DeploymentConfig $deploymentConfig,
ComponentRegistrarInterface $componentRegistrar,
ReadFactory $readFactory,
array $data = []
) {
$this->deploymentConfig = $deploymentConfig;
Expand All @@ -46,11 +63,11 @@ public function __construct(
/**
* Render button
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @param AbstractElement $element
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
* @throws LocalizedException
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
public function render(AbstractElement $element)
{
// Remove scope label
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
Expand All @@ -60,11 +77,11 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
/**
* Return element html
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @param AbstractElement $element
* @return string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
protected function _getElementHtml(AbstractElement $element)
{
return 'v' . $this->getVersion();
}
Expand Down Expand Up @@ -93,12 +110,12 @@ public function getModuleName()
* Get module composer version
*
* @param $moduleName
* @return \Magento\Framework\Phrase|string|void
* @return Phrase|string|void
*/
public function getComposerVersion($moduleName)
{
$path = $this->componentRegistrar->getPath(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
ComponentRegistrar::MODULE,
$moduleName
);

Expand All @@ -110,7 +127,7 @@ public function getComposerVersion($moduleName)
$data = json_decode($composerJsonData);
return !empty($data->version) ? $data->version : __('Unknown');
}
} catch (\Exception $e) {
} catch (Exception $e) {
//
}

Expand Down
36 changes: 23 additions & 13 deletions Block/Adminhtml/System/Config/Form/Module/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,37 @@
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | [email protected]
*/
* https://www.magepal.com | [email protected]
*/

namespace MagePal\GuestToCustomer\Block\Adminhtml\System\Config\Form\Module;

class Version extends \Magento\Config\Block\System\Config\Form\Field
use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Module\ModuleListInterface;

/**
* Class Version
* @package MagePal\GuestToCustomer\Block\Adminhtml\System\Config\Form\Module
*/
class Version extends Field
{

/**
* @var \Magento\Framework\Module\ModuleListInterface
* @var ModuleListInterface
*/
protected $_moduleList;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Module\ModuleListInterface $moduleList
* @param Context $context
* @param ModuleListInterface $moduleList
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Module\ModuleListInterface $moduleList,
Context $context,
ModuleListInterface $moduleList,
array $data = []
) {
parent::__construct($context, $data);
Expand All @@ -32,11 +42,11 @@ public function __construct(
/**
* Render button
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @param AbstractElement $element
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
* @throws LocalizedException
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
public function render(AbstractElement $element)
{
// Remove scope label
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
Expand All @@ -46,11 +56,11 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
/**
* Return element html
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @param AbstractElement $element
* @return string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
protected function _getElementHtml(AbstractElement $element)
{
return 'v' . $this->getVersion();
}
Expand Down
39 changes: 29 additions & 10 deletions Block/Customer/LookupForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,38 @@
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | [email protected]
*/
* https://www.magepal.com | [email protected]
*/

namespace MagePal\GuestToCustomer\Block\Customer;

use Magento\Customer\Api\AccountManagementInterface;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Customer\Model\Session;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\Newsletter\Model\Subscriber;
use Magento\Newsletter\Model\SubscriberFactory;

class LookupForm extends \Magento\Framework\View\Element\Template
/**
* Class LookupForm
* @package MagePal\GuestToCustomer\Block\Customer
*/
class LookupForm extends Template
{
/**
* @var \Magento\Newsletter\Model\Subscriber
* @var Subscriber
*/
protected $subscription;

/**
* @var \Magento\Customer\Model\Session
* @var Session
*/
protected $customerSession;

/**
* @var \Magento\Newsletter\Model\SubscriberFactory
* @var SubscriberFactory
*/
protected $subscriberFactory;

Expand All @@ -37,10 +47,19 @@ class LookupForm extends \Magento\Framework\View\Element\Template
*/
protected $customerAccountManagement;

/**
* LookupForm constructor.
* @param Context $context
* @param Session $customerSession
* @param SubscriberFactory $subscriberFactory
* @param CustomerRepositoryInterface $customerRepository
* @param AccountManagementInterface $customerAccountManagement
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Customer\Model\Session $customerSession,
\Magento\Newsletter\Model\SubscriberFactory $subscriberFactory,
Context $context,
Session $customerSession,
SubscriberFactory $subscriberFactory,
CustomerRepositoryInterface $customerRepository,
AccountManagementInterface $customerAccountManagement,
array $data = []
Expand All @@ -55,7 +74,7 @@ public function __construct(
/**
* Return the Customer given the customer Id stored in the session.
*
* @return \Magento\Customer\Api\Data\CustomerInterface
* @return CustomerInterface
*/
public function getCustomer()
{
Expand Down
23 changes: 16 additions & 7 deletions Block/View/Element/Html/Link/Current.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,37 @@
/**
* Copyright © MagePal LLC, Inc. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | [email protected]
* https://www.magepal.com | [email protected]
*/
namespace MagePal\GuestToCustomer\Block\View\Element\Html\Link;

use Magento\Framework\App\DefaultPathInterface;
use Magento\Framework\View\Element\Template\Context;
use MagePal\GuestToCustomer\Helper\Data;

/**
* Class Current
* @package MagePal\GuestToCustomer\Block\View\Element\Html\Link
*/
class Current extends \Magento\Framework\View\Element\Html\Link\Current
{

/* @var \MagePal\GuestToCustomer\Helper\Data*/
/* @var Data*/
protected $helperData;

/**
* Constructor
*
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \MagePal\GuestToCustomer\Helper\Data $helperData
* @param Context $context
* @param DefaultPathInterface $defaultPath
* @param array $data
* @param Data $helperData
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\App\DefaultPathInterface $defaultPath,
Context $context,
DefaultPathInterface $defaultPath,
array $data = [],
\MagePal\GuestToCustomer\Helper\Data $helperData
Data $helperData
) {
parent::__construct($context, $defaultPath, $data);
$this->helperData = $helperData;
Expand Down
Loading

0 comments on commit 865af1e

Please sign in to comment.