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

fix: candyman-gmbh/projektplanung#81 - Shipping costs by billing address and...

fix: candyman-gmbh/projektplanung#81 - Shipping costs by billing address and not by delivery address
Übergeordneter 84b30b8c
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
......@@ -110,11 +110,13 @@ public function canUsedInOrder(
/**
* @param QUI\Interfaces\Users\User $User
* @param QUI\ERP\Shipping\Api\ShippingInterface $ShippingEntry
* @param QUI\ERP\Order\AbstractOrder $Order
* @return bool
*/
public function canUsedBy(
QUI\Interfaces\Users\User $User,
QUI\ERP\Shipping\Api\ShippingInterface $ShippingEntry
QUI\ERP\Shipping\Api\ShippingInterface $ShippingEntry,
QUI\ERP\Order\AbstractOrder $Order
) {
if ($ShippingEntry->isActive() === false) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: is not active");
......@@ -133,10 +135,11 @@ public function canUsedBy(
return true;
}
$Address = $Order->getDeliveryAddress();
$areasValue = \explode(',', \trim($areasValue, ','));
// not in area
if (!empty($areasValue) && !AreaUtils::isUserInAreas($User, $areasValue)) {
if (!empty($areasValue) && !AreaUtils::isAddressInArea($Address, $areasValue)) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: User is not in areas");
return false;
......
......@@ -78,10 +78,10 @@ public function getBody()
QUI\ERP\Shipping\Debug::enable();
QUI\ERP\Shipping\Debug::addLog('# '.$DebugShippingEntry->getTitle());
if ($DebugShippingEntry->canUsedBy($User)) {
if ($DebugShippingEntry->canUsedBy($User, $Order)) {
$DebugShippingEntry->isValid();
$DebugShippingEntry->canUsedInOrder($Order);
$DebugShippingEntry->canUsedBy($User);
$DebugShippingEntry->canUsedBy($User, $Order);
}
$debugStack = \array_merge($debugStack, QUI\ERP\Shipping\Debug::getLogStack());
......@@ -192,7 +192,7 @@ public function validate()
return;
}
if (!$Shipping->canUsedBy($User)) {
if (!$Shipping->canUsedBy($User, $Order)) {
throw new QUI\ERP\Order\Exception([
'quiqqer/shipping',
'exception.shipping.is.not.allowed'
......@@ -215,7 +215,7 @@ protected function getValidShipping()
$Order = $this->getOrder();
$User = $Order->getCustomer();
$userShipping = QUI\ERP\Shipping\Shipping::getInstance()->getUserShipping($User);
$userShipping = QUI\ERP\Shipping\Shipping::getInstance()->getUserShipping($User, $Order);
$shippingList = [];
foreach ($userShipping as $ShippingEntry) {
......@@ -223,7 +223,7 @@ protected function getValidShipping()
if ($ShippingEntry->isValid()
&& $ShippingEntry->canUsedInOrder($Order)
&& $ShippingEntry->canUsedBy($User)) {
&& $ShippingEntry->canUsedBy($User, $Order)) {
$shippingList[] = $ShippingEntry;
}
}
......@@ -257,7 +257,7 @@ public function save()
$ShippingEntry = $Shipping->getShippingEntry($shipping);
$ShippingEntry->setOrder($Order);
if (!$ShippingEntry->canUsedBy($User)) {
if (!$ShippingEntry->canUsedBy($User, $Order)) {
return;
}
......
......@@ -255,24 +255,27 @@ public function getShippingList($queryParams = [])
* Return all shipping entries for the user
*
* @param \QUI\Interfaces\Users\User|null $User - optional
* @param QUI\ERP\Order\AbstractOrder $Order - optional
* @return QUI\ERP\Shipping\Types\ShippingEntry[]
*/
public function getUserShipping($User = null)
public function getUserShipping($User = null, $Order = null)
{
if ($User === null) {
$User = QUI::getUserBySession();
}
$shipping = \array_filter($this->getShippingList(), function ($Shipping) use ($User) {
if ($Order === null) {
return [];
}
return \array_filter($this->getShippingList(), function ($Shipping) use ($User, $Order) {
/* @var $Shipping QUI\ERP\Shipping\Types\ShippingEntry */
if ($Shipping->isActive() === false) {
return false;
}
return $Shipping->canUsedBy($User);
return $Shipping->canUsedBy($User, $Order);
});
return $shipping;
}
/**
......
......@@ -8,6 +8,7 @@
use QUI;
use QUI\CRUD\Factory;
use QUI\ERP\Order\AbstractOrder;
use QUI\Translator;
use QUI\Permissions\Permission;
......@@ -228,11 +229,14 @@ public function getPrice()
* is the user allowed to use this shipping
*
* @param QUI\Interfaces\Users\User $User
* @param QUI\ERP\Order\AbstractOrder $Order
*
* @return boolean
*/
public function canUsedBy(QUI\Interfaces\Users\User $User)
{
public function canUsedBy(
QUI\Interfaces\Users\User $User,
QUI\ERP\Order\AbstractOrder $Order
) {
if ($this->isActive() === false) {
return false;
}
......@@ -241,7 +245,7 @@ public function canUsedBy(QUI\Interfaces\Users\User $User)
$ShippingType = $this->getShippingType();
if (\method_exists($ShippingType, 'canUsedBy')) {
return $ShippingType->canUsedBy($User, $this);
return $ShippingType->canUsedBy($User, $this, $Order);
}
} catch (QUI\Exception $Exception) {
return false;
......
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