Skip to content

Commit

Permalink
Merge branch 'main' into ci/upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Venatum authored Oct 25, 2024
2 parents 55f776c + 26ad8fa commit d7eb14d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
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
24 changes: 24 additions & 0 deletions upgrade/Upgrade-3.2.1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* @return bool
*/
function upgrade_module_3_2_1()
{
$db = Db::getInstance();

// Delete all entries with type "cart_rules" from eventbus_incremental_sync
$db->delete('eventbus_incremental_sync', '`type` = "cart_rules"');

// reset full sync for cart_rules
$db->update(
'eventbus_type_sync',
[
'offset' => 0,
'full_sync_finished' => 0,
],
'`type` = "cart_rules"'
);

return true;
}

0 comments on commit d7eb14d

Please sign in to comment.