Skip to content
Commits auf Quelle (3)
  • Henning Leutz's avatar
    fix(Basket): improve basket id handling and user check in Basket.php · 30906ba4
    verfasst von Henning Leutz
    Added a conditional check in src/QUI/ERP/Order/Basket/Basket.php to convert basketId to actual id
    from user's session if it is a boolean value. This fixes potential issues that may arise with
    non-integer basketIds.
    
    Also, introduced a safeguard check before saving to ensure there is a valid User. If not, the save
    function is exited early to prevent potential errors or undesired actions.
    30906ba4
  • Henning Leutz's avatar
    refactor: update union types with null · ca954d77
    verfasst von Henning Leutz
    Improve readability and interpretability of code by explicitly stating null in union types. This
    change has been applied across multiple files and functions.
    
    PHP8.4 compatibility
    ca954d77
  • Henning Leutz's avatar
    Merge branch 'next-2.x' into 'main' · a2a73f70
    verfasst von Henning Leutz
    fix(Basket): improve basket id handling and user check in Basket.php
    
    See merge request !138
    a2a73f70
......@@ -62,7 +62,7 @@ class Basket
* @param ?QUI\Interfaces\Users\User $User
* @throws ExceptionStack
*/
public function __construct(bool|int $basketId, QUI\Interfaces\Users\User $User = null)
public function __construct(bool | int $basketId, null | QUI\Interfaces\Users\User $User = null)
{
if (!$User) {
$User = QUI::getUserBySession();
......@@ -78,6 +78,14 @@ public function __construct(bool|int $basketId, QUI\Interfaces\Users\User $User
$this->List->setUser($User);
$this->FrontendMessages = new QUI\ERP\Comments();
if (is_bool($basketId)) {
try {
$Basket = Handler::getInstance()->getBasketFromUser(QUI::getUserBySession());
$basketId = $Basket->getId();
} catch (QUI\Exception) {
}
}
try {
$data = Handler::getInstance()->getBasketData($basketId, $User);
} catch (QUI\Exception $Exception) {
......@@ -220,6 +228,10 @@ public function save(): void
return;
}
if (!$this->User) {
return;
}
// save only product ids with custom fields, we need not more
$result = [];
$products = $this->List->getProducts();
......
......@@ -66,7 +66,7 @@ class BasketOrder
* @throws Exception
* @throws QUI\Exception
*/
public function __construct(string $orderHash, QUI\Interfaces\Users\User $User = null)
public function __construct(string $orderHash, null | QUI\Interfaces\Users\User $User = null)
{
if (!$User) {
$User = QUI::getUserBySession();
......
......@@ -20,7 +20,7 @@ abstract class AbstractOrderingStep extends QUI\Control implements OrderingStepI
* @param Locale|null $Locale
* @return string
*/
public function getTitle(QUI\Locale $Locale = null): string
public function getTitle(null | QUI\Locale $Locale = null): string
{
if ($Locale === null) {
$Locale = QUI::getLocale();
......
......@@ -71,7 +71,7 @@ public function __construct(array $attributes = [])
* @param null|QUI\Locale $Locale
* @return string
*/
public function getName(QUI\Locale $Locale = null): string
public function getName(null | QUI\Locale $Locale = null): string
{
return 'Basket';
}
......
......@@ -183,7 +183,7 @@ public function getBody(): string
* @param null|QUI\Locale $Locale
* @return string
*/
public function getName(QUI\Locale $Locale = null): string
public function getName(null | QUI\Locale $Locale = null): string
{
return 'Customer';
}
......
......@@ -40,7 +40,7 @@ public function getBody(): string
* @param null|Locale $Locale
* @return string
*/
public function getName(Locale $Locale = null): string
public function getName(null | Locale $Locale = null): string
{
return 'Delivery';
}
......
......@@ -138,7 +138,7 @@ public function setProcessingProvider(QUI\ERP\Order\AbstractOrderProcessProvider
* @param null|QUI\Locale $Locale
* @return string
*/
public function getName($Locale = null): string
public function getName(null | QUI\Locale $Locale = null): string
{
return 'Processing';
}
......@@ -203,7 +203,7 @@ public function savePayment($payment): void
* @param Locale|null $Locale
* @return string
*/
public function getTitle(QUI\Locale $Locale = null): string
public function getTitle(null | QUI\Locale $Locale = null): string
{
if (!empty($this->title)) {
return $this->title;
......@@ -254,7 +254,7 @@ public function setContent(string $content): void
* @param Locale|null $Locale
* @return string|null
*/
public function getContent(QUI\Locale $Locale = null): ?string
public function getContent(null | QUI\Locale $Locale = null): ?string
{
if ($Locale === null) {
$Locale = QUI::getLocale();
......
......@@ -17,13 +17,13 @@ interface OrderingStepInterface
* @param null|Locale $Locale
* @return string
*/
public function getName(Locale $Locale = null): string;
public function getName(null | Locale $Locale = null): string;
/**
* @param null|Locale $Locale $Locale
* @return mixed
*/
public function getTitle(Locale $Locale = null): mixed;
public function getTitle(null | Locale $Locale = null): mixed;
/**
* @throws Exception
......
......@@ -36,7 +36,7 @@ class Factory extends QUI\Utils\Singleton
* @throws QUI\ERP\Order\Exception
*/
public function create(
QUI\Interfaces\Users\User $PermissionUser = null,
null | QUI\Interfaces\Users\User $PermissionUser = null,
bool | string $hash = false,
?int $id = null,
string $globalProcessId = ''
......@@ -162,7 +162,7 @@ public function createOrderProcess($PermissionUser = null): OrderInProcess
* @throws QUI\Exception
* @throws QUI\ERP\Order\Exception
*/
public function createOrderInProcess(QUI\Interfaces\Users\User $PermissionUser = null): OrderInProcess
public function createOrderInProcess(null | QUI\Interfaces\Users\User $PermissionUser = null): OrderInProcess
{
if ($PermissionUser === null) {
$PermissionUser = QUI::getUserBySession();
......@@ -185,7 +185,7 @@ public function createOrderInProcess(QUI\Interfaces\Users\User $PermissionUser =
* @return int - OrderInProcess ID
* @throws QUI\Database\Exception
*/
public function createOrderInProcessDataBaseEntry(QUI\Interfaces\Users\User $PermissionUser = null): int
public function createOrderInProcessDataBaseEntry(null | QUI\Interfaces\Users\User $PermissionUser = null): int
{
if ($PermissionUser === null) {
$PermissionUser = QUI::getUserBySession();
......
......@@ -916,7 +916,7 @@ public function getBasketFromUser(QUI\Interfaces\Users\User $User): Basket
* @throws QUI\Database\Exception
* @throws QUI\Exception
*/
public function getBasketData(int|string $basketId, QUI\Interfaces\Users\User $User = null): array
public function getBasketData(int | string $basketId, null | QUI\Interfaces\Users\User $User = null): array
{
if ($User === null) {
$User = QUI::getUserBySession();
......
......@@ -24,7 +24,7 @@ class Order implements NumberRangeInterface
*
* @return string
*/
public function getTitle(QUI\Locale $Locale = null): string
public function getTitle(null | QUI\Locale $Locale = null): string
{
if ($Locale === null) {
$Locale = QUI::getLocale();
......
......@@ -976,8 +976,9 @@ public function getLastStep(): mixed
*
* @throws Exception
*/
public function getNextStep(AbstractOrderingStep $StartStep = null): FinishControl|bool|AbstractOrderingStep
{
public function getNextStep(
null | AbstractOrderingStep $StartStep = null
): FinishControl | bool | AbstractOrderingStep {
if ($StartStep === null) {
$step = $this->getCurrentStepName();
} else {
......@@ -1038,7 +1039,7 @@ public function getNextStep(AbstractOrderingStep $StartStep = null): FinishContr
* @throws Exception
* @throws QUI\Exception
*/
public function getPreviousStep(AbstractOrderingStep $StartStep = null): ?AbstractOrderingStep
public function getPreviousStep(null | AbstractOrderingStep $StartStep = null): ?AbstractOrderingStep
{
if ($StartStep === null) {
$step = $this->getCurrentStepName();
......@@ -1148,7 +1149,7 @@ protected function getCurrentStepName(): string
* @throws Exception
* @throws QUI\Exception
*/
protected function getNextStepName(AbstractOrderingStep $StartStep = null): bool|string
protected function getNextStepName(null | AbstractOrderingStep $StartStep = null): bool | string
{
$Next = $this->getNextStep($StartStep);
......@@ -1168,7 +1169,7 @@ protected function getNextStepName(AbstractOrderingStep $StartStep = null): bool
* @throws Exception
* @throws QUI\Exception
*/
protected function getPreviousStepName(AbstractOrderingStep $StartStep = null): bool|string
protected function getPreviousStepName(null | AbstractOrderingStep $StartStep = null): bool | string
{
$Prev = $this->getPreviousStep($StartStep);
......
......@@ -42,7 +42,7 @@ public static function getType(): string
* @param Locale|null $Locale $Locale (optional) - If omitted use \QUI::getLocale()
* @return string
*/
public static function getTypeTitle(Locale $Locale = null): string
public static function getTypeTitle(null | Locale $Locale = null): string
{
if (empty($Locale)) {
$Locale = QUI::getLocale();
......
......@@ -271,8 +271,11 @@ public function createNotificationTranslations(int $id): void
*
* @throws QUI\Exception
*/
public function sendStatusChangeNotification(AbstractOrder $Order, int $statusId, string $message = null): void
{
public function sendStatusChangeNotification(
AbstractOrder $Order,
int $statusId,
null | string $message = null
): void {
$Customer = $Order->getCustomer();
$customerEmail = $Customer->getAttribute('email');
......
......@@ -85,7 +85,7 @@ public function getId(): int
* @param null|QUI\Locale $Locale (optional) $Locale
* @return string
*/
public function getTitle(QUI\Locale $Locale = null): string
public function getTitle(null | QUI\Locale $Locale = null): string
{
if (!($Locale instanceof QUI\Locale)) {
$Locale = QUI::getLocale();
......@@ -101,7 +101,7 @@ public function getTitle(QUI\Locale $Locale = null): string
* @param QUI\Locale|null $Locale (optional) - [default: QUI::getLocale()]
* @return string
*/
public function getStatusChangeNotificationText(AbstractOrder $Order, QUI\Locale $Locale = null): string
public function getStatusChangeNotificationText(AbstractOrder $Order, null | QUI\Locale $Locale = null): string
{
if (!($Locale instanceof QUI\Locale)) {
$Locale = QUI::getLocale();
......@@ -155,7 +155,7 @@ public function isAutoNotification(): bool
* @param null|QUI\Locale $Locale - optional. if no locale, all translations would be returned
* @return array
*/
public function toArray(QUI\Locale $Locale = null): array
public function toArray(null | QUI\Locale $Locale = null): array
{
$title = $this->getTitle($Locale);
$statusChangeText = [];
......
......@@ -43,7 +43,7 @@ public function __construct()
* @param null|QUI\Locale $Locale (optional) $Locale
* @return string
*/
public function getTitle(QUI\Locale $Locale = null): string
public function getTitle(null | QUI\Locale $Locale = null): string
{
if (!($Locale instanceof QUI\Locale)) {
$Locale = QUI::getLocale();
......