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

fix: consider user default delivery address

Übergeordneter 7c5ab370
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
<event on="onQuiqqerOrderOrderProcessCheckoutOutput" <event on="onQuiqqerOrderOrderProcessCheckoutOutput"
fire="\QUI\ERP\Shipping\EventHandler::onQuiqqerOrderOrderProcessCheckoutOutput" fire="\QUI\ERP\Shipping\EventHandler::onQuiqqerOrderOrderProcessCheckoutOutput"
/> />
<event on="onQuiqqerOrderOrderProcessCheckoutOutputBefore"
fire="\QUI\ERP\Shipping\EventHandler::onQuiqqerOrderOrderProcessCheckoutOutputBefore"
/>
<event on="onUserSaveBegin" <event on="onUserSaveBegin"
fire="\QUI\ERP\Shipping\EventHandler::onUserSaveBegin" fire="\QUI\ERP\Shipping\EventHandler::onUserSaveBegin"
/> />
......
...@@ -7,10 +7,14 @@ ...@@ -7,10 +7,14 @@
namespace QUI\ERP\Shipping; namespace QUI\ERP\Shipping;
use QUI; use QUI;
use QUI\ERP\Products\Handler\Fields as ProductFields;
use QUI\ERP\Order\Controls\OrderProcess\Checkout as OrderCheckoutStepControl; use QUI\ERP\Order\Controls\OrderProcess\Checkout as OrderCheckoutStepControl;
use QUI\Template; use QUI\ERP\Products\Handler\Fields as ProductFields;
use \Quiqqer\Engine\Collector; use Quiqqer\Engine\Collector;
use function array_merge;
use function explode;
use function json_decode;
use function method_exists;
/** /**
* Class EventHandler * Class EventHandler
...@@ -137,7 +141,7 @@ public static function onQuiqqerOrderBasketToOrderEnd( ...@@ -137,7 +141,7 @@ public static function onQuiqqerOrderBasketToOrderEnd(
$Order->getArticles()->calc(); $Order->getArticles()->calc();
if (\method_exists($Order, 'save')) { if (method_exists($Order, 'save')) {
$Order->save(); $Order->save();
} }
} }
...@@ -168,7 +172,7 @@ public static function onQuiqqerPaymentCanUsedInOrder( ...@@ -168,7 +172,7 @@ public static function onQuiqqerPaymentCanUsedInOrder(
return; return;
} }
$payments = \explode(',', $payments); $payments = explode(',', $payments);
$Payments = QUI\ERP\Accounting\Payments\Payments::getInstance(); $Payments = QUI\ERP\Accounting\Payments\Payments::getInstance();
foreach ($payments as $paymentId) { foreach ($payments as $paymentId) {
...@@ -211,6 +215,42 @@ public static function onOrderProcessCustomerDataEnd( ...@@ -211,6 +215,42 @@ public static function onOrderProcessCustomerDataEnd(
$Collector->append($Control->create()); $Collector->append($Control->create());
} }
public static function onQuiqqerOrderOrderProcessCheckoutOutputBefore(
OrderCheckoutStepControl $Checkout
) {
if (Shipping::getInstance()->shippingDisabled()) {
return;
}
$Order = $Checkout->getOrder();
if (!$Order) {
return;
}
if ($Order->hasDeliveryAddress()) {
return;
}
$SessionUser = QUI::getUserBySession();
$Customer = $Order->getCustomer();
if ($SessionUser->getId() !== $Customer->getId()) {
return;
}
$addressId = $SessionUser->getAttribute('quiqqer.delivery.address');
if ($addressId) {
try {
$DeliveryAddress = $Customer->getAddress($addressId);
$Order->setDeliveryAddress($DeliveryAddress);
$Order->save(QUI::getUsers()->getSystemUser());
} catch (\Exception $Exception) {
}
}
}
/** /**
* quiqqer/order: onQuiqqerOrderOrderProcessCheckoutOutput * quiqqer/order: onQuiqqerOrderOrderProcessCheckoutOutput
* *
...@@ -240,13 +280,13 @@ public static function onQuiqqerOrderOrderProcessCheckoutOutput(OrderCheckoutSte ...@@ -240,13 +280,13 @@ public static function onQuiqqerOrderOrderProcessCheckoutOutput(OrderCheckoutSte
if (!empty($deliveryAddressId)) { if (!empty($deliveryAddressId)) {
try { try {
$DeliveryAddress = $Customer->getAddress($deliveryAddressId); $DeliveryAddress = $Customer->getAddress($deliveryAddressId);
$ErpDeliveryAddres = new QUI\ERP\Address( $ErpDeliveryAddress = new QUI\ERP\Address(
\json_decode($DeliveryAddress->toJSON(), true), json_decode($DeliveryAddress->toJSON(), true),
$Order->getCustomer() $Order->getCustomer()
); );
$Order->setDeliveryAddress($ErpDeliveryAddres); $Order->setDeliveryAddress($ErpDeliveryAddress);
$Order->save(QUI::getUsers()->getSystemUser()); $Order->save(QUI::getUsers()->getSystemUser());
} catch (\Exception $Exception) { } catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception); QUI\System\Log::writeException($Exception);
...@@ -292,7 +332,7 @@ public static function onQuiqqerOrderCustomerDataSave( ...@@ -292,7 +332,7 @@ public static function onQuiqqerOrderCustomerDataSave(
} }
$ErpAddress = new QUI\ERP\Address( $ErpAddress = new QUI\ERP\Address(
\array_merge($Address->getAttributes(), ['id' => $Address->getId()]) array_merge($Address->getAttributes(), ['id' => $Address->getId()])
); );
$Order->setDeliveryAddress($ErpAddress); $Order->setDeliveryAddress($ErpAddress);
...@@ -345,11 +385,14 @@ public static function onUserSaveBegin(QUI\Users\User $User) ...@@ -345,11 +385,14 @@ public static function onUserSaveBegin(QUI\Users\User $User)
try { try {
$Address = $User->getAddress($address); $Address = $User->getAddress($address);
$User->setAttribute('quiqqer.delivery.address', $Address->getId()); $User->setAttribute('quiqqer.delivery.address', $Address->getId());
} catch (QUI\Exception $Exception) { } catch (QUI\Exception $Exception) {
QUI\System\Log::writeDebugException($Exception); QUI\System\Log::writeDebugException($Exception);
} }
if (isset($Address)) {
QUI\ERP\Utils\User::setUserCurrentAddress($User, $Address);
}
} }
/** /**
...@@ -445,7 +488,7 @@ public static function onQuiqqerProductsPriceEnd(Collector $Collector, QUI\ERP\P ...@@ -445,7 +488,7 @@ public static function onQuiqqerProductsPriceEnd(Collector $Collector, QUI\ERP\P
} }
$Engine = QUI::getTemplateManager()->getEngine(); $Engine = QUI::getTemplateManager()->getEngine();
$html = $Engine->fetch(dirname(__FILE__).'/templates/shippingInformation.html'); $html = $Engine->fetch(dirname(__FILE__) . '/templates/shippingInformation.html');
$Collector->append($html); $Collector->append($html);
} }
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
use QUI; use QUI;
use QUI\ERP\Shipping\Shipping as ShippingHandler; use QUI\ERP\Shipping\Shipping as ShippingHandler;
use function count;
/** /**
* Class Shipping * Class Shipping
* *
...@@ -25,7 +27,7 @@ public function __construct($attributes = []) ...@@ -25,7 +27,7 @@ public function __construct($attributes = [])
{ {
parent::__construct($attributes); parent::__construct($attributes);
$this->addCSSFile(\dirname(__FILE__).'/Shipping.css'); $this->addCSSFile(\dirname(__FILE__) . '/Shipping.css');
} }
/** /**
...@@ -76,7 +78,7 @@ public function getBody() ...@@ -76,7 +78,7 @@ public function getBody()
$DebugShippingEntry->setOrder($Order); $DebugShippingEntry->setOrder($Order);
QUI\ERP\Shipping\Debug::enable(); QUI\ERP\Shipping\Debug::enable();
QUI\ERP\Shipping\Debug::addLog('# '.$DebugShippingEntry->getTitle()); QUI\ERP\Shipping\Debug::addLog('# ' . $DebugShippingEntry->getTitle());
if ($DebugShippingEntry->canUsedBy($User, $Order)) { if ($DebugShippingEntry->canUsedBy($User, $Order)) {
$DebugShippingEntry->isValid(); $DebugShippingEntry->isValid();
...@@ -92,7 +94,7 @@ public function getBody() ...@@ -92,7 +94,7 @@ public function getBody()
QUI\ERP\Shipping\Debug::disable(); QUI\ERP\Shipping\Debug::disable();
$Logger->info("\n\n".\implode("\n", $debugStack)); $Logger->info("\n\n" . \implode("\n", $debugStack));
$Engine->assign('debug', \implode("\n", $debugStack)); $Engine->assign('debug', \implode("\n", $debugStack));
} }
...@@ -128,7 +130,7 @@ public function getBody() ...@@ -128,7 +130,7 @@ public function getBody()
'shippingList' => $shippingList 'shippingList' => $shippingList
]); ]);
return $Engine->fetch(\dirname(__FILE__).'/Shipping.html'); return $Engine->fetch(\dirname(__FILE__) . '/Shipping.html');
} }
/** /**
...@@ -157,7 +159,7 @@ public function validate() ...@@ -157,7 +159,7 @@ public function validate()
// if shipping are selectable and no shipping is selected // if shipping are selectable and no shipping is selected
$shippingList = $this->getValidShipping(); $shippingList = $this->getValidShipping();
if ($Shipping === null && \count($shippingList) === 1) { if ($Shipping === null && count($shippingList) === 1) {
try { try {
$Order->setShipping($shippingList[0]); $Order->setShipping($shippingList[0]);
$Order->save(); $Order->save();
......
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