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

feat: quiqqer v2 compatibility - typing

Übergeordneter 0e6b49fb
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
3 Merge Requests!29feat!: quiqqer v2,!28feat!: quiqqer v2,!27feat!: quiqqer v2
werden angezeigt mit 188 Ergänzungen und 179 Löschungen
......@@ -89,10 +89,10 @@ public function getClass(): string
abstract public function getTitle($Locale = null): string;
/**
* @param null $Locale
* @param null|QUI\Locale $Locale
* @return string
*/
abstract public function getDescription($Locale = null): string;
abstract public function getDescription(QUI\Locale $Locale = null): string;
/**
* @return string
......
......@@ -18,5 +18,5 @@ abstract class AbstractShippingProvider
*
* @return array
*/
abstract public function getShippingTypes();
abstract public function getShippingTypes(): array;
}
......@@ -8,6 +8,8 @@
use QUI;
use function get_class;
/**
* Shipping abstract class
* This is the parent shipping class for all shipping methods
......@@ -19,16 +21,16 @@ abstract class AbstractShippingType extends QUI\QDOM implements QUI\ERP\Shipping
/**
* @return string
*/
public function getType()
public function getType(): string
{
return \get_class($this);
return get_class($this);
}
/**
* @param QUI\Locale|null $Locale
* @return array
*/
public function toArray($Locale = null)
public function toArray(QUI\Locale $Locale = null): array
{
if ($Locale === null) {
$Locale = QUI::getLocale();
......@@ -41,13 +43,13 @@ public function toArray($Locale = null)
}
/**
* @param $Locale
* @return array|string
* @param QUI\Locale|null $Locale
* @return string
*/
abstract public function getTitle($Locale = null);
abstract public function getTitle(QUI\Locale $Locale = null): string;
/**
* @return string
*/
abstract public function getIcon();
abstract public function getIcon(): string;
}
......@@ -7,6 +7,7 @@
namespace QUI\ERP\Shipping\Api;
use QUI;
use QUI\ERP\Shipping\Exception;
/**
* Interface for a Shipping Entry
......@@ -15,46 +16,46 @@
interface ShippingInterface
{
/**
* @return integer
* @return int|string
*/
public function getId();
public function getId(): int|string;
/**
* @param null|QUI\Locale $Locale
* @return string
*/
public function getTitle($Locale = null);
public function getTitle(QUI\Locale $Locale = null): string;
/**
* @param null|QUI\Locale $Locale
* @return string
*/
public function getDescription($Locale = null);
public function getDescription(QUI\Locale $Locale = null): string;
/**
* @return string
*/
public function getIcon();
public function getIcon(): string;
/**
* @return string
* @throws QUI\ERP\Shipping\Exception
* @return ShippingTypeInterface
* @throws Exception
*/
public function getShippingType();
public function getShippingType(): ShippingTypeInterface;
/**
* Return the price of the shipping entry
*
* @return float|int
*/
public function getPrice();
public function getPrice(): float|int;
/**
* Return the price display
*
* @return string
*/
public function getPriceDisplay();
public function getPriceDisplay(): string;
//region attributes
......@@ -62,19 +63,19 @@ public function getPriceDisplay();
* @param string $name
* @return mixed
*/
public function getAttribute($name);
public function getAttribute(string $name): mixed;
/**
* @return array
*/
public function toArray();
public function toArray(): array;
/**
* Return the shipping as an json array
* Return the shipping as a json array
*
* @return string
*/
public function toJSON();
public function toJSON(): string;
//endregion
......@@ -83,7 +84,7 @@ public function toJSON();
/**
* @return bool
*/
public function isActive();
public function isActive(): bool;
/**
* Activate ths shipping entry
......
......@@ -16,18 +16,18 @@ interface ShippingTypeInterface
/**
* @return string
*/
public function getType();
public function getType(): string;
/**
* @param null|QUI\Locale $Locale
* @return string
*/
public function getTitle($Locale = null);
public function getTitle(QUI\Locale $Locale = null): string;
/**
* @return string
*/
public function getIcon();
public function getIcon(): string;
//endregion
......@@ -35,5 +35,5 @@ public function getIcon();
* @param QUI\Locale|null $Locale
* @return array
*/
public function toArray($Locale = null);
public function toArray(QUI\Locale $Locale = null): array;
}
......@@ -2,24 +2,33 @@
namespace QUI\ERP\Shipping\Methods\Digital;
use Exception;
use QUI;
use QUI\ERP\Areas\Utils as AreaUtils;
use QUI\ERP\Products\Handler\Products;
use QUI\ERP\Products\Product\Types\DigitalProduct;
use QUI\ERP\Shipping\Debug;
use QUI\Locale;
use function array_filter;
use function array_map;
use function explode;
use function in_array;
use function is_numeric;
use function trim;
/**
* Class DigitalType
*
* Shipping for digital products that are deliverd via download and/or email.
* Shipping for digital products that are delivered via download and/or email.
*/
class ShippingType extends QUI\ERP\Shipping\Api\AbstractShippingType
{
/**
* @param null $Locale
* @return array|string
* @param Locale|null $Locale
* @return string
*/
public function getTitle($Locale = null)
public function getTitle(?QUI\Locale $Locale = null): string
{
if ($Locale === null) {
$Locale = QUI::getLocale();
......@@ -31,7 +40,7 @@ public function getTitle($Locale = null)
/**
* @return string
*/
public function getIcon()
public function getIcon(): string
{
return QUI\ERP\Shipping\Shipping::getInstance()->getHost() .
URL_OPT_DIR
......@@ -46,7 +55,7 @@ public function getIcon()
public function canUsedInOrder(
QUI\ERP\ErpEntityInterface $Entity,
QUI\ERP\Shipping\Types\ShippingEntry $ShippingEntry
) {
): bool {
if ($ShippingEntry->isActive() === false) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: is not active");
......@@ -62,7 +71,7 @@ public function canUsedInOrder(
foreach ($Entity->getArticles() as $Article) {
try {
// Do not parse coupon codes / discounts
if (empty($Article->getId()) || !\is_numeric($Article->getId())) {
if (empty($Article->getId()) || !is_numeric($Article->getId())) {
continue;
}
......@@ -77,7 +86,7 @@ public function canUsedInOrder(
return false;
}
} catch (\Exception $Exception) {
} catch (Exception $Exception) {
QUI\System\Log::writeDebugException($Exception);
}
}
......@@ -91,13 +100,13 @@ public function canUsedInOrder(
};
if (!empty($articles)) {
$articles = \array_map($toInt, \explode(',', $articles));
$articles = array_map($toInt, explode(',', $articles));
} else {
$articles = [];
}
if (!empty($categories)) {
$categories = \array_map($toInt, \explode(',', $categories));
$categories = array_map($toInt, explode(',', $categories));
} else {
$categories = [];
}
......@@ -116,32 +125,30 @@ public function canUsedInOrder(
try {
$productId = $Article->getId();
if (!empty($articles) && \in_array($productId, $articles)) {
if (!empty($articles) && in_array($productId, $articles)) {
Debug::addLog(
"{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: product {$productId} is in allowed list [ok]"
"{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: product $productId is in allowed list [ok]"
);
return true;
}
if (\is_array($categories)) {
$Product = QUI\ERP\Products\Handler\Products::getProduct($productId);
$articleCategories = $Product->getCategories();
$Product = QUI\ERP\Products\Handler\Products::getProduct($productId);
$articleCategories = $Product->getCategories();
/* @var $Category QUI\ERP\Products\Category\Category */
foreach ($articleCategories as $Category) {
$categoryId = $Category->getId();
/* @var $Category QUI\ERP\Products\Category\Category */
foreach ($articleCategories as $Category) {
$categoryId = $Category->getId();
if (\in_array($categoryId, $categories)) {
Debug::addLog(
"{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: category {$categoryId} is in allowed list [ok]"
);
if (in_array($categoryId, $categories)) {
Debug::addLog(
"{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: category $categoryId is in allowed list [ok]"
);
return true;
}
return true;
}
}
} catch (QUI\Exception $Exception) {
} catch (QUI\Exception) {
return false;
}
}
......@@ -161,7 +168,7 @@ public function canUsedBy(
QUI\Interfaces\Users\User $User,
QUI\ERP\Shipping\Api\ShippingInterface $ShippingEntry,
QUI\ERP\ErpEntityInterface $Entity
) {
): bool {
if ($ShippingEntry->isActive() === false) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: is not active");
......@@ -171,7 +178,7 @@ public function canUsedBy(
if ($User instanceof QUI\ERP\User) {
try {
$User = QUI::getUsers()->get($User->getId());
} catch (QUI\Exception $Exception) {
} catch (QUI\Exception) {
}
}
......@@ -188,10 +195,10 @@ public function canUsedBy(
$Address = $Entity->getDeliveryAddress();
$areasValue = \trim($areasValue);
$areasValue = \trim($areasValue, ',');
$areasValue = \explode(',', $areasValue);
$areasValue = \array_filter($areasValue);
$areasValue = trim($areasValue);
$areasValue = trim($areasValue, ',');
$areasValue = explode(',', $areasValue);
$areasValue = array_filter($areasValue);
// not in area
if (!empty($areasValue) && !AreaUtils::isAddressInArea($Address, $areasValue)) {
......@@ -217,8 +224,8 @@ public function canUsedBy(
// user checking
foreach ($discountUsers as $uid) {
if ($User->getId() == $uid) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: user found {$uid} [OK]");
if ($User->getId() == $uid || $User->getUUID() == $uid) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: user found $uid [OK]");
return true;
}
......@@ -230,8 +237,8 @@ public function canUsedBy(
/* @var $Group QUI\Groups\Group */
foreach ($discountGroups as $gid) {
foreach ($groupsOfUser as $Group) {
if ($Group->getId() == $gid) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: group found {$gid} [OK]");
if ($Group->getId() == $gid || $Group->getUUID() == $gid) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: group found $gid [OK]");
return true;
}
......
......@@ -6,6 +6,7 @@
namespace QUI\ERP\Shipping\Methods\Standard;
use Exception;
use QUI;
use QUI\ERP\Areas\Utils as AreaUtils;
use QUI\ERP\Products\Handler\Products;
......@@ -29,10 +30,10 @@
class ShippingType extends QUI\ERP\Shipping\Api\AbstractShippingType
{
/**
* @param null $Locale
* @return array|string
* @param ?QUI\Locale $Locale
* @return string
*/
public function getTitle($Locale = null)
public function getTitle(?QUI\Locale $Locale = null): string
{
if ($Locale === null) {
$Locale = QUI::getLocale();
......@@ -44,7 +45,7 @@ public function getTitle($Locale = null)
/**
* @return string
*/
public function getIcon()
public function getIcon(): string
{
return QUI\ERP\Shipping\Shipping::getInstance()->getHost() .
URL_OPT_DIR
......@@ -59,7 +60,7 @@ public function getIcon()
public function canUsedInOrder(
QUI\ERP\ErpEntityInterface $Entity,
QUI\ERP\Shipping\Types\ShippingEntry $ShippingEntry
) {
): bool {
if ($ShippingEntry->isActive() === false) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: is not active");
......@@ -72,7 +73,7 @@ public function canUsedInOrder(
try {
$ArticleList = $Entity->getArticles();
} catch (\Exception $exception) {
} catch (Exception) {
return false;
}
......@@ -94,7 +95,7 @@ public function canUsedInOrder(
$digitalProductsOnly = false;
break;
}
} catch (\Exception $Exception) {
} catch (Exception $Exception) {
QUI\System\Log::writeDebugException($Exception);
}
}
......@@ -143,30 +144,28 @@ public function canUsedInOrder(
if (!empty($articles) && in_array($productId, $articles)) {
Debug::addLog(
"{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: product {$productId} is in allowed list [ok]"
"{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: product $productId is in allowed list [ok]"
);
return true;
}
if (is_array($categories)) {
$Product = QUI\ERP\Products\Handler\Products::getProduct($productId);
$articleCategories = $Product->getCategories();
$Product = QUI\ERP\Products\Handler\Products::getProduct($productId);
$articleCategories = $Product->getCategories();
/* @var $Category QUI\ERP\Products\Category\Category */
foreach ($articleCategories as $Category) {
$categoryId = $Category->getId();
/* @var $Category QUI\ERP\Products\Category\Category */
foreach ($articleCategories as $Category) {
$categoryId = $Category->getId();
if (in_array($categoryId, $categories)) {
Debug::addLog(
"{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: category {$categoryId} is in allowed list [ok]"
);
if (in_array($categoryId, $categories)) {
Debug::addLog(
"{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: category $categoryId is in allowed list [ok]"
);
return true;
}
return true;
}
}
} catch (QUI\Exception $Exception) {
} catch (QUI\Exception) {
return false;
}
}
......@@ -186,7 +185,7 @@ public function canUsedBy(
QUI\Interfaces\Users\User $User,
QUI\ERP\Shipping\Api\ShippingInterface $ShippingEntry,
QUI\ERP\ErpEntityInterface $Entity
) {
): bool {
if ($ShippingEntry->isActive() === false) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: is not active");
......@@ -196,7 +195,7 @@ public function canUsedBy(
if ($User instanceof QUI\ERP\User) {
try {
$User = QUI::getUsers()->get($User->getId());
} catch (QUI\Exception $Exception) {
} catch (QUI\Exception) {
}
}
......@@ -244,8 +243,8 @@ public function canUsedBy(
// user checking
foreach ($discountUsers as $uid) {
if ($User->getId() == $uid) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: user found {$uid} [OK]");
if ($User->getId() == $uid || $User->getUUID() == $uid) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: user found $uid [OK]");
return true;
}
......@@ -257,8 +256,8 @@ public function canUsedBy(
/* @var $Group QUI\Groups\Group */
foreach ($discountGroups as $gid) {
foreach ($groupsOfUser as $Group) {
if ($Group->getId() == $gid) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: group found {$gid} [OK]");
if ($Group->getId() == $gid || $Group->getUUID() == $gid) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: group found $gid [OK]");
return true;
}
......
......@@ -13,8 +13,11 @@
use function array_filter;
use function array_flip;
use function is_array;
use function is_int;
use function is_integer;
use function is_numeric;
use function json_encode;
use function mb_strlen;
use const ARRAY_FILTER_USE_KEY;
......@@ -47,8 +50,6 @@ public function __construct()
{
parent::__construct();
$self = $this;
$this->Events->addEvent('onCreateBegin', function () {
Permission::checkPermission('quiqqer.shipping.rule.create');
});
......@@ -61,12 +62,11 @@ public function __construct()
/**
* @param array $data
*
* @return ShippingRule
*
* @throws QUI\Exception
*/
public function createChild($data = [])
public function createChild(array $data = []): QUI\CRUD\Child
{
// filter
$allowed = array_flip([
......@@ -94,21 +94,21 @@ public function createChild($data = [])
}, ARRAY_FILTER_USE_KEY);
if (!isset($data['active']) || !\is_integer($data['active'])) {
if (!isset($data['active']) || !is_integer($data['active'])) {
$data['active'] = 0;
}
if (!isset($data['purchase_quantity_from']) || !\is_integer($data['purchase_quantity_from'])) {
if (!isset($data['purchase_quantity_from']) || !is_integer($data['purchase_quantity_from'])) {
$data['purchase_quantity_from'] = 0;
}
if (!isset($data['purchase_quantity_until']) || !\is_integer($data['purchase_quantity_until'])) {
if (!isset($data['purchase_quantity_until']) || !is_integer($data['purchase_quantity_until'])) {
$data['purchase_quantity_until'] = 0;
}
if (!isset($data['priority']) || !is_numeric($data['priority'])) {
$data['priority'] = 0;
} elseif (!\is_int($data['priority'])) {
} elseif (!is_int($data['priority'])) {
$data['priority'] = (int)$data['priority'];
}
......@@ -165,8 +165,6 @@ public function createChild($data = [])
$data['discount_type'] = RuleFactory::DISCOUNT_TYPE_ABS;
}
$attributes['discount'] = \floatval($data['discount']);
// start creating
QUI::getEvents()->fireEvent('shippingRuleCreateBegin', [$data]);
......@@ -188,11 +186,11 @@ public function createChild($data = [])
);
// set translations
if (isset($data['title']) && !empty($data['title']) && is_array($data['title'])) {
if (!empty($data['title']) && is_array($data['title'])) {
$title = [];
foreach ($data['title'] as $lang => $v) {
if (\mb_strlen($lang) === 2) {
if (mb_strlen($lang) === 2) {
$title[$lang] = $v;
}
}
......@@ -205,11 +203,11 @@ public function createChild($data = [])
);
}
if (isset($data['workingTitle']) && !empty($data['workingTitle']) && is_array($data['workingTitle'])) {
if (!empty($data['workingTitle']) && is_array($data['workingTitle'])) {
$title = [];
foreach ($data['workingTitle'] as $lang => $v) {
if (\mb_strlen($lang) === 2) {
if (mb_strlen($lang) === 2) {
$title[$lang] = $v;
}
}
......@@ -237,7 +235,7 @@ public function createChild($data = [])
/**
* @return string
*/
public function getDataBaseTableName()
public function getDataBaseTableName(): string
{
return 'shipping_rules';
}
......@@ -245,7 +243,7 @@ public function getDataBaseTableName()
/**
* @return string
*/
public function getChildClass()
public function getChildClass(): string
{
return ShippingRule::class;
}
......@@ -253,7 +251,7 @@ public function getChildClass()
/**
* @return array
*/
public function getChildAttributes()
public function getChildAttributes(): array
{
return [
'id',
......@@ -290,7 +288,7 @@ public function getChildAttributes()
*
* @throws QUI\Exception
*/
public function getChild($id)
public function getChild($id): QUI\CRUD\Child
{
/* @var QUI\ERP\Shipping\Api\AbstractShippingEntry $Shipping */
$Shipping = parent::getChild($id);
......@@ -304,7 +302,7 @@ public function getChild($id)
* @param $var
* @param $title
*/
protected function createShippingLocale($var, $title)
protected function createShippingLocale($var, $title): void
{
$current = QUI::getLocale()->getCurrent();
......
......@@ -26,8 +26,6 @@ public function __construct()
{
parent::__construct();
$self = $this;
$this->Events->addEvent('onCreateBegin', function () {
Permission::checkPermission('quiqqer.shipping.create');
});
......@@ -46,7 +44,7 @@ public function __construct()
* @throws QUI\ERP\Shipping\Exception
* @throws QUI\Exception
*/
public function createChild($data = [])
public function createChild(array $data = []): QUI\CRUD\Child
{
if (!isset($data['active']) || !is_integer($data['active'])) {
$data['active'] = 0;
......@@ -96,7 +94,7 @@ public function createChild($data = [])
/**
* @return string
*/
public function getDataBaseTableName()
public function getDataBaseTableName(): string
{
return 'shipping';
}
......@@ -104,7 +102,7 @@ public function getDataBaseTableName()
/**
* @return string
*/
public function getChildClass()
public function getChildClass(): string
{
return ShippingEntry::class;
}
......@@ -112,7 +110,7 @@ public function getChildClass()
/**
* @return array
*/
public function getChildAttributes()
public function getChildAttributes(): array
{
return [
'id',
......@@ -136,7 +134,7 @@ public function getChildAttributes()
*
* @throws QUI\Exception
*/
public function getChild($id)
public function getChild($id): QUI\CRUD\Child
{
/* @var QUI\ERP\Shipping\Types\ShippingEntry $Shipping */
$Shipping = parent::getChild($id);
......@@ -150,7 +148,7 @@ public function getChild($id)
* @param $var
* @param $title
*/
protected function createShippingLocale($var, $title)
protected function createShippingLocale($var, $title): void
{
if (QUI::getLocale()->isLocaleString($title)) {
$parts = QUI::getLocale()->getPartsOfLocaleString($title);
......@@ -166,7 +164,7 @@ protected function createShippingLocale($var, $title)
try {
QUI\Translator::add('quiqqer/shipping', $var, 'quiqqer/shipping', 'php,js');
QUI\Translator::add('quiqqer/shipping', $var, 'quiqqer/shipping');
QUI\Translator::update('quiqqer/shipping', $var, 'quiqqer/shipping', $data);
} catch (QUI\Exception $Exception) {
QUI\System\Log::addNotice($Exception->getMessage());
......
......@@ -13,6 +13,7 @@
use QUI\ERP\Shipping\Rules\Factory as RuleFactory;
use QUI\ERP\Shipping\Rules\ShippingRule;
use QUI\Exception;
use QUI\Locale;
use QUI\Permissions\Permission;
use QUI\Translator;
......@@ -41,7 +42,7 @@ class ShippingEntry extends QUI\CRUD\Child implements Api\ShippingInterface
/**
* @var null|QUI\ERP\Address|QUI\Users\Address
*/
protected $Address = null;
protected QUI\Users\Address|QUI\ERP\Address|null $Address = null;
/**
* Shipping constructor.
......@@ -217,7 +218,7 @@ public function getPriceDisplay(): string
try {
$price = $DefaultCurrency->convert($price, $UserCurrency);
$Price = new QUI\ERP\Money\Price($price, $UserCurrency);
} catch (Exception $exception) {
} catch (Exception) {
$Price = new QUI\ERP\Money\Price($price, $DefaultCurrency);
}
} else {
......@@ -257,7 +258,7 @@ public function getPriceDisplay(): string
*
* @return float|int
*/
public function getPrice()
public function getPrice(): float|int
{
$rules = $this->getShippingRules();
$price = 0;
......@@ -274,22 +275,18 @@ public function getPrice()
}
if ($type === QUI\ERP\Shipping\Rules\Factory::DISCOUNT_TYPE_PC_ORDER && $ErpEntity) {
try {
$ErpEntity = $this->ErpEntity;
$Calculation = $ErpEntity->getPriceCalculation();
$nettoSum = $Calculation->getNettoSum()->get();
if (!$nettoSum) {
continue;
}
$pc = round($nettoSum * ($discount / 100));
$price = $price + $pc;
$ErpEntity = $this->ErpEntity;
$Calculation = $ErpEntity->getPriceCalculation();
$nettoSum = $Calculation->getNettoSum()->get();
if (!$nettoSum) {
continue;
} catch (Exception $Exception) {
QUI\System\Log::addDebug($Exception->getMessage());
}
$pc = round($nettoSum * ($discount / 100));
$price = $price + $pc;
continue;
}
$pc = round($price * ($discount / 100));
......@@ -325,7 +322,7 @@ public function canUsedBy(
if (method_exists($ShippingType, 'canUsedBy')) {
return $ShippingType->canUsedBy($User, $this, $Entity);
}
} catch (Exception $Exception) {
} catch (Exception) {
return false;
}
......@@ -353,7 +350,7 @@ public function canUsedInErpEntity(QUI\ERP\ErpEntityInterface $Entity): bool
if (method_exists($ShippingType, 'canUsedIn')) {
return $ShippingType->canUsedIn($Entity, $this);
}
} catch (Exception $Exception) {
} catch (Exception) {
return false;
}
......@@ -365,7 +362,7 @@ public function canUsedInErpEntity(QUI\ERP\ErpEntityInterface $Entity): bool
*
* @throws QUI\ExceptionStack|Exception
*/
public function activate()
public function activate(): void
{
$this->setAttribute('active', 1);
$this->update();
......@@ -387,7 +384,7 @@ public function isActive(): bool
*
* @throws QUI\ExceptionStack|Exception
*/
public function deactivate()
public function deactivate(): void
{
$this->setAttribute('active', 0);
$this->update();
......@@ -399,10 +396,10 @@ public function deactivate()
/**
* Return the shipping title
*
* @param null $Locale
* @return array|string
* @param null|Locale $Locale
* @return string
*/
public function getTitle($Locale = null)
public function getTitle(QUI\Locale $Locale = null): string
{
if ($Locale === null) {
$Locale = QUI::getLocale();
......@@ -418,9 +415,9 @@ public function getTitle($Locale = null)
* Return the shipping description
*
* @param null $Locale
* @return array|string
* @return string
*/
public function getDescription($Locale = null)
public function getDescription($Locale = null): string
{
if ($Locale === null) {
$Locale = QUI::getLocale();
......@@ -438,7 +435,7 @@ public function getDescription($Locale = null)
* @param null $Locale
* @return array|string
*/
public function getWorkingTitle($Locale = null)
public function getWorkingTitle($Locale = null): array|string
{
if ($Locale === null) {
$Locale = QUI::getLocale();
......@@ -484,7 +481,7 @@ public function getIcon(): string
*
* @param array $titles
*/
public function setTitle(array $titles)
public function setTitle(array $titles): void
{
$this->setShippingLocale(
'shipping.' . $this->getId() . '.title',
......@@ -497,7 +494,7 @@ public function setTitle(array $titles)
*
* @param array $descriptions
*/
public function setDescription(array $descriptions)
public function setDescription(array $descriptions): void
{
$this->setShippingLocale(
'shipping.' . $this->getId() . '.description',
......@@ -510,7 +507,7 @@ public function setDescription(array $descriptions)
*
* @param array $titles
*/
public function setWorkingTitle(array $titles)
public function setWorkingTitle(array $titles): void
{
$this->setShippingLocale(
'shipping.' . $this->getId() . '.workingTitle',
......@@ -521,7 +518,7 @@ public function setWorkingTitle(array $titles)
/**
* @param string $icon - image.php?
*/
public function setIcon(string $icon)
public function setIcon(string $icon): void
{
if (QUI\Projects\Media\Utils::isMediaUrl($icon)) {
$this->setAttribute('icon', $icon);
......@@ -531,7 +528,7 @@ public function setIcon(string $icon)
/**
* Remove the shipping entry icon
*/
public function removeIcon()
public function removeIcon(): void
{
$this->setAttribute('icon', false);
}
......@@ -542,7 +539,7 @@ public function removeIcon()
* @param string $var
* @param array $title
*/
protected function setShippingLocale(string $var, array $title)
protected function setShippingLocale(string $var, array $title): void
{
$data = [
'datatype' => 'php,js',
......@@ -586,7 +583,7 @@ protected function setShippingLocale(string $var, array $title)
/**
* @param ShippingRule $Rule
*/
public function addShippingRule(ShippingRule $Rule)
public function addShippingRule(ShippingRule $Rule): void
{
$shippingRules = $this->getAttribute('shipping_rules');
$shippingRules = json_decode($shippingRules, true);
......@@ -608,7 +605,7 @@ public function addShippingRule(ShippingRule $Rule)
* @param integer $shippingRuleId
* @throws Exception
*/
public function addShippingRuleId(int $shippingRuleId)
public function addShippingRuleId(int $shippingRuleId): void
{
/* @var $Rule ShippingRule */
$Rule = RuleFactory::getInstance()->getChild($shippingRuleId);
......@@ -779,7 +776,7 @@ public function isValid(): bool
*
* @param QUI\ERP\ErpEntityInterface $ErpEntity
*/
public function setErpEntity(QUI\ERP\ErpEntityInterface $ErpEntity)
public function setErpEntity(QUI\ERP\ErpEntityInterface $ErpEntity): void
{
$this->ErpEntity = $ErpEntity;
}
......@@ -787,7 +784,7 @@ public function setErpEntity(QUI\ERP\ErpEntityInterface $ErpEntity)
/**
* @deprecated use setErpEntity()
*/
public function setOrder(QUI\ERP\ErpEntityInterface $ErpEntity)
public function setOrder(QUI\ERP\ErpEntityInterface $ErpEntity): void
{
$this->setErpEntity($ErpEntity);
}
......@@ -816,7 +813,7 @@ public function toPriceFactor(
if ($DefaultCurrency->getCode() !== $EntityCurrency->getCode()) {
try {
$price = $DefaultCurrency->convert($price, $EntityCurrency);
} catch (Exception $exception) {
} catch (Exception) {
}
}
......@@ -858,7 +855,7 @@ public function toPriceFactor(
/**
* @param $Address
*/
public function setAddress($Address)
public function setAddress($Address): void
{
$this->Address = $Address;
}
......@@ -866,7 +863,7 @@ public function setAddress($Address)
/**
* Return the address
*/
public function getAddress()
public function getAddress(): QUI\ERP\Address|QUI\Users\Address|null
{
return $this->Address;
}
......
......@@ -6,9 +6,16 @@
use QUI\ERP\Shipping\Api;
use QUI\ERP\Shipping\Api\ShippingInterface;
use QUI\ERP\Shipping\Api\ShippingTypeInterface;
use QUI\ERP\Shipping\Exception;
use function class_exists;
use function floatval;
use function json_encode;
/**
* Class ShippingUnique
* - This class represent a Shipping Entry, but its only a database container
* - This class represent a Shipping Entry, but it's only a database container
* - This shipping is created from pure shipping data, for example an invoice.
* - This shipping cannot perform database operations.
*
......@@ -19,22 +26,22 @@ class ShippingUnique implements ShippingInterface
/**
* @var array
*/
protected $attributes = [];
protected array $attributes = [];
/**
* ShippingUnique constructor.
*
* @param array $attributes - shipping data
*/
public function __construct($attributes = [])
public function __construct(array $attributes = [])
{
$this->attributes = $attributes;
}
/**
* @return int
* @return int|string
*/
public function getId()
public function getId(): int|string
{
if (isset($this->attributes['id'])) {
return $this->attributes['id'];
......@@ -47,7 +54,7 @@ public function getId()
* @param null|QUI\Locale $Locale
* @return string
*/
public function getTitle($Locale = null)
public function getTitle($Locale = null): string
{
if ($Locale === null) {
$Locale = QUI::getLocale();
......@@ -66,7 +73,7 @@ public function getTitle($Locale = null)
* @param null|QUI\Locale $Locale
* @return string
*/
public function getDescription($Locale = null)
public function getDescription($Locale = null): string
{
if ($Locale === null) {
$Locale = QUI::getLocale();
......@@ -84,7 +91,7 @@ public function getDescription($Locale = null)
/**
* @return string
*/
public function getIcon()
public function getIcon(): string
{
if (isset($this->attributes['icon'])) {
return $this->attributes['icon'];
......@@ -98,7 +105,7 @@ public function getIcon()
*
* @return string
*/
public function getPriceDisplay()
public function getPriceDisplay(): string
{
$Price = new QUI\ERP\Money\Price(
$this->getPrice(),
......@@ -113,24 +120,24 @@ public function getPriceDisplay()
*
* @return float|int
*/
public function getPrice()
public function getPrice(): float|int
{
if (isset($this->attributes['price'])) {
return \floatval($this->attributes['price']);
return floatval($this->attributes['price']);
}
return 0;
}
/**
* @return string
* @throws QUI\ERP\Shipping\Exception
* @return ShippingTypeInterface
* @throws Exception
*/
public function getShippingType()
public function getShippingType(): Api\ShippingTypeInterface
{
$type = $this->getAttribute('shipping_type');
if (!\class_exists($type)) {
if (!class_exists($type)) {
throw new QUI\ERP\Shipping\Exception([
'quiqqer/shipping',
'exception.shipping.type.not.found',
......@@ -157,7 +164,7 @@ public function getShippingType()
* @param string $name
* @return mixed
*/
public function getAttribute($name)
public function getAttribute(string $name): mixed
{
if (isset($this->attributes[$name])) {
return $this->attributes[$name];
......@@ -169,19 +176,19 @@ public function getAttribute($name)
/**
* @return array
*/
public function toArray()
public function toArray(): array
{
return $this->attributes;
}
/**
* Return the shipping as an json array
* Return the shipping as a json array
*
* @return string
*/
public function toJSON()
public function toJSON(): string
{
return \json_encode($this->toArray());
return json_encode($this->toArray());
}
//endregion
......@@ -191,7 +198,7 @@ public function toJSON()
/**
* @return bool
*/
public function isActive()
public function isActive(): bool
{
return true;
}
......
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