Skip to content

Commit

Permalink
Feature/512/sync order files on order callback trigger (#476)
Browse files Browse the repository at this point in the history
* added: file sync logic within order callback action

* added: activity logs for callbacks

* fixed: issue saving file when callback recieved
  • Loading branch information
bhupeshappfoster authored Sep 28, 2023
1 parent af650e1 commit 37f09b7
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public function actionOrderCallback()
Craft::$app->end('Invalid orderId');
} else {
echo 'Order found'.PHP_EOL;
$order->logActivity('Order callback received.');
Craft::$app->getElements()->saveElement($order);
}

// don't process published orders
Expand Down Expand Up @@ -110,7 +112,15 @@ public function actionOrderCallback()
if (!$success) {
Craft::$app->end('Couldn’t save the order');
} else {
echo 'Saving order'.PHP_EOL;
echo 'Order changes saved'.PHP_EOL;
echo 'Starting file sync' . PHP_EOL;

foreach($order->getFiles() as $file) {
$translationService->updateFile($order, $file);
Translations::$plugin->fileRepository->saveFile($file);
}

echo 'File sync successful' . PHP_EOL;
}

Craft::$app->end('OK');
Expand Down Expand Up @@ -156,6 +166,8 @@ public function actionFileCallback()
Craft::$app->end('Couldn’t find the order');
} else {
echo 'Found order'.PHP_EOL;
$order->logActivity('File callback received.');
Craft::$app->getElements()->saveElement($order);
}

$translationService = $order->getTranslationService();
Expand Down

0 comments on commit 37f09b7

Please sign in to comment.