Skip to content

Commit

Permalink
Added fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjas1997 committed Oct 12, 2023
1 parent 3e38d3a commit 5638518
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions saferpayofficial.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ public function hookActionEmailSendBefore($params)
$canSendOrderConfirmationEmail = $this->getService(\Invertus\SaferPay\Core\Order\Verification\CanSendOrderConfirmationEmail::class);

if ($params['template'] === 'order_conf') {
return $canSendOrderConfirmationEmail->verify($order);
return $canSendOrderConfirmationEmail->verify($order, (int) $order->current_state);
}

if ($params['template'] === 'new_order') {
Expand Down Expand Up @@ -560,13 +560,13 @@ public function hookActionOrderStatusUpdate($params = [])

$saferPayAuthorizedStatus = (int) Configuration::get(\Invertus\SaferPay\Config\SaferPayConfig::SAFERPAY_PAYMENT_AUTHORIZED);
if ($orderStatus->id === $saferPayAuthorizedStatus && Configuration::get(\Invertus\SaferPay\Config\SaferPayConfig::SAFERPAY_SEND_NEW_ORDER_MAIL)) {
$mailService->sendNewOrderMail($order, $orderStatus->id);
$mailService->sendNewOrderMail($order, (int) $orderStatus->id);
}

/** @var \Invertus\SaferPay\Core\Order\Verification\CanSendOrderConfirmationEmail $canSendOrderConfirmationEmail */
$canSendOrderConfirmationEmail = $this->getService(\Invertus\SaferPay\Core\Order\Verification\CanSendOrderConfirmationEmail::class);

if ($canSendOrderConfirmationEmail->verify($order)) {
if ($canSendOrderConfirmationEmail->verify($order, (int) $orderStatus->id)) {
$mailService->sendOrderConfMail($order, (int)$orderStatus->id);
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/Core/Order/Verification/CanSendOrderConfirmationEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,30 @@

class CanSendOrderConfirmationEmail
{
public function verify(\Order $order)
public function verify(\Order $order, $orderStatusId)
{
if (!\Configuration::get(\Invertus\SaferPay\Config\SaferPayConfig::SAFERPAY_SEND_ORDER_CONFIRMATION)) {
return false;
}

if (!$this->isOrderStatusValid($order)) {
if (!$this->isOrderStatusValid($orderStatusId)) {
return false;
}

return true;
}

private function isOrderStatusValid(\Order $order): bool
private function isOrderStatusValid($orderStatusId)
{
if ((int) \Configuration::get(SaferPayConfig::SAFERPAY_PAYMENT_AUTHORIZED) === (int) $order->current_state) {
if ((int) \Configuration::get(SaferPayConfig::SAFERPAY_PAYMENT_AUTHORIZED) === (int) $orderStatusId) {
return true;
}

if ((int) \Configuration::get(SaferPayConfig::SAFERPAY_PAYMENT_COMPLETED) === (int) $order->current_state) {
if ((int) \Configuration::get(SaferPayConfig::SAFERPAY_PAYMENT_COMPLETED) === (int) $orderStatusId) {
return true;
}

if ((int) \Configuration::get(SaferPayConfig::STATUS_PS_OS_OUTOFSTOCK_PAID) === (int) $order->current_state) {
if ((int) \Configuration::get(SaferPayConfig::STATUS_PS_OS_OUTOFSTOCK_PAID) === (int) $orderStatusId) {
return true;
}

Expand Down

0 comments on commit 5638518

Please sign in to comment.