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

feat: open simple checkout with products

Übergeordneter b5541dce
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
2 Merge Requests!2Next,!1Dev
<?php
/**
* This file contains package_quiqqer_order-simple-checkout_ajax_frontend_newOrderInProcess
*/
use QUI\ERP\Products\Handler\Products;
QUI::$Ajax->registerFunction(
'package_quiqqer_order-simple-checkout_ajax_frontend_newOrderInProcess',
function ($products) {
$products = json_decode($products, true);
$Orders = QUI\ERP\Order\Handler::getInstance();
if (!count($products)) {
// select the last order in processing
try {
return $Orders->getLastOrderInProcessFromUser($this->getUser())->getHash();
} catch (QUI\Exception $exception) {
return QUI\ERP\Order\Factory::getInstance()->createOrderInProcess()->getHash();
}
}
$OrderInProcess = QUI\ERP\Order\Factory::getInstance()->createOrderInProcess();
foreach ($products as $product) {
try {
$productId = null;
if (isset($product['productId'])) {
$productId = $product['productId'];
}
if (isset($product['id'])) {
$productId = $product['id'];
}
if (empty($productId)) {
continue;
}
Products::getProduct($productId); // check if product exists
if (empty($product['fields'])) {
$product['fields'] = [];
}
$BasketProduct = new QUI\ERP\Order\Basket\Product($productId, [
'fields' => $product['fields']
]);
if (isset($product['quantity'])) {
$BasketProduct->setQuantity($product['quantity']);
}
$OrderInProcess->addArticle($BasketProduct->toArticle());
} catch (\Exception $exception) {
continue;
}
}
$OrderInProcess->save();
return $OrderInProcess->getHash();
},
['products']
);
......@@ -14,7 +14,7 @@ function ($orderHash, $orderData) {
$orderData = json_decode($orderData, true);
if (!is_array($orderData)) {
return;
return false;
}
$Checkout = new Checkout(['orderHash' => $orderHash]);
......
......@@ -20,6 +20,10 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
'$onImport'
],
options: {
orderHash: false
},
initialize: function(options) {
this.parent(options);
......@@ -55,7 +59,7 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
this.$Delivery.addEvent('change', () => {
this.Loader.show();
console.log('change');
this.update().then(() => {
if (this.$Shipping) {
return this.$Shipping.refresh().then(() => {
......@@ -96,20 +100,55 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
},
$onInject: function() {
QUIAjax.get(
'package_quiqqer_order-simple-checkout_ajax_frontend_getSimpleCheckoutControl',
(html) => {
this.getElm().set('html', html);
this.$loadProducts().then(() => {
return this.$loadCheckout();
});
},
$loadProducts: function() {
if (this.getAttribute('products') && !this.getAttribute('orderHash')) {
return new Promise((resolve) => {
QUIAjax.post(
'package_quiqqer_order-simple-checkout_ajax_frontend_newOrderInProcess',
(orderHash) => {
this.setAttribute('orderHash', orderHash);
resolve();
},
{
'package': 'quiqqer/order-simple-checkout',
products: JSON.encode(this.getAttribute('products'))
}
);
});
}
return Promise.resolve();
},
$loadCheckout: function() {
return new Promise((resolve) => {
QUIAjax.get('package_quiqqer_order-simple-checkout_ajax_frontend_getSimpleCheckoutControl', (html) => {
const Ghost = new Element('div', {
html: html
});
const Checkout = Ghost.getElement('.quiqqer-simple-checkout');
this.getElm().addClass(Checkout.className);
this.getElm().set('data-qui', Checkout.get('data-qui'));
this.getElm().set('html', Checkout.get('html'));
Ghost.getElements('style').inject(this.getElm());
QUI.parse(this.getElm()).then(() => {
this.fireEvent('loaded', [this]);
this.$onImport();
resolve();
});
}, {
'package': 'quiqqer/order-simple-checkout',
orderHash: this.getAttribute('orderHash')
}
);
});
});
},
orderWithCosts: function() {
......@@ -143,8 +182,6 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
opacity: 0
}, {
callback: () => {
console.log(result);
Container.set('html', result.html);
QUI.parse(Container).then(() => {
......@@ -178,6 +215,14 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
Node.addEvent('load', () => {
resolve(QUI.Controls.getById(Node.get('data-quiid')));
});
}).then((Instance) => {
if (!Instance) {
return null;
}
Instance.setAttribute('Checkout', this);
return Instance;
});
},
......@@ -190,7 +235,8 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
this.Loader.hide();
resolve();
}, {
'package': 'quiqqer/order-simple-checkout'
'package': 'quiqqer/order-simple-checkout',
orderHash: this.getAttribute('orderHash')
});
});
},
......@@ -206,7 +252,8 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
this.$refreshBasket().then(resolve);
}, {
'package': 'quiqqer/order-simple-checkout',
orderData: JSON.encode(orderData)
orderData: JSON.encode(orderData),
orderHash: this.getAttribute('orderHash')
});
});
}
......
define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleCheckoutDelivery', [
'qui/QUI',
'qui/controls/Control',
'qui/utils/Form',
'Ajax'
'qui/controls/Control'
], function(QUI, QUIControl, QUIFormUtils, QUIAjax) {
], function(QUI, QUIControl) {
'use strict';
return new Class({
......
......@@ -53,7 +53,15 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
},
refresh: function() {
return new Promise(() => {
return new Promise((resolve) => {
if (!this.getAttribute('Checkout')) {
return new Promise((r) => {
(() => {
return this.refresh().then(r);
}).delay(200);
});
}
QUIAjax.get('package_quiqqer_order-simple-checkout_ajax_frontend_payments', (html) => {
const Ghost = new Element('div', {
html: html
......@@ -63,8 +71,10 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
Ghost.getElements('style').inject(this.getElm());
this.$registerEvents();
resolve();
}, {
'package': 'quiqqer/order-simple-checkout'
'package': 'quiqqer/order-simple-checkout',
orderHash: this.getAttribute('Checkout').getAttribute('orderHash')
});
});
}
......
......@@ -54,6 +54,13 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
refresh: function() {
// @todo loader
if (!this.getAttribute('Checkout')) {
return new Promise((r) => {
(() => {
return this.refresh().then(r);
}).delay(200);
});
}
return new Promise(() => {
QUIAjax.get('package_quiqqer_order-simple-checkout_ajax_frontend_shipping', (html) => {
......@@ -66,7 +73,8 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
this.$registerEvents();
}, {
'package': 'quiqqer/order-simple-checkout'
'package': 'quiqqer/order-simple-checkout',
orderHash: this.getAttribute('Checkout').getAttribute('orderHash')
});
});
}
......
define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleCheckoutWindow', [
'qui/QUI',
'qui/controls/windows/Popup'
'qui/controls/windows/Popup',
'package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleCheckout'
], function(QUI, QUIWindow) {
], function(QUI, QUIWindow, SimpleCheckout) {
'use strict';
return new Class({
......@@ -24,28 +25,30 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
maxWidth: 1200
});
this.$Checkout = null;
this.addEvents({
onOpen: this.$onOpen
});
},
$onOpen: function() {
if (this.$Checkout) {
return;
}
this.Loader.show();
this.getContent().set('html', '');
this.getContent().setStyle('padding', 0);
require([
'package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleCheckout'
], (SimpleCheckout) => {
const Checkout = new SimpleCheckout({
events: {
onLoaded: () => {
this.Loader.hide();
}
this.$Checkout = new SimpleCheckout({
products: this.getAttribute('products'),
events: {
onLoaded: () => {
this.Loader.hide();
}
}).inject(this.getContent());
});
}
}).inject(this.getContent());
}
});
});
......@@ -63,7 +63,7 @@
<section class="quiqqer-simple-checkout-basket">
<div class="quiqqer-simple-checkout-basket--sticky">
{$BasketDisplay->create()}
{$Basket->create()}
</div>
</section>
</div>
\ No newline at end of file
......@@ -42,9 +42,11 @@ public function getBody(): string
$template = $this->getAttribute('template');
}
// put the basket articles to the order in process
$Basket = QUI\ERP\Order\Handler::getInstance()->getBasketFromUser($this->getUser());
$Basket->toOrder($this->getOrder());
// put the basket articles to the order in process, if the current order has no articles
if (!$this->getOrder()->getArticles()->count()) {
$Basket = QUI\ERP\Order\Handler::getInstance()->getBasketFromUser($this->getUser());
$Basket->toOrder($this->getOrder());
}
$Checkout = new QUI\ERP\Order\Controls\OrderProcess\Checkout();
......@@ -65,8 +67,7 @@ public function getBody(): string
$Engine->assign([
'Order' => $this->getOrder(),
'Basket' => $Basket,
'BasketDisplay' => new Basket($this),
'Basket' => new Basket($this),
'User' => $this->getUser(),
'Delivery' => new CheckoutDelivery($this),
'Shipping' => new CheckoutShipping($this),
......
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