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

fix: ux - entering customer data is extremely annoying

Related: quiqqer/order-simple-checkout#17
Übergeordneter d7944d0b
No related branches found
No related tags found
2 Merge Requests!39fix: basket does not work after registration,!33Update 'next-3.x' with latest changes from 'main'
Pipeline #12240 mit Warnungen bestanden mit Phase
in 3 Minuten und 10 Sekunden
<?php
/**
* This file contains package_quiqqer_order-simple-checkout_ajax_frontend_delivery
*/
QUI::getAjax()->registerFunction(
'package_quiqqer_order-simple-checkout_ajax_frontend_delivery',
function ($orderHash, $addressId) {
$Checkout = new QUI\ERP\Order\SimpleCheckout\Checkout([
'orderHash' => $orderHash
]);
if (!empty($addressId)) {
try {
$Order = $Checkout->getOrder();
$Address = QUI::getUserBySession()->getAddress($addressId);
if ($Order) {
$ErpAddress = new QUI\ERP\Address($Address->getAttributes(), QUI::getUserBySession());
$Order->setDeliveryAddress($ErpAddress);
$Order->setInvoiceAddress($ErpAddress);
$Order->save();
}
} catch (QUI\Exception) {
}
}
return $Checkout->getDelivery();
},
['orderHash', 'addressId']
);
......@@ -9,13 +9,6 @@
QUI::getAjax()->registerFunction(
'package_quiqqer_order-simple-checkout_ajax_frontend_orderWithCosts',
function ($orderHash) {
$SessionUser = QUI::getUserBySession();
$userIsGuest = false;
if ($SessionUser->getId() === 6) {
$userIsGuest = true;
}
$Checkout = new Checkout([
'orderHash' => $orderHash
]);
......@@ -33,87 +26,12 @@ function ($orderHash) {
);
}
$InvoiceAddress = $Order->getInvoiceAddress();
$DefaultAddress = $SessionUser->getStandardAddress();
$hasDeliveryAddress = $Order->hasDeliveryAddress();
// check addresses
if (method_exists($SessionUser, 'getAddressList')) {
$addresses = $SessionUser->getAddressList();
foreach ($addresses as $Address) {
if (Checkout::isSameAddress($InvoiceAddress, $Address)) {
$Order->setInvoiceAddress($Address);
$Order->save(QUI::getUsers()->getSystemUser());
return $Checkout->orderWithCosts();
}
}
}
// if default address is empty, we set it
if (
$DefaultAddress
&& $DefaultAddress->getAttribute('firstname') === ''
&& $DefaultAddress->getAttribute('lastname') === ''
&& $DefaultAddress->getAttribute('street_no') === ''
&& $DefaultAddress->getAttribute('zip') === ''
&& $DefaultAddress->getAttribute('city') === ''
&& method_exists($DefaultAddress, 'save')
&& $hasDeliveryAddress === false
) {
// set invoice address to default, if only invoice exist and no delivery
$DefaultAddress->setAttribute('firstname', $InvoiceAddress->getAttribute('firstname'));
$DefaultAddress->setAttribute('lastname', $InvoiceAddress->getAttribute('lastname'));
$DefaultAddress->setAttribute('street_no', $InvoiceAddress->getAttribute('street_no'));
$DefaultAddress->setAttribute('zip', $InvoiceAddress->getAttribute('zip'));
$DefaultAddress->setAttribute('city', $InvoiceAddress->getAttribute('city'));
$DefaultAddress->setAttribute('country', $InvoiceAddress->getAttribute('country'));
if ($InvoiceAddress->getAttribute('company')) {
$DefaultAddress->setAttribute('company', $InvoiceAddress->getAttribute('company'));
}
$DefaultAddress->save(QUI::getUsers()->getSystemUser());
$Order->setInvoiceAddress($DefaultAddress);
$Order->save(QUI::getUsers()->getSystemUser());
} elseif (
$DefaultAddress
&& $DefaultAddress->getAttribute('firstname') === ''
&& $DefaultAddress->getAttribute('lastname') === ''
&& $DefaultAddress->getAttribute('street_no') === ''
&& $DefaultAddress->getAttribute('zip') === ''
&& $DefaultAddress->getAttribute('city') === ''
&& method_exists($DefaultAddress, 'save')
&& $hasDeliveryAddress
) {
// set delivery address to default
$DeliveryAddress = $Order->getInvoiceAddress();
// set invoice address to default
$DefaultAddress->setAttribute('firstname', $DeliveryAddress->getAttribute('firstname'));
$DefaultAddress->setAttribute('lastname', $DeliveryAddress->getAttribute('lastname'));
$DefaultAddress->setAttribute('street_no', $DeliveryAddress->getAttribute('street_no'));
$DefaultAddress->setAttribute('zip', $DeliveryAddress->getAttribute('zip'));
$DefaultAddress->setAttribute('city', $DeliveryAddress->getAttribute('city'));
$DefaultAddress->setAttribute('country', $DeliveryAddress->getAttribute('country'));
if ($InvoiceAddress->getAttribute('company')) {
$DefaultAddress->setAttribute('company', $InvoiceAddress->getAttribute('company'));
}
$DefaultAddress->save(QUI::getUsers()->getSystemUser());
} elseif (method_exists($SessionUser, 'addAddress') && !$userIsGuest) {
// add new address
$NewAddress = $SessionUser->addAddress($InvoiceAddress->getAttributes());
if ($NewAddress) {
$Order->setInvoiceAddress($NewAddress);
}
if (!$Checkout->isValid()) {
throw new QUI\Exception(
QUI::getLocale()->get('quiqqer/order-simple-checkout', 'exception.order.has.no.items')
);
}
$Order->save(QUI::getUsers()->getSystemUser());
return $Checkout->orderWithCosts();
},
['orderHash']
......
......@@ -13,6 +13,7 @@
'package_quiqqer_order-simple-checkout_ajax_frontend_update',
function ($orderHash, $orderData) {
$orderData = json_decode($orderData, true);
$User = QUI::getUserBySession();
if (!is_array($orderData)) {
return false;
......@@ -42,11 +43,20 @@ function ($orderHash, $orderData) {
}
// get user address
$Address = Checkout::getUserAddressByErpAddress($ErpAddress);
if (!$Address) {
// default address wird gegebenenfalls angepasst
$Address = QUI::getUserBySession()->getStandardAddress();
if (isset($orderData['addresses'])) {
try {
$Address = $User->getAddress($orderData['addresses']);
} catch (QUI\Exception) {
$Address = $User->getStandardAddress();
}
} elseif (isset($orderData['address'])) {
try {
$Address = $User->getAddress($orderData['address']);
} catch (QUI\Exception) {
$Address = $User->getStandardAddress();
}
} else {
$Address = $User->getStandardAddress();
}
$erpAddressData['uuid'] = $Address->getUUID();
......
......@@ -117,6 +117,10 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
return;
}
if (this.getElm().getElement('[data-qui="package/quiqqer/order/bin/frontend/controls/orderProcess/Login"]')) {
return;
}
this.Loader.show();
this.$BasketLoader = new Element('span', {
......@@ -261,6 +265,8 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
return this.$Shipping.refresh().then(() => {
return this.$Payment.refresh();
});
} else {
return this.$Payment.refresh();
}
});
});
......@@ -662,8 +668,14 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
},
update: function() {
this.$BasketLoader.style.display = '';
return new Promise((resolve) => {
const orderData = QUIFormUtils.getFormData(this.getElm().getElement('form'));
const Form = this.getElm().getElement('form');
const orderData = QUIFormUtils.getFormData(Form);
// because of disabled
orderData.country = QUI.Controls.getById(Form.elements['country'].get('data-quiid')).getValue();
QUIAjax.post('package_quiqqer_order-simple-checkout_ajax_frontend_update', (isValid) => {
if (isValid) {
......
define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleCheckoutDelivery', [
'qui/QUI',
'qui/controls/Control'
'qui/controls/Control',
'Ajax'
], function(QUI, QUIControl) {
], function(QUI, QUIControl, QUIAjax) {
'use strict';
let loading = false;
return new Class({
Extends: QUIControl,
......@@ -21,6 +24,7 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
this.$labels = [];
this.$Countries = null;
this.$changeTimeout = null;
this.$Loader = null;
this.addEvents({
onImport: this.$onImport
......@@ -28,46 +32,88 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
},
$onImport: function() {
let loaded = false;
this.$labels = [];
this.$Loader = new Element('span', {
'class': 'fa fa-spin fa-circle-notch simpleCheckout-details-section-loader'
}).inject(this.getElm().getParent('.simpleCheckout-details-section'));
this.$registerEvents().then(() => {
loading = true;
this.$Loader.style.display = 'none';
});
},
refresh: function() {
const Addresses = this.getElm().getElement('[name="addresses"]');
if (!Addresses) {
return Promise.resolve();
}
loading = true;
this.$Loader.style.display = '';
this.fireEvent('refreshBegin', [this]);
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_delivery', (html) => {
const Ghost = new Element('div', {
html: html
});
this.getElm().set('html', Ghost.getFirst('div').get('html'));
Ghost.getElements('style').inject(this.getElm());
QUI.parse(this.getElm()).then(() => {
return this.$registerEvents();
}).then(() => {
this.fireEvent('refreshEnd', [this]);
this.$Loader.style.display = 'none';
loading = false;
this.$onChange();
resolve();
});
}, {
'package': 'quiqqer/order-simple-checkout',
orderHash: this.getAttribute('Checkout').getAttribute('orderHash'),
addressId: Addresses.value
});
});
},
$registerEvents: function() {
const BusinessType = this.getElm().getElement('[name="businessType"]');
const Company = this.getElm().getElement('.quiqqer-order-customerData-edit-company');
const VatId = this.getElm().getElement('.quiqqer-order-customerData-edit-vatId');
const chUID = this.getElm().getElement('.quiqqer-order-customerData-edit-chUID');
const Addresses = this.getElm().getElement('[name="addresses"]');
VatId.setStyle('display', null);
chUID.setStyle('display', 'none');
// country change
const CountryNode = this.getElm().getElement('[name="country"]');
if (CountryNode) {
new Promise((resolve) => {
if (CountryNode.get('data-quiid')) {
resolve(QUI.Controls.getById(CountryNode.get('data-quiid')));
return;
if (Addresses) {
// disable all addresses
this.getElm().querySelectorAll('select,input').forEach((Node) => {
if (Node.name !== 'addresses') {
Node.disabled = true;
}
});
let checkInterval = setInterval(() => {
if (CountryNode.get('data-quiid')) {
clearInterval(checkInterval);
resolve(QUI.Controls.getById(CountryNode.get('data-quiid')));
}
}, 10);
}).then((QUICountries) => {
this.$Countries = QUICountries;
this.$Countries.addEvent('change', () => {
if (this.$Countries.getValue() === 'CH') {
chUID.setStyle('display', null);
VatId.setStyle('display', 'none');
} else {
chUID.setStyle('display', 'none');
VatId.setStyle('display', null);
}
});
Addresses.addEventListener('change', () => {
this.refresh();
});
}
VatId.setStyle('display', null);
chUID.setStyle('display', 'none');
if (Company) {
this.$labels.push(Company);
}
......@@ -82,7 +128,7 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
this.$showB2B();
}
if (loaded) {
if (loading) {
this.$onChange();
}
});
......@@ -91,10 +137,52 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
}
this.getElm().getElements('input').addEvent('change', this.$onChange);
loaded = true;
// country change
const CountryNode = this.getElm().getElement('[name="country"]');
if (!CountryNode) {
return Promise.resolve();
}
return new Promise((resolve) => {
if (CountryNode.get('data-quiid')) {
resolve(QUI.Controls.getById(CountryNode.get('data-quiid')));
return;
}
let checkInterval = setInterval(() => {
if (CountryNode.get('data-quiid')) {
clearInterval(checkInterval);
resolve(QUI.Controls.getById(CountryNode.get('data-quiid')));
}
}, 10);
}).then((QUICountries) => {
this.$Countries = QUICountries;
if (Addresses) {
this.$Countries.disable();
}
this.$Countries.addEvent('change', () => {
if (this.$Countries.getValue() === 'CH') {
chUID.setStyle('display', null);
VatId.setStyle('display', 'none');
} else {
chUID.setStyle('display', 'none');
VatId.setStyle('display', null);
}
this.$onChange();
});
});
},
$onChange: function() {
if (!loading) {
return;
}
if (this.$changeTimeout) {
clearTimeout(this.$changeTimeout);
}
......
......@@ -84,6 +84,10 @@
<de><![CDATA[Eine andere Rechnungsadresse verwenden]]></de>
<en><![CDATA[Use a different billing address]]></en>
</locale>
<locale name="ordering.step.title.CustomerData.addresses">
<de><![CDATA[Deine vorhandenen Addressen]]></de>
<en><![CDATA[Your existing addresses]]></en>
</locale>
lCheckoutPayment.enter_address_to_show_payment_options
<locale name="CheckoutPayment.enter_address_to_show_payment_options">
......
......@@ -4,8 +4,6 @@
use QUI;
use QUI\ERP\Order\Basket\ExceptionBasketNotFound;
use QUI\ERP\Order\Controls\Checkout\Login;
use QUI\ERP\Order\Controls\Checkout\Registration;
use QUI\ERP\Order\OrderInProcess;
use QUI\ERP\Order\OrderInterface;
use QUI\ERP\Order\SimpleCheckout\Steps\CheckoutBillingAddress;
......@@ -312,6 +310,27 @@ public function getUser(): QUI\Interfaces\Users\User
return QUI::getUserBySession();
}
/**
* Get the shipping html for the current order.
*
* @return string The shipping information
* @throws \Exception
*/
public function getDelivery(): string
{
$Delivery = new CheckoutDelivery($this);
$Output = new QUI\Output();
$result = $Delivery->create();
$css = QUI\Control\Manager::getCSS();
try {
return $Output->parse($css . $result);
} catch (QUI\Exception $exception) {
QUI\System\Log::writeException($exception);
return '';
}
}
/**
* Get the shipping html for the current order.
*
......@@ -376,41 +395,4 @@ public function getBasket(): string
}
//endregion
//region utils
public static function isSameAddress(?QUI\Users\Address $a, ?QUI\Users\Address $b): bool
{
if (
$a
&& $b
&& $a->getAttribute('firstname') === $b->getAttribute('firstname')
&& $a->getAttribute('lastname') === $b->getAttribute('lastname')
&& $a->getAttribute('street_no') === $b->getAttribute('street_no')
&& $a->getAttribute('zip') === $b->getAttribute('zip')
&& $a->getAttribute('city') === $b->getAttribute('city')
&& $a->getAttribute('company') === $b->getAttribute('company')
) {
return true;
}
return false;
}
public static function getUserAddressByErpAddress(QUI\ERP\Address $ErpAddress): ?QUI\Users\Address
{
$SessionUser = QUI::getUserBySession();
$addresses = $SessionUser->getAddressList();
foreach ($addresses as $Address) {
if (self::isSameAddress($ErpAddress, $Address)) {
return $Address;
}
}
return null;
}
//endregion
}
{if count($addresses) > 1}
<label class="quiqqer-order-customerData-edit-businessType">
<span>
{locale group="quiqqer/order-simple-checkout" var="ordering.step.title.CustomerData.addresses"}
</span>
<select name="addresses">
{foreach $addresses as $AddressEntry}
<option value="{$AddressEntry->getUUID()}"
{if $AddressEntry->getUUID() == $Address->getUUID()}selected="selected"{/if}
>{$AddressEntry->getText()}</option>
{/foreach}
</select>
</label>
{else}
<input type="hidden" name="address" value="{$Address->getUUID()}" />
{/if}
{if $businessTypeIsChangeable}
<label class="quiqqer-order-customerData-edit-businessType">
<span>
......
......@@ -106,6 +106,7 @@ public function getBody(): string
}
$Engine->assign([
'addresses' => $User->getAddressList(),
'User' => $User,
'Address' => $this->getInvoiceAddress(),
'b2bSelected' => $isUserB2B(),
......
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