Skip to content
Code-Schnipsel Gruppen Projekte
Bestätigt Commit 4e588632 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

refactor: refreshing of all stuff

Übergeordneter 76e8e146
No related branches found
No related tags found
2 Merge Requests!2Next,!1Dev
werden angezeigt mit 282 Ergänzungen und 32 Löschungen
<?php
/**
* This file contains package_quiqqer_order-simple-checkout_ajax_frontend_basket
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_order-simple-checkout_ajax_frontend_basket',
function ($orderHash) {
$Checkout = new QUI\ERP\Order\SimpleCheckout\Checkout([
'orderHash' => $orderHash
]);
return $Checkout->getBasket();
},
['orderHash']
);
...@@ -7,6 +7,11 @@ ...@@ -7,6 +7,11 @@
QUI::$Ajax->registerFunction( QUI::$Ajax->registerFunction(
'package_quiqqer_order-simple-checkout_ajax_frontend_payments', 'package_quiqqer_order-simple-checkout_ajax_frontend_payments',
function ($orderHash) { function ($orderHash) {
$Checkout = new QUI\ERP\Order\SimpleCheckout\Checkout([
'orderHash' => $orderHash
]);
return $Checkout->getPayments();
}, },
['orderHash'] ['orderHash']
); );
...@@ -29,7 +29,15 @@ function ($orderHash, $orderData) { ...@@ -29,7 +29,15 @@ function ($orderHash, $orderData) {
$Order->removeShipping(); $Order->removeShipping();
} }
if (!empty($orderData['payment'])) {
$Order->setPayment($orderData['payment']);
} else {
$Order->clearPayment();
}
$Order->save(); $Order->save();
return $Checkout->isValid();
}, },
['orderHash', 'orderData'] ['orderHash', 'orderData']
); );
...@@ -2,10 +2,11 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko ...@@ -2,10 +2,11 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
'qui/QUI', 'qui/QUI',
'qui/controls/Control', 'qui/controls/Control',
'qui/controls/loader/Loader',
'qui/utils/Form', 'qui/utils/Form',
'Ajax' 'Ajax'
], function(QUI, QUIControl, QUIFormUtils, QUIAjax) { ], function(QUI, QUIControl, QUILoader, QUIFormUtils, QUIAjax) {
'use strict'; 'use strict';
return new Class({ return new Class({
...@@ -30,13 +31,13 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko ...@@ -30,13 +31,13 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
}, },
$onImport: function() { $onImport: function() {
this.BasketLoader = new QUILoader().inject(this.getElm().getElement('.quiqqer-simple-checkout-basket'));
Promise.all([ Promise.all([
this.$getControl(this.getElm().getElement('.quiqqer-simple-checkout-delivery')), this.$getControl(this.getElm().getElement('.quiqqer-simple-checkout-delivery')),
this.$getControl(this.getElm().getElement('.quiqqer-simple-checkout-shipping')), this.$getControl(this.getElm().getElement('.quiqqer-simple-checkout-shipping')),
this.$getControl(this.getElm().getElement('.quiqqer-simple-checkout-payment')) this.$getControl(this.getElm().getElement('.quiqqer-simple-checkout-payment'))
]).then((instances) => { ]).then((instances) => {
console.log(instances);
this.$Delivery = instances[0]; this.$Delivery = instances[0];
this.$Shipping = instances[1]; this.$Shipping = instances[1];
this.$Payment = instances[2]; this.$Payment = instances[2];
...@@ -86,13 +87,34 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko ...@@ -86,13 +87,34 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
}); });
}, },
$refreshBasket: function() {
console.log('$refreshBasket');
this.BasketLoader.show();
return new Promise((resolve) => {
QUIAjax.get('package_quiqqer_order-simple-checkout_ajax_frontend_basket', (basket) => {
this.getElm().getElement('.quiqqer-simple-checkout-basket--sticky').set('html', basket);
this.BasketLoader.hide();
resolve();
}, {
'package': 'quiqqer/order-simple-checkout'
});
});
},
update: function() { update: function() {
console.log('update'); console.log('update');
const PayButton = this.getElm().getElement('[name="pay"]');
return new Promise((resolve) => { return new Promise((resolve) => {
const orderData = QUIFormUtils.getFormData(this.getElm().getElement('form')); const orderData = QUIFormUtils.getFormData(this.getElm().getElement('form'));
QUIAjax.post('package_quiqqer_order-simple-checkout_ajax_frontend_update', resolve, { QUIAjax.post('package_quiqqer_order-simple-checkout_ajax_frontend_update', (isValid) => {
PayButton.disabled = !isValid;
this.$refreshBasket().then(resolve);
}, {
'package': 'quiqqer/order-simple-checkout', 'package': 'quiqqer/order-simple-checkout',
orderData: JSON.encode(orderData) orderData: JSON.encode(orderData)
}); });
......
define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleCheckoutPayment', [ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleCheckoutPayment', [
'qui/QUI', 'qui/QUI',
'qui/controls/Control' 'qui/controls/Control',
'Ajax'
], function(QUI, QUIControl) { ], function(QUI, QUIControl, QUIAjax) {
'use strict'; 'use strict';
return new Class({ return new Class({
...@@ -11,6 +12,10 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko ...@@ -11,6 +12,10 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
Extends: QUIControl, Extends: QUIControl,
Type: 'package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleCheckoutPayment', Type: 'package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleCheckoutPayment',
Binds: [
'$onChange'
],
initialize: function(options) { initialize: function(options) {
this.parent(options); this.parent(options);
...@@ -20,11 +25,48 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko ...@@ -20,11 +25,48 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
}, },
$onImport: function() { $onImport: function() {
this.$registerEvents();
},
$registerEvents: function() {
this.getElm().getElements('[type="radio"]').addEvent('change', this.$onChange);
this.getElm().getElements('[type="radio"]').forEach((Node) => {
Node.getParent('.quiqqer-order-step-payments-list-entry').addEvent('click', (e) => {
let Target = e.target;
if (!Target.hasClass('quiqqer-order-step-payments-list-entry')) {
Target = Target.getParent('.quiqqer-order-step-payments-list-entry');
}
Target.getElement('input').set('checked', true);
this.$onChange();
});
});
},
$onChange: function(e) {
if (typeOf(e) === 'domevent') {
e.stop();
}
this.fireEvent('change');
}, },
refresh: function() { refresh: function() {
return new Promise(() => {
QUIAjax.get('package_quiqqer_order-simple-checkout_ajax_frontend_payments', (html) => {
const Ghost = new Element('div', {
html: html
});
this.getElm().set('html', Ghost.getFirst('div').get('html'));
Ghost.getElements('style').inject(this.getElm());
this.$registerEvents();
}, {
'package': 'quiqqer/order-simple-checkout'
});
});
} }
}); });
}); });
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
<de><![CDATA[ ]]></de> <de><![CDATA[ ]]></de>
<en><![CDATA[ ]]></en> <en><![CDATA[ ]]></en>
</locale> </locale>
<locale name="title.contact">
<de><![CDATA[Konto / Kontakt]]></de>
<en><![CDATA[Account / Contact]]></en>
</locale>
</groups> </groups>
</locales> </locales>
\ No newline at end of file
{template_event name="quiqqer::order::simple::basket::begin"}
{$UniqueArticles->toHTML()}
{template_event name="quiqqer::order::simple::basket::beforeCheckoutButton"}
<?php
namespace QUI\ERP\Order\SimpleCheckout;
use QUI;
use QUI\ERP\Order\Basket\Exception;
use QUI\ERP\Order\Basket\ExceptionBasketNotFound;
use function dirname;
class Basket extends QUI\Control
{
protected Checkout $Checkout;
/**
* @throws ExceptionBasketNotFound
* @throws Exception
* @throws QUI\Database\Exception
*/
public function __construct(Checkout $Checkout, $attributes = [])
{
$this->Checkout = $Checkout;
parent::__construct($attributes);
$this->addCSSFile(dirname(__FILE__) . '/Basket.css');
}
/**
* @return string
* @throws QUI\Exception
*/
public function getBody(): string
{
$Engine = QUI::getTemplateManager()->getEngine();
$Order = $this->Checkout->getOrder();
$Articles = $Order->getArticles();
if (!$Articles->count()) {
return '';
}
$Articles->setCurrency($Order->getCurrency());
$UniqueArticles = $Articles->toUniqueList();
$UniqueArticles->hideHeader();
$Engine->assign([
'UniqueArticles' => $UniqueArticles
]);
return $Engine->fetch(dirname(__FILE__) . '/Basket.html');
}
}
<div class="quiqqer-simple-checkout-container"> <div class="quiqqer-simple-checkout-container">
<form class="quiqqer-simple-checkout-data" method="post" action=""> <form class="quiqqer-simple-checkout-data" method="post" action="">
{template_event name="quiqqer::order::orderProcessBasketEnd" Basket=$Basket Order=$Order assign=expressButtons}
{if !empty($expressButtons)}
<div class="quiqqer-simple-checkout-data-express"> <div class="quiqqer-simple-checkout-data-express">
<p>Express checkout</p> <p>Express checkout</p>
<div></div> <div>
{$expressButtons}
</div>
</div> </div>
<div class="quiqqer-simple-checkout-data-or" role="separator"> <div class="quiqqer-simple-checkout-data-or" role="separator">
<div>OR</div> <div>OR</div>
</div> </div>
{/if}
<div class="quiqqer-simple-checkout-data-contact"> <div class="quiqqer-simple-checkout-data-contact">
<h1>Contact</h1> <h1>
{locale group="quiqqer/order-simple-checkout" var="title.contact"}
</h1>
{if $User} {if $User}
<div>Eingeloggt als: {$User->getName()}</div> <div>Eingeloggt als: {$User->getName()}</div>
...@@ -22,28 +31,30 @@ ...@@ -22,28 +31,30 @@
</div> </div>
<div class="quiqqer-simple-checkout-data-delivery"> <div class="quiqqer-simple-checkout-data-delivery">
<h1>Delivery</h1> <h1>{locale group="quiqqer/order" var="ordering.step.title.CustomerData"}</h1>
{$Delivery->create()} {$Delivery->create()}
</div> </div>
<div class="quiqqer-simple-checkout-data-shipping"> <div class="quiqqer-simple-checkout-data-shipping">
<h1>Shipping</h1> <h1>{locale group="quiqqer/shipping" var="ordering.step.title.Shipping"}</h1>
{$Shipping->create()} {$Shipping->create()}
</div> </div>
<div class="quiqqer-simple-checkout-data-payment"> <div class="quiqqer-simple-checkout-data-payment">
<h1>Payment</h1> <h1>{locale group="quiqqer/order" var="ordering.step.title.Payment"}</h1>
{$Payment->create()} {$Payment->create()}
</div> </div>
<div class="quiqqer-simple-checkout-data-pay"> <div class="quiqqer-simple-checkout-data-pay">
<button name="pay" disabled>Pay now</button> <button name="pay" disabled>
{locale group="quiqqer/order" var="ordering.btn.pay.to.order"}
</button>
</div> </div>
</form> </form>
<section class="quiqqer-simple-checkout-basket"> <section class="quiqqer-simple-checkout-basket">
<div class="quiqqer-simple-checkout-basket--sticky"> <div class="quiqqer-simple-checkout-basket--sticky">
{$Basket->create()} {$BasketDisplay->create()}
</div> </div>
</section> </section>
</div> </div>
\ No newline at end of file
...@@ -42,13 +42,14 @@ public function getBody(): string ...@@ -42,13 +42,14 @@ public function getBody(): string
$template = $this->getAttribute('template'); $template = $this->getAttribute('template');
} }
$Control = new QUI\ERP\Order\Controls\Basket\Small(); // put the basket articles to the order in process
$Control->setBasket( $Basket = QUI\ERP\Order\Handler::getInstance()->getBasketFromUser($this->getUser());
QUI\ERP\Order\Handler::getInstance()->getBasketFromUser($this->getUser()) $Basket->toOrder($this->getOrder());
);
$Engine->assign([ $Engine->assign([
'Basket' => $Control, 'Order' => $this->getOrder(),
'Basket' => $Basket,
'BasketDisplay' => new Basket($this),
'User' => $this->getUser(), 'User' => $this->getUser(),
'Delivery' => new CheckoutDelivery($this), 'Delivery' => new CheckoutDelivery($this),
'Shipping' => new CheckoutShipping($this), 'Shipping' => new CheckoutShipping($this),
...@@ -58,22 +59,41 @@ public function getBody(): string ...@@ -58,22 +59,41 @@ public function getBody(): string
return $Engine->fetch($template); return $Engine->fetch($template);
} }
public function send() /**
* Check if the order is valid and the order can be executed
*
* @return bool Returns true if the order is valid, false otherwise.
*/
public function isValid(): bool
{ {
$Order = $this->getOrder(); // check address
try {
$Order = $this->getOrder();
// set all stuff to the order QUI\ERP\Order\Controls\OrderProcess\CustomerData::validateAddress(
$Order->setInvoiceAddress(); $Order->getInvoiceAddress()
$Order->setShipping(); );
$Order->setPayment(); } catch (QUI\Exception $exception) {
return false;
}
// check payment
$Payment = $Order->getPayment();
if (!$Payment) {
return false;
}
// all runs fine // check shipping
if ($Order instanceof OrderInProcess) { if (QUI::getPackageManager()->isInstalled('quiqqer/shipping') && !$Order->getShipping()) {
$OrderInProcess = $Order; return false;
$Order = $Order->createOrder();
$OrderInProcess->delete();
} }
return true;
}
public function send()
{
} }
// region getter // region getter
...@@ -134,7 +154,47 @@ public function getShipping(): string ...@@ -134,7 +154,47 @@ public function getShipping(): string
$result = $Shipping->create(); $result = $Shipping->create();
$css = QUI\Control\Manager::getCSS(); $css = QUI\Control\Manager::getCSS();
return $Output->parse($css . $result); try {
return $Output->parse($css . $result);
} catch (QUI\Exception $exception) {
QUI\System\Log::writeException($exception);
return '';
}
}
/**
* Get the payment html for the current order.
*
* @return string The shipping information
*/
public function getPayments(): string
{
$Payments = new CheckoutPayment($this);
$Output = new QUI\Output();
$result = $Payments->create();
$css = QUI\Control\Manager::getCSS();
try {
return $Output->parse($css . $result);
} catch (QUI\Exception $exception) {
QUI\System\Log::writeException($exception);
return '';
}
}
public function getBasket(): string
{
$Basket = new Basket($this);
$Output = new QUI\Output();
$result = $Basket->create();
$css = QUI\Control\Manager::getCSS();
try {
return $Output->parse($css . $result);
} catch (QUI\Exception $exception) {
QUI\System\Log::writeException($exception);
return '';
}
} }
//endregion //endregion
......
{if !isset($Payment)}
<div class="order-simple-checkout-payment--info"> <div class="order-simple-checkout-payment--info">
Enter your delivery address to view available payment methods. Enter your delivery address to view available payment methods.
</div> </div>
\ No newline at end of file {else}
{$Payment->create()}
{/if}
\ No newline at end of file
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace QUI\ERP\Order\SimpleCheckout\Steps; namespace QUI\ERP\Order\SimpleCheckout\Steps;
use QUI; use QUI;
use QUI\ERP\Accounting\Payments\Order\Payment;
use QUI\ERP\Order\SimpleCheckout\Checkout; use QUI\ERP\Order\SimpleCheckout\Checkout;
use QUI\ERP\Order\SimpleCheckout\CheckoutStepInterface; use QUI\ERP\Order\SimpleCheckout\CheckoutStepInterface;
...@@ -28,6 +29,20 @@ public function __construct(Checkout $Checkout, $attributes = []) ...@@ -28,6 +29,20 @@ public function __construct(Checkout $Checkout, $attributes = [])
public function getBody(): string public function getBody(): string
{ {
$Engine = QUI::getTemplateManager()->getEngine(); $Engine = QUI::getTemplateManager()->getEngine();
$Delivery = new CheckoutDelivery($this->Checkout);
try {
$Delivery->validate();
} catch (QUI\Exception $exception) {
return $Engine->fetch(dirname(__FILE__) . '/CheckoutPayment.html');
}
$Payment = new Payment([
'Order' => $this->Checkout->getOrder()
]);
$Engine->assign('Payment', $Payment);
return $Engine->fetch(dirname(__FILE__) . '/CheckoutPayment.html'); return $Engine->fetch(dirname(__FILE__) . '/CheckoutPayment.html');
} }
......
...@@ -2,3 +2,7 @@ ...@@ -2,3 +2,7 @@
background: #f5f5f5; background: #f5f5f5;
padding: 1.7rem; padding: 1.7rem;
} }
.quiqqer-simple-checkout-payment .quiqqer-order-step-payments header {
display: none;
}
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren