Skip to content

Commit 79d87bb

Browse files
committed
Merge branch 'fix/refactor-setup-scripts' of github.com:magento-commerce/facebook-for-magento2 into fix/refactor-setup-scripts
2 parents 3fc2c00 + e733255 commit 79d87bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1994
-1455
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
# the repo. Unless a later match takes precedence,
66
# @global-owner1 and @global-owner2 will be requested for
77
# review when someone opens a pull request.
8-
* @zlik @omiroshnichenko @dahcsguy @nofuss
8+
* @zlik @omiroshnichenko @dahcsguy @nofuss @dabramovici

app/code/Meta/BusinessExtension/Block/Adminhtml/Setup.php

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Meta\BusinessExtension\Model\System\Config as SystemConfig;
2222
use Magento\Backend\Block\Template\Context;
2323
use Magento\Backend\Block\Template;
24+
use Magento\Store\Api\StoreRepositoryInterface;
2425

2526
/**
2627
* @api
@@ -37,24 +38,34 @@ class Setup extends Template
3738
*/
3839
private $systemConfig;
3940

41+
/**
42+
* @var StoreRepositoryInterface
43+
*/
44+
public $storeRepo;
45+
4046
/**
4147
* @param Context $context
4248
* @param FBEHelper $fbeHelper
4349
* @param SystemConfig $systemConfig
50+
* @param StoreRepositoryInterface $storeRepo
4451
* @param array $data
4552
*/
4653
public function __construct(
4754
Context $context,
4855
FBEHelper $fbeHelper,
4956
SystemConfig $systemConfig,
57+
StoreRepositoryInterface $storeRepo,
5058
array $data = []
5159
) {
5260
$this->fbeHelper = $fbeHelper;
5361
parent::__construct($context, $data);
5462
$this->systemConfig = $systemConfig;
63+
$this->storeRepo = $storeRepo;
5564
}
5665

5766
/**
67+
* Get pixel ajax route
68+
*
5869
* @return mixed
5970
*/
6071
public function getPixelAjaxRoute()
@@ -63,6 +74,8 @@ public function getPixelAjaxRoute()
6374
}
6475

6576
/**
77+
* Get access token ajax route
78+
*
6679
* @return mixed
6780
*/
6881
public function getAccessTokenAjaxRoute()
@@ -71,6 +84,8 @@ public function getAccessTokenAjaxRoute()
7184
}
7285

7386
/**
87+
* Get profiles ajax route
88+
*
7489
* @return mixed
7590
*/
7691
public function getProfilesAjaxRoute()
@@ -79,6 +94,8 @@ public function getProfilesAjaxRoute()
7994
}
8095

8196
/**
97+
* Get aam settings route
98+
*
8299
* @return mixed
83100
*/
84101
public function getAAMSettingsRoute()
@@ -87,23 +104,31 @@ public function getAAMSettingsRoute()
87104
}
88105

89106
/**
107+
* Fetch pixel id
108+
*
109+
* @param int $storeId
90110
* @return string|null
91111
*/
92-
public function fetchPixelId()
112+
public function fetchPixelId($storeId)
93113
{
94-
return $this->systemConfig->getPixelId();
114+
return $this->systemConfig->getPixelId($storeId);
95115
}
96116

97117
/**
118+
* Get external business id
119+
*
120+
* @param int $storeId
98121
* @return string|null
99122
* @throws \Magento\Framework\Exception\NoSuchEntityException
100123
*/
101-
public function getExternalBusinessId()
124+
public function getExternalBusinessId($storeId)
102125
{
103-
return $this->fbeHelper->getFBEExternalBusinessId();
126+
return $this->fbeHelper->getFBEExternalBusinessId($storeId);
104127
}
105128

106129
/**
130+
* Fetch configuration ajax route
131+
*
107132
* @return mixed
108133
*/
109134
public function fetchConfigurationAjaxRoute()
@@ -112,6 +137,8 @@ public function fetchConfigurationAjaxRoute()
112137
}
113138

114139
/**
140+
* Get delete asset ids ajax route
141+
*
115142
* @return mixed
116143
*/
117144
public function getDeleteAssetIdsAjaxRoute()
@@ -120,6 +147,8 @@ public function getDeleteAssetIdsAjaxRoute()
120147
}
121148

122149
/**
150+
* Get currency code
151+
*
123152
* @return mixed
124153
* @throws \Magento\Framework\Exception\NoSuchEntityException
125154
*/
@@ -129,18 +158,33 @@ public function getCurrencyCode()
129158
}
130159

