Skip to content

Commit 98958df

Browse files
bgiamarinonabhanmaswood98vbandapalletoddbcsdaugherty-rp
authored
Fix/static tests (#160)
* Remove dependencies for other Meta modules in Meta_BusinessExtension This fixes Static Tests for Magento\Test\Integrity\DependencyTest.testUndeclared for the ones related to the other meta modules * Add undeclared Magento dependencies for Meta modules * Fix docblocks and max line length for Static Tests This fixes those issues for the Magento\Test\Php\LiveCodeTest.testCodeStyle test * Replace discouraged functions in GraphAPIAdapter.php from Static Tests Replaces the curl functions with magneto's curl class and replaced 'print_r' with 'json_encode' * Remove dependencies not being used * Log exception with logger instead of helper class. Remove dependency * Remove unused rule params from list * Move product retrievers to di.xml. Remove unused dependencies * Move gender and dob loops to private functions * Update di.xml to use array param. Refactor dependecies * Move matching fields normalization to private function. Add doc blocks * Correct some unused local variables. * Mark some required unused arguments. * Move carrier list to di.xml. This allows it to be updated from other modules which is convenient, and also cleans up the mess detector warning. * Refactor buildPromoEntry(). * Correct return type doc for getOrderShipEvent(). * Update getStockStatus() func name. * Cleanup trimAttribute() method. * Refactor generateProductRequestData(). * Correct argument order in InitiateCheckout. * Fix output syntax. * Cleanup some simple line length issues. * Cleanup ServerEventFactory. * Switch ServerEventFactory from static methods. * Use DI for custom data field mapping. * Add PHPMD suppress warnings for setUserData function and test function Unable to refactor because UserData object from Facebook SDK does not have generic getter/setter functions * Update abstractAjax class to implement post action * Remove PHPMD suppress notes for admin controller classes * Update class to implement deleteActionInterface * Update class to implement GetActionInterface * Updating 'protected to 'private' for classes without inheritance Changes made from PR review * Removing unused InventoryStock class and refactoring CategoryCollection * Dummy commit * Fix static tests issues with whitespace and missing docblocks Also fixes the code copy test that was new issue from the last commit * Add suppress notes for unused $element param Reviewing the core code, the $element param is required by the parent class * Fix missing docblocks, spaces and escaping output for Static Tests * remove unused formal parameter * Remove unused variables * fix excessive method length createOrder. break into smaller utility methods and methods that build out product data * Move large source data array to di.xml * phpmd notice fixes - remove direct object manager usage - remove unused dependencies - fix max line length warnings - fix type not specified warnings - fix doc block description warnings * change member properties to private. remove unused dependency. update order of use statements with phpcs * add copyright * supress warnings * fixed minor phpcs issues in Catalog module * fixed general phpcs issues in Conversion module * fixed general phpcs issues in Promotion module * Update variable doc block type * Remove unused variables and params * Clean Magento cache after installing/uninstalling FBE (#107) * Clean Magento cache after installing/uninstalling FBE * updated test * remove queries to old config table * added dedicated controller to clean config cache after setting and deleting FBE connection * remove unnecessary use * updated controllers * cleanup * cleanup * added __() * update inventory upload interval and graph api version (#126) * update inventory upload interval and graph api version * update inventory upload interval and graph api version * update inventory upload interval and graph api version * add i18n * Feature flag on commerce modules (#123) * implement feature flag * implement feature flag * implement feature flag * implement feature flag * implement feature flag * implement feature flag * implement feature flag * implement feature flag * update according to comment * update to comment * update to comment * fixed issue with the variants name in meta catalog * updated comment * fixed static test issues * added changes to fetch the products final price * Refactor magentoDataHelper to avoid high coupling -Move functions with one only usage to other class -Remove functions with no usages -Remove AbstractHelper inheritance * start to fix coupling between objects warning for commerce helper * fixed general phpcs issues in Sales module * more md fixes and steps towards fixing coupling for commerce helper * remove unused classes * decouple order item mapping out of commerce helper * remove more excessive fields from commerce helper * remove interface alias * fix too many fields warning in commerce helper. refactored create order logic into separate class * Refactor FBEHelper by moving subscribeToNewsletter function * Refactor FBEHelper. Move generateCategoryNameMap function * Refactor FBEHelper. Move deleteConfigKeys function * Refactor FBEHelper. Move getBaseUrlMedia and getStoreName to Builder.php Remove some unnecessary dependencies in Builder.php * Remove unused function in FBEHelper * Refactor FBEHelper dependencies -Remove inheritance from AbstractHelper -Pull in single use constant * fix ExcessiveParameterList warning for create order class * fix CouplingBetweenObjects wardning for commerce helper / create order class * Update action class to implement HTTPPostActionInterface * Update class to implement HTTPGetActionInterface * Correct location of suppress tag for $element param * fixed typos * fixed general phpcs issues * fixed additional phpcs issues * Remediate failed Unit Tests * Remediate Integrity tests 1 & 2 * Integrity Test 3 - remove duplicate preference * Remediate static tests * Remediate static tests * Address syntax errors from refactor * Static tests * Move customerSession object usage to Head class to fix code mess warning Sessions can be used in Head.php because it extends \Magento\Framework\View\Element\Template * Update unit test classes after updates to Head and AAMFieldsExtractorHelper classes/functions * Remove checkoutSession usage from MagentoDataHelper and refactor functions to fix mess detector error Include quote in dispatched event data instead * Update class to get quote data from event and pass to functions * Update class to inject checkout and quote data to pass to functions This class can use checkoutSession because it extends \Magento\Framework\View\Element\Template * Remove session usage from Purchase class and update event data to include last order * Update constructor calls to Common.php class * Move retrieval of refund items to seperate function to fix code mess error * Update app/code/Meta/Promotions/Controller/Adminhtml/Ajax/PromotionFeedUpload.php Co-authored-by: Oleksandr Miroshnichenko <[email protected]> * make some promotion feed builder class members private * make sync orders helper method private. not used anywhere else * remove duplicate constant * remove unused dependencies in Meta_BusinessExtension * Pull in constant to fix code mess issue with high coupling * Move some functions to Tools class to fix high coupling error in Builder * Move FBEHelper single use functions to fix high coupling error * observer has extra public method * fix incorrect constructor argument sequence * There must be exactly one blank line before tags * fix static warnings * add missing docblocks * add missing docblock * Remove objectManager from Head constructor -Fixes code mess with excessive number of params in Head constructor -remove objectManager in parent - Common.php -Remove objectManager in classes that extend Common * fix line length warning * line length warning and types * add missing param/types * add types and missing param declaration on method * add missing param arguments in docblock + types * Fix PHPStan errors with Exception class not found * Fix PHPstan errors for syntax issues * Ensure getValue() function returns a value or null * strict type declarations and change access of const in source model being used publically * fix new line after closing brace of else statement * remove space in phpcs:ignore comment to see if that suppresses warning about intentional addslashes usage * missing params for arguments and types * class member visibility, use statement ordering, types in method docblocks and params * fix direct use of super global * fix phpcs ignore statement * Fix PHPStan undefined property errors * Fix PHPStan errors with constructor and undefined property * Fix PHPStan issue with constructor call args * Fix return type error * Fix undefined property errors and refactor class * Remove Redundant Dependencies * Address exception thrown on System Config Edit Page for accessing uninitailized variable * fix HeadTest unit tests * unit test updates * Update AddToCartTest file with changes from main * fix server event factory unit tests * Correct Fbdeleteasset controller request handling. Fixes a merge conflict and makes the unit test pass again. * Correct Fbdeleteasset static test failures. * Correct test failure, oops. * Correct some minor formatting errors. * fix testInitiateCheckoutEventCreated unit test * fix testPurchaseEventCreated unit test * fix testEventWithRequestedUserDataWhenAamEnabled unit test * move static method to const array * fix mulitple empty lines in a row warning * fix fbehelpertest * Address static Tests * Address Healthcheck failures --------- Co-authored-by: nabhanmaswood98 <[email protected]> Co-authored-by: Vivek Bandapalle <[email protected]> Co-authored-by: Todd Christensen <[email protected]> Co-authored-by: vbandapalle <[email protected]> Co-authored-by: Seth Daugherty <[email protected]> Co-authored-by: Priyambad Pandey <[email protected]> Co-authored-by: Alex Zarichnyi <[email protected]> Co-authored-by: Wayne Zhang <[email protected]> Co-authored-by: Seth Daugherty <[email protected]> Co-authored-by: Oleksandr Miroshnichenko <[email protected]>
1 parent 7b5ff25 commit 98958df

File tree

127 files changed

+5606
-3429
lines changed

Some content is hidden

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

127 files changed

+5606
-3429
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
# Meta Business Extension For Magento2
2+
# Meta Business Extension For Magento2
33

44
## Facebook Connects Businesses with People
55

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,16 @@ public function fetchPixelId($storeId)
119119
*
120120
* @param int $storeId
121121
* @return string|null
122-
* @throws \Magento\Framework\Exception\NoSuchEntityException
123122
*/
124123
public function getExternalBusinessId($storeId)
125124
{
126-
return $this->fbeHelper->getFBEExternalBusinessId($storeId);
125+
$storedExternalId = $this->systemConfig->getExternalBusinessId($storeId);
126+
if ($storedExternalId) {
127+
return $storedExternalId;
128+
}
129+
$storeId = $this->fbeHelper->getStore()->getId();
130+
$this->fbeHelper->log("Store id---" . $storeId);
131+
return uniqid('fbe_magento_' . $storeId . '_');
127132
}
128133

129134
/**
@@ -147,6 +152,8 @@ public function getCleanCacheAjaxRoute()
147152
}
148153

149154
/**
155+
* Get Delete Asset IDs Ajax Route
156+
*
150157
* @return mixed
151158
*/
152159
public function getDeleteAssetIdsAjaxRoute()

app/code/Meta/BusinessExtension/Block/Adminhtml/System/Config/ModuleInfo.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public function render(AbstractElement $element)
6767
*
6868
* @param AbstractElement $element
6969
* @return string
70+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
7071
*/
7172
protected function _getElementHtml(AbstractElement $element)
7273
{
@@ -84,6 +85,8 @@ public function getModuleVersion()
8485
}
8586

8687
/**
88+
* Retrieve Store Id
89+
*
8790
* @return mixed
8891
*/
8992
private function getStoreId()
@@ -92,6 +95,8 @@ private function getStoreId()
9295
}
9396

9497
/**
98+
* Retrieve Commerce Account Id
99+
*
95100
* @return string
96101
*/
97102
public function getCommerceAccountId()
@@ -100,6 +105,8 @@ public function getCommerceAccountId()
100105
}
101106

102107
/**
108+
* Retrieve Page Id
109+
*
103110
* @return string
104111
*/
105112
public function getPageId()
@@ -108,6 +115,8 @@ public function getPageId()
108115
}
109116

110117
/**
118+
* Retrieve Catalog Id
119+
*
111120
* @return string
112121
*/
113122
public function getCatalogId()
@@ -116,6 +125,8 @@ public function getCatalogId()
116125
}
117126

118127
/**
128+
* Retrieve Commerce Manager Url
129+
*
119130
* @return string
120131
*/
121132
public function getCommerceManagerUrl()
@@ -124,6 +135,8 @@ public function getCommerceManagerUrl()
124135
}
125136

126137
/**
138+
* Retrieve Catalog Manager Url
139+
*
127140
* @return string
128141
*/
129142
public function getCatalogManagerUrl()
@@ -132,6 +145,8 @@ public function getCatalogManagerUrl()
132145
}
133146

134147
/**
148+
* Retrieve Support Url
149+
*
135150
* @return string
136151
*/
137152
public function getSupportUrl()

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
use Magento\Backend\App\Action\Context;
2424
use Magento\Framework\Controller\Result\JsonFactory;
2525
use Magento\Security\Model\AdminSessionsManager;
26+
use Magento\Framework\Exception\LocalizedException;
27+
use Magento\Framework\App\Action\HttpPostActionInterface;
2628

27-
abstract class AbstractAjax extends Action
29+
abstract class AbstractAjax extends Action implements HttpPostActionInterface
2830
{
2931
/**
3032
* @var JsonFactory
@@ -37,6 +39,8 @@ abstract class AbstractAjax extends Action
3739
private $fbeHelper;
3840

3941
/**
42+
* Construct
43+
*
4044
* @param Context $context
4145
* @param JsonFactory $resultJsonFactory
4246
* @param FBEHelper $fbeHelper
@@ -51,9 +55,16 @@ public function __construct(
5155
$this->fbeHelper = $fbeHelper;
5256
}
5357

58+
/**
59+
* Execute for json
60+
*
61+
* @return array
62+
*/
5463
abstract public function executeForJson();
5564

5665
/**
66+
* Execute function
67+
*
5768
* @throws Exception
5869
*/
5970
public function execute()
@@ -64,16 +75,16 @@ public function execute()
6475
->createObject(AdminSessionsManager::class)
6576
->getCurrentSession();
6677
if (!$adminSession && $adminSession->getStatus() != 1) {
67-
throw new Exception('Oops, this endpoint is for logged in admin and ajax only!');
78+
throw new LocalizedException(__('Oops, this endpoint is for logged in admin and ajax only!'));
6879
} else {
6980
try {
7081
$json = $this->executeForJson();
7182
return $result->setData($json);
7283
} catch (Exception $e) {
7384
$this->fbeHelper->logCritical($e->getMessage());
74-
throw new Exception(
75-
'Oops, there was error while processing your request.' .
76-
' Please contact admin for more details.'
85+
throw new LocalizedException(
86+
__('Oops, there was error while processing your request.' .
87+
' Please contact admin for more details.')
7788
);
7889
}
7990
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public function __construct(
5353
$this->systemConfig = $systemConfig;
5454
}
5555

56+
/**
57+
* @inheritDoc
58+
*/
5659
public function executeForJson()
5760
{
5861
try {

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

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

24-
/**
25-
* @SuppressWarnings(PHPMD)
26-
*/
2724
class Fbaamsettings extends AbstractAjax
2825
{
2926
/**

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

Lines changed: 114 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,66 +17,163 @@
1717

1818
namespace Meta\BusinessExtension\Controller\Adminhtml\Ajax;
1919

20-
use Magento\Backend\App\Action\Context;
2120
use Magento\Framework\Controller\Result\JsonFactory;
21+
use Magento\Framework\Exception\LocalizedException;
2222
use Meta\BusinessExtension\Helper\FBEHelper;
23+
use Magento\Framework\App\Action\HttpDeleteActionInterface;
24+
use Magento\Framework\App\RequestInterface;
25+
use Magento\Security\Model\AdminSessionsManager;
26+
use Meta\BusinessExtension\Model\System\Config as SystemConfig;
27+
use Magento\Framework\App\ResourceConnection;
2328

24-
class Fbdeleteasset extends AbstractAjax
29+
class Fbdeleteasset implements HttpDeleteActionInterface
2530
{
26-
public const DELETE_SUCCESS_MESSAGE = "You have successfully deleted Meta Business Extension.
27-
The pixel installed on your website is now deleted.";
31+
public const DELETE_SUCCESS_MESSAGE = "You have successfully deleted Meta Business Extension." .
32+
" The pixel installed on your website is now deleted.";
2833

2934
private const DELETE_FAILURE_MESSAGE = "There was a problem deleting the connection.
30-
Please try again.";
35+
Please try again.";
36+
37+
/**
38+
* @var JsonFactory
39+
*/
40+
private $resultJsonFactory;
3141

3242
/**
3343
* @var FBEHelper
3444
*/
3545
private $fbeHelper;
3646

3747
/**
38-
* Construct
39-
*
40-
* @param Context $context
48+
* @var AdminSessionsManager
49+
*/
50+
private $adminSessionManager;
51+
52+
/**
53+
* @var ResourceConnection
54+
*/
55+
private $resourceConnection;
56+
57+
/**
58+
* @var SystemConfig
59+
*/
60+
private $systemConfig;
61+
62+
/**
63+
* @var RequestInterface
64+
*/
65+
private RequestInterface $request;
66+
67+
/**
4168
* @param JsonFactory $resultJsonFactory
4269
* @param FBEHelper $fbeHelper
70+
* @param AdminSessionsManager $adminSessionManager
71+
* @param ResourceConnection $resourceConnection
72+
* @param SystemConfig $systemConfig
73+
* @param RequestInterface $request
4374
*/
4475
public function __construct(
45-
Context $context,
4676
JsonFactory $resultJsonFactory,
47-
FBEHelper $fbeHelper
77+
FBEHelper $fbeHelper,
78+
AdminSessionsManager $adminSessionManager,
79+
ResourceConnection $resourceConnection,
80+
SystemConfig $systemConfig,
81+
RequestInterface $request
4882
) {
49-
parent::__construct($context, $resultJsonFactory, $fbeHelper);
83+
$this->resultJsonFactory = $resultJsonFactory;
5084
$this->fbeHelper = $fbeHelper;
85+
$this->adminSessionManager = $adminSessionManager;
86+
$this->resourceConnection = $resourceConnection;
87+
$this->systemConfig = $systemConfig;
88+
$this->request = $request;
89+
}
90+
91+
/**
92+
* Execute
93+
*
94+
* @throws LocalizedException
95+
*/
96+
public function execute()
97+
{
98+
$result = $this->resultJsonFactory->create();
99+
// TODO : Move all String objects to constants.
100+
$adminSession = $this->adminSessionManager->getCurrentSession();
101+
if (!$adminSession && $adminSession->getStatus() != 1) {
102+
throw new LocalizedException('Oops, this endpoint is for logged in admin and ajax only!');
103+
} else {
104+
try {
105+
$json = $this->executeForJson();
106+
return $result->setData($json);
107+
} catch (\Exception $e) {
108+
$this->fbeHelper->logCritical($e->getMessage());
109+
throw new LocalizedException(
110+
'Oops, there was error while processing your request.' .
111+
' Please contact admin for more details.'
112+
);
113+
}
114+
}
51115
}
52116

53117
/**
54118
* Execute for json
55119
*
56-
* @return array
120+
* Run actual processing after request validation.
121+
* Only public to allow for more direct unit testing.
122+
*
123+
* @inheritdoc
57124
*/
58125
public function executeForJson()
59126
{
60-
$storeId = $this->getRequest()->getParam('storeId');
127+
$storeId = $this->request->getParam('storeId');
61128
if ($storeId === null) {
62129
return [
63130
'success' => false,
64-
'error_message' => __(self::DELETE_FAILURE_MESSAGE)
131+
'error_message' => __('' . self::DELETE_FAILURE_MESSAGE)
65132
];
66133
}
67134
try {
68-
$this->fbeHelper->deleteConfigKeys($storeId);
135+
$this->deleteConfigKeys($storeId);
69136
$response = [
70137
'success' => true,
71-
'message' => __(self::DELETE_SUCCESS_MESSAGE),
138+
'message' => __('' . self::DELETE_SUCCESS_MESSAGE),
72139
];
73140
} catch (\Exception $e) {
74141
$this->fbeHelper->log($e->getMessage());
75142
$response = [
76143
'success' => false,
77-
'error_message' => __(self::DELETE_FAILURE_MESSAGE),
144+
'error_message' => __(
145+
"There was a problem deleting the connection. Please try again."
146+
),
78147
];
79148
}
80149
return $response;
81150
}
151+
152+
/**
153+
* Delete config keys
154+
*
155+
* @param string|int|null $storeId Store ID to delete from.
156+
* @return array
157+
*/
158+
private function deleteConfigKeys($storeId)
159+
{
160+
$this->systemConfig->deleteConfig(
161+
SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_EXTERNAL_BUSINESS_ID,
162+
$storeId
163+
)
164+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_INSTALLED, $storeId)
165+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_ACCESS_TOKEN, $storeId)
166+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_PAGE_ID, $storeId)
167+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_PAGE_ACCESS_TOKEN, $storeId)
168+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_COMMERCE_ACCOUNT_ID, $storeId)
169+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_PIXEL_ID, $storeId)
170+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_PIXEL_AAM_SETTINGS, $storeId)
171+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_PROFILES, $storeId)
172+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_CATALOG_ID, $storeId)
173+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_FEED_ID, $storeId)
174+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_API_VERSION, $storeId)
175+
->deleteConfig(SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_API_VERSION_LAST_UPDATE, $storeId);
176+
177+
return $this;
178+
}
82179
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
use Magento\Store\Model\ScopeInterface;
2424
use Meta\BusinessExtension\Model\System\Config as SystemConfig;
2525

26-
/**
27-
* @SuppressWarnings(PHPMD)
28-
*/
2926
class Fbpixel extends AbstractAjax
3027
{
3128
/**

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
use Meta\BusinessExtension\Model\System\Config as SystemConfig;
2424
use Magento\Store\Model\ScopeInterface;
2525

26-
/**
27-
* @SuppressWarnings(PHPMD)
28-
*/
2926
class Fbprofiles extends AbstractAjax
3027
{
3128
/**

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
use Meta\BusinessExtension\Model\System\Config as SystemConfig;
2424
use Magento\Store\Model\ScopeInterface;
2525

26-
/**
27-
* @SuppressWarnings(PHPMD)
28-
*/
2926
class Fbtoken extends AbstractAjax
3027
{
3128
/**

0 commit comments

Comments
 (0)