Skip to content

Commit 2b0b755

Browse files
Merge branch 'main' of github.com:magento-commerce/facebook-for-magento2 into 1.0.0-release
2 parents 4e9ef8d + 47c7254 commit 2b0b755

File tree

27 files changed

+292
-91
lines changed

27 files changed

+292
-91
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323

2424
class Fbdeleteasset extends AbstractAjax
2525
{
26-
const DELETE_SUCCESS_MESSAGE = "You have successfully deleted Meta Business Extension.
26+
public const DELETE_SUCCESS_MESSAGE = "You have successfully deleted Meta Business Extension.
2727
The pixel installed on your website is now deleted.";
2828

29-
const DELETE_FAILURE_MESSAGE = "There was a problem deleting the connection.
29+
private const DELETE_FAILURE_MESSAGE = "There was a problem deleting the connection.
3030
Please try again.";
3131

3232
/**
@@ -51,12 +51,21 @@ public function __construct(
5151
}
5252

5353
/**
54+
* Execute for json
55+
*
5456
* @return array
5557
*/
5658
public function executeForJson()
5759
{
60+
$storeId = $this->getRequest()->getParam('storeId');
61+
if ($storeId === null) {
62+
return [
63+
'success' => false,
64+
'error_message' => __(self::DELETE_FAILURE_MESSAGE)
65+
];
66+
}
5867
try {
59-
$this->fbeHelper->deleteConfigKeys();
68+
$this->fbeHelper->deleteConfigKeys($storeId);
6069
$response = [
6170
'success' => true,
6271
'message' => __(self::DELETE_SUCCESS_MESSAGE),

app/code/Meta/BusinessExtension/Helper/FBEHelper.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -423,18 +423,27 @@ public function logPixelEvent($pixelId, $pixelEvent)
423423
/**
424424
* Delete config keys
425425
*
426+
* @param string $storeId
426427
* @return FBEHelper
427428
*/
428-
public function deleteConfigKeys()
429+
public function deleteConfigKeys($storeId)
429430
{
430-
$this->systemConfig->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_EXTERNAL_BUSINESS_ID)
431-
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_PIXEL_ID)
432-
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_PIXEL_AAM_SETTINGS)
433-
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_PROFILES)
434-
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_CATALOG_ID)
435-
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_FEED_ID)
436-
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_API_VERSION)
437-
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_API_VERSION_LAST_UPDATE);
431+
$this->systemConfig->deleteConfig(
432+
SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_EXTERNAL_BUSINESS_ID,
433+
$storeId
434+
)
435+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_INSTALLED, $storeId)
436+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_ACCESS_TOKEN, $storeId)
437+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_PAGE_ID, $storeId)
438+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_PAGE_ACCESS_TOKEN, $storeId)
439+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_COMMERCE_ACCOUNT_ID, $storeId)
440+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_PIXEL_ID, $storeId)
441+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_PIXEL_AAM_SETTINGS, $storeId)
442+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_PROFILES, $storeId)
443+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_CATALOG_ID, $storeId)
444+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_FEED_ID, $storeId)
445+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_API_VERSION, $storeId)
446+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_API_VERSION_LAST_UPDATE, $storeId);
438447

439448
return $this;
440449
}

app/code/Meta/BusinessExtension/Helper/GraphAPIAdapter.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
namespace Meta\BusinessExtension\Helper;
1919

2020
use CURLFile;
21-
use Meta\Sales\Model\FacebookOrder;
2221
use Meta\BusinessExtension\Model\System\Config as SystemConfig;
2322
use GuzzleHttp\Client;
2423
use GuzzleHttp\Exception\BadResponseException;
@@ -29,6 +28,9 @@ class GraphAPIAdapter
2928
{
3029
const GET_ORDERS_LIMIT = 25;
3130

31+
/** @var string */
32+
private const ORDER_STATE_CREATED = 'CREATED';
33+
3234
/**
3335
* @var mixed
3436
*/
@@ -375,7 +377,7 @@ public function getOrders($pageId, $cursorAfter = false)
375377
];
376378
$request = [
377379
'access_token' => $this->accessToken,
378-
'state' => FacebookOrder::STATE_CREATED,
380+
'state' => self::ORDER_STATE_CREATED,
379381
'fields' => implode(',', $requestFields),
380382
'limit' => self::GET_ORDERS_LIMIT,
381383
];
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Meta\BusinessExtension\Setup\Patch\Data;
6+
7+
use Magento\Framework\Setup\Patch\DataPatchInterface;
8+
use Magento\Framework\Setup\ModuleDataSetupInterface;
9+
10+
class DeleteLegacyData implements DataPatchInterface
11+
{
12+
/**
13+
* @var ModuleDataSetupInterface
14+
*/
15+
private ModuleDataSetupInterface $moduleDataSetup;
16+
17+
/**
18+
* @param ModuleDataSetupInterface $moduleDataSetup
19+
*/
20+
public function __construct(
21+
ModuleDataSetupInterface $moduleDataSetup
22+
) {
23+
$this->moduleDataSetup = $moduleDataSetup;
24+
}
25+
26+
/**
27+
* Get dependencies for the data patch
28+
*
29+
* @return array
30+
*/
31+
public static function getDependencies(): array
32+
{
33+
return [];
34+
}
35+
36+
/**
37+
* Get alias for the data patch
38+
*
39+
* @return array
40+
*/
41+
public function getAliases(): array
42+
{
43+
return [];
44+
}
45+
46+
/**
47+
* Delete unnecessary data from the legacy version of the extension
48+
*
49+
* @return void
50+
*/
51+
public function apply(): void
52+
{
53+
$productAttributesToDelete = [
54+
'facebook_age_group',
55+
'facebook_gender',
56+
'facebook_pattern',
57+
'facebook_decor_style',
58+
'facebook_color',
59+
'facebook_capacity',
60+
'facebook_material',
61+
'facebook_size',
62+
'facebook_style',
63+
'facebook_brand',
64+
'facebook_product_length',
65+
'facebook_product_width',
66+
'facebook_product_height',
67+
'facebook_model',
68+
'facebook_product_depth',
69+
'facebook_ingredients',
70+
'facebook_resolution',
71+
'facebook_age_range',
72+
'facebook_screen_size',
73+
'facebook_maximum_weight',
74+
'facebook_minimum_weight',
75+
'facebook_display_technology',
76+
'facebook_operating_system',
77+
'facebook_is_assembly_required',
78+
'facebook_storage_capacity',
79+
'facebook_number_of_licenses',
80+
'facebook_product_form',
81+
'facebook_compatible_devices',
82+
'facebook_video_game_platform',
83+
'facebook_system_requirements',
84+
'facebook_baby_food_stage',
85+
'facebook_recommended_use',
86+
'facebook_digital_zoom',
87+
'facebook_scent',
88+
'facebook_health_concern',
89+
'facebook_megapixels',
90+
'facebook_thread_count',
91+
'facebook_gemstone',
92+
'facebook_optical_zoom',
93+
'facebook_package_quantity',
94+
'facebook_shoe_width',
95+
'facebook_finish',
96+
'facebook_product_weight',
97+
];
98+
99+
$connection = $this->moduleDataSetup->getConnection();
100+
101+
$connection->startSetup();
102+
103+
// drop legacy facebook_business_extension_config table
104+
$connection->dropTable('facebook_business_extension_config');
105+
106+
// delete legacy product attributes
107+
$eavAttributeTable = $connection->getTableName('eav_attribute');
108+
foreach ($productAttributesToDelete as $attributeCode) {
109+
$connection->delete($eavAttributeTable, ['attribute_code = ?' => $attributeCode]);
110+
}
111+
112+
// delete legacy attribute group
113+
$eavAttributeGroupTable = $connection->getTableName('eav_attribute_group');
114+
$connection->delete($eavAttributeGroupTable, ['attribute_group_name = ?' => 'Facebook Attribute Group']);
115+
116+
$connection->endSetup();
117+
}
118+
}

app/code/Meta/BusinessExtension/Test/Unit/Controller/Adminhtml/Ajax/FbdeleteassetTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ public function setUp(): void
6969
*/
7070
public function testExecuteForJson()
7171
{
72+
$storeId = 2;
73+
$this->request->method('getParam')->willReturn($storeId);
7274
$this->fbeHelper->expects($this->once())
73-
->method('deleteConfigKeys');
75+
->method('deleteConfigKeys')->with($storeId)->willReturnSelf();
7476

7577
$result = $this->fbdeleteasset->executeForJson();
7678
$this->assertNotNull($result);

app/code/Meta/BusinessExtension/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"magento/module-backend": "*",
1111
"magento/module-catalog": "*",
1212
"magento/module-config": "*",
13+
"magento/module-eav": "*",
1314
"magento/module-security": "*",
1415
"magento/module-store": "*",
1516
"magento/module-newsletter": "*",

app/code/Meta/BusinessExtension/etc/adminhtml/system.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<resource>Meta_BusinessExtension::system_config</resource>
1212
<group id="business_extension" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="1">
1313
<label>Setup</label>
14+
<fieldset_css>meta-section-config</fieldset_css>
1415
<attribute type="expanded">1</attribute>
1516
<field id="active" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="1">
1617
<label>Activate Integration</label>
@@ -32,6 +33,7 @@
3233
</group>
3334
<group id="debug" translate="label" type="text" sortOrder="70" showInDefault="1" showInWebsite="0" showInStore="1">
3435
<label>Debug</label>
36+
<fieldset_css>meta-section-config</fieldset_css>
3537
<depends>
3638
<field id="facebook_business_extension/business_extension/active">1</field>
3739
</depends>

app/code/Meta/BusinessExtension/etc/module.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<module name="Magento_Backend"/>
77
<module name="Magento_Catalog"/>
88
<module name="Magento_Config"/>
9+
<module name="Magento_Eav"/>
910
<module name="Magento_Security"/>
1011
<module name="Magento_Store"/>
1112
<module name="Magento_Newsletter"/>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
div.meta-section-config {
2+
border-bottom: 0;
3+
4+
&:last-child {
5+
> .entry-edit-head {
6+
> a {
7+
border-bottom: 0;
8+
}
9+
}
10+
}
11+
12+
&.active {
13+
> fieldset.config {
14+
border-bottom: 1px solid @collapsible__border-color;
15+
}
16+
17+
> .entry-edit-head {
18+
> a {
19+
border-bottom: 0;
20+
}
21+
}
22+
}
23+
24+
> .entry-edit-head {
25+
> a {
26+
border-bottom: 1px solid @collapsible__border-color;
27+
}
28+
}
29+
}

app/code/Meta/Catalog/Block/Adminhtml/System/Config/ProductFeed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function getButtonHtml()
7979
{
8080
/** @var Button $button */
8181
$button = $this->getLayout()->createBlock(Button::class);
82-
return $button->setData(['id' => 'fb_feed_upload_btn', 'label' => __('Upload to Facebook')])
82+
return $button->setData(['id' => 'fb_feed_upload_btn', 'label' => __('Upload to Meta')])
8383
->toHtml();
8484
}
8585
}

0 commit comments

Comments
 (0)