Skip to content

Commit

Permalink
Merge pull request #26 from buckaroo-it/develop
Browse files Browse the repository at this point in the history
Update-Test-Release-1.1.0
  • Loading branch information
vegimcarkaxhija authored Nov 6, 2024
2 parents 6cdda77 + 0fc24f2 commit 32da57d
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 119 deletions.
6 changes: 5 additions & 1 deletion Controller/Checkout/SecondChance.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public function execute()
if ($token = $this->getRequest()->getParam('token')) {
$this->secondChanceRepository->getSecondChanceByToken($token);
}
return $this->_redirect('checkout', ['_fragment' => 'payment']);
return $this->handleRedirect('checkout', ['_fragment' => 'payment']);
}
public function handleRedirect($path, $arguments = [])
{
return $this->_redirect($path, $arguments);
}
}
29 changes: 20 additions & 9 deletions Model/SecondChanceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use Magento\Framework\Reflection\DataObjectProcessor;
use Magento\Store\Model\StoreManagerInterface;
use Buckaroo\Magento2SecondChance\Api\Data\SecondChanceInterface;
use Magento\Catalog\Model\Product\Type;

class SecondChanceRepository implements SecondChanceRepositoryInterface
{
Expand Down Expand Up @@ -297,9 +298,11 @@ public function deleteById($secondChanceId)
public function deleteByOrderId($orderId)
{
$this->logging->addDebug(__METHOD__ . '|1|');
$secondChance = $this->getByOrderId($orderId);

return $this->delete($secondChance);
if ($orderId) {
$secondChance = $this->getByOrderId($orderId);
return $this->delete($secondChance);
}
return false;
}

/**
Expand Down Expand Up @@ -494,13 +497,21 @@ public function sendMail($order, $secondChance, $step)

$store = $order->getStore();
$vars = [
'order' => $order,
'billing' => $order->getBillingAddress(),
'payment_html' => $this->getPaymentHtml($order),
'store' => $store,
'order' => $order,
'order_id' => $order->getId(),
'billing' => $order->getBillingAddress(),
'payment_html' => $this->getPaymentHtml($order),
'store' => $order->getStore(),
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
'created_at_formatted' => $order->getCreatedAtFormatted(2),
'secondChanceToken' => $secondChance->getToken(),
'order_data' => [
'customer_name' => $order->getCustomerName(),
'is_not_virtual' => $order->getIsNotVirtual(),
'email_customer_note' => $order->getEmailCustomerNote(),
'frontend_status_label' => $order->getFrontendStatusLabel()
]
];

$templateId = ($step == 1) ?
Expand All @@ -517,7 +528,7 @@ public function sendMail($order, $secondChance, $step)
'store' => $store->getId(),
]
)->setTemplateVars($vars)
->setFrom(
->setFromByScope(
[
'email' => $this->configProvider->getFromEmail($store),
'name' => $this->configProvider->getFromName($store),
Expand Down
35 changes: 26 additions & 9 deletions Observer/ProcessHandleFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,53 +19,70 @@
*/
namespace Buckaroo\Magento2SecondChance\Observer;

class ProcessHandleFailed implements \Magento\Framework\Event\ObserverInterface
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\RequestInterface;

class ProcessHandleFailed implements ObserverInterface
{
protected $logging;

protected $configProvider;

protected $quoteRecreate;

protected $customerSession;

protected $checkoutSession;
protected $request;

/**
* @param \Magento\Checkout\Model\Cart $cart
* Constructor
*
* @param \Buckaroo\Magento2\Logging\Log $logging
* @param \Buckaroo\Magento2SecondChance\Model\ConfigProvider\SecondChance $configProvider
* @param \Buckaroo\Magento2SecondChance\Service\Sales\Quote\Recreate $quoteRecreate
* @param \Magento\Customer\Model\Session $customerSession
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param RequestInterface $request
*/
public function __construct(
\Buckaroo\Magento2\Logging\Log $logging,
\Buckaroo\Magento2SecondChance\Model\ConfigProvider\SecondChance $configProvider,
\Buckaroo\Magento2SecondChance\Service\Sales\Quote\Recreate $quoteRecreate,
\Magento\Customer\Model\Session $customerSession,
\Magento\Checkout\Model\Session $checkoutSession
\Magento\Checkout\Model\Session $checkoutSession,
RequestInterface $request
) {
$this->logging = $logging;
$this->configProvider = $configProvider;
$this->quoteRecreate = $quoteRecreate;
$this->customerSession = $customerSession;
$this->checkoutSession = $checkoutSession;
$this->request = $request;
}

/**
* @param \Magento\Framework\Event\Observer $observer
* Execute observer
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$this->logging->addDebug(__METHOD__ . '|1|');

/* @var $order \Magento\Sales\Model\Order */
$order = $observer->getEvent()->getOrder();
$response = $this->request->getParams();
$this->logging->addDebug(__METHOD__ . '|Response|' . var_export($response, true));

// Convert all keys to lowercase to ensure consistency
$response = array_change_key_case($response, CASE_LOWER);

if (!$order) {
$this->logging->addDebug(__METHOD__ . '|no observer order|');
$order = $this->checkoutSession->getLastRealOrder();
}

if ($order && $this->configProvider->isSecondChanceEnabled($order->getStore())) {
$this->quoteRecreate->duplicate($order);
// Pass the response array to the duplicate method
$this->quoteRecreate->duplicate($order, $response);
$this->customerSession->setSkipHandleFailedRecreate(1);
}
}
Expand Down
56 changes: 39 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
<p align="center">
<img src="https://www.buckaroo.nl/media/2975/m2_icon.jpg" width="150px" position="center">
<img src="https://github.com/user-attachments/assets/8da148e4-63ec-410b-af0e-033a8ad2aa9e" width="200px" position="center">
</p>

# Buckaroo Magento 2 Second Chance extension
# Buckaroo Magento 2 Second Chance plugin
[![Latest release](https://badgen.net/github/release/buckaroo-it/Magento2_SecondChance)](https://github.com/buckaroo-it/Magento2_SecondChance/releases)

## Installation
### Index
- [About](#about)
- [Installation](#installation)
- [Requirements](#requirements)
- [Configuration](#configuration)
- [Contribute](#contribute)
- [Versioning](#versioning)
- [Additional information](#additional-information)
---

### About
The Second Chance module makes it possible to follow up unpaid orders with one or two reminder emails. This extension to the Buckaroo Payment module ensures a higher conversion rate.The Second Chance functionality is fully white-labelled, e-mails can be sent from your own corporate identity and mail servers. On top of that, the module can optionally also take into account whether or not stock is available.

### Installation
```
composer require buckaroo/magento2secondchance
php bin/magento module:enable Buckaroo_Magento2SecondChance
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
```

## Usage
### General information
The Second Chance module makes it possible to follow up unpaid orders with one or two reminder emails. This extension to the Buckaroo Payment module ensures a higher conversion rate.The Second Chance functionality is fully white-labelled, e-mails can be sent from your own corporate identity and mail servers. On top of that, the module can optionally also take into account whether or not stock is available.

### Requirements
To use the plugin you must use:
- Magento Open Source version 2.3.x & 2.4.x
- Buckaroo Magento 2 Payment module 1.39.0 or greater

**To use the plugin you must use:**
- Magento Open Source version 2.4.5, 2.4.6, and 2.4.7
- Buckaroo Magento 2 Payments plugin 1.50.2 or higher.

### Configuration
In the module configuration, various settings are available to build an ideal Second Chance flow to suit everyone. The settings below can be adjusted manually.
Expand All @@ -33,13 +44,24 @@ In the module configuration, various settings are available to build an ideal Se
<img src="https://www.buckaroo.nl/media/2973/secondchance.png" width="750px" position="center">
</p>

### Additional information
For more information on Second Chance please visit:
https://support.buckaroo.nl/categorieen/plugins/magento-2/magento-2-second-chance-extensie
### Contribute

We really appreciate it when developers contribute to improve the Buckaroo plugins.
If you want to contribute as well, then please follow our [Contribution Guidelines](CONTRIBUTING.md).

### Versioning

## Contribute
See [Contribution Guidelines](CONTRIBUTING.md)
<p align="left">
<img src="https://www.buckaroo.nl/media/3480/magento_versioning.png" width="500px" position="center">
</p>

- **MAJOR:** Breaking changes that require additional testing/caution.
- **MINOR:** Changes that should not have a big impact.
- **PATCHES:** Bug and hotfixes only.

## Support:
### Additional information
- **Support:** https://support.buckaroo.eu/contact
- **Contact:** [[email protected]](mailto:[email protected]) or [+31 (0)30 711 50 50](tel:+310307115050)

https://support.buckaroo.nl/contact
<b>Please note:</b><br>
This file has been prepared with the greatest possible care and is subject to language and/or spelling errors.
Loading

0 comments on commit 32da57d

Please sign in to comment.