Skip to content

Commit

Permalink
Array flip makes voucher strings to int (#161)
Browse files Browse the repository at this point in the history
* 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 309e6ad.
  • Loading branch information
Daniel-Ateles authored Apr 15, 2024
1 parent 3c4645e commit d75b6a6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/OrderManager/V7/OrderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/VoucherService/TokenManager/Single.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d75b6a6

Please sign in to comment.