Skip to content

Commit

Permalink
Merge pull request #19 from AfterShip/webhook
Browse files Browse the repository at this point in the history
Trigger product webhook when getting order updates
  • Loading branch information
yangyao authored Oct 8, 2023
2 parents d19e6bf + 2319576 commit 138716e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class Constants

public const WEBHOOK_RESOURCE_ORDERS = 'orders';
public const WEBHOOK_RESOURCE_PRODUCTS = 'products';
public const AFTERSHIP_TIKTOK_SHOP_VERSION = '1.0.13';

public const AFTERSHIP_TIKTOK_SHOP_VERSION = '1.0.14';

public const WEBHOOK_CONFIG_SCOPE_PATH = 'aftership/webhooks/webhooks';

Expand Down
22 changes: 22 additions & 0 deletions Observer/SalesOrderUpdateObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,28 @@ public function execute(Observer $observer)
->setResource(Constants::WEBHOOK_RESOURCE_ORDERS)
->setEvent($webhookEvent);
$this->publisher->execute($event);
// Send product update event for each order item.
$orderItems = $order->getAllItems();
foreach ($orderItems as $orderItem) {
try {
$productId = $orderItem->getProductId();
if (!$productId) {
continue;
}
$event = new WebhookEvent();
$event->setId($productId)
->setResource(Constants::WEBHOOK_RESOURCE_PRODUCTS)
->setEvent(Constants::WEBHOOK_EVENT_UPDATE);
$this->publisher->execute($event);
} catch (\Exception $e) {
$this->logger->error(
sprintf(
'[AfterShip TikTokShop] Failed to send order related products webhook on OrderUpdateObserver, %s',
$e->getMessage()
)
);
}
}
} catch (\Exception $e) {
$this->logger->error(
sprintf(
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "aftership/tiktok-shop",
"description": "Aftership TikTok Shop extension for Magento 2. Allows connect with TikTok Shop and more.",
"type": "magento2-module",
"version": "1.0.13",
"version": "1.0.14",
"minimum-stability": "stable",
"license": "MIT",
"keywords": ["aftership", "magento", "magento2", "magento-2", "tiktok", "shopping", "shop", "feed"],
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="AfterShip_TikTokShop" setup_version="1.0.13" schema_version="1.0.13">
<module name="AfterShip_TikTokShop" setup_version="1.0.14" schema_version="1.0.14">
</module>
</config>

0 comments on commit 138716e

Please sign in to comment.