Skip to content

Commit 5e50889

Browse files
authored
Quick release fixes (#410)
* quick fixes * quick fixes * quick fixes * quick fixes * quick fixes * quick fixes * fix app -> var * fixes * fixes
1 parent b4cc457 commit 5e50889

File tree

14 files changed

+162
-105
lines changed

14 files changed

+162
-105
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ class PostFBEOnboardingSync extends AbstractAjax
5353
private $shippingSyncer;
5454

5555
/**
56-
5756
* Construct
5857
*
5958
* @param Context $context
6059
* @param JsonFactory $resultJsonFactory
6160
* @param FBEHelper $fbeHelper
6261
* @param SystemConfig $systemConfig
6362
* @param CatalogSyncHelper $catalogSyncHelper
63+
* @param ShippingSyncer $shippingSyncer
6464
*/
6565
public function __construct(
6666
Context $context,

app/code/Meta/Catalog/Model/Feed/CategoryCollection.php

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
class CategoryCollection
3636
{
37-
3837
/**
3938
* @var ProductCollectionFactory
4039
*/
@@ -90,8 +89,7 @@ public function __construct(
9089
SystemConfig $systemConfig,
9190
ProductIdentifier $productIdentifier,
9291
CategoryImageService $imageService
93-
)
94-
{
92+
) {
9593
$this->categoryCollection = $categoryCollection;
9694
$this->categoryRepository = $categoryRepository;
9795
$this->productCollectionFactory = $productCollectionFactory;
@@ -125,7 +123,7 @@ public function makeHttpRequestsAfterCategorySave(Category $category, bool $isNa
125123
if ($isNameChanged) {
126124
$categories = $this->getAllActiveChildrenCategories($category, $storeId);
127125
} else {
128-
$categories[] = $this->categoryRepository->get($category->getId(), $storeId);;
126+
$categories[] = $this->categoryRepository->get($category->getId(), $storeId);
129127
}
130128

131129
if (!$this->systemConfig->isCatalogSyncEnabled($storeId)) {
@@ -145,14 +143,14 @@ public function makeHttpRequestsAfterCategorySave(Category $category, bool $isNa
145143

146144
$this->pushCategoriesToFBCollections($categories, $accessToken, $storeId);
147145
} catch (\Throwable $e) {
148-
$extra_data = [
146+
$extraData = [
149147
'category_id' => $category->getId(),
150148
'category_name' => $category->getName(),
151149
'num_of_stores_for_category' => count($storeIds)
152150
];
153151
$this->fbeHelper->logExceptionImmediatelyToMeta(
154152
$e,
155-
$this->getCategoryLoggerContext($storeId, 'category_sync_real_time', $extra_data)
153+
$this->getCategoryLoggerContext($storeId, 'category_sync_real_time', $extraData)
156154
);
157155
}
158156
}
@@ -164,7 +162,7 @@ public function makeHttpRequestsAfterCategorySave(Category $category, bool $isNa
164162
* If the category is Tops we might create "Default Category > Men > Tops"
165163
*
166164
* @param Category $category
167-
* @param $storeId
165+
* @param int $storeId
168166
* @return string
169167
*/
170168
private function getCategoryPathName(Category $category, $storeId)
@@ -218,6 +216,7 @@ private function getCategoryMetaData(Category $category): ?array
218216

219217
/**
220218
* Get category landing page URL.
219+
*
221220
* It first tries request path and URL finder for category, if fails to fetch it return category canonical URL
222221
*
223222
* @param Category $category
@@ -230,9 +229,9 @@ private function getDirectCategoryURL(Category $category): string
230229
$url = $category->getUrl();
231230

232231
// if url returned by getURL is category admin page url, replace it with category canonical URL
233-
if (str_contains($url, 'admin/catalog/category/view/s')) {
232+
if (strpos($url, 'admin/catalog/category/view/s') !== false) {
234233
// if nothing works return URL by category ID (canonical URL)
235-
$urlKey = $category->getUrlKey() ? $category->getUrlKey() : $category->formatUrlKey($category->getName());
234+
$urlKey = $category->getUrlKey() ?? $category->formatUrlKey($category->getName());
236235

237236
$url = $category->getUrlInstance()->getDirectUrl(
238237
sprintf('catalog/category/view/s/%s/id/%s/', $urlKey, $category->getId())
@@ -263,7 +262,7 @@ private function getDirectCategoryURL(Category $category): string
263262
*
264263
* @param Category $category
265264
* @param string $setId
266-
* @param $storeId
265+
* @param int $storeId
267266
* @throws \Throwable
268267
*/
269268
private function saveFBProductSetID(Category $category, string $setId, $storeId): void
@@ -281,8 +280,10 @@ private function saveFBProductSetID(Category $category, string $setId, $storeId)
281280
}
282281

283282
/**
283+
* Save category for store
284+
*
284285
* @param Category $category
285-
* @param $storeId
286+
* @param int $storeId
286287
*/
287288
private function saveCategoryForStore(Category $category, $storeId): void
288289
{
@@ -308,7 +309,7 @@ private function saveCategoryForStore(Category $category, $storeId): void
308309
* Get all children node in category tree recursion is being used.
309310
*
310311
* @param Category $category
311-
* @param $storeId
312+
* @param int $storeId
312313
* @param bool $onlyActiveCategories
313314
* @return Collection
314315
* @throws \Throwable
@@ -326,16 +327,16 @@ private function getAllChildrenCategories(
326327
->setStoreId($storeId)
327328
->addAttributeToSelect('*')
328329
->addAttributeToFilter(
329-
array(
330-
array(
330+
[
331+
[
331332
"attribute" => "path",
332333
"like" => $categoryPath . "/%"
333-
),
334-
array(
334+
],
335+
[
335336
"attribute" => "path",
336337
"like" => $categoryPath
337-
)
338-
)
338+
]
339+
]
339340
);
340341

341342
if ($onlyActiveCategories) {
@@ -348,7 +349,7 @@ private function getAllChildrenCategories(
348349
* Get all children categories
349350
*
350351
* @param Category $category
351-
* @param $storeId
352+
* @param int $storeId
352353
* @return Collection
353354
* @throws \Throwable
354355
*/
@@ -361,10 +362,9 @@ private function getAllActiveChildrenCategories(Category $category, $storeId): C
361362
/**
362363
* Get all active categories
363364
*
364-
* @param $storeId
365+
* @param int $storeId
365366
* @return Collection
366367
* @throws \Throwable
367-
* @throws \Throwable
368368
*/
369369
private function getAllActiveCategories($storeId): Collection
370370
{
@@ -381,15 +381,14 @@ private function getAllActiveCategories($storeId): Collection
381381
* Initial collection call after fbe installation, please not we only push leaf category to collection,
382382
* this means if a category contains any category, we won't create a collection for it.
383383
*
384-
* @param $storeId
384+
* @param int $storeId
385385
* @return string|null
386386
* @throws \Throwable
387387
*/
388388
public function pushAllCategoriesToFbCollections($storeId): ?string
389389
{
390-
391390
$accessToken = $this->systemConfig->getAccessToken($storeId);
392-
if ($accessToken == null) {
391+
if (!$accessToken) {
393392
$this->fbeHelper->log(
394393
"Category force update: can't find access token, abort pushAllCategoriesToFbCollections"
395394
);
@@ -407,9 +406,9 @@ public function pushAllCategoriesToFbCollections($storeId): ?string
407406
/**
408407
* Push categories to FB collections
409408
*
410-
* @param $categories
411-
* @param $accessToken
412-
* @param $storeId
409+
* @param Collection $categories
410+
* @param string $accessToken
411+
* @param int $storeId
413412
* @return string|null
414413
*/
415414
private function pushCategoriesToFBCollections($categories, $accessToken, $storeId): ?string
@@ -422,7 +421,7 @@ private function pushCategoriesToFBCollections($categories, $accessToken, $store
422421
foreach ($categories as $category) {
423422
try {
424423
$syncEnabled = $category->getData(MetaCatalogAttributes::CATEGORY_SYNC_TO_FACEBOOK);
425-
if ($syncEnabled === "0") {
424+
if ($syncEnabled === '0') {
426425
$this->fbeHelper->log(
427426
sprintf(
428427
"Category update: user disabled category sync, category name: %s for store id: %s",
@@ -478,14 +477,14 @@ private function pushCategoriesToFBCollections($categories, $accessToken, $store
478477
"please check the error log for more details",
479478
$category->getName()
480479
);
481-
$extra_data = [
480+
$extraData = [
482481
'category_id' => $category->getId(),
483482
'category_name' => $category->getName(),
484483
'num_categories_for_update' => count($categories)
485484
];
486485
$this->fbeHelper->logExceptionImmediatelyToMeta(
487486
$e,
488-
$this->getCategoryLoggerContext($storeId, 'categories_push_to_meta', $extra_data)
487+
$this->getCategoryLoggerContext($storeId, 'categories_push_to_meta', $extraData)
489488
);
490489
}
491490
}
@@ -495,15 +494,15 @@ private function pushCategoriesToFBCollections($categories, $accessToken, $store
495494
$this->flushCategoryBatchRequest($requests, $updatedCategories,
496495
$currentBatch, $accessToken, $storeId));
497496
} catch (\Throwable $e) {
498-
$extra_data = [
497+
$extraData = [
499498
'num_categories_for_update' => count($categories)
500499
];
501500
$this->fbeHelper->logExceptionImmediatelyToMeta(
502501
$e,
503502
$this->getCategoryLoggerContext(
504503
$storeId,
505504
'categories_push_to_meta_last_page',
506-
$extra_data
505+
$extraData
507506
)
508507
);
509508
}
@@ -541,7 +540,7 @@ private function getCategoryProductFilter(ProductCollection $productCollection):
541540
* e.g. {'retailer_id': {'is_any': ['10', '100']}}
542541
*
543542
* @param Category $category
544-
* @param $storeId
543+
* @param int $storeId
545544
* @return ProductCollection
546545
*/
547546
private function getCategoryProducts(Category $category, $storeId): ProductCollection
@@ -563,8 +562,9 @@ private function getCategoryProducts(Category $category, $storeId): ProductColle
563562
* Api link: https://developers.facebook.com/docs/marketing-api/reference/product-set/
564563
*
565564
* @param Category $category
565+
* @param ProductCollection $products
566566
* @param string $setId
567-
* @param $storeId
567+
* @param int $storeId
568568
* @return array
569569
*/
570570
private function updateCategoryWithFBRequestJson(
@@ -593,8 +593,9 @@ private function updateCategoryWithFBRequestJson(
593593
* Api link: https://developers.facebook.com/docs/marketing-api/reference/product-set/
594594
*
595595
* @param Category $category
596+
* @param ProductCollection $products
596597
* @param string $catalogId
597-
* @param $storeId
598+
* @param int $storeId
598599
* @return array
599600
*/
600601
private function pushCategoryWithFBRequestJson(
@@ -674,7 +675,6 @@ private function processCategoryBatchResponse(
674675
$setId = $responseData['id'];
675676
$this->saveFBProductSetID($category, $setId, $storeId);
676677
}
677-
678678
} else {
679679
$this->fbeHelper->log(sprintf(
680680
"Error occurred while syncing category %s, response body %s",
@@ -699,7 +699,7 @@ private function processCategoryBatchResponse(
699699
/**
700700
* Returns request JSON for product set delete batch API
701701
*
702-
* Api link: https://developers.facebook.com/docs/marketing-api/reference/product-set/
702+
* API link: https://developers.facebook.com/docs/marketing-api/reference/product-set/
703703
*
704704
* @param string $setId
705705
* @return array
@@ -712,9 +712,8 @@ private function deleteCategoryWithFBRequestJson(string $setId): array
712712
);
713713
}
714714

715-
716715
/**
717-
* Call the api delete existing product set under category
716+
* Call the API delete existing product set under category
718717
*
719718
* When user deletes a category on magento, we first get all sub categories(including itself), and check if we
720719
* have created a collection set on fb side, if yes then we make delete api call.
@@ -766,14 +765,14 @@ public function deleteCategoryAndSubCategoryFromFB(Category $category): void
766765
$currentBatch++;
767766
}
768767
} catch (\Throwable $e) {
769-
$extra_data = [
768+
$extraData = [
770769
'category_id' => $category->getId(),
771770
'category_name' => $category->getName(),
772771
'num_categories_for_delete' => count($childrenCategories)
773772
];
774773
$this->fbeHelper->logExceptionImmediatelyToMeta(
775774
$e,
776-
$this->getCategoryLoggerContext($storeId, 'delete_categories', $extra_data)
775+
$this->getCategoryLoggerContext($storeId, 'delete_categories', $extraData)
777776
);
778777
}
779778
}
@@ -782,14 +781,14 @@ public function deleteCategoryAndSubCategoryFromFB(Category $category): void
782781
try {
783782
$this->flushCategoryDeleteBatchRequest($requests, $currentBatch, $accessToken, $storeId);
784783
} catch (\Throwable $e) {
785-
$extra_data = [
784+
$extraData = [
786785
'category_id' => $category->getId(),
787786
'category_name' => $category->getName(),
788787
'num_categories_for_delete' => count($childrenCategories)
789788
];
790789
$this->fbeHelper->logExceptionImmediatelyToMeta(
791790
$e,
792-
$this->getCategoryLoggerContext($storeId, 'delete_categories_last_page', $extra_data)
791+
$this->getCategoryLoggerContext($storeId, 'delete_categories_last_page', $extraData)
793792
);
794793
}
795794
}
@@ -801,8 +800,8 @@ public function deleteCategoryAndSubCategoryFromFB(Category $category): void
801800
*
802801
* @param array $requests
803802
* @param int $currentBatch
804-
* @param $accessToken
805-
* @param $storeId
803+
* @param string $accessToken
804+
* @param int $storeId
806805
* @return void
807806
* @throws \Throwable
808807
*/
@@ -843,19 +842,19 @@ private function flushCategoryDeleteBatchRequest(
843842
/**
844843
* Return Category logger context for be logged
845844
*
846-
* @param $storeId
847-
* @param $eventType
848-
* @param $extra_data
845+
* @param int $storeId
846+
* @param string $eventType
847+
* @param array $extraData
849848
* @return array
850849
*/
851-
private function getCategoryLoggerContext($storeId, $eventType, $extra_data): array
850+
private function getCategoryLoggerContext($storeId, $eventType, $extraData): array
852851
{
853852
return [
854853
'store_id' => $storeId,
855854
'event' => 'category_sync',
856855
'event_type' => $eventType,
857856
'catalog_id' => $this->systemConfig->getCatalogId($storeId),
858-
'extra_data' => $extra_data
857+
'extra_data' => $extraData
859858
];
860859
}
861860
}

app/code/Meta/Catalog/Model/Product/Feed/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ private function getStatus(Product $product)
607607
private function getAgeGroup(Product $product)
608608
{
609609
$ageGroup = '';
610-
if(isset($this->attrMap[self::ATTR_AGE_GROUP])) {
610+
if (isset($this->attrMap[self::ATTR_AGE_GROUP])) {
611611
$ageGroup = $product->getData($this->attrMap[self::ATTR_AGE_GROUP]);
612612
}
613613
if (empty($ageGroup)) {

app/code/Meta/Catalog/Model/Product/Feed/Builder/AdditionalAttributes.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,8 @@ public function getCustomAttributeText(Product $product, string $attributeCode):
128128
* @param string $attribute
129129
* @return mixed
130130
*/
131-
public function getCorrectText(Product $product, string $attribute): mixed
131+
public function getCorrectText(Product $product, string $attribute)
132132
{
133-
134133
if ($product->getData($attribute)) {
135134
$text = $product->getAttributeText($attribute);
136135
if (!$text) {

app/code/Meta/Catalog/etc/crontab.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<job name="facebook_automation_catalog_update_cleanup" instance="Meta\Catalog\Cron\CatalogUpdateCleanup" method="execute">
1717
<schedule>0 0 * * 0</schedule>
1818
</job>
19-
<job name="facebook_business_extension_category_sync_cronjob" instance="Meta\Catalog\Cron\CategorySyncCron" method="execute">
19+
<job name="facebook_automation_category_sync" instance="Meta\Catalog\Cron\CategorySyncCron" method="execute">
2020
<schedule>0 0 * * *</schedule>
2121
</job>
2222
</group>

0 commit comments

Comments
 (0)