Skip to content

Commit

Permalink
Merge pull request #5 from AlphaJanus/module-offer
Browse files Browse the repository at this point in the history
Add_group_creation
  • Loading branch information
AlphaJanus authored May 7, 2019
2 parents 473242d + 18b03e8 commit d555690
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
78 changes: 77 additions & 1 deletion Setup/InstallData.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,96 @@

namespace Netzexpert\Offer\Setup;

use Magento\Customer\Api\GroupRepositoryInterface;
use Magento\Customer\Api\Data\GroupInterfaceFactory;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Tax\Helper\Data as TaxHelper;
use Magento\TestFramework\Inspection\Exception;
use Psr\Log\LoggerInterface;

class InstallData implements InstallDataInterface
{
/**
* Function install
* @var GroupInterfaceFactory
*/
private $groupFactory;

/**
* @var GroupRepositoryInterface
*/
private $groupRepository;

/** @var SearchCriteriaBuilder */
private $searchCriteriaBuilder;

/** @var ScopeConfigInterface */
private $scopeConfig;

/**
* @var LoggerInterface
*/
private $logger;

/**
* InstallData constructor.
* @param GroupInterfaceFactory $groupFactory
* @param GroupRepositoryInterface $groupRepository
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param TaxHelper $taxHelper
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(
GroupInterfaceFactory $groupFactory,
GroupRepositoryInterface $groupRepository,
SearchCriteriaBuilder $searchCriteriaBuilder,
ScopeConfigInterface $scopeConfig,
LoggerInterface $logger
) {
$this->groupFactory = $groupFactory;
$this->groupRepository = $groupRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->scopeConfig = $scopeConfig;
$this->logger = $logger;
}

/**
* Install data for a module
*
* @param ModuleDataSetupInterface $setup
* @param ModuleContextInterface $context
* @return void
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();

$searchCriteria = $this->searchCriteriaBuilder->addFilter('customer_group_code', 'Mitarbeiter')
->create();
try {
$groupList = $this->groupRepository->getList($searchCriteria);
} catch (\Exception $e) {
$this->logger->alert('Could not get list of groups');
}
if (!$groupList->getTotalCount()) {
$group = $this->groupFactory->create();
$group->setCode('Mitarbeiter')
->setTaxClassId(
$this->scopeConfig->getValue(
TaxHelper::CONFIG_DEFAULT_CUSTOMER_TAX_CLASS,
ScopeInterface::SCOPE_STORE
)
);
try {
$this->groupRepository->save($group);
} catch (\Exception $e) {
$this->logger->alert('Could not save group');
}
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"magento/framework": ">=100.0.0 <103"
},
"type": "magento2-module",
"version": "1.0.5",
"version": "1.0.6",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down

0 comments on commit d555690

Please sign in to comment.