Module Maintenance + création du module Recette
This commit is contained in:
65
local/modules/PayPlugModule/Hook/BackHookManager.php
Executable file
65
local/modules/PayPlugModule/Hook/BackHookManager.php
Executable file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace PayPlugModule\Hook;
|
||||
|
||||
|
||||
use PayPlugModule\Model\OrderPayPlugData;
|
||||
use PayPlugModule\Model\OrderPayPlugDataQuery;
|
||||
use PayPlugModule\Model\OrderPayPlugMultiPaymentQuery;
|
||||
use PayPlugModule\PayPlugModule;
|
||||
use Propel\Runtime\Map\TableMap;
|
||||
use Thelia\Core\Event\Hook\HookRenderEvent;
|
||||
use Thelia\Core\Hook\BaseHook;
|
||||
use Thelia\Model\OrderQuery;
|
||||
use Thelia\Model\OrderStatus;
|
||||
|
||||
class BackHookManager extends BaseHook
|
||||
{
|
||||
/**
|
||||
* @param HookRenderEvent $event
|
||||
* @throws \Propel\Runtime\Exception\PropelException
|
||||
*/
|
||||
public function onOrderEditPaymentModuleBottom(HookRenderEvent $event)
|
||||
{
|
||||
$order = OrderQuery::create()
|
||||
->filterByPaymentModuleId(PayPlugModule::getModuleId())
|
||||
->filterById($event->getArgument('order_id'))
|
||||
->findOne();
|
||||
|
||||
if (null === $order) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var OrderPayPlugData $orderPayPlugData */
|
||||
$orderPayPlugData = OrderPayPlugDataQuery::create()
|
||||
->findOneById($order->getId());
|
||||
|
||||
if (null === $orderPayPlugData) {
|
||||
return;
|
||||
}
|
||||
|
||||
$orderPayPlugMultiPayments = OrderPayPlugMultiPaymentQuery::create()
|
||||
->filterByOrderId($order->getId())
|
||||
->find()
|
||||
->toArray(null, false,TableMap::TYPE_CAMELNAME);
|
||||
|
||||
$isPaid = !in_array($order->getOrderStatus()->getCode(), [OrderStatus::CODE_NOT_PAID, OrderStatus::CODE_CANCELED]);
|
||||
$event->add(
|
||||
$this->render(
|
||||
'PayPlugModule/order_pay_plug.html',
|
||||
array_merge(
|
||||
$event->getArguments(),
|
||||
[
|
||||
'isPaid' => $isPaid,
|
||||
'currency' => $order->getCurrency()->getSymbol()
|
||||
],
|
||||
$orderPayPlugData->toArray(TableMap::TYPE_CAMELNAME),
|
||||
[
|
||||
'multiPayments' => $orderPayPlugMultiPayments
|
||||
]
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
95
local/modules/PayPlugModule/Hook/FrontHookManager.php
Executable file
95
local/modules/PayPlugModule/Hook/FrontHookManager.php
Executable file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace PayPlugModule\Hook;
|
||||
|
||||
use PayPlugModule\Model\PayPlugCardQuery;
|
||||
use PayPlugModule\Model\PayPlugConfigValue;
|
||||
use PayPlugModule\PayPlugModule;
|
||||
use Thelia\Core\Event\Hook\HookRenderEvent;
|
||||
use Thelia\Core\Hook\BaseHook;
|
||||
use Thelia\Model\Country;
|
||||
use Thelia\TaxEngine\TaxEngine;
|
||||
|
||||
class FrontHookManager extends BaseHook
|
||||
{
|
||||
/** @var TaxEngine */
|
||||
protected $taxEngine;
|
||||
|
||||
public function __construct(TaxEngine $taxEngine)
|
||||
{
|
||||
$this->taxEngine = $taxEngine;
|
||||
}
|
||||
|
||||
public function onOrderInvoiceAfterJsInclude(HookRenderEvent $event)
|
||||
{
|
||||
$payPlugModuleId = PayPlugModule::getModuleId();
|
||||
if (PayPlugModule::getConfigValue(PayPlugConfigValue::PAYMENT_PAGE_TYPE) === "lightbox") {
|
||||
$event->add($this->render(
|
||||
'PayPlugModule/order-invoice-after-js-include.html',
|
||||
compact('payPlugModuleId')
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public function onOrderInvoicePaymentExtra(HookRenderEvent $event)
|
||||
{
|
||||
if ((int)$event->getArgument('module') !== PayPlugModule::getModuleId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->displayOneClickPayment($event);
|
||||
$this->displayMultiPayment($event);
|
||||
}
|
||||
|
||||
protected function displayMultiPayment(HookRenderEvent $event)
|
||||
{
|
||||
if (!PayPlugModule::getConfigValue(PayPlugConfigValue::MULTI_PAYMENT_ENABLED)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$nTimes = PayPlugModule::getConfigValue(PayPlugConfigValue::MULTI_PAYMENT_TIMES);
|
||||
$minimumAmount = PayPlugModule::getConfigValue(PayPlugConfigValue::MULTI_PAYMENT_MINIMUM);
|
||||
$maximumAmount = PayPlugModule::getConfigValue(PayPlugConfigValue::MULTI_PAYMENT_MAXIMUM);
|
||||
|
||||
/** @var Country $country */
|
||||
$country = $this->taxEngine->getDeliveryCountry();
|
||||
|
||||
$cart = $this->getSession()->getSessionCart();
|
||||
$cartAmount = $cart->getTaxedAmount($country);
|
||||
if ($cartAmount <= $minimumAmount || $cartAmount >= $maximumAmount) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->add(
|
||||
$this->render(
|
||||
'PayPlugModule/multi-payment.html',
|
||||
compact("nTimes")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function displayOneClickPayment(HookRenderEvent $event)
|
||||
{
|
||||
if (!PayPlugModule::getConfigValue(PayPlugConfigValue::ONE_CLICK_PAYMENT_ENABLED)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$customerId = $this->getSession()->getCustomerUser()->getId();
|
||||
|
||||
$payPlugCard = PayPlugCardQuery::create()
|
||||
->findOneByCustomerId($customerId);
|
||||
|
||||
if (null === $payPlugCard) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->add(
|
||||
$this->render(
|
||||
'PayPlugModule/one-click-payment.html',
|
||||
[
|
||||
'last4' => $payPlugCard->getLast4()
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user