Skip to content

Commit 6f38a3b

Browse files
authored
Address product API errors (#271)
* Address product API errors * Fixed unit tests
1 parent 04ea853 commit 6f38a3b

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

app/code/Meta/Catalog/Block/Adminhtml/Product/Form/Diagnostics.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,16 @@ public function setProduct(ProductInterface $product)
111111
* @return array
112112
* @throws GuzzleException
113113
*/
114-
private function getFacebookProductDiagnostics()
114+
private function getFacebookProductDiagnostics(): array
115115
{
116+
// @todo #269 Missing catalog ID for product diagnostics
117+
$catalogId = $this->systemConfig->getCatalogId($this->storeId);
118+
if (!$catalogId) {
119+
return [];
120+
}
121+
116122
try {
117123
$retailerId = $this->productIdentifier->getMagentoProductRetailerId($this->product);
118-
$catalogId = $this->systemConfig->getCatalogId($this->storeId);
119124
$product = $this->graphApiAdapter->getProductByRetailerId($catalogId, $retailerId);
120125
$fbProductId = $product['data'][0]['id'] ?? false;
121126
if ($fbProductId) {

app/code/Meta/Catalog/Observer/Product/DeleteAfter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ private function deleteProduct($storeId, $product): void
110110
{
111111
$isActive = $this->systemConfig->isActiveExtension($storeId);
112112
$shouldIncrement = $this->systemConfig->isActiveIncrementalProductUpdates($storeId);
113+
$catalogId = $this->systemConfig->getCatalogId($storeId);
113114

114-
if (!($isActive && $shouldIncrement)) {
115+
if (!($isActive && $shouldIncrement && $catalogId)) {
115116
return;
116117
}
117118

@@ -123,7 +124,6 @@ private function deleteProduct($storeId, $product): void
123124
];
124125
$this->graphApiAdapter->setDebugMode($this->systemConfig->isDebugMode($storeId))
125126
->setAccessToken($this->systemConfig->getAccessToken($storeId));
126-
$catalogId = $this->systemConfig->getCatalogId($storeId);
127127
$this->graphApiAdapter->catalogBatchRequest($catalogId, [$requestData]);
128128
} catch (GuzzleException $e) {
129129
$this->messageManager->addErrorMessage(

app/code/Meta/Catalog/Observer/Product/SaveAfter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ private function updateProduct($storeId, $productId): void
121121
{
122122
$isActive = $this->systemConfig->isActiveExtension($storeId);
123123
$shouldIncrement = $this->systemConfig->isActiveIncrementalProductUpdates($storeId);
124+
$catalogId = $this->systemConfig->getCatalogId($storeId);
124125

125-
if (!($isActive && $shouldIncrement)) {
126+
if (!($isActive && $shouldIncrement && $catalogId)) {
126127
return;
127128
}
128129

@@ -137,7 +138,6 @@ private function updateProduct($storeId, $productId): void
137138
// @todo implement async call
138139
$this->graphApiAdapter->setDebugMode($this->systemConfig->isDebugMode($storeId))
139140
->setAccessToken($this->systemConfig->getAccessToken($storeId));
140-
$catalogId = $this->systemConfig->getCatalogId($storeId);
141141
$requestData = $this->batchApi->buildRequestForIndividualProduct($product);
142142
$this->graphApiAdapter->catalogBatchRequest($catalogId, [$requestData]);
143143
} catch (NoSuchEntityException $e) {

app/code/Meta/Catalog/Test/Unit/Observer/ProcessProductAfterDeleteEventObserverTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public function testExecution()
112112
{
113113
$this->systemConfig->method('isActiveExtension')->willReturn(true);
114114
$this->systemConfig->method('isActiveIncrementalProductUpdates')->willReturn(true);
115+
$this->systemConfig->method('getCatalogId')->willReturn("12345");
116+
$this->_graphApi->method('setDebugMode')->willReturn($this->_graphApi);
115117
$this->_graphApi->expects($this->atLeastOnce())->method('catalogBatchRequest');
116118
$this->systemConfig->method('isActiveExtension')->willReturn(true);
117119
$this->processProductAfterDeleteEventObserver->execute($this->_eventObserverMock);

app/code/Meta/Catalog/Test/Unit/Observer/ProcessProductAfterSaveEventObserverTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ public function testExecute(): void
121121

122122
$productMock->method('getSendToFacebook')->willReturn(1);
123123

124+
$this->graphApiAdapterMock->method('setDebugMode')->willReturn($this->graphApiAdapterMock);
125+
124126
$this->systemConfigMock->method('getCatalogId')->willReturn("12345");
125127

126128
$this->batchApiMock->expects($this->once())

0 commit comments

Comments
 (0)