Skip to content

Commit e203ad5

Browse files
done
1 parent f053b94 commit e203ad5

6 files changed

Lines changed: 18 additions & 11 deletions

File tree

app/Helpers/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function user () {
1313
static $user;
1414

1515
if ( config('app.env') === 'local' )
16-
return $user ??= User::role(in_array('admin', request()->segments()) ? 'admin' : 'client')->first();
16+
return $user ??= User::role(in_array('admin', request()->segments()) ? 'admin' : 'client')->latest()->first();
1717

1818
return $user ??= auth()->user() ?? auth('sanctum')->user();
1919

app/Repositories/OrderRepository.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,16 @@ public function newOrder ( Product $product, User $user, array $data = [] ) {
4040
'amount' => positive($data['total_price'] ?? 0),
4141
'quantity' => positive($data['quantity'] ?? 1),
4242
'discount' => positive($data['discount'] ?? 0),
43+
'ref_id' => integer($data['ref_id'] ?? 0),
4344
'gift_code_id' => integer($data['gift_code_id']),
4445
'coupon_id' => integer($data['coupon_id'] ?? 0),
4546
'coupon_code' => string($data['coupon_code'] ?? null),
46-
'delivery_method' => string($data['delivery_method'] ?? null),
4747
'user_id' => $user->id,
4848
'product_id' => $product->id,
4949
'cancel_cost' => $product->cancel_cost,
5050
'cancel_before' => $product->cancel_before,
5151
'refund_before' => $product->refund_before,
52+
'delivery_method' => $product->delivery_method,
5253
'allow_cancel' => $product->has('allow_cancel'),
5354
'allow_refund' => $product->has('allow_refunds'),
5455
'allow_pay_later' => $product->has('allow_pay_later'),

app/Services/DomainService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ public function resolveDomains ( array $data = [] ) {
1919
return collect([
2020
['dest' => 'client', 'name' => $client = data_get($data, 'client_domain_name', 'www')],
2121
['dest' => 'admin', 'name' => data_get($data, 'admin_domain_name', $client === 'www' ? 'admin' : null)],
22-
['dest' => 'api', 'name' => data_get($data, 'api_domain_name', 'api')],
2322
['dest' => 'vendor', 'name' => data_get($data, 'vendor_domain_name')],
2423
['dest' => 'delivery', 'name' => data_get($data, 'delivery_domain_name')],
2524
['dest' => 'blog', 'name' => data_get($data, 'blog_domain_name')],
2625
['dest' => 'app', 'name' => data_get($data, 'app_domain_name')],
26+
['dest' => 'api', 'name' => data_get($data, 'api_domain_name')],
2727
['dest' => 'cdn', 'name' => data_get($data, 'cdn_domain_name')],
2828
])->filter(fn($item) => $item['name'])->all();
2929

app/Services/OrderService.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function buildChain ( Product $product, User $user, int $quantity, string
6868

6969
}
7070

71-
return $chain;
71+
return $chain->reverse();
7272

7373
}
7474
public function startOrder ( array $data = [] ) {
@@ -80,17 +80,22 @@ public function startOrder ( array $data = [] ) {
8080

8181
return $this->orderRepository->dbTransaction(function () use ( $product, $user, $quantity, $payType, $data ) {
8282

83-
return $this->buildChain($product, $user, $quantity, $payType, $data)->map(function ( $item ) {
83+
$ref_id = null;
84+
85+
return $this->buildChain($product, $user, $quantity, $payType, $data)->map(function ( $item ) use ( &$ref_id ) {
8486

85-
return $this->withTenant($item->storeId, function () use ( $item ) {
87+
return $this->withTenant($item->storeId, function () use ( $item, &$ref_id ) {
8688

87-
$data = $this->applyCoupon($item->product, $item->user, $item->quantity, $item->pay_type, $item->data);
88-
$data = $this->applyGiftCode($item->product, $item->user, $data);
89-
return $this->completeOrder($item->product, $item->user, $item->quantity, $item->pay_type, $data);
89+
$data = $this->applyCoupon($item->product, $item->user, $item->quantity, $item->pay_type, $item->data);
90+
$data = $this->applyGiftCode($item->product, $item->user, $data);
91+
$order = $this->completeOrder($item->product, $item->user, $item->quantity, $item->pay_type, [...$data, 'ref_id' => $ref_id]);
9092

93+
$ref_id = integer(data_get($order, 'original.item.id'));
94+
return $order;
95+
9196
});
9297

93-
})->first();
98+
})->last();
9499

95100
});
96101

database/migrations/2024_05_24_105742_create_orders_table.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public function up () {
1111
Schema::create('orders', function (Blueprint $table) {
1212
$table->id();
1313
$table->integer('store_id')->default(0);
14+
$table->integer('ref_id')->default(0);
1415
$table->integer('product_id')->default(0);
1516
$table->integer('coupon_id')->default(0);
1617
$table->integer('user_id')->default(0);

resources/views/mails/invoice.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<table width="100%" cellpadding="0" cellspacing="0" border="0">
5757
<tr>
5858
<td valign="top" width="64" style="padding-right:12px;">
59-
<img src="{{ $message->embed(storage_path('app/public/' . $order->product?->getImage())) }}" alt="" width="64" height="64" style="display:block;border-radius:4px;border:1px solid #eef1f5;object-fit:cover;">
59+
<img src="{{ asset('storage/' . $order->product?->getImage()) }}" alt="" width="64" height="64" style="display:block;border-radius:4px;border:1px solid #eef1f5;object-fit:cover;">
6060
</td>
6161
<td valign="top">
6262
<div style="width: 100%; display: flex; justify-content: space-between; align-items: center;">

0 commit comments

Comments
 (0)