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

feat: use user / group uuids

Übergeordneter fe49e667
No related branches found
No related tags found
3 Merge Requests!8fix(CouponCodeInput): mobile buttons adjusted,!7fix(CouponCodeInput): mobile buttons adjusted,!3feat!: quiqqer v2
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
use function in_array; use function in_array;
use function is_array; use function is_array;
use function is_null; use function is_null;
use function is_numeric;
use function json_decode; use function json_decode;
use function json_encode; use function json_encode;
use function method_exists; use function method_exists;
...@@ -154,10 +155,30 @@ public function __construct(int $id) ...@@ -154,10 +155,30 @@ public function __construct(int $id)
$this->userIds = json_decode($data['userIds'], true); $this->userIds = json_decode($data['userIds'], true);
} }
// migrate user ids
foreach ($this->userIds as $k => $userId) {
if (is_numeric($userId)) {
try {
$this->userIds[$k] = QUI::getUsers()->get($userId)->getUUID();
} catch (QUI\Exception) {
}
}
}
if (!empty($data['groupIds'])) { if (!empty($data['groupIds'])) {
$this->groupIds = json_decode($data['groupIds'], true); $this->groupIds = json_decode($data['groupIds'], true);
} }
// migrate user ids
foreach ($this->groupIds as $k => $groupId) {
if (is_numeric($groupId)) {
try {
$this->groupIds[$k] = QUI::getGroups()->get($groupId)->getUUID();
} catch (QUI\Exception) {
}
}
}
if (!empty($data['maxUsages'])) { if (!empty($data['maxUsages'])) {
$this->maxUsages = $data['maxUsages']; $this->maxUsages = $data['maxUsages'];
} }
...@@ -293,7 +314,7 @@ public function redeem(QUI\Interfaces\Users\User $User = null, QUI\ERP\Order\Ord ...@@ -293,7 +314,7 @@ public function redeem(QUI\Interfaces\Users\User $User = null, QUI\ERP\Order\Ord
$Now = new DateTime(); $Now = new DateTime();
$usage = [ $usage = [
'userId' => $User->getId(), 'userId' => $User->getUUID(),
'date' => $Now->format('Y-m-d H:i:s'), 'date' => $Now->format('Y-m-d H:i:s'),
'orderPrefixedId' => false 'orderPrefixedId' => false
]; ];
...@@ -396,7 +417,7 @@ public function checkRedemption(QUI\Interfaces\Users\User $User) ...@@ -396,7 +417,7 @@ public function checkRedemption(QUI\Interfaces\Users\User $User)
// Restriction to QUIQQER user(s) // Restriction to QUIQQER user(s)
if (!empty($this->userIds)) { if (!empty($this->userIds)) {
if (in_array($User->getId(), $this->userIds)) { if (in_array($User->getUUID(), $this->userIds)) {
if ( if (
$this->maxUsages !== Handler::MAX_USAGE_UNLIMITED $this->maxUsages !== Handler::MAX_USAGE_UNLIMITED
&& $this->hasUserRedeemed($User) && $this->hasUserRedeemed($User)
...@@ -539,7 +560,7 @@ public function isValid(): bool ...@@ -539,7 +560,7 @@ public function isValid(): bool
*/ */
public function hasUserRedeemed(QUI\Interfaces\Users\User $User): bool public function hasUserRedeemed(QUI\Interfaces\Users\User $User): bool
{ {
$userId = $User->getId(); $userId = $User->getUUID();
foreach ($this->usages as $usage) { foreach ($this->usages as $usage) {
if ($usage['userId'] === $userId) { if ($usage['userId'] === $userId) {
......
...@@ -111,8 +111,8 @@ public static function createCouponCodesFromOrder(QUI\ERP\Order\AbstractOrder $O ...@@ -111,8 +111,8 @@ public static function createCouponCodesFromOrder(QUI\ERP\Order\AbstractOrder $O
\rename($couponPdfFile, $newCouponPdfFile); \rename($couponPdfFile, $newCouponPdfFile);
// Add PDF file to customer files // Add PDF file to customer files
CustomerFiles::addFileToCustomer($Customer->getId(), $newCouponPdfFile); CustomerFiles::addFileToCustomer($Customer->getUUID(), $newCouponPdfFile);
CustomerFiles::addFileToDownloadEntry($Customer->getId(), \basename($newCouponPdfFile)); CustomerFiles::addFileToDownloadEntry($Customer->getUUID(), \basename($newCouponPdfFile));
$customerDir = CustomerFiles::getFolderPath($Customer); $customerDir = CustomerFiles::getFolderPath($Customer);
$couponFilePathCustomerDir = $customerDir . DIRECTORY_SEPARATOR . \basename($newCouponPdfFile); $couponFilePathCustomerDir = $customerDir . DIRECTORY_SEPARATOR . \basename($newCouponPdfFile);
...@@ -210,7 +210,7 @@ protected static function createCouponCodeFromProduct( ...@@ -210,7 +210,7 @@ protected static function createCouponCodeFromProduct(
$isTransferable = $Product->getFieldValue(self::PRODUCT_FIELD_ID_TRANSFERABLE); $isTransferable = $Product->getFieldValue(self::PRODUCT_FIELD_ID_TRANSFERABLE);
if (empty($isTransferable)) { if (empty($isTransferable)) {
$couponAttributes['userIds'] = [$User->getId()]; $couponAttributes['userIds'] = [$User->getUUID()];
} }
} }
......
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren