fix transaction bug

This commit is contained in:
2026-08-27 14:01:34 +03:30
parent 17d79c0ce6
commit acf229006e
5 changed files with 353 additions and 15 deletions
@@ -318,12 +318,35 @@ class CartController extends Controller
'title' => "سبد خرید"
], 12, false, false);
foreach ($cart->items as $item) {
$wallet_interface_product = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type, null, $item->product_id);
$wallet_interface_product->wallet->gold = intval($wallet_interface_product->wallet->gold);
$wallet_interface_product->wallet->save();
$productId = (int) $item->product_id;
$customerId = (int) auth('customer')->id();
$ownerType = (int) auth('customer')->user()->type;
if (self::isMainWalletProduct($productId)) {
app(\App\Services\WalletBalanceService::class)->consolidateOrphanedForOwner(
$customerId,
$ownerType,
$productId
);
}
$wallet_interface_product = new WalletInterface(
$customerId,
$ownerType,
null,
self::effectiveProductWalletId($productId)
);
$product = Product::query()->find($productId);
if (
$wallet_interface_product->wallet
&& $wallet_interface_product->wallet->product_id !== null
&& $product
&& self::isCountBasedProduct(self::productUnitPayload($product))
) {
$wallet_interface_product->wallet->gold = intval($wallet_interface_product->wallet->gold);
$wallet_interface_product->wallet->save();
}
new TransactionInterface($wallet_interface_product, [
"gold" => $item->quantity,
"product_id" => $item->product_id,
"product_id" => $productId,
'expire_at' => now(),
'active' => true,
'order_id' => $order->id,