Skip to content

Commit

Permalink
Adaptando a instalação do módulo ao padrão de dir Setup/Data/
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandercamps0 committed Jun 7, 2023
1 parent bbe35c3 commit 8a39a07
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 45 deletions.
36 changes: 35 additions & 1 deletion Setup/Patch/Data/AttributeContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
namespace Frenet\Shipping\Setup\Patch\Data;

use Frenet\Shipping\Model\Catalog\Product\AttributesMappingInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Console\Cli;

/**
* Class AttributeContainer
*/
class AttributeContainer
class AttributeContainer implements DataPatchInterface
{
/**
* @var array
Expand Down Expand Up @@ -73,6 +75,38 @@ class AttributeContainer
'label', 'description', 'note'
];

/**
* @inheritdoc
*/
public function apply()
{
return Cli::RETURN_SUCCESS;
}

/**
* @inheritdoc
*/
public static function getDependencies()
{
return [];
}

/**
* @inheritdoc
*/
public static function getVersion()
{
return '2.4.5';
}

/**
* @inheritdoc
*/
public function getAliases()
{
return [ "frenetshipping-2.4.5.4" ];
}

/**
* @param string $attributeCode
*
Expand Down
30 changes: 0 additions & 30 deletions Setup/Patch/Data/CatalogProductAttributeInstaller.php

This file was deleted.

42 changes: 40 additions & 2 deletions Setup/Patch/Data/EavAttributeInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
namespace Frenet\Shipping\Setup\Patch\Data;

use Frenet\Shipping\Model\Catalog\ProductType;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Console\Cli;

/**
* Class EavAttributeInstaller
*/
abstract class EavAttributeInstaller
class EavAttributeInstaller implements DataPatchInterface
{
/**
* @var \Psr\Log\LoggerInterface
Expand All @@ -46,6 +48,39 @@ public function __construct(
$this->logger = $logger;
}


/**
* @inheritdoc
*/
public function apply()
{
return Cli::RETURN_SUCCESS;
}

/**
* @inheritdoc
*/
public static function getDependencies()
{
return [];
}

/**
* @inheritdoc
*/
public static function getVersion()
{
return '2.4.5';
}

/**
* @inheritdoc
*/
public function getAliases()
{
return [ "frenetshipping-2.4.5.4" ];
}

/**
* @param string $code
* @param array $config
Expand All @@ -71,7 +106,10 @@ public function install($code, array $config = [])
/**
* @return string
*/
abstract protected function getEntityType();
protected function getEntityType()
{
return \Magento\Catalog\Model\Product::ENTITY;
}

/**
* @param array $config
Expand Down
113 changes: 113 additions & 0 deletions Setup/Patch/Data/FrenetQuotePatchData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php
/**
* Frenet Shipping Gateway
*
* @category Frenet
*
* @author Frenet Gateway <[email protected]>
* @link https://github.com/FrenetGatewaydeFretes/frenet-magento2
* @link https://www.frenet.com.br
*
* Copyright (c) 2023.
*/

declare(strict_types = 1);

namespace Frenet\Shipping\Setup\Patch\Data;

use Frenet\Shipping\Model\Catalog\ProductType;
use Frenet\Shipping\Model\Cache\Type\Frenet;
use Magento\Framework\Console\Cli;
use Magento\Framework\Locale\Bundle\DataBundle;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchVersionInterface;

class FrenetQuotePatchData implements DataPatchInterface, PatchVersionInterface
{
/**
* @var Frenet
*/
protected $cacheType;

/**
* @var AttributeContainer
*/
protected $attributeContainer;

/**
* @var EavAttributeInstaller
*/
private $attributeInstaller;

/**
* Constructor
*
* @param Frenet $cacheType
* @param AttributeContainer $attributeContainer
* @param EavAttributeInstaller $attributeInstaller
*/
public function __construct(
Frenet $cacheType,
AttributeContainer $attributeContainer,
EavAttributeInstaller $attributeInstaller
) {
$this->cacheType = $cacheType;
$this->attributeContainer = $attributeContainer;
$this->attributeInstaller = $attributeInstaller;
}

/**
* @inheritdoc
*/
public function apply()
{
/**
* Run for new installation only.
*/
$this->configureNewInstallation();
return Cli::RETURN_SUCCESS;
}

/**
* @inheritdoc
*/
public static function getDependencies()
{
return [];
}

/**
* @inheritdoc
*/
public static function getVersion()
{
return '2.4.5';
}

/**
* @inheritdoc
*/
public function getAliases()
{
return [ "frenetshipping-2.4.5.4" ];
}

/**
* Creates the new attributes during the module installation.
*/
private function configureNewInstallation()
{
/**
* @var string $code
* @var array $data
*/
foreach ($this->attributeContainer->getAttributeProperties() as $code => $data) {
$this->attributeInstaller->install($code, (array) $data);
}

/** Set the Frenet cache type enabled by default when module is installed. */
$this->cacheType->setEnabled(true);
}
}
27 changes: 15 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@
}
},
"description":"Integrate your Magento 2 with Frenet Services in a simple way.",
"repositories": [
{
"repositories": {
"mage": {
"type": "composer",
"url": "https://repo.magento.com",
"exclude": [ "frenet/frenet-magento2", "frenet/frenet-php" ]
},
"packagist": {
"type": "composer",
"url": "https://repo.magento.com/"
"url": "https://packagist.org"
}
],
},
"require": {
"php": "^7.0|>=8.0",
"frenet/frenet-php": "^1.3.1",
Expand All @@ -25,18 +30,16 @@
"magento/module-catalog": "^101.0.0|^102.0.0|^103.0.0|^104.0.0",
"magento/module-quote": "^101.0.0|^102.0.0|^103.0.0|^104.0.0",
"magento/module-shipping": "^100.0.0",
"magento/module-directory": "^101.0.0|^102.0.0|^103.0.0|^104.0.0",
"magento/module-directory": "^100.0.0",
"magento/module-bundle": "^101.0.0|^102.0.0|^103.0.0|^104.0.0",
"magento/module-grouped-product": "^101.0.0|^102.0.0|^103.0.0|^104.0.0",
"magento/module-configurable-product": "^101.0.0|^102.0.0|^103.0.0|^104.0.0",
"magento/module-downloadable": "^101.0.0|^102.0.0|^103.0.0|^104.0.0",
"magento/module-store": "^101.0.0|^102.0.0|^103.0.0|^104.0.0"
"magento/module-grouped-product": "^100.0.0",
"magento/module-configurable-product": "^100.0.0",
"magento/module-downloadable": "^100.0.0",
"magento/module-store": "^101.0.0"
},
"require-dev": {
"magento/magento-coding-standard": "~4.0.0",
"magento/magento2-functional-testing-framework": "^101.0.0|^102.0.0|^103.0.0|^104.0.0",
"phpmd/phpmd": "@stable",
"phpunit/phpunit": "~6.5.0"
"phpmd/phpmd": "@stable"
},
"license": "proprietary",
"suggest": {},
Expand Down

0 comments on commit 8a39a07

Please sign in to comment.