131160
/**
161+
* Is fbe installed
162+
*
163+
* @param int $storeId
132164
* @return string
133165
*/
134-
public function isFBEInstalled()
166+
public function isFBEInstalled($storeId)
135167
{
136-
return $this->systemConfig->isFBEInstalled() ? 'true' : 'false';
168+
return $this->systemConfig->isFBEInstalled($storeId) ? 'true' : 'false';
137169
}
138170

139171
/**
172+
* Get app id
173+
*
140174
* @return string
141175
*/
142176
public function getAppId()
143177
{
144178
return $this->systemConfig->getAppId();
145179
}
180+
181+
/**
182+
* Get stores
183+
*
184+
* @return \Magento\Store\Api\Data\StoreInterface[]
185+
*/
186+
public function getStores()
187+
{
188+
return $this->storeRepo->getList();
189+
}
146190
}

app/code/Meta/BusinessExtension/Controller/Adminhtml/Ajax/Fbaamsettings.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
use Magento\Framework\Controller\Result\JsonFactory;
2222
use Meta\BusinessExtension\Helper\FBEHelper;
2323

24+
/**
25+
* @SuppressWarnings(PHPMD)
26+
*/
2427
class Fbaamsettings extends AbstractAjax
2528
{
2629
/**
@@ -29,6 +32,8 @@ class Fbaamsettings extends AbstractAjax
2932
private $fbeHelper;
3033

3134
/**
35+
* Construct
36+
*
3237
* @param Context $context
3338
* @param JsonFactory $resultJsonFactory
3439
* @param FBEHelper $fbeHelper
@@ -42,15 +47,21 @@ public function __construct(
4247
$this->fbeHelper = $fbeHelper;
4348
}
4449

50+
/**
51+
* Execute for json
52+
*
53+
* @return array
54+
*/
4555
public function executeForJson()
4656
{
4757
$response = [
4858
'success' => false,
4959
'settings' => null,
5060
];
5161
$pixelId = $this->getRequest()->getParam('pixelId');
62+
$storeId = $this->getRequest()->getParam('storeId');
5263
if ($pixelId) {
53-
$settingsAsString = $this->fbeHelper->fetchAndSaveAAMSettings($pixelId);
64+
$settingsAsString = $this->fbeHelper->fetchAndSaveAAMSettings($pixelId, $storeId);
5465
if ($settingsAsString) {
5566
$response['success'] = true;
5667
$response['settings'] = $settingsAsString;

app/code/Meta/BusinessExtension/Controller/Adminhtml/Ajax/Fbpixel.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@
2020
use Magento\Backend\App\Action\Context;
2121
use Magento\Framework\Controller\Result\JsonFactory;
2222
use Meta\BusinessExtension\Helper\FBEHelper;
23+
use Magento\Store\Model\ScopeInterface;
2324
use Meta\BusinessExtension\Model\System\Config as SystemConfig;
2425

26+
/**
27+
* @SuppressWarnings(PHPMD)
28+
*/
2529
class Fbpixel extends AbstractAjax
2630
{
2731
/**
@@ -35,6 +39,8 @@ class Fbpixel extends AbstractAjax
3539
private $systemConfig;
3640

3741
/**
42+
* Construct
43+
*
3844
* @param Context $context
3945
* @param JsonFactory $resultJsonFactory
4046
* @param FBEHelper $fbeHelper
@@ -51,18 +57,34 @@ public function __construct(
5157
$this->systemConfig = $systemConfig;
5258
}
5359

54-
// Yet to verify how to use the pii info, hence have commented the part of code.
60+
/**
61+
* Execute for json
62+
*
63+
* Yet to verify how to use the pii info, hence have commented the part of code.
64+
*
65+
* @return array
66+
*/
5567
public function executeForJson()
5668
{
57-
$oldPixelId = $this->systemConfig->getPixelId();
69+
$storeId = $this->getRequest()->getParam('storeId');
70+
$oldPixelId = $this->systemConfig->getPixelId($storeId, ScopeInterface::SCOPE_STORES);
5871
$response = [
5972
'success' => false,
6073
'pixelId' => $oldPixelId
6174
];
6275
$pixelId = $this->getRequest()->getParam('pixelId');
76+
6377
if ($pixelId && $this->fbeHelper->isValidFBID($pixelId)) {
64-
$this->systemConfig->saveConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_PIXEL_ID, $pixelId);
65-
$this->systemConfig->saveConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_INSTALLED, true);
78+
$this->systemConfig->saveConfig(
79+
SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_PIXEL_ID,
80+
$pixelId,
81+
$storeId
82+
);
83+
$this->systemConfig->saveConfig(
84+
SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_INSTALLED,
85+
true,
86+
$storeId
87+
);
6688
$response['success'] = true;
6789
$response['pixelId'] = $pixelId;
6890
if ($oldPixelId && $oldPixelId != $pixelId) {

app/code/Meta/BusinessExtension/Controller/Adminhtml/Ajax/Fbprofiles.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
use Magento\Framework\Controller\Result\JsonFactory;
2222
use Meta\BusinessExtension\Helper\FBEHelper;
2323
use Meta\BusinessExtension\Model\System\Config as SystemConfig;
24+
use Magento\Store\Model\ScopeInterface;
2425

26+
/**
27+
* @SuppressWarnings(PHPMD)
28+
*/
2529
class Fbprofiles extends AbstractAjax
2630
{
2731
/**
@@ -30,6 +34,8 @@ class Fbprofiles extends AbstractAjax
3034
private $systemConfig;
3135

3236
/**
37+
* Construct
38+
*
3339
* @param Context $context
3440
* @param JsonFactory $resultJsonFactory
3541
* @param FBEHelper $fbeHelper
@@ -45,17 +51,26 @@ public function __construct(
4551
$this->systemConfig = $systemConfig;
4652
}
4753

48-
54+
/**
55+
* Execute for json
56+
*
57+
* @return array
58+
*/
4959
public function executeForJson()
5060
{
51-
$oldProfiles = $this->systemConfig->getProfiles();
61+
$storeId = $this->getRequest()->getParam('storeId');
62+
$oldProfiles = $this->systemConfig->getProfiles($storeId, ScopeInterface::SCOPE_STORES);
5263
$response = [
5364
'success' => false,
5465
'profiles' => $oldProfiles
5566
];
5667
$profiles = $this->getRequest()->getParam('profiles');
5768
if ($profiles) {
58-
$this->systemConfig->saveConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_PROFILES, $profiles);
69+
$this->systemConfig->saveConfig(
70+
SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_PROFILES,
71+
$profiles,
72+
$storeId
73+
);
5974
$response['success'] = true;
6075
$response['profiles'] = $profiles;
6176
}

app/code/Meta/BusinessExtension/Controller/Adminhtml/Ajax/Fbtoken.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
use Magento\Framework\Controller\Result\JsonFactory;
2222
use Meta\BusinessExtension\Helper\FBEHelper;
2323
use Meta\BusinessExtension\Model\System\Config as SystemConfig;
24+
use Magento\Store\Model\ScopeInterface;
2425

26+
/**
27+
* @SuppressWarnings(PHPMD)
28+
*/
2529
class Fbtoken extends AbstractAjax
2630
{
2731
/**
@@ -35,6 +39,8 @@ class Fbtoken extends AbstractAjax
3539
private $systemConfig;
3640

3741
/**
42+
* Construct
43+
*
3844
* @param Context $context
3945
* @param JsonFactory $resultJsonFactory
4046
* @param FBEHelper $fbeHelper
@@ -51,16 +57,26 @@ public function __construct(
5157
$this->systemConfig = $systemConfig;
5258
}
5359

60+
/**
61+
* Execute for json
62+
*
63+
* @return array
64+
*/
5465
public function executeForJson()
5566
{
56-
$oldAccessToken = $this->systemConfig->getAccessToken();
67+
$storeId = $this->getRequest()->getParam('storeId');
68+
$oldAccessToken = $this->systemConfig->getAccessToken($storeId, ScopeInterface::SCOPE_STORES);
5769
$response = [
5870
'success' => false,
5971
'accessToken' => $oldAccessToken
6072
];
6173
$accessToken = $this->getRequest()->getParam('accessToken');
6274
if ($accessToken) {
63-
$this->systemConfig->saveConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_ACCESS_TOKEN, $accessToken);
75+
$this->systemConfig->saveConfig(
76+
SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_ACCESS_TOKEN,
77+
$accessToken,
78+
$storeId
79+
);
6480
$response['success'] = true;
6581
$response['accessToken'] = $accessToken;
6682
if ($oldAccessToken && $oldAccessToken != $accessToken) {

0 commit comments

Comments
 (0)