Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(live-sync): Fix compound content #386

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions ps_eventbus.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ public function hookActionObjectProductAddAfter($parameters)
$product = $parameters['object'];
if (isset($product->id)) {
$synchronizationService->sendLiveSync('products', $product->id, 'upsert');
$synchronizationService->sendLiveSync('custom-product-carriers', $product->id, 'upsert');
$synchronizationService->sendLiveSync('custom_product_carriers', $product->id, 'upsert');
$synchronizationService->sendLiveSync('stocks', $product->id, 'upsert');

$synchronizationService->insertIncrementalSyncObject(
Expand Down Expand Up @@ -661,7 +661,7 @@ public function hookActionObjectProductUpdateAfter($parameters)

if (isset($product->id)) {
$synchronizationService->sendLiveSync('products', $product->id, 'upsert');
$synchronizationService->sendLiveSync('custom-product-carriers', $product->id, 'upsert');
$synchronizationService->sendLiveSync('custom_product_carriers', $product->id, 'upsert');
$synchronizationService->sendLiveSync('stocks', $product->id, 'upsert');

$synchronizationService->insertIncrementalSyncObject(
Expand Down Expand Up @@ -1152,7 +1152,7 @@ public function hookActionObjectCartRuleAddAfter($parameters)
$cartRule = $parameters['object'];

if (isset($cartRule->id)) {
$synchronizationService->sendLiveSync('cart-rules', $cartRule->id, 'upsert');
$synchronizationService->sendLiveSync('cart_rules', $cartRule->id, 'upsert');
$synchronizationService->insertIncrementalSyncObject(
$cartRule->id,
Config::COLLECTION_CART_RULES,
Expand All @@ -1175,7 +1175,7 @@ public function hookActionObjectCartRuleDeleteAfter($parameters)
$cartRule = $parameters['object'];

if (isset($cartRule->id)) {
$synchronizationService->sendLiveSync('cart-rules', $cartRule->id, 'delete');
$synchronizationService->sendLiveSync('cart_rules', $cartRule->id, 'delete');
$synchronizationService->insertDeletedObject(
$cartRule->id,
Config::COLLECTION_CART_RULES,
Expand All @@ -1198,7 +1198,7 @@ public function hookActionObjectCartRuleUpdateAfter($parameters)
$cartRule = $parameters['object'];

if (isset($cartRule->id)) {
$synchronizationService->sendLiveSync('cart-rules', $cartRule->id, 'upsert');
$synchronizationService->sendLiveSync('cart_rules', $cartRule->id, 'upsert');
$synchronizationService->insertIncrementalSyncObject(
$cartRule->id,
Config::COLLECTION_CART_RULES,
Expand Down Expand Up @@ -1689,7 +1689,7 @@ public function hookActionObjectSpecificPriceAddAfter($parameters)

if ($specificPrice instanceof SpecificPrice) {
if (isset($specificPrice->id)) {
$synchronizationService->sendLiveSync('specific-prices', $specificPrice->id, 'upsert');
$synchronizationService->sendLiveSync('specific_prices', $specificPrice->id, 'upsert');
$synchronizationService->insertIncrementalSyncObject(
$specificPrice->id,
Config::COLLECTION_SPECIFIC_PRICES,
Expand All @@ -1715,7 +1715,7 @@ public function hookActionObjectSpecificPriceUpdateAfter($parameters)

if ($specificPrice instanceof SpecificPrice) {
if (isset($specificPrice->id)) {
$synchronizationService->sendLiveSync('specific-prices', $specificPrice->id, 'upsert');
$synchronizationService->sendLiveSync('specific_prices', $specificPrice->id, 'upsert');
$synchronizationService->insertIncrementalSyncObject(
$specificPrice->id,
Config::COLLECTION_SPECIFIC_PRICES,
Expand All @@ -1741,7 +1741,7 @@ public function hookActionObjectSpecificPriceDeleteAfter($parameters)

if ($specificPrice instanceof SpecificPrice) {
if (isset($specificPrice->id)) {
$synchronizationService->sendLiveSync('specific-prices', $specificPrice->id, 'delete');
$synchronizationService->sendLiveSync('specific_prices', $specificPrice->id, 'delete');
$synchronizationService->insertDeletedObject(
$specificPrice->id,
Config::COLLECTION_SPECIFIC_PRICES,
Expand Down
5 changes: 4 additions & 1 deletion src/Api/LiveSyncApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ private function getClient($timeout = Config::SYNC_API_MAX_TIMEOUT)
*/
public function liveSync($shopContent, $shopContentId, $action)
{
// shop content send to the API must be in kebab-case
$kebabCasedShopContent = str_replace('_', '-', $shopContent);

$response = $this->getClient(3)->sendRequest(
new Request(
'POST',
Expand All @@ -83,7 +86,7 @@ public function liveSync($shopContent, $shopContentId, $action)
'User-Agent' => 'ps-eventbus/' . $this->module->version,
'Content-Type' => 'application/json',
],
'{"shopContents": ["' . $shopContent . '"], "shopContentId": ' . $shopContentId . ', "action": "' . $action . '"}'
'{"shopContents": ["' . $kebabCasedShopContent . '"], "shopContentId": ' . $shopContentId . ', "action": "' . $action . '"}'
)
);

Expand Down
Loading