|
21 | 21 | use Bavix\Wallet\Services\AssistantServiceInterface; |
22 | 22 | use Bavix\Wallet\Services\AtomicServiceInterface; |
23 | 23 | use Bavix\Wallet\Services\BasketServiceInterface; |
| 24 | +use Bavix\Wallet\Services\CastServiceInterface; |
24 | 25 | use Bavix\Wallet\Services\ConsistencyServiceInterface; |
25 | 26 | use Bavix\Wallet\Services\PrepareServiceInterface; |
26 | 27 | use Bavix\Wallet\Services\PurchaseServiceInterface; |
@@ -107,27 +108,32 @@ public function safePayCart(CartInterface $cart, bool $force = false): array |
107 | 108 | public function payCart(CartInterface $cart, bool $force = false): array |
108 | 109 | { |
109 | 110 | return app(AtomicServiceInterface::class)->block($this, function () use ($cart, $force) { |
| 111 | + $basketDto = $cart->getBasketDto(); |
110 | 112 | $basketService = app(BasketServiceInterface::class); |
111 | 113 | $availabilityAssembler = app(AvailabilityDtoAssemblerInterface::class); |
112 | | - if (!$basketService->availability($availabilityAssembler->create($this, $cart->getBasketDto(), $force))) { |
| 114 | + if (!$basketService->availability($availabilityAssembler->create($this, $basketDto, $force))) { |
113 | 115 | throw new ProductEnded( |
114 | 116 | app(TranslatorServiceInterface::class)->get('wallet::errors.product_stock'), |
115 | 117 | ExceptionInterface::PRODUCT_ENDED |
116 | 118 | ); |
117 | 119 | } |
118 | 120 |
|
| 121 | + $prices = []; |
119 | 122 | $transfers = []; |
120 | | - $basketDto = $cart->getBasketDto(); |
| 123 | + $castService = app(CastServiceInterface::class); |
121 | 124 | $prepareService = app(PrepareServiceInterface::class); |
122 | 125 | $assistantService = app(AssistantServiceInterface::class); |
123 | 126 | foreach ($cart->getBasketDto()->items() as $item) { |
124 | | - foreach ($item->getItems() as $_item) { |
125 | | - $product = $item->getProduct(); |
| 127 | + foreach ($item->getItems() as $product) { |
| 128 | + $productId = $product::class.':'.$castService->getModel($product)->getKey(); |
| 129 | + $prices[$productId] = $item->getPricePerItem() |
| 130 | + ?? $prices[$productId] |
| 131 | + ?? $product->getAmountProduct($this); |
126 | 132 | $transfers[] = $prepareService->transferLazy( |
127 | 133 | $this, |
128 | 134 | $product, |
129 | 135 | Transfer::STATUS_PAID, |
130 | | - $item->getPricePerItem() ?? $product->getAmountProduct($this), |
| 136 | + $prices[$productId], |
131 | 137 | $assistantService->getMeta($basketDto, $product) |
132 | 138 | ); |
133 | 139 | } |
|
0 commit comments