20
20
21
21
namespace Meta \BusinessExtension \Controller \Adminhtml \Ajax ;
22
22
23
+ use GuzzleHttp \Exception \GuzzleException ;
23
24
use Meta \BusinessExtension \Helper \FBEHelper ;
24
25
use Meta \BusinessExtension \Helper \GraphAPIAdapter ;
25
26
use Meta \BusinessExtension \Model \System \Config as SystemConfig ;
@@ -47,17 +48,17 @@ class PersistConfiguration extends AbstractAjax
47
48
/**
48
49
* Construct
49
50
*
50
- * @param Context $context
51
- * @param JsonFactory $resultJsonFactory
52
- * @param FBEHelper $fbeHelper
53
- * @param SystemConfig $systemConfig
51
+ * @param Context $context
52
+ * @param JsonFactory $resultJsonFactory
53
+ * @param FBEHelper $fbeHelper
54
+ * @param SystemConfig $systemConfig
54
55
* @param GraphAPIAdapter $graphApiAdapter
55
56
*/
56
57
public function __construct (
57
- Context $ context ,
58
- JsonFactory $ resultJsonFactory ,
59
- FBEHelper $ fbeHelper ,
60
- SystemConfig $ systemConfig ,
58
+ Context $ context ,
59
+ JsonFactory $ resultJsonFactory ,
60
+ FBEHelper $ fbeHelper ,
61
+ SystemConfig $ systemConfig ,
61
62
GraphAPIAdapter $ graphApiAdapter
62
63
) {
63
64
parent ::__construct ($ context , $ resultJsonFactory , $ fbeHelper );
@@ -81,12 +82,13 @@ public function executeForJson()
81
82
$ catalogId = $ this ->getRequest ()->getParam ('catalogId ' );
82
83
$ pageId = $ this ->getRequest ()->getParam ('pageId ' );
83
84
$ commercePartnerIntegrationId = $ this ->getRequest ()->getParam ('commercePartnerIntegrationId ' );
85
+ $ isOnsiteEligible = $ this ->getRequest ()->getParam ('isOnsiteEligible ' ) === 'true ' ;
84
86
85
87
$ this ->saveExternalBusinessId ($ externalBusinessId , $ storeId )
86
88
->saveCatalogId ($ catalogId , $ storeId )
87
89
->saveCommercePartnerIntegrationId ($ commercePartnerIntegrationId , $ storeId )
88
90
->saveInstalledFlag ($ storeId )
89
- ->completeOnsiteOnboarding ($ accessToken , $ pageId , $ storeId )
91
+ ->completeOnsiteOnboarding ($ accessToken , $ pageId , $ storeId, $ isOnsiteEligible )
90
92
->enableCatalogSync ($ commercePartnerIntegrationId , $ storeId );
91
93
92
94
$ response ['success ' ] = true ;
@@ -110,8 +112,8 @@ public function executeForJson()
110
112
/**
111
113
* Save catalog id
112
114
*
113
- * @param int $catalogId
114
- * @param int $storeId
115
+ * @param int $catalogId
116
+ * @param int $storeId
115
117
* @return $this
116
118
*/
117
119
public function saveCatalogId ($ catalogId , $ storeId )
@@ -122,16 +124,16 @@ public function saveCatalogId($catalogId, $storeId)
122
124
$ catalogId ,
123
125
$ storeId
124
126
);
125
- $ this ->fbeHelper ->log ('Catalog ID saved on instance --- ' . $ catalogId );
127
+ $ this ->fbeHelper ->log ('Catalog ID saved on instance --- ' . $ catalogId );
126
128
}
127
129
return $ this ;
128
130
}
129
131
130
132
/**
131
133
* Save commerce partner integration id
132
134
*
133
- * @param int $commercePartnerIntegrationId
134
- * @param int $storeId
135
+ * @param int $commercePartnerIntegrationId
136
+ * @param int $storeId
135
137
* @return $this
136
138
*/
137
139
public function saveCommercePartnerIntegrationId ($ commercePartnerIntegrationId , $ storeId )
@@ -153,8 +155,8 @@ public function saveCommercePartnerIntegrationId($commercePartnerIntegrationId,
153
155
/**
154
156
* Based on commerce PI presence it enables catalog sync.
155
157
*
156
- * @param int $commercePartnerIntegrationId
157
- * @param int $storeId
158
+ * @param int $commercePartnerIntegrationId
159
+ * @param int $storeId
158
160
* @return $this
159
161
*/
160
162
public function enableCatalogSync ($ commercePartnerIntegrationId , $ storeId )
@@ -174,8 +176,8 @@ public function enableCatalogSync($commercePartnerIntegrationId, $storeId)
174
176
/**
175
177
* Save external business id
176
178
*
177
- * @param int $externalBusinessId
178
- * @param int $storeId
179
+ * @param int $externalBusinessId
180
+ * @param int $storeId
179
181
* @return $this
180
182
*/
181
183
public function saveExternalBusinessId ($ externalBusinessId , $ storeId )
@@ -186,20 +188,20 @@ public function saveExternalBusinessId($externalBusinessId, $storeId)
186
188
$ externalBusinessId ,
187
189
$ storeId
188
190
);
189
- $ this ->fbeHelper ->log ('External business ID saved on instance --- ' . $ externalBusinessId );
191
+ $ this ->fbeHelper ->log ('External business ID saved on instance --- ' . $ externalBusinessId );
190
192
}
191
193
return $ this ;
192
194
}
193
195
194
196
/**
195
197
* Update install flag to true and save
196
198
*
197
- * @param int $storeId
199
+ * @param int $storeId
198
200
* @return $this
199
201
*/
200
202
public function saveInstalledFlag ($ storeId )
201
203
{
202
- // set installed to true
204
+ // set installed to true
203
205
$ this ->systemConfig ->saveConfig (
204
206
SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_INSTALLED ,
205
207
true ,
@@ -211,15 +213,16 @@ public function saveInstalledFlag($storeId)
211
213
/**
212
214
* Complete onsite onboarding
213
215
*
214
- * @param string $accessToken
215
- * @param int $pageId
216
- * @param int $storeId
216
+ * @param string $accessToken
217
+ * @param int $pageId
218
+ * @param int $storeId
219
+ * @param bool $isOnsiteEligible
217
220
* @return $this
218
221
* @throws LocalizedException
219
- * @throws \GuzzleHttp\Exception\ GuzzleException
222
+ * @throws GuzzleException
220
223
*/
221
224
222
- public function completeOnsiteOnboarding ($ accessToken , $ pageId , $ storeId )
225
+ public function completeOnsiteOnboarding ($ accessToken , $ pageId , $ storeId, $ isOnsiteEligible )
223
226
{
224
227
if (!$ accessToken ) {
225
228
$ this ->fbeHelper ->log ('No access token available, skipping onboarding to onsite checkout ' );
@@ -237,7 +240,7 @@ public function completeOnsiteOnboarding($accessToken, $pageId, $storeId)
237
240
$ pageId ,
238
241
$ storeId
239
242
);
240
- $ this ->fbeHelper ->log ('Page ID saved on instance --- ' . $ pageId );
243
+ $ this ->fbeHelper ->log ('Page ID saved on instance --- ' . $ pageId );
241
244
242
245
// retrieve page access token
243
246
$ pageAccessToken = $ this ->graphApiAdapter ->getPageAccessToken ($ accessToken , $ pageId );
@@ -266,6 +269,13 @@ public function completeOnsiteOnboarding($accessToken, $pageId, $storeId)
266
269
$ storeId
267
270
);
268
271
272
+ // save if onsite eligible
273
+ $ this ->systemConfig ->saveConfig (
274
+ SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_IS_ONSITE_ELIGIBLE ,
275
+ $ isOnsiteEligible ? 1 : 0 ,
276
+ $ storeId
277
+ );
278
+
269
279
// enable API integration
270
280
$ this ->graphApiAdapter ->associateMerchantSettingsWithApp ($ commerceAccountId , $ accessToken );
271
281
0 commit comments