Skip to content

Commit

Permalink
Merge pull request #34 in DEV-MO/shopware5-module from hotfix/ETS-54_…
Browse files Browse the repository at this point in the history
…fix_bidirectionality_cronjob to release/5.3.0

* commit 'd8235c620dec25527fac476a0d91e872280cf111':
  [ETS-54] catch errors in cronjob for bidirectionality
  • Loading branch information
MTroesken committed Nov 1, 2018
2 parents e7c2f6d + d8235c6 commit 7067e11
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 119 deletions.
35 changes: 18 additions & 17 deletions Bootstrapping/Events/UpdateTransactionsSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

namespace RpayRatePay\Bootstrapping\Events;

use Doctrine\ORM\Query\Expr;
use RpayRatePay\Component\Service\Logger;

class UpdateTransactionsSubscriber implements \Enlight\Event\SubscriberInterface
{
const JOB_NAME = 'Shopware_Cronjob_UpdateRatepayTransactions';

const MSG_NOTIFY_UPDATES_TO_RATEPAY = '[%d/%d] Processing order %d ...notify needed updates to RatePAY';

/**
* @var string
*/
Expand Down Expand Up @@ -49,12 +52,7 @@ public function updateRatepayTransactions(\Shopware_Components_Cron_CronJob $job
/* @var \Shopware\Models\Order\Order $order */
$order = Shopware()->Models()->find('Shopware\Models\Order\Order', $orderId);
Logger::singleton()->info(
sprintf(
'[%d/%d] Processing order %d ...notify needed updated to RatePAY',
($key + 1),
$totalOrders,
$orderId
)
sprintf(self::MSG_NOTIFY_UPDATES_TO_RATEPAY, ($key + 1), $totalOrders, $orderId)
);
$orderProcessor->informRatepayOfOrderStatusChange($order);
}
Expand All @@ -64,11 +62,13 @@ public function updateRatepayTransactions(\Shopware_Components_Cron_CronJob $job
);
return $e->getMessage();
}

return 'Success';
}

/**
* @return mixed
* @throws \Exception
*/
private function getLastUpdateDate()
{
Expand All @@ -92,21 +92,22 @@ private function getLastUpdateDate()
*/
private function findCandidateOrdersForUpdate($config)
{
$orderStatus = [
$config['RatePayFullDelivery'],
$config['RatePayFullCancellation'],
$config['RatePayFullReturn'],
$allowedOrderStates = [
$config->RatePayFullDelivery,
$config->RatePayFullCancellation,
$config->RatePayFullReturn,
];
$paymentMethods = $this->getAllowedPaymentMethods();
$changeDate = $this->getChangeDateLimit();

$query = 'SELECT o.id FROM s_order o
INNER JOIN s_order_history oh ON oh.orderID = o.id
LEFT JOIN s_core_paymentmeans cp ON cp.id = o.paymentID
WHERE cp.name in (' . join(',', $paymentMethods) . ')
AND o.status in (' . join(',', $orderStatus) . ')
AND oh.change_date >= :changeDate
GROUP BY o.id';
$query = Shopware()->Db()->select()
->from(['history' => 's_order_history'], null)
->joinLeft(['order' => 's_order'], 'history.orderID = order.id', ['id'])
->joinLeft(['payment' => 's_core_paymentmeans'], 'order.paymentID = payment.id', null)
->where('history.change_date >= :changeDate')
->where('order.status IN (' . join(', ', $allowedOrderStates) . ')')
->where('payment.name IN (' . join(', ', $paymentMethods) . ')')
->distinct(true);

$rows = Shopware()->Db()->fetchAll($query, [':changeDate' => $changeDate]);

Expand Down
4 changes: 4 additions & 0 deletions Component/Mapper/ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,10 @@ public function callConfirmationDeliver($operationData)
*
* @param $operationData
* @return bool
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
* @throws \Doctrine\ORM\TransactionRequiredException
* @throws \RatePAY\Exception\ModelException
*/
public function callPaymentChange($operationData)
{
Expand Down
Loading

0 comments on commit 7067e11

Please sign in to comment.