From d75b6a6e52be1d3635ef2fc435082794becc88a4 Mon Sep 17 00:00:00 2001 From: Daniel defdac Larsson <58037739+Daniel-Ateles@users.noreply.github.com> Date: Mon, 15 Apr 2024 10:39:22 +0200 Subject: [PATCH] Array flip makes voucher strings to int (#161) * Update Rule.php Sometimes legacy data could trigger an exception because of null-values. * [bugfix] cast because of stronger typing When adding voucher-tokens that are all numbers the array_flip function will make then int's so we need to cast to string in OrderManager. We also need to cast to int when reading configuration->getUsages() because it returns string. * Revert "Update Rule.php" This reverts commit 309e6adbfa1d9a415c9404e8a682ae7e6ae52a73. --- src/OrderManager/V7/OrderManager.php | 2 +- src/VoucherService/TokenManager/Single.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OrderManager/V7/OrderManager.php b/src/OrderManager/V7/OrderManager.php index e56fa54d..b0c92eb3 100644 --- a/src/OrderManager/V7/OrderManager.php +++ b/src/OrderManager/V7/OrderManager.php @@ -708,7 +708,7 @@ protected function applyVoucherTokens(AbstractOrder $order, CartInterface $cart) //add new tokens - which are the remaining entries of $flippedVoucherTokens foreach ($flippedVoucherTokens as $code => $x) { - $this->voucherService->applyToken($code, $cart, $order); + $this->voucherService->applyToken((string)$code, $cart, $order); } } } diff --git a/src/VoucherService/TokenManager/Single.php b/src/VoucherService/TokenManager/Single.php index 4ff915a7..9c64adc2 100644 --- a/src/VoucherService/TokenManager/Single.php +++ b/src/VoucherService/TokenManager/Single.php @@ -208,7 +208,7 @@ public function reserveToken(string $code, CartInterface $cart): bool public function applyToken(string $code, CartInterface $cart, AbstractOrder $order): OnlineShopVoucherToken|bool { if ($token = Token::getByCode($code)) { - if ($token->check($this->configuration->getUsages(), true)) { + if ($token->check((int)$this->configuration->getUsages(), true)) { if ($token->apply()) { $orderToken = \Pimcore\Model\DataObject\OnlineShopVoucherToken::getByToken($code, 1); if (!$orderToken instanceof \Pimcore\Model\DataObject\OnlineShopVoucherToken) {