forked from rvvup/magento-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Product type restriction bugfix - Pending payments bugfix - Load assets from rvvup backend - Rvvup messaging bugfix ff588f4fb68e2547840a463b6a3d5cdf3a5a4dbf
- Loading branch information
Showing
17 changed files
with
231 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rvvup\Payments\Plugin; | ||
|
||
use Magento\Sales\Model\CronJob\CleanExpiredOrders; | ||
use Magento\Sales\Model\Order; | ||
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory; | ||
use Rvvup\Payments\Gateway\Method; | ||
use Psr\Log\LoggerInterface; | ||
use Magento\Store\Model\StoresConfig; | ||
|
||
class PreventOrderClean | ||
{ | ||
private const METHOD = 'method'; | ||
private const DELETE_PENDING_AFTER = 'sales/orders/delete_pending_after'; | ||
|
||
/** | ||
* @var CollectionFactory | ||
*/ | ||
private CollectionFactory $collectionFactory; | ||
|
||
/** | ||
* @var LoggerInterface | ||
*/ | ||
private LoggerInterface $logger; | ||
|
||
/** | ||
* @var StoresConfig | ||
*/ | ||
private StoresConfig $storesConfig; | ||
|
||
/** | ||
* @param CollectionFactory $collectionFactory | ||
* @param StoresConfig $storesConfig | ||
* @param LoggerInterface $logger | ||
*/ | ||
public function __construct( | ||
CollectionFactory $collectionFactory, | ||
StoresConfig $storesConfig, | ||
LoggerInterface $logger | ||
) { | ||
$this->collectionFactory = $collectionFactory; | ||
$this->storesConfig = $storesConfig; | ||
$this->logger = $logger; | ||
} | ||
|
||
/** | ||
* @param CleanExpiredOrders $subject | ||
* @return array | ||
*/ | ||
public function beforeExecute(CleanExpiredOrders $subject): array | ||
{ | ||
$ids = []; | ||
$lifetimes = $this->storesConfig->getStoresConfigByPath(self::DELETE_PENDING_AFTER); | ||
foreach ($lifetimes as $storeId => $lifetime) { | ||
$collection = $this->collectionFactory->create(); | ||
$collection->addFieldToFilter('status', Order::STATE_PENDING_PAYMENT); | ||
$collection->addFieldToFilter('store_id', $storeId); | ||
|
||
$time = $lifetime * 60; | ||
$expression = new \Zend_Db_Expr( | ||
'TIME_TO_SEC(TIMEDIFF(CURRENT_TIMESTAMP, `updated_at`)) >= ' . $time | ||
); | ||
|
||
$collection->getSelect()->where($expression); | ||
$ids[] = $collection->getAllIds(); | ||
} | ||
|
||
$ids = array_unique(array_merge(...$ids)); | ||
|
||
if (empty($ids)) { | ||
return []; | ||
} | ||
|
||
$collection = $this->collectionFactory->create(); | ||
$collection->join( | ||
["sop" => "sales_order_payment"], | ||
'main_table.entity_id = sop.parent_id', | ||
[self::METHOD] | ||
); | ||
|
||
$collection->addFieldToFilter( | ||
self::METHOD, | ||
['like' => Method::PAYMENT_TITLE_PREFIX . '%'] | ||
); | ||
|
||
$collection->addFieldToFilter('entity_id', ['in' => $ids]); | ||
|
||
$connection = $collection->getConnection(); | ||
|
||
try { | ||
$connection->beginTransaction(); | ||
|
||
$condition = ["entity_id in (?)" => $collection->getAllIds()]; | ||
$value = ['updated_at' => new \Zend_Db_Expr('CURRENT_TIMESTAMP')]; | ||
|
||
$connection->update('sales_order', $value, $condition); | ||
|
||
$connection->commit(); | ||
} catch (\Exception $exception) { | ||
$this->logger->debug( | ||
sprintf( | ||
'Exception caught while preventing order cleaning, %s', | ||
$exception->getMessage() | ||
) | ||
); | ||
$connection->rollBack(); | ||
} | ||
|
||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Rvvup\Payments\Plugin\PreventOrderClean"> | ||
<arguments> | ||
<argument name="logger" xsi:type="object">RvvupLog</argument> | ||
</arguments> | ||
</type> | ||
|
||
<type name="Magento\Sales\Model\CronJob\CleanExpiredOrders"> | ||
<plugin name="prevent_cleaning_rvvup_orders" | ||
type="Rvvup\Payments\Plugin\PreventOrderClean" | ||
sortOrder="1"/> | ||
</type> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
view/frontend/templates/head/additional/clearpay-script.phtml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.