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

refactor: order steps

Übergeordneter ee33b211
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
2 Merge Requests!2Next,!1Dev
werden angezeigt mit 780 Ergänzungen und 5 Löschungen
define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleCheckout', [], function() {
define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleCheckout', [
'qui/QUI',
'qui/controls/Control'
], function(QUI, QUIControl) {
'use strict';
return new Class({
Extends: QUIControl,
Type: '',
Type: 'package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleCheckout',
initialize: function(options) {
this.parent(options);
......@@ -15,7 +20,7 @@ define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleChecko
},
$onImport: function() {
}
});
});
define('package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleCheckoutDelivery', [
'qui/QUI',
'qui/controls/Control'
], function(QUI, QUIControl) {
'use strict';
return new Class({
Extends: QUIControl,
Type: 'package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleCheckoutDelivery',
initialize: function(options) {
this.parent(options);
this.$labels = [];
this.addEvents({
onImport: this.$onImport
});
},
$onImport: 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');
if (Company) {
this.$labels.push(Company);
}
if (VatId) {
this.$labels.push(VatId);
}
if (chUID) {
this.$labels.push(chUID);
}
if (BusinessType) {
BusinessType.addEvent('change', () => {
if (BusinessType.value === 'b2c') {
this.$hideB2B();
}
if (BusinessType.value === 'b2b') {
this.$showB2B();
}
});
}
BusinessType.fireEvent('change');
},
$hideB2B: function() {
this.$labels.forEach((Label) => {
Label.setStyle('position', 'relative');
Label.setStyle('overflow', 'hidden');
});
moofx(this.$labels).animate({
height: 0,
opacity: 0,
margin: 0,
padding: 0
}, {
callback: () => {
this.$labels.forEach((Label) => {
Label.setStyle('display', 'none');
});
}
});
},
$showB2B: function() {
this.$labels.forEach((Label) => {
Label.setStyle('position', 'relative');
Label.setStyle('opacity', 0);
Label.setStyle('display', null);
Label.setStyle('overflow', 'hidden');
Label.setStyle('height', 0);
Label.setStyle('margin', null);
moofx(Label).animate({
opacity: 1,
height: Label.getScrollSize().y
});
});
}
});
});
......@@ -20,7 +20,7 @@
},
"require": {
"php": ">=7.4",
"quiqqer\/order": "*"
"quiqqer\/order": "^1.10|@dev"
},
"autoload": {
"psr-4": {
......
.quiqqer-simple-checkout {
width: 100%;
}
.quiqqer-simple-checkout-container {
display: flex;
width: 100%;
}
.quiqqer-simple-checkout-data {
padding-right: 1rem;
width: 50%;
}
.quiqqer-simple-checkout-data > div {
margin-bottom: 2rem;
width: 100%;
}
.quiqqer-simple-checkout-data-express {
text-align: center;
}
.quiqqer-simple-checkout-data-or {
text-align: center;
position: relative;
}
.quiqqer-simple-checkout-data-or > div:before {
border-color: #dedede;
border-style: solid;
border-width: 1px;
content: "";
display: block;
flex-grow: 1;
position: absolute;
right: calc(50% + 20px);
top: 10px;
width: calc(50% - 30px);
}
.quiqqer-simple-checkout-data-or > div:after {
border-color: #dedede;
border-style: solid;
border-width: 1px;
content: "";
display: block;
flex-grow: 1;
position: absolute;
left: calc(50% + 20px);
top: 10px;
width: calc(50% - 30px);
}
.quiqqer-simple-checkout-data-pay > button {
font-size: 1.25rem;
text-align: center;
padding: 1.4rem;
width: 100%;
}
/** right side
============================================= */
.quiqqer-simple-checkout-basket {
background: #f5f5f5;
border-left: 1px solid #d6d6d6;
padding: 2rem;
width: 50%;
}
.quiqqer-simple-checkout-basket--sticky {
position: sticky;
top: 80px;
}
<div class="quiqqer-simple-checkout-container">
<form class="quiqqer-simple-checkout-data" method="post" action="">
<div class="quiqqer-simple-checkout-data-express">
<p>Express checkout</p>
<div></div>
</div>
<div class="quiqqer-simple-checkout-data-or" role="separator">
<div>OR</div>
</div>
<div class="quiqqer-simple-checkout-data-contact">
<h1>Contact</h1>
{if $User}
<div>Eingeloggt als: {$User->getName()}</div>
{else}
<div>
<span>Have an account? Log in</span>
</div>
{/if}
</div>
<div class="quiqqer-simple-checkout-data-delivery">
<h1>Delivery</h1>
{$Delivery->create()}
</div>
<div class="quiqqer-simple-checkout-data-shipping">
<h1>Shipping</h1>
{$Shipping->create()}
</div>
<div class="quiqqer-simple-checkout-data-payment">
<h1>Payment</h1>
{$Payment->create()}
</div>
<div class="quiqqer-simple-checkout-data-pay">
<button name="pay" disabled>Pay now</button>
</div>
</form>
<section class="quiqqer-simple-checkout-basket">
<div class="quiqqer-simple-checkout-basket--sticky">
{$Basket->create()}
</div>
</section>
</div>
\ No newline at end of file
......@@ -3,6 +3,8 @@
namespace QUI\ERP\Order\SimpleCheckout;
use QUI;
use QUI\ERP\Order\OrderInProcess;
use QUI\Exception;
use function dirname;
use function file_exists;
......@@ -16,6 +18,9 @@ public function __construct($attributes = [])
'data-qui' => 'package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleCheckout'
]);
$this->addCSSClass('quiqqer-simple-checkout');
$this->addCSSFile(dirname(__FILE__) . '/Checkout.css');
parent::__construct($attributes);
}
......@@ -28,7 +33,69 @@ public function getBody(): string
$template = $this->getAttribute('template');
}
$Control = new QUI\ERP\Order\Controls\Basket\Small();
$Control->setBasket(
QUI\ERP\Order\Handler::getInstance()->getBasketFromUser($this->getUser())
);
$Engine->assign([
'Basket' => $Control,
'User' => $this->getUser(),
'Delivery' => new CheckoutDelivery(),
'Shipping' => new CheckoutShipping(),
'Payment' => new CheckoutPayment()
]);
return $Engine->fetch($template);
}
public function send()
{
$Order = $this->getOrder();
// set all stuff to the order
$Order->setInvoiceAddress();
$Order->setShipping();
$Order->setPayment();
// all runs fine
if ($Order instanceof OrderInProcess) {
$OrderInProcess = $Order;
$Order = $Order->createOrder();
$OrderInProcess->delete();
}
}
/**
* @throws Exception
* @throws QUI\ERP\Order\Exception
*/
public function getOrder(): ?OrderInProcess
{
$Order = null;
$Orders = QUI\ERP\Order\Handler::getInstance();
try {
// select the last order in processing
$OrderInProcess = $Orders->getLastOrderInProcessFromUser($this->getUser());
if (!$OrderInProcess->getOrderId()) {
$Order = $OrderInProcess;
}
} catch (QUI\Exception $Exception) {
}
return $Engine->assign($template);
if ($Order === null) {
// if no order exists, we create one
$Order = QUI\ERP\Order\Factory::getInstance()->createOrderInProcess();
}
return $Order;
}
public function getUser(): QUI\Interfaces\Users\User
{
return QUI::getUserBySession();
}
}
.quiqqer-simple-checkout-delivery label {
clear: both;
display: block;
margin-bottom: 1rem;
width: 100%;
}
.quiqqer-simple-checkout-delivery label select,
.quiqqer-simple-checkout-delivery label input[type="text"],
.quiqqer-simple-checkout-delivery label input[type="tel"],
.quiqqer-simple-checkout-delivery label input[type="fax"] {
width: 100%;
}
.quiqqer-simple-checkout-delivery label .qui-select {
float: initial;
width: 100%;
}
.quiqqer-simple-checkout-delivery label > span {
display: block;
width: 100%;
}
.quiqqer-order-customerData-edit-firstname,
.quiqqer-order-customerData-edit-lastname,
.quiqqer-order-customerData-edit-zip,
.quiqqer-order-customerData-edit-city {
float: left;
width: calc(50% - 10px) !important;
}
.quiqqer-order-customerData-edit-lastname,
.quiqqer-order-customerData-edit-city {
clear: initial !important;
margin-left: 20px;
}
{if $businessTypeIsChangeable}
<label class="quiqqer-order-customerData-edit-businessType">
<span>
{locale group="quiqqer/order" var="ordering.step.title.CustomerData.businessType"}
</span>
<select name="businessType">
<option value="b2c">
{locale group="quiqqer/order" var="ordering.step.title.CustomerData.businessType.b2c"}
</option>
<option value="b2b" {$b2bSelected}>
{locale group="quiqqer/order" var="ordering.step.title.CustomerData.businessType.b2b"}
</option>
</select>
</label>
{/if}
{if $isB2B}
<label class="quiqqer-order-customerData-edit-company">
{assign var=r value=""}
{if $settings.company.required}{assign var=r value="required"}{/if}
<span>
{locale group="quiqqer/order" var="company"}
{if $settings.company.required}*{/if}
</span>
<input type="text"
name="company"
autocomplete="organization"
value="{$Address->getAttribute('company')|escape:'html'}"
{$r}
/>
</label>
<label class="quiqqer-order-customerData-edit-vatId">
<span>{locale group="quiqqer/order" var="vatId"}</span>
<input type="text"
name="vatId"
value="{$User->getAttribute('quiqqer.erp.euVatId')|escape:'html'}"
/>
</label>
<label class="quiqqer-order-customerData-edit-chUID">
<span>{locale group="quiqqer/order" var="chUID"}</span>
<input type="text"
name="chUID"
value="{$User->getAttribute('quiqqer.erp.chUID')|escape:'html'}"
/>
</label>
{/if}
{if $isOnlyB2B || $isOnlyB2C}
<style>
.quiqqer-order-customerData-edit-businessType {
display: none;
}
</style>
{/if}
{if $isB2B === false}
<style type="text/css">
.quiqqer-order-customerData-edit-company,
.quiqqer-order-customerData-edit-vatId,
.quiqqer-order-customerData-edit-chUID {
display: none;
}
</style>
{/if}
{if $settings.salutation.show}
<label class="quiqqer-order-customerData-edit-salutation">
{assign var=r value=""}
{if $settings.salutation.required}{assign var=r value="required"}{/if}
<span>
{locale group="quiqqer/frontend-users" var="salutation"}
{if $settings.salutation.required}*{/if}
</span>
<input type="text"
name="salutation"
autocomplete
maxlength="10"
value="{$Address->getAttribute('salutation')|escape:'html'}"
{$r}
/>
</label>
{/if}
{if $settings.firstname.show}
<label class="quiqqer-order-customerData-edit-firstname">
{assign var=r value=""}
{if $settings.firstname.required}{assign var=r value="required"}{/if}
<span>
{locale group="quiqqer/frontend-users" var="firstname"}
{if $settings.firstname.required}*{/if}
</span>
<input type="text"
name="firstname"
autocomplete="given-name"
value="{$Address->getAttribute('firstname')|escape:'html'}"
{$r}
/>
</label>
{/if}
{if $settings.lastname.show}
<label class="quiqqer-order-customerData-edit-lastname">
{assign var=r value=""}
{if $settings.lastname.required}{assign var=r value="required"}{/if}
<span>
{locale group="quiqqer/frontend-users" var="lastname"}
{if $settings.lastname.required}*{/if}
</span>
<input type="text"
name="lastname"
autocomplete="family-name"
value="{$Address->getAttribute('lastname')|escape:'html'}"
{$r}
/>
</label>
{/if}
{if $settings.street_no.show}
<label class="quiqqer-order-customerData-edit-street_no">
{assign var=r value=""}
{if $settings.street_no.required}{assign var=r value="required"}{/if}
<span>
{locale group="quiqqer/frontend-users" var="street_no"}
{if $settings.street_no.required}*{/if}
</span>
{if empty($Address->getAttribute('street_no'))}
<input type="text" name="street" value="" autocomplete="shipping street-address" {$r}>
<input type="text" name="street_number" value="">
{else}
<input type="text"
name="street_no"
autocomplete="address-line1"
value="{$Address->getAttribute('street_no')|escape:'html'}"
{$r}
/>
{/if}
</label>
{/if}
{if $settings.zip.show}
<label class="quiqqer-order-customerData-edit-zip">
{assign var=r value=""}
{if $settings.zip.required}{assign var=r value="required"}{/if}
<span>
{locale group="quiqqer/frontend-users" var="zip"}
{if $settings.zip.required}*{/if}
</span>
<input type="text"
name="zip"
autocomplete="postal-code"
value="{$Address->getAttribute('zip')|escape:'html'}"
{$r}
/>
</label>
{/if}
{if $settings.city.show}
<label class="quiqqer-order-customerData-edit-city">
{assign var=r value=""}
{if $settings.city.required}{assign var=r value="required"}{/if}
<span>
{locale group="quiqqer/frontend-users" var="city"}
{if $settings.city.required}*{/if}
</span>
<input type="text"
name="city"
autocomplete="city-name locality"
value="{$Address->getAttribute('city')|escape:'html'}"
{$r}
/>
</label>
{/if}
{if $settings.country.show}
<label class="quiqqer-order-customerData-edit-country">
<span>
{locale group="quiqqer/frontend-users" var="country"}
{if $settings.country.required}*{/if}
</span>
{control name="country" control="QUI\Countries\Controls\Select"
selected=$Address->getAttribute('country')
required=$settings.country.required
use-geo-location=true
}
</label>
{/if}
{if $settings.phone.show}
<label class="quiqqer-order-customerData-edit-tel">
{assign var=r value=""}
{if $settings.phone.required}{assign var=r value="required"}{/if}
<span>
{locale group="quiqqer/frontend-users" var="phone"}
{if $settings.phone.required}*{/if}
</span>
<input type="tel"
name="tel"
autocomplete="tel"
value="{if $Address->getPhone()}{$Address->getPhone()}{/if}"
{$r}
/>
</label>
{/if}
{if $settings.mobile.show}
<label class="quiqqer-order-customerData-edit-tel">
{assign var=r value=""}
{if $settings.mobile.required}{assign var=r value="required"}{/if}
<span>
{locale group="quiqqer/frontend-users" var="mobile"}
{if $settings.mobile.required}*{/if}
</span>
<input type="tel"
name="mobile"
autocomplete="mobile"
value="{if $Address->getMobile()}{$Address->getMobile()}{/if}"
{$r}
/>
</label>
{/if}
{if $settings.fax.show}
<label class="quiqqer-order-customerData-edit-tel">
{assign var=r value=""}
{if $settings.fax.required}{assign var=r value="required"}{/if}
<span>
{locale group="quiqqer/frontend-users" var="fax"}
{if $settings.fax.required}*{/if}
</span>
<input type="tel"
name="fax"
autocomplete="fax"
value="{if $Address->getFax()}{$Address->getFax()}{/if}"
{$r}
/>
</label>
{/if}
<?php
namespace QUI\ERP\Order\SimpleCheckout;
use QUI;
use QUI\Exception;
use QUI\Users\User;
use function dirname;
use function is_string;
use function json_decode;
/**
* Class CheckoutDelivery
*
* @package Your\Package\Namespace
*/
class CheckoutDelivery extends QUI\Control
{
/**
* Constructor method for the SimpleCheckoutDelivery class.
*
* @param array $attributes Optional attributes to be passed to the parent constructor.
* @return void
*/
public function __construct($attributes = [])
{
parent::__construct($attributes);
$this->addCSSFile(dirname(__FILE__) . '/CheckoutDelivery.css');
$this->addCSSClass('quiqqer-simple-checkout-delivery');
$this->setJavaScriptControl(
'package/quiqqer/order-simple-checkout/bin/frontend/controls/SimpleCheckoutDelivery'
);
}
/**
* Returns the HTML body content for the checkout delivery step.
*
* @return string The HTML body content for the checkout delivery step.
* @throws Exception
*/
public function getBody(): string
{
$Engine = QUI::getTemplateManager()->getEngine();
$User = QUI::getUserBySession();
$isUserB2B = function () use ($User) {
if (!$User) {
return '';
}
if ($User->getAttribute('quiqqer.erp.isNettoUser') === QUI\ERP\Utils\User::IS_NETTO_USER) {
return ' selected="selected"';
}
if ($User->getAttribute('quiqqer.erp.isNettoUser') !== false) {
return '';
}
if (
QUI\ERP\Utils\Shop::isB2CPrioritized() ||
QUI\ERP\Utils\Shop::isOnlyB2C()
) {
return '';
}
if (QUI\ERP\Utils\Shop::isB2B()) {
return ' selected="selected"';
}
return '';
};
$isB2B = QUI\ERP\Utils\Shop::isB2B();
$isB2C = QUI\ERP\Utils\Shop::isB2C();
$isOnlyB2B = QUI\ERP\Utils\Shop::isOnlyB2B();
$isOnlyB2C = QUI\ERP\Utils\Shop::isOnlyB2C();
// frontend users address profile settings
try {
$Conf = QUI::getPackage('quiqqer/frontend-users')->getConfig();
$settings = $Conf->getValue('profile', 'addressFields');
if (!empty($settings)) {
$settings = json_decode($settings, true);
}
} catch (QUI\Exception $Exception) {
$settings = [];
}
if (empty($settings) || is_string($settings)) {
$settings = [];
}
$settings = QUI\FrontendUsers\Controls\Address\Address::checkSettingsArray($settings);
$businessTypeIsChangeable = !(QUI\ERP\Utils\Shop::isOnlyB2C() || QUI\ERP\Utils\Shop::isOnlyB2B());
if ($this->existsAttribute('businessTypeIsChangeable')) {
$businessTypeIsChangeable = $this->getAttribute('businessTypeIsChangeable');
}
$Engine->assign([
'User' => $User,
'Address' => $this->getInvoiceAddress(),
'b2bSelected' => $isUserB2B(),
'isB2C' => $isB2C,
'isB2B' => $isB2B,
'isOnlyB2B' => $isOnlyB2B,
'isOnlyB2C' => $isOnlyB2C,
'settings' => $settings,
'businessTypeIsChangeable' => $businessTypeIsChangeable,
]);
return $Engine->fetch(dirname(__FILE__) . '/CheckoutDelivery.html');
}
/**
* Retrieves the invoice address for the current user.
*
* @return false|QUI\Users\Address|null
*/
protected function getInvoiceAddress()
{
$User = QUI::getUserBySession();
if ($User->getAttribute('quiqqer.erp.address')) {
try {
return $User->getAddress($User->getAttribute('quiqqer.erp.address'));
} catch (QUI\Exception $Exception) {
QUI\System\Log::writeDebugException($Exception);
}
}
try {
/* @var $User User */
return $User->getStandardAddress();
} catch (QUI\Exception $Exception) {
QUI\System\Log::writeDebugException($Exception);
}
return null;
}
}
.order-simple-checkout-payment--info {
background: #f5f5f5;
padding: 1.7rem;
}
<div class="order-simple-checkout-payment--info">
Enter your delivery address to view available payment methods.
</div>
\ No newline at end of file
<?php
namespace QUI\ERP\Order\SimpleCheckout;
use QUI;
use function dirname;
class CheckoutPayment extends QUI\Control
{
public function __construct($attributes = [])
{
parent::__construct($attributes);
$this->addCSSFile(dirname(__FILE__) . '/CheckoutPayment.css');
$this->addCSSClass('quiqqer-simple-checkout-payment');
}
public function getBody(): string
{
$Engine = QUI::getTemplateManager()->getEngine();
return $Engine->fetch(dirname(__FILE__) . '/CheckoutPayment.html');
}
}
.order-simple-checkout-shipping--info {
background: #f5f5f5;
padding: 1.7rem;
}
<div class="order-simple-checkout-shipping--info">
Enter your delivery address to view available shipping methods.
</div>
\ No newline at end of file
<?php
namespace QUI\ERP\Order\SimpleCheckout;
use QUI;
use function dirname;
class CheckoutShipping extends QUI\Control
{
public function __construct($attributes = [])
{
parent::__construct($attributes);
$this->addCSSFile(dirname(__FILE__) . '/CheckoutShipping.css');
$this->addCSSClass('quiqqer-simple-checkout-shipping');
}
public function getBody(): string
{
$Engine = QUI::getTemplateManager()->getEngine();
return $Engine->fetch(dirname(__FILE__) . '/CheckoutShipping.html');
}
}
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