Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
srenon committed May 1, 2020
1 parent e3fb359 commit 6a70b35
Show file tree
Hide file tree
Showing 22 changed files with 352 additions and 37 deletions.
Empty file modified .github/FUNDING.yml
100644 → 100755
Empty file.
39 changes: 39 additions & 0 deletions .github/issue_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@


<!--- Before adding a new issue, please check all closed and existing issues to make sure this is not a duplicate -->


<!--- https://www.magepal.com/ for fast Premium Support -->


#### Magento version #:

#### Edition (EE, CE, OS, etc):

#### Expected behavior:

#### Actual behavior:

#### Steps to reproduce:

#### Preconditions
<!--- Provide a more detailed information of environment you use -->
<!--- Magento version, tag, HEAD, etc., PHP & MySQL version, etc.. -->


<!---
PLEASE NOTE:
We receive multiple emails & support tickets almost daily asking for help.
In most cases these issues have nothing to do with our extension and mostly
caused by lack of basic Magento knowledge or not following installation instructions.
At MagePal, our goal is to develop a wide variety of both free and paid extension
and due to our limited resources, our main focus are fixing reported bugs and developing
other great extensions.
Because of this, we cannot provide free support for our free extensions.
However, we do offer very affordable support options and/or training.
For more information visit www.magepal.com or email us at support@magepal.com.
-->
11 changes: 11 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: PHPCS
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: PHPCS
run: docker run --rm -v $PWD:/code:ro domw/phpcs phpcs --colors --standard=Magento2 --report=full,summary,gitblame --extensions=php,phtml ./
- name: compatibility
run: docker run --rm -v $PWD:/code:ro domw/phpcompatibility phpcs --standard=PHPCompatibility --runtime-set testVersion 5.6-7.3 --colors --warning-severity=0 --report=full,summary --extensions=php,phtml ./
123 changes: 123 additions & 0 deletions Block/Adminhtml/System/Config/Form/Composer/Version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | support@magepal.com
*/

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

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 as AbstractElementAlias;
use Magento\Framework\Filesystem\Directory\ReadFactory;
use Magento\Framework\Phrase;

/**
* Admin block class for composer version
*/
class Version extends Field
{

/**
* @var DeploymentConfig
*/
protected $deploymentConfig;

/**
* @var ComponentRegistrarInterface
*/
protected $componentRegistrar;

/**
* @var ReadFactory
*/
protected $readFactory;

/**
* @param Context $context
* @param DeploymentConfig $deploymentConfig
* @param ComponentRegistrarInterface $componentRegistrar
* @param ReadFactory $readFactory
* @param array $data
*/
public function __construct(
Context $context,
DeploymentConfig $deploymentConfig,
ComponentRegistrarInterface $componentRegistrar,
ReadFactory $readFactory,
array $data = []
) {
$this->deploymentConfig = $deploymentConfig;
$this->componentRegistrar = $componentRegistrar;
$this->readFactory = $readFactory;
parent::__construct($context, $data);
}

/**
* Render button
*
* @param AbstractElementAlias $element
* @return string
*/
public function render(AbstractElementAlias $element)
{
// Remove scope label
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
return parent::render($element);
}

/**
* Return element html
*
* @param AbstractElementAlias $element
* @return string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function _getElementHtml(AbstractElementAlias $element)
{
return 'v' . $this->getVersion();
}

/**
* Get Module version number
*
* @return string
*/
public function getVersion()
{
return $this->getComposerVersion($this->getModuleName());
}

/**
* Get module composer version
*
* @param $moduleName
* @return Phrase|string|void
*/
public function getComposerVersion($moduleName)
{
$path = $this->componentRegistrar->getPath(
ComponentRegistrar::MODULE,
$moduleName
);

try {
$directoryRead = $this->readFactory->create($path);
$composerJsonData = $directoryRead->readFile('composer.json');
if ($composerJsonData) {
$data = json_decode($composerJsonData);
if (!empty($data->version)) {
return $data->version;
}
}
return __('Unknown');
} catch (Exception $e) {
return __('Unknown');
}
}
}
75 changes: 75 additions & 0 deletions Block/Adminhtml/System/Config/Form/Module/Version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | support@magepal.com
*/

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

use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\Module\ModuleListInterface;

/**
* Admin block class for module version
*/
class Version extends Field
{

/**
* @var ModuleListInterface
*/
protected $_moduleList;

/**
* @param Context $context
* @param ModuleListInterface $moduleList
* @param array $data
*/
public function __construct(
Context $context,
ModuleListInterface $moduleList,
array $data = []
) {
parent::__construct($context, $data);
$this->_moduleList = $moduleList;
}

/**
* Render button
*
* @param AbstractElement $element
* @return string
*/
public function render(AbstractElement $element)
{
// Remove scope label
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
return parent::render($element);
}

/**
* Return element html
*
* @param AbstractElement $element
* @return string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function _getElementHtml(AbstractElement $element)
{
return 'v' . $this->getVersion();
}

/**
* Get Module version number
*
* @return string
*/
public function getVersion()
{
$moduleInfo = $this->_moduleList->getOne($this->getModuleName());
return $moduleInfo['setup_version'];
}
}
5 changes: 1 addition & 4 deletions Model/Accessory.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | support@magepal.com
*/

namespace MagePal\LinkProduct\Model;
Expand All @@ -11,10 +12,6 @@
use Magento\Framework\DataObject;
use MagePal\LinkProduct\Model\Product\Link;

/**
* Class Accessory
* @package MagePal\LinkProduct\Model
*/
class Accessory extends DataObject
{
/**
Expand Down
5 changes: 1 addition & 4 deletions Model/Product/CopyConstructor/Accessory.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | support@magepal.com
*/

namespace MagePal\LinkProduct\Model\Product\CopyConstructor;
Expand All @@ -10,10 +11,6 @@
use Magento\Catalog\Model\Product\CopyConstructorInterface;
use Magento\Catalog\Model\Product\Link;

/**
* Class Accessory
* @package MagePal\LinkProduct\Model\Product\CopyConstructor
*/
class Accessory implements CopyConstructorInterface
{
/**
Expand Down
5 changes: 1 addition & 4 deletions Model/Product/Link.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | support@magepal.com
*/

namespace MagePal\LinkProduct\Model\Product;

/**
* Class Link
* @package MagePal\LinkProduct\Model\Product
*/
class Link extends \Magento\Catalog\Model\Product\Link
{
const LINK_TYPE_ACCESSORY = 7;
Expand Down
5 changes: 1 addition & 4 deletions Model/ProductLink/CollectionProvider/Accessory.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | support@magepal.com
*/

namespace MagePal\LinkProduct\Model\ProductLink\CollectionProvider;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\ProductLink\CollectionProviderInterface;

/**
* Class Accessory
* @package MagePal\LinkProduct\Model\ProductLink\CollectionProvider
*/
class Accessory implements CollectionProviderInterface
{
/** @var \MagePal\LinkProduct\Model\Accessory */
Expand Down
14 changes: 8 additions & 6 deletions Plugin/CatalogImportExport/Model/Import/Product.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
<?php
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | support@magepal.com
*/

namespace MagePal\LinkProduct\Plugin\CatalogImportExport\Model\Import;

use Magento\CatalogImportExport\Model\Import\Product as ProductImportExport;
use MagePal\LinkProduct\Model\Product\Link;

/**
* @see Product::getLinkNameToId
*/
class Product
{
/**
* REMARK: needs core patch
* https://github.com/magento/magento2/pull/21230/commits/0846e9aed7040659e7ce3e109eb91df3f5fdfb7e.patch
*
* @param Product $subject
* @param ProductImportExport $subject
* @param $result
* @return mixed
*/
public function afterGetLinkNameToId(\Magento\CatalogImportExport\Model\Import\Product $subject, $result)
public function afterGetLinkNameToId(ProductImportExport $subject, $result)
{
$result['_accessory_'] = Link::LINK_TYPE_ACCESSORY;
return $result;
}

}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Custom Product Relation Sample Extension for Magento 2.2.x and 2.3.x (with zero class rewrite or hacks)

[![Total Downloads](https://poser.okvpn.org/magepal/magento2-link-product/downloads)](https://packagist.org/packages/magepal/magento2-link-product)
[![Latest Stable Version](https://poser.okvpn.org/magepal/magento2-link-product/v/stable)](https://packagist.org/packages/magepal/magento2-link-product)


Create a new product accessory relationship in additional to the default Up-sell products, Related products, and Cross-sell products options available in Magento.

Expand Down
5 changes: 1 addition & 4 deletions Setup/InstallSchema.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | support@magepal.com
*/

namespace MagePal\LinkProduct\Setup;
Expand All @@ -12,10 +13,6 @@
use MagePal\LinkProduct\Model\Product\Link;
use MagePal\LinkProduct\Ui\DataProvider\Product\Form\Modifier\Accessory;

/**
* Class InstallSchema
* @package MagePal\LinkProduct\Setup
*/
class InstallSchema implements InstallSchemaInterface
{

Expand Down
Loading

0 comments on commit 6a70b35

Please sign in to comment.