Skip to content
Code-Schnipsel Gruppen Projekte
Commit 2f44d45e erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

feat: payment changeable -> payment methods can be changed after the order...

feat: payment changeable -> payment methods can be changed after the order process, if there was an error during the payment process
Übergeordneter 640b266e
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
<?php
/**
* This file contains package_quiqqer_order_ajax_frontend_order_processing_getPayments
*/
/**
* Return the payments, if an error exists in the processing step
*
* @param integer $orderId
* @return string
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_order_ajax_frontend_order_processing_getPayments',
function ($orderHash) {
$Processing = new QUI\ERP\Order\Controls\OrderProcess\Processing();
$OrderProcess = new QUI\ERP\Order\OrderProcess([
'orderHash' => $orderHash,
'step' => $Processing->getName()
]);
/* @var $Processing \QUI\ERP\Order\Controls\OrderProcess\Processing */
$Processing = $OrderProcess->getCurrentStep();
$Order = $OrderProcess->getOrder();
$Processing->setAttribute('Order', $Order);
return $Processing->getProcessingPayments();
},
['orderHash']
);
<?php
/**
* This file contains package_quiqqer_order_ajax_frontend_order_processing_savePayment
*/
/**
* save the payment
*
* @param integer $orderId
* @return string
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_order_ajax_frontend_order_processing_savePayment',
function ($orderHash, $payment) {
$Processing = new QUI\ERP\Order\Controls\OrderProcess\Processing();
$OrderProcess = new QUI\ERP\Order\OrderProcess([
'orderHash' => $orderHash,
'step' => $Processing->getName()
]);
/* @var $Processing \QUI\ERP\Order\Controls\OrderProcess\Processing */
$Processing = $OrderProcess->getCurrentStep();
$Order = $OrderProcess->getOrder();
$Processing->setAttribute('Order', $Order);
$Processing->savePayment($payment);
},
['orderHash', 'payment']
);
......@@ -169,6 +169,25 @@ define('package/quiqqer/order/bin/frontend/classes/Orders', [
showError: false
});
});
},
/**
* Save (Change) the payment method during a processing step
*
* @param {String} orderHash - order hash
* @param {String|Number} payment - payment id
* @return {Promise}
*/
saveProcessingPaymentChange: function (orderHash, payment) {
return new Promise(function (resolve, reject) {
QUIAjax.post('package_quiqqer_order_ajax_frontend_order_processing_savePayment', resolve, {
'package': 'quiqqer/order',
orderHash: orderHash,
payment : payment,
onError : reject,
showError: false
});
});
}
});
});
\ No newline at end of file
......@@ -43,7 +43,8 @@ define('package/quiqqer/order/bin/frontend/controls/OrderProcess', [
'$onChangeState',
'$refreshButtonEvents',
'$beginResultRendering',
'$endResultRendering'
'$endResultRendering',
'$onProcessingError'
],
options: {
......@@ -528,6 +529,7 @@ define('package/quiqqer/order/bin/frontend/controls/OrderProcess', [
this.setAttribute('current', result.step);
// content
var Error = Ghost.getElement('.quiqqer-order-ordering-error');
var StepContent = Ghost.getElement('.quiqqer-order-ordering-step');
......@@ -604,13 +606,19 @@ define('package/quiqqer/order/bin/frontend/controls/OrderProcess', [
duration: 500
});
self.Loader.hide();
// add processing events
QUI.Controls.getControlsInElement(self.$StepContainer).each(function (Control) {
Control.addEvent('onProcessingError', self.$onProcessingError);
});
return Promise.all([
Prom1,
Prom2
]).then(function () {
return self.resize();
}).then(function () {
self.fireEvent('change', [self]);
self.Loader.hide();
});
});
},
......@@ -623,6 +631,8 @@ define('package/quiqqer/order/bin/frontend/controls/OrderProcess', [
* @return {Promise}
*/
$beginResultRendering: function (moveDirection) {
this.Loader.show();
var Container = this.$StepContainer.getChildren();
var leftPos = 0;
......@@ -647,7 +657,6 @@ define('package/quiqqer/order/bin/frontend/controls/OrderProcess', [
this.getElm().getElements('.quiqqer-order-ordering-error').destroy();
this.Loader.show();
this.$runningAnimation = true;
return this.$animate(Container, {
......@@ -825,6 +834,60 @@ define('package/quiqqer/order/bin/frontend/controls/OrderProcess', [
options.callback = resolve;
moofx(Elm).animate(styles, options);
});
},
/**
* Execute a processing error
* This method is triggered when a payment trigger a payment error
* The processing step can now display a payment change step
*/
$onProcessingError: function () {
if (this.getAttribute('current') !== 'Processing') {
return;
}
this.Loader.show();
var self = this,
Container = this.getElm().getElement('.quiqqer-order-step-processing'),
Payments = Container.getElement('quiqqer-order-processing-payments');
if (!Payments) {
Payments = new Element('div', {
'class': 'quiqqer-order-processing-payments'
}).inject(Container);
}
QUIAjax.get('package_quiqqer_order_ajax_frontend_order_processing_getPayments', function (result) {
Payments.set('html', result);
QUI.parse(Payments).then(function () {
Payments.getElement('[name="change-payment"]').addEvent('click', function (event) {
event.stop();
self.Loader.show();
// save new payment method
var paymentId = Payments.getElement('input:checked').value;
var orderHash = self.getAttribute('orderHash');
Orders.saveProcessingPaymentChange(
orderHash,
paymentId
).then(function () {
return self.send();
}).then(function () {
self.Loader.hide();
});
});
self.resize();
self.Loader.hide();
});
}, {
'package': 'quiqqer/order',
orderHash: this.getAttribute('orderHash')
});
}
});
});
\ No newline at end of file
......@@ -284,6 +284,19 @@
<en><![CDATA[Done!]]></en>
</locale>
<locale name="ordering.processing.change.payment.title">
<de><![CDATA[Bezahlungsweise ändern]]></de>
<en><![CDATA[Change payment]]></en>
</locale>
<locale name="ordering.processing.change.payment.message" html="true">
<de><![CDATA[Falls Ihre Bezahlung nicht geklappt hat können Sie eine alternative Bezahlweise wählen.]]></de>
<en><![CDATA[If your payment did not work you can choose an alternative method of payment.]]></en>
</locale>
<locale name="ordering.processing.change.payment.button">
<de><![CDATA[Zahlungsweise ändern]]></de>
<en><![CDATA[Change payment]]></en>
</locale>
<locale name="ordering.step.title.CustomerData.customerNo">
<de><![CDATA[Kunden-Nr.]]></de>
<en><![CDATA[Customer no]]></en>
......
.quiqqer-order-step-processing {
float: left;
padding-bottom: 20px;
width: 100%;
}
.quiqqer-order-step-processing header {
margin-bottom: 20px;
......@@ -6,3 +11,22 @@
.quiqqer-order-step-processing-description {
margin-bottom: 20px;
}
.quiqqer-order-processing-payments {
float: left;
margin-bottom: 20px;
margin-top: 50px;
width: 100%;
}
.quiqqer-order-processing-payments-message {
margin-bottom: 20px;
}
.quiqqer-order-processing-payments .quiqqer-order-step-payments {
padding: 0;
}
.quiqqer-order-processing-payments .quiqqer-order-step-payments header {
display: none;
}
......@@ -60,6 +60,7 @@ public function getBody()
return '';
}
$Engine->assign([
'display' => $this->ProcessingProvider->getDisplay($this->getOrder(), $this),
'this' => $this
......@@ -68,6 +69,46 @@ public function getBody()
return $Engine->fetch(dirname(__FILE__).'/Processing.html');
}
/**
* Return the processing payments, if the current payment does not work
* This method checks if the payment can be changed
*
* @return string
*/
public function getProcessingPayments()
{
if (!class_exists('\QUI\ERP\Accounting\Payments\Order\Payment')) {
return '';
}
// check if payment can be changed
$Order = $this->getOrder();
$Payment = $Order->getPayment();
if (QUI\ERP\Order\Utils\Utils::isPaymentChangeable($Payment) === false) {
return '';
}
try {
$Engine = QUI::getTemplateManager()->getEngine();
$PaymentStep = new QUI\ERP\Accounting\Payments\Order\Payment([
'Order' => $this->getOrder()
]);
$Engine->assign([
'this' => $this,
'PaymentStep' => $PaymentStep
]);
} catch (\Exception $Exception) {
QUI\System\Log::writeDebugException($Exception);
return '';
}
return $Engine->fetch(dirname(__FILE__).'/ProcessingPayments.html');
}
/**
* @param QUI\ERP\Order\AbstractOrderProcessProvider $ProcessingProvider
*/
......@@ -107,6 +148,38 @@ public function save()
{
}
/**
* Save the payment to the order
*
* @param $payment
* @return void
*
* @throws QUI\ERP\Order\Exception
* @throws QUI\Exception
* @throws QUI\Permissions\Exception
*/
public function savePayment($payment)
{
if (!class_exists('\QUI\ERP\Accounting\Payments\Order\Payment')) {
return;
}
// check if payment can be changed
$Order = $this->getOrder();
$Payment = $Order->getPayment();
if (QUI\ERP\Order\Utils\Utils::isPaymentChangeable($Payment) === false) {
return;
}
$PaymentStep = new QUI\ERP\Accounting\Payments\Order\Payment([
'Order' => $this->getOrder(),
'payment' => $payment
]);
$PaymentStep->save();
}
//region title
/**
......
<h1>{locale group="quiqqer/order" var="ordering.processing.change.payment.title"}</h1>
<div class="quiqqer-order-processing-payments-message">
{locale group="quiqqer/order" var="ordering.processing.change.payment.message"}
</div>
{$PaymentStep->getBody()}
<button type="submit" name="change-payment" class="btn btn-secondary btn-outline">
{locale group="quiqqer/order" var="ordering.processing.change.payment.button"}
</button>
\ No newline at end of file
......@@ -203,4 +203,17 @@ public static function getOrderPrefix()
return mb_substr($prefix, 0, 100);
}
/**
* Can another payment method be chosen if the payment method does not work in an order?
*
* @param QUI\ERP\Accounting\Payments\Types\Payment $Payment
* @return bool
*/
public static function isPaymentChangeable(QUI\ERP\Accounting\Payments\Types\Payment $Payment)
{
$Settings = QUI\ERP\Order\Settings::getInstance();
return (bool)$Settings->get('paymentChangeable', $Payment->getId());
}
}
0% Lade oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren