Skip to content

Commit

Permalink
Remove IntegrationTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
yangyao committed Jun 6, 2023
1 parent a129227 commit b765258
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 59 deletions.
57 changes: 0 additions & 57 deletions Setup/IntegrationTrait.php

This file was deleted.

43 changes: 41 additions & 2 deletions Setup/RecurringData.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
use Magento\Integration\Api\IntegrationServiceInterface;
use Magento\Integration\Api\AuthorizationServiceInterface;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Integration\Model\Integration;
use Magento\Store\Api\StoreRepositoryInterface;

class RecurringData implements InstallDataInterface
{
use IntegrationTrait;

/**
* @var StoreRepositoryInterface
Expand Down Expand Up @@ -47,6 +47,45 @@ public function __construct(

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$this->run($setup, $context);
$storeList = $this->storeRepository->getList();
$integrationNames = [];
foreach ($storeList as $index => $item) {
$storeId = $item->getId();
if ($storeId == 0) continue;
foreach ($this->apps as $app) {
$this->createIntegration($this->buildIntegrationData($app, $storeId, $item->getCode()));
}
}
}

private function buildIntegrationData($app, $storeId, $storeCode)
{
$name = sprintf("AfterShip %s For Store: %s", ucfirst($app), $storeCode);
$identityLinkUrl = sprintf("https://accounts.aftership.com/oauth/%s/magento-2/identity", $app);
$endpoint = sprintf("https://accounts.aftership.com/oauth/%s/magento-2/callback?store_id=%d", $app, $storeId);
if ($app === 'tracking') {
$endpoint = sprintf("https://accounts.aftership.com/oauth/magento-2/callback?store_id=%d", $storeId);
$identityLinkUrl = 'https://accounts.aftership.com/oauth/magento-2/identity';
}
$integrationData = [
'name' => $name,
'email' => '[email protected]',
'endpoint' => $endpoint,
'identity_link_url' => $identityLinkUrl
];
return $integrationData;
}

private function createIntegration($integrationData)
{
$integration = $this->integrationService->findByName($integrationData['name']);
if ($integration->getId()) {
$integrationData[Integration::ID] = $integration->getId();
$this->integrationService->update($integrationData);
} else {
$integration = $this->integrationService->create($integrationData);
}
$this->authorizationService->grantAllPermissions($integration->getId());
return $integration;
}
}

0 comments on commit b765258

Please sign in to comment.