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

WIP extended logging of OrderStateService #878

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ const ApiService = Shopware.Classes.ApiService;

export default class MolliePaymentsConfigService extends ApiService {


/**
*
* @param httpClient
* @param loginService
* @param currentLocale
*/
constructor(httpClient, loginService, currentLocale) {
super(httpClient, loginService, 'mollie');

this.currentLocale = currentLocale;
this.cache = {};
// Cache expiration time in milliseconds (e.g., 60 seconds)
this.cacheExpirationTime = 60000;
}

/**
Expand Down Expand Up @@ -78,6 +74,16 @@ export default class MolliePaymentsConfigService extends ApiService {
* @returns {*}
*/
getRefundManagerConfig(salesChannelId, orderId) {
const cacheKey = `${salesChannelId}_${orderId}`;

const now = new Date().getTime();
const cachedEntry = this.cache[cacheKey];

if (cachedEntry && (now - cachedEntry.timestamp < this.cacheExpirationTime)) {
return Promise.resolve(cachedEntry.data);
}

// If there's no valid cache, make the API request
return this.httpClient
.post(
`_action/${this.getApiBasePath()}/config/refund-manager`,
Expand All @@ -89,7 +95,14 @@ export default class MolliePaymentsConfigService extends ApiService {
headers: this.getBasicHeaders(),
}
).then((response) => {
return ApiService.handleResponse(response);
const responseData = ApiService.handleResponse(response);

this.cache[cacheKey] = {
data: responseData,
timestamp: now
};

return responseData;
});
}

Expand Down
5 changes: 5 additions & 0 deletions src/Service/Order/OrderStateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public function setOrderState(OrderEntity $order, string $orderState, Context $c
$e->getMessage(),
[
'function' => 'payment-automate-order-state',
'order.id' => $order->getId(),
'order.number' => $order->getOrderNumber(),
'new.state' => $orderState,
'old.state' => $currentStatus,
'trace' => $e->getTraceAsString(),
]
);
}
Expand Down
Loading