Skip to content

Commit 150f248

Browse files
committed
PurchaseService fix
1 parent 7c4e213 commit 150f248

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

changelog.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [9.0.1] - 2022-05-19
10+
### Fixed
11+
- Fixed a bug that prevented items from being returned via `Cart::withItem`
12+
913
## [9.0.0] - 2022-05-02 [#481](https://github.com/bavix/laravel-wallet/pull/481)
1014
### Added
1115
- ExtraDtoInterface #479
@@ -868,7 +872,8 @@ The operation is now executed in the transaction and updates the new `refund` fi
868872
- Exceptions: AmountInvalid, BalanceIsEmpty.
869873
- Models: Transfer, Transaction.
870874

871-
[Unreleased]: https://github.com/bavix/laravel-wallet/compare/9.0.0...develop
875+
[Unreleased]: https://github.com/bavix/laravel-wallet/compare/9.0.1...develop
876+
[9.0.1]: https://github.com/bavix/laravel-wallet/compare/9.0.0...9.0.1
872877
[9.0.0]: https://github.com/bavix/laravel-wallet/compare/8.4.1...9.0.0
873878
[8.4.1]: https://github.com/bavix/laravel-wallet/compare/8.4.0...8.4.1
874879
[8.4.0]: https://github.com/bavix/laravel-wallet/compare/8.3.0...8.4.0

src/Services/PurchaseService.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@ public function already(Customer $customer, BasketDtoInterface $basketDto, bool
2121
: [Transfer::STATUS_PAID];
2222

2323
$arrays = [];
24+
$wallets = [];
25+
$productCounts = [];
2426
$query = $customer->transfers();
2527
foreach ($basketDto->items() as $itemDto) {
2628
$wallet = $this->castService->getWallet($itemDto->getProduct());
29+
$wallets[$wallet->uuid] = $wallet;
2730

31+
$productCounts[$wallet->uuid] = ($productCounts[$wallet->uuid] ?? 0) + count($itemDto);
32+
}
33+
34+
foreach ($wallets as $wallet) {
2835
/**
2936
* As part of my work, "with" was added, it gives a 50x boost for a huge number of returns. In this case,
3037
* it's a crutch. It is necessary to come up with a more correct implementation of the internal and external
@@ -36,7 +43,7 @@ public function already(Customer $customer, BasketDtoInterface $basketDto, bool
3643
->where('to_id', $wallet->getKey())
3744
->whereIn('status', $status)
3845
->orderBy('id', 'desc')
39-
->limit(count($itemDto))
46+
->limit($productCounts[$wallet->uuid])
4047
->get()
4148
->all()
4249
;

tests/Units/Domain/ProductTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ public function testPayCustomPrice(): void
290290
self::assertSame(2, $cart->getQuantity($productIn));
291291
self::assertSame(0, $buyer->balanceInt);
292292
self::assertCount(2, $transfers);
293+
294+
self::assertTrue($buyer->refundCart($cart));
293295
}
294296

295297
/**

0 commit comments

Comments
 (0)