Skip to content
Code-Schnipsel Gruppen Projekte

fix(Basket): improve basket id handling and user check in Basket.php

Zusammengeführt Henning Leutz requested to merge next-2.x into main
16 Dateien
+ 76
60
Änderungen vergleichen
  • Nebeneinander
  • In der Reihe
Dateien
16
@@ -31,7 +31,7 @@ class Basket
*
* @var integer|bool
*/
protected int|bool $id = false;
protected int | bool $id = false;
/**
* List of products
@@ -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) {
@@ -102,7 +110,7 @@ public function __construct(bool|int $basketId, QUI\Interfaces\Users\User $User
*
* @return bool|int
*/
public function getId(): bool|int
public function getId(): bool | int
{
return $this->id;
}
@@ -166,13 +174,13 @@ public function addProduct(Product $Product): void
//endregion
/**
/**
* Import the products to the basket
*
* @param array|null $products
* @throws ExceptionStack
*/
public function import(array|null $products = []): void
public function import(array | null $products = []): void
{
$this->clear();
@@ -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();
Lade