|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 7 | + * |
| 8 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | + * you may not use this file except in compliance with the License. |
| 10 | + * You may obtain a copy of the License at |
| 11 | + * |
| 12 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | + * |
| 14 | + * Unless required by applicable law or agreed to in writing, software |
| 15 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | + * See the License for the specific language governing permissions and |
| 18 | + * limitations under the License. |
| 19 | + */ |
| 20 | + |
| 21 | +namespace Meta\Catalog\Cron; |
| 22 | + |
| 23 | +use Meta\BusinessExtension\Helper\FBEHelper; |
| 24 | +use Meta\BusinessExtension\Model\System\Config as SystemConfig; |
| 25 | +use Meta\Catalog\Model\Product\Feed\Method\RatingsAndReviewsFeedApi; |
| 26 | + |
| 27 | +class RatingsAndReviewsFeedUploadCron |
| 28 | +{ |
| 29 | + /** |
| 30 | + * @var RatingsAndReviewsFeedApi |
| 31 | + */ |
| 32 | + private RatingsAndReviewsFeedApi $ratingsAndReviewsFeedApi; |
| 33 | + |
| 34 | + /** |
| 35 | + * @var SystemConfig |
| 36 | + */ |
| 37 | + private SystemConfig $systemConfig; |
| 38 | + |
| 39 | + /** |
| 40 | + * @var FBEHelper |
| 41 | + */ |
| 42 | + private FBEHelper $fbeHelper; |
| 43 | + |
| 44 | + /** |
| 45 | + * RatingsAndReviewsFeedUploadCron constructor |
| 46 | + * |
| 47 | + * @param RatingsAndReviewsFeedApi $ratingsAndReviewsFeedApi |
| 48 | + * @param SystemConfig $systemConfig |
| 49 | + * @param FBEHelper $fbeHelper |
| 50 | + */ |
| 51 | + public function __construct( |
| 52 | + RatingsAndReviewsFeedApi $ratingsAndReviewsFeedApi, |
| 53 | + SystemConfig $systemConfig, |
| 54 | + FBEHelper $fbeHelper |
| 55 | + ) { |
| 56 | + $this->ratingsAndReviewsFeedApi = $ratingsAndReviewsFeedApi; |
| 57 | + $this->systemConfig = $systemConfig; |
| 58 | + $this->fbeHelper = $fbeHelper; |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Sync ratings and reviews from Magento platform to Meta through feed upload API |
| 63 | + * |
| 64 | + * @return void |
| 65 | + */ |
| 66 | + public function execute() |
| 67 | + { |
| 68 | + foreach ($this->systemConfig->getAllFBEInstalledStores() as $store) { |
| 69 | + $storeId = (int)$store->getId(); |
| 70 | + try { |
| 71 | + if ($this->systemConfig->isCatalogSyncEnabled($storeId)) { |
| 72 | + $this->ratingsAndReviewsFeedApi->execute($storeId); |
| 73 | + } |
| 74 | + } catch (\Throwable $e) { |
| 75 | + $this->fbeHelper->logExceptionImmediatelyToMeta( |
| 76 | + $e, |
| 77 | + [ |
| 78 | + 'store_id' => $storeId, |
| 79 | + 'event' => 'ratings_and_reviews_sync', |
| 80 | + 'event_type' => 'cron_job', |
| 81 | + 'catalog_id' => $this->systemConfig->getCatalogId($storeId), |
| 82 | + ] |
| 83 | + ); |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | +} |
0 commit comments