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

fix: #20 - Shipping type can be skipped

Übergeordneter 8e6d1eab
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
......@@ -110,6 +110,10 @@
<de><![CDATA[Sie können mit der Bestellung leider nicht fortfahren.]]></de>
<en><![CDATA[Unfortunately you cannot continue with your order.]]></en>
</locale>
<locale name="exception.no.shipping.selected">
<de><![CDATA[Bitte wählen Sie eine Versandart aus.]]></de>
<en><![CDATA[Please select a shipping method.]]></en>
</locale>
<locale name="shipping.mail.settings.title">
<de><![CDATA[Bestell Verhalten]]></de>
<en><![CDATA[Order behavior]]></en>
......
......@@ -62,19 +62,7 @@ public function getBody()
$Customer = $Order->getCustomer();
$Shipping = QUI\ERP\Shipping\Shipping::getInstance();
$userShipping = $Shipping->getUserShipping($User);
$shippingList = [];
foreach ($userShipping as $ShippingEntry) {
$ShippingEntry->setOrder($Order);
if ($ShippingEntry->isValid()
&& $ShippingEntry->canUsedInOrder($Order)
&& $ShippingEntry->canUsedBy($User)) {
$shippingList[] = $ShippingEntry;
}
}
$shippingList = $this->getValidShipping();
// debugging logger
if (QUI\ERP\Shipping\Shipping::getInstance()->debuggingEnabled()) {
......@@ -166,7 +154,30 @@ public function validate()
}
// if shipping are selectable and no shipping is selected
$shippingList = $this->getValidShipping();
if ($Shipping === null && \count($shippingList) === 1) {
try {
$Order->setShipping($shippingList[0]);
$Order->save();
} catch (QUI\Exception $Exception) {
QUI\System\Log::addDebug($Exception->getMessage());
}
$Shipping = $Order->getShipping();
}
if ($Shipping === null && !empty($shippingList)) {
throw new QUI\ERP\Order\Exception([
'quiqqer/shipping',
'exception.no.shipping.selected'
]);
}
// if no shipping exists, BUT order can be continued
// and if really no shipping is selectable
if ($Shipping === null
&& $behavior === ShippingHandler::NO_RULE_FOUND_ORDER_CANCEL) {
throw new QUI\ERP\Order\Exception([
......@@ -196,6 +207,30 @@ public function validate()
}
}
/**
* @return array
*/
protected function getValidShipping()
{
$Order = $this->getOrder();
$User = $Order->getCustomer();
$userShipping = QUI\ERP\Shipping\Shipping::getInstance()->getUserShipping($User);
$shippingList = [];
foreach ($userShipping as $ShippingEntry) {
$ShippingEntry->setOrder($Order);
if ($ShippingEntry->isValid()
&& $ShippingEntry->canUsedInOrder($Order)
&& $ShippingEntry->canUsedBy($User)) {
$shippingList[] = $ShippingEntry;
}
}
return $shippingList;
}
/**
* Save the shipping to the order
*
......
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