Skip to content

Commit f7018be

Browse files
committed
fix method "getMeta"
1 parent 72a4a83 commit f7018be

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

src/Services/AssistantService.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Bavix\Wallet\Services;
66

7-
use Bavix\Wallet\Interfaces\CartInterface;
87
use Bavix\Wallet\Interfaces\ProductInterface;
8+
use Bavix\Wallet\Internal\Dto\BasketDtoInterface;
99
use Bavix\Wallet\Internal\Dto\TransactionDtoInterface;
1010
use Bavix\Wallet\Internal\Dto\TransferDtoInterface;
1111
use Bavix\Wallet\Internal\Service\MathServiceInterface;
@@ -47,19 +47,17 @@ public function getSums(array $transactions): array
4747
return array_filter($amounts, fn (string $amount): bool => $this->mathService->compare($amount, 0) !== 0);
4848
}
4949

50-
public function getMeta(CartInterface $cart, ProductInterface $product): ?array
50+
public function getMeta(BasketDtoInterface $basketDto, ProductInterface $product): ?array
5151
{
52-
$metaCart = $cart->getBasketDto()
53-
->meta()
54-
;
52+
$metaBasket = $basketDto->meta();
5553
$metaProduct = $product->getMetaProduct();
5654

5755
if ($metaProduct !== null) {
58-
return array_merge($metaCart, $metaProduct);
56+
return array_merge($metaBasket, $metaProduct);
5957
}
6058

61-
if ($metaCart !== []) {
62-
return $metaCart;
59+
if ($metaBasket !== []) {
60+
return $metaBasket;
6361
}
6462

6563
return null;

src/Services/AssistantServiceInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Bavix\Wallet\Services;
66

7-
use Bavix\Wallet\Interfaces\CartInterface;
87
use Bavix\Wallet\Interfaces\ProductInterface;
8+
use Bavix\Wallet\Internal\Dto\BasketDtoInterface;
99
use Bavix\Wallet\Internal\Dto\TransactionDtoInterface;
1010
use Bavix\Wallet\Internal\Dto\TransferDtoInterface;
1111

@@ -25,5 +25,5 @@ public function getUuids(array $objects): array;
2525
*/
2626
public function getSums(array $transactions): array;
2727

28-
public function getMeta(CartInterface $cart, ProductInterface $product): ?array;
28+
public function getMeta(BasketDtoInterface $basketDto, ProductInterface $product): ?array;
2929
}

src/Traits/CartPay.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ trait CartPay
5151
public function payFreeCart(CartInterface $cart): array
5252
{
5353
return app(AtomicServiceInterface::class)->block($this, function () use ($cart) {
54+
$basketDto = $cart->getBasketDto();
5455
$basketService = app(BasketServiceInterface::class);
5556
$availabilityAssembler = app(AvailabilityDtoAssemblerInterface::class);
56-
if (!$basketService->availability($availabilityAssembler->create($this, $cart->getBasketDto(), false))) {
57+
if (!$basketService->availability($availabilityAssembler->create($this, $basketDto, false))) {
5758
throw new ProductEnded(
5859
app(TranslatorServiceInterface::class)->get('wallet::errors.product_stock'),
5960
ExceptionInterface::PRODUCT_ENDED
@@ -65,13 +66,13 @@ public function payFreeCart(CartInterface $cart): array
6566
$transfers = [];
6667
$prepareService = app(PrepareServiceInterface::class);
6768
$assistantService = app(AssistantServiceInterface::class);
68-
foreach ($cart->getBasketDto()->cursor() as $product) {
69+
foreach ($basketDto->cursor() as $product) {
6970
$transfers[] = $prepareService->transferLazy(
7071
$this,
7172
$product,
7273
Transfer::STATUS_PAID,
7374
0,
74-
$assistantService->getMeta($cart, $product)
75+
$assistantService->getMeta($basketDto, $product)
7576
);
7677
}
7778

@@ -116,6 +117,7 @@ public function payCart(CartInterface $cart, bool $force = false): array
116117
}
117118

118119
$transfers = [];
120+
$basketDto = $cart->getBasketDto();
119121
$prepareService = app(PrepareServiceInterface::class);
120122
$assistantService = app(AssistantServiceInterface::class);
121123
foreach ($cart->getBasketDto()->cursor() as $product) {
@@ -124,7 +126,7 @@ public function payCart(CartInterface $cart, bool $force = false): array
124126
$product,
125127
Transfer::STATUS_PAID,
126128
$product->getAmountProduct($this),
127-
$assistantService->getMeta($cart, $product)
129+
$assistantService->getMeta($basketDto, $product)
128130
);
129131
}
130132

@@ -173,8 +175,9 @@ public function safeRefundCart(CartInterface $cart, bool $force = false, bool $g
173175
public function refundCart(CartInterface $cart, bool $force = false, bool $gifts = false): bool
174176
{
175177
return app(AtomicServiceInterface::class)->block($this, function () use ($cart, $force, $gifts) {
176-
$transfers = app(PurchaseServiceInterface::class)->already($this, $cart->getBasketDto(), $gifts);
177-
if (count($transfers) !== $cart->getBasketDto()->total()) {
178+
$basketDto = $cart->getBasketDto();
179+
$transfers = app(PurchaseServiceInterface::class)->already($this, $basketDto, $gifts);
180+
if (count($transfers) !== $basketDto->total()) {
178181
throw new ModelNotFoundException(
179182
"No query results for model [{$this->transfers()
180183
->getMorphClass()}]",
@@ -188,14 +191,14 @@ public function refundCart(CartInterface $cart, bool $force = false, bool $gifts
188191
$transfers = array_values($transfers);
189192
$prepareService = app(PrepareServiceInterface::class);
190193
$assistantService = app(AssistantServiceInterface::class);
191-
foreach ($cart->getBasketDto()->cursor() as $product) {
194+
foreach ($basketDto->cursor() as $product) {
192195
$transferIds[] = $transfers[$index]->getKey();
193196
$objects[] = $prepareService->transferLazy(
194197
$product,
195198
$transfers[$index]->withdraw->wallet,
196199
Transfer::STATUS_TRANSFER,
197200
$transfers[$index]->deposit->amount,
198-
$assistantService->getMeta($cart, $product)
201+
$assistantService->getMeta($basketDto, $product)
199202
);
200203

201204
++$index;

0 commit comments

Comments
 (0)