diff --git a/bootstrap/app.php b/bootstrap/app.php
index 1638cb68..cf794139 100644
--- a/bootstrap/app.php
+++ b/bootstrap/app.php
@@ -50,6 +50,10 @@
return front_route('login.index');
}
});
+
+ $middleware->validateCsrfTokens(except: [
+ 'callback*'
+ ]);
})
->withExceptions(function (Exceptions $exceptions) {
//
diff --git a/innopacks/common/config/innoshop.php b/innopacks/common/config/innoshop.php
index 3d6e22bd..b191e3e1 100644
--- a/innopacks/common/config/innoshop.php
+++ b/innopacks/common/config/innoshop.php
@@ -8,7 +8,7 @@
*/
return [
- 'version' => '0.2.0',
- 'build' => '20240729',
+ 'version' => '0.2.1',
+ 'build' => '20240730',
'api_url' => env('INNOSHOP_API_URL', 'https://www.innoshop.cn'),
];
\ No newline at end of file
diff --git a/innopacks/common/helpers.php b/innopacks/common/helpers.php
index d29268d3..41e1b0fe 100644
--- a/innopacks/common/helpers.php
+++ b/innopacks/common/helpers.php
@@ -716,7 +716,7 @@ function innoshop_version(): string
* @param mixed $builder
* @return string
*/
- function to_sql(Builder $builder): string
+ function to_sql(mixed $builder): string
{
$sql = $builder->toSql();
$driver = DB::getDriverName();
diff --git a/innopacks/common/src/Models/Order.php b/innopacks/common/src/Models/Order.php
index 7acf340b..e8cfdf05 100644
--- a/innopacks/common/src/Models/Order.php
+++ b/innopacks/common/src/Models/Order.php
@@ -9,6 +9,7 @@
namespace InnoShop\Common\Models;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Notifications\Notifiable;
use InnoShop\Common\Models\Order\Fee;
@@ -39,6 +40,14 @@ class Order extends BaseModel
'status_format',
];
+ /**
+ * @return BelongsTo
+ */
+ public function customer(): BelongsTo
+ {
+ return $this->belongsTo(Customer::class, 'customer_id', 'id');
+ }
+
/**
* Order items.
*
diff --git a/innopacks/common/src/Repositories/CartItemRepo.php b/innopacks/common/src/Repositories/CartItemRepo.php
index b83194b4..4b3ab821 100644
--- a/innopacks/common/src/Repositories/CartItemRepo.php
+++ b/innopacks/common/src/Repositories/CartItemRepo.php
@@ -77,7 +77,7 @@ public function create($data): mixed
*/
private function handleData($requestData): array
{
- $skuId = $requestData['skuId'] ?? 0;
+ $skuId = $requestData['skuId'] ?? ($requestData['sku_id'] ?? 0);
$sku = Sku::query()->findOrFail($skuId);
$customerID = $requestData['customer_id'] ?? 0;
@@ -89,7 +89,7 @@ private function handleData($requestData): array
'customer_id' => $customerID,
'guest_id' => $customerID ? '' : $guestID,
'selected' => true,
- 'quantity' => (int) ($requestData['quantity'] ?? 0),
+ 'quantity' => (int) ($requestData['quantity'] ?? 1),
];
}
}
diff --git a/innopacks/common/src/Repositories/CategoryRepo.php b/innopacks/common/src/Repositories/CategoryRepo.php
index 41107063..e04a1bdd 100644
--- a/innopacks/common/src/Repositories/CategoryRepo.php
+++ b/innopacks/common/src/Repositories/CategoryRepo.php
@@ -52,6 +52,14 @@ public function builder(array $filters = []): Builder
$builder->where('slug', $slug);
}
+ $parentSlug = $filters['parent_slug'] ?? '';
+ if ($parentSlug) {
+ $category = Category::query()->where('slug', $parentSlug)->first();
+ if ($category) {
+ $filters['parent_id'] = $category->id;
+ }
+ }
+
if (isset($filters['parent_id'])) {
$parentID = (int) $filters['parent_id'];
if ($parentID == 0) {
diff --git a/innopacks/common/src/Repositories/Order/ItemRepo.php b/innopacks/common/src/Repositories/Order/ItemRepo.php
index 3ea69753..ebb41f86 100644
--- a/innopacks/common/src/Repositories/Order/ItemRepo.php
+++ b/innopacks/common/src/Repositories/Order/ItemRepo.php
@@ -9,6 +9,7 @@
namespace InnoShop\Common\Repositories\Order;
+use Exception;
use InnoShop\Common\Models\Order;
use InnoShop\Common\Models\Product\Sku;
use InnoShop\Common\Repositories\BaseRepo;
@@ -19,9 +20,14 @@ class ItemRepo extends BaseRepo
* @param Order $order
* @param $items
* @return void
+ * @throws Exception
*/
public function createItems(Order $order, $items): void
{
+ if (empty($items)) {
+ throw new Exception('Empty cart list when create order items.');
+ }
+
$orderItems = [];
foreach ($items as $item) {
$orderItems[] = $this->handleItem($order, $item);
diff --git a/innopacks/common/src/Repositories/OrderRepo.php b/innopacks/common/src/Repositories/OrderRepo.php
index 2b2e2a2f..c3034d8e 100644
--- a/innopacks/common/src/Repositories/OrderRepo.php
+++ b/innopacks/common/src/Repositories/OrderRepo.php
@@ -24,13 +24,15 @@ class OrderRepo extends BaseRepo
*/
public function getFilterStatuses(): array
{
- return [
+ $statuses = [
StateMachineService::UNPAID,
StateMachineService::PAID,
StateMachineService::SHIPPED,
StateMachineService::COMPLETED,
StateMachineService::CANCELLED,
];
+
+ return fire_hook_filter('common.repo.order.statuses', $statuses);
}
/**
@@ -44,13 +46,27 @@ public function list(array $filters = []): LengthAwarePaginator
return $builder->paginate();
}
+ /**
+ * @return Builder
+ */
+ public function baseBuilder(): Builder
+ {
+ return Order::query();
+ }
+
/**
* @param array $filters
* @return Builder
*/
public function builder(array $filters = []): Builder
{
- $builder = Order::query();
+ $relations = [
+ 'customer',
+ 'items',
+ ];
+
+ $relations = array_merge($this->relations, $relations);
+ $builder = $this->baseBuilder()->with($relations);
$filters = array_merge($this->filters, $filters);
@@ -79,6 +95,11 @@ public function builder(array $filters = []): Builder
$builder->where('status', $status);
}
+ $statuses = $filters['statuses'] ?? [];
+ if ($statuses) {
+ $builder->whereIn('status', $statuses);
+ }
+
$start = $filters['start'] ?? '';
if ($start) {
$builder->where('created_at', '>', $start);
diff --git a/innopacks/common/src/Repositories/ProductRepo.php b/innopacks/common/src/Repositories/ProductRepo.php
index 28c7e723..ffe73a83 100644
--- a/innopacks/common/src/Repositories/ProductRepo.php
+++ b/innopacks/common/src/Repositories/ProductRepo.php
@@ -11,7 +11,9 @@
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
+use InnoShop\Common\Models\Category;
use InnoShop\Common\Models\Product;
use InnoShop\Common\Repositories\Product\ImageRepo;
@@ -238,6 +240,14 @@ private function syncImages(Product $product, $images): void
}
}
+ /**
+ * @return Builder
+ */
+ public function baseBuilder(): Builder
+ {
+ return Product::query();
+ }
+
/**
* @param array $filters
* @return Builder
@@ -251,7 +261,10 @@ public function builder(array $filters = []): Builder
'translation',
'categories.translation',
];
- $builder = Product::query()->with($relations);
+
+ $relations = array_merge($this->relations, $relations);
+
+ $builder = $this->baseBuilder()->with($relations);
$filters = array_merge($this->filters, $filters);
@@ -262,7 +275,22 @@ public function builder(array $filters = []): Builder
});
}
+ $categorySlug = $filters['category_slug'] ?? '';
+ if ($categorySlug) {
+ $category = Category::query()->where('slug', $categorySlug)->first();
+ if ($category) {
+ $categories = CategoryRepo::getInstance()->builder(['parent_id' => $category->id])->get();
+
+ $filters['category_ids'] = $categories->pluck('id');
+ $filters['category_ids'][] = $category->id;
+ }
+ }
+
$categoryIds = $filters['category_ids'] ?? [];
+ if ($categoryIds instanceof Collection) {
+ $categoryIds = $categoryIds->toArray();
+ }
+ $categoryIds = array_unique($categoryIds);
if ($categoryIds) {
$builder->whereHas('categories', function (Builder $query) use ($categoryIds) {
$query->whereIn('category_id', $categoryIds);
diff --git a/innopacks/common/src/Resources/CartListItem.php b/innopacks/common/src/Resources/CartListItem.php
index 6d90487e..b70a577a 100644
--- a/innopacks/common/src/Resources/CartListItem.php
+++ b/innopacks/common/src/Resources/CartListItem.php
@@ -43,7 +43,7 @@ public function toArray(Request $request): array
'origin_price_format' => $sku->origin_price_format,
'subtotal' => $subtotal,
'subtotal_format' => currency_format($subtotal),
- 'image' => image_resize($sku->image->path ?? $product->image->path),
+ 'image' => image_resize($sku->image->path ?? ($product->image->path ?? '')),
'selected' => (bool) $this->selected,
];
}
diff --git a/innopacks/common/src/Resources/ProductSimple.php b/innopacks/common/src/Resources/ProductSimple.php
new file mode 100644
index 00000000..76c2febb
--- /dev/null
+++ b/innopacks/common/src/Resources/ProductSimple.php
@@ -0,0 +1,42 @@
+
+ * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ */
+
+namespace InnoShop\Common\Resources;
+
+use Exception;
+use Illuminate\Http\Request;
+use Illuminate\Http\Resources\Json\JsonResource;
+
+class ProductSimple extends JsonResource
+{
+ /**
+ * Transform the resource into an array.
+ *
+ * @param Request $request
+ * @return array
+ * @throws Exception
+ */
+ public function toArray(Request $request): array
+ {
+ $sku = $this->masterSku;
+
+ return [
+ 'sku_id' => $sku->id,
+ 'product_id' => $this->id,
+ 'slug' => $this->slug,
+ 'url' => $this->url,
+ 'name' => $this->translation->name,
+ 'summary' => $this->translation->summary,
+ 'image_small' => image_resize($sku->image->path ?? ($this->image->path ?? '')),
+ 'image_big' => image_resize($sku->image->path ?? ($this->image->path ?? ''), 600, 600),
+ 'price_format' => $sku->price_format,
+ 'origin_price_format' => $sku->origin_price_format,
+ ];
+ }
+}
diff --git a/innopacks/common/src/Services/Checkout/BillingService.php b/innopacks/common/src/Services/Checkout/BillingService.php
index 21f1d7c1..a5d20cbe 100644
--- a/innopacks/common/src/Services/Checkout/BillingService.php
+++ b/innopacks/common/src/Services/Checkout/BillingService.php
@@ -12,8 +12,16 @@
use InnoShop\Plugin\Repositories\PluginRepo;
use InnoShop\Plugin\Resources\Checkout\PaymentMethodItem;
-class BillingService extends BaseService
+class BillingService
{
+ /**
+ * @return static
+ */
+ public static function getInstance(): static
+ {
+ return new static();
+ }
+
/**
* @throws \Exception
*/
diff --git a/innopacks/common/src/Services/CheckoutService.php b/innopacks/common/src/Services/CheckoutService.php
index 0b177bea..eb38f6f8 100644
--- a/innopacks/common/src/Services/CheckoutService.php
+++ b/innopacks/common/src/Services/CheckoutService.php
@@ -245,7 +245,7 @@ public function getCheckoutResult(): array
'cart_list' => $this->getCartList(),
'address_list' => $this->getAddressList(),
'shipping_methods' => ShippingService::getInstance($this)->getMethods(),
- 'billing_methods' => BillingService::getInstance($this)->getMethods(),
+ 'billing_methods' => BillingService::getInstance()->getMethods(),
'checkout' => $this->getCheckoutData(),
'fee_list' => $this->getFeeList(),
'total' => $this->getTotal(),
diff --git a/innopacks/front/lang/en/common.php b/innopacks/front/lang/en/common.php
index 30140787..e110f12f 100644
--- a/innopacks/front/lang/en/common.php
+++ b/innopacks/front/lang/en/common.php
@@ -8,32 +8,33 @@
*/
return [
- 'home' => 'Home',
- 'login' => 'Login',
- 'register' => 'Register',
- 'cancel' => 'Cancel',
- 'confirm' => 'Confirm',
- 'delete' => 'Delete',
- 'edit' => 'Edit',
- 'action' => 'Action',
- 'add' => 'Add',
- 'text_hint' => 'Hint',
- 'image' => 'Image',
- 'all' => 'All',
- 'status' => 'Status',
- 'view' => 'View',
- 'submit' => 'Submit',
- 'products' => 'Products',
- 'news' => 'Articles',
- 'pages' => 'Pages',
- 'search' => 'Search',
- 'back_page' => 'Go Back',
- 'telephone' => 'Telephone',
- 'created_at' => 'Created at',
+ 'home' => 'Home',
+ 'login' => 'Login',
+ 'register' => 'Register',
+ 'cancel' => 'Cancel',
+ 'confirm' => 'Confirm',
+ 'delete' => 'Delete',
+ 'edit' => 'Edit',
+ 'action' => 'Action',
+ 'add' => 'Add',
+ 'text_hint' => 'Hint',
+ 'image' => 'Image',
+ 'all' => 'All',
+ 'status' => 'Status',
+ 'view' => 'View',
+ 'submit' => 'Submit',
+ 'products' => 'Products',
+ 'news' => 'Articles',
+ 'pages' => 'Pages',
+ 'search' => 'Search',
+ 'back_page' => 'Go Back',
+ 'telephone' => 'Telephone',
+ 'created_at' => 'Created at',
+ 'delete_confirm' => 'You sure you want to delete it?',
- 'delete_confirm' => 'You sure you want to delete it?',
- 'get_success' => 'Get successfully',
- 'saved_success' => 'Saved successfully',
- 'updated_success' => 'Updated successfully',
- 'deleted_success' => 'Deleted successfully',
+ 'get_success' => 'Get successfully',
+ 'saved_success' => 'Saved successfully',
+ 'updated_success' => 'Updated successfully',
+ 'deleted_success' => 'Deleted successfully',
+ 'submitted_success' => 'Submitted successfully',
];
diff --git a/innopacks/front/lang/es/common.php b/innopacks/front/lang/es/common.php
index 8605cd52..60148b27 100644
--- a/innopacks/front/lang/es/common.php
+++ b/innopacks/front/lang/es/common.php
@@ -8,32 +8,33 @@
*/
return [
- 'home' => 'Inicio',
- 'login' => 'Iniciar sesión',
- 'register' => 'Registrarse',
- 'cancel' => 'Cancelar',
- 'confirm' => 'Confirmar',
- 'delete' => 'Eliminar',
- 'edit' => 'Editar',
- 'action' => 'Acción',
- 'add' => 'Agregar',
- 'text_hint' => 'Sugerencia',
- 'image' => 'Imagen',
- 'all' => 'Todos',
- 'status' => 'Estado',
- 'view' => 'Ver',
- 'submit' => 'Enviar',
- 'products' => 'Productos',
- 'news' => 'Artículos',
- 'pages' => 'Páginas',
- 'search' => 'Buscar',
- 'back_page' => 'Volver',
- 'telephone' => 'Teléfono',
- 'created_at' => 'Creado el',
+ 'home' => 'Inicio',
+ 'login' => 'Iniciar sesión',
+ 'register' => 'Registrarse',
+ 'cancel' => 'Cancelar',
+ 'confirm' => 'Confirmar',
+ 'delete' => 'Eliminar',
+ 'edit' => 'Editar',
+ 'action' => 'Acción',
+ 'add' => 'Agregar',
+ 'text_hint' => 'Sugerencia',
+ 'image' => 'Imagen',
+ 'all' => 'Todos',
+ 'status' => 'Estado',
+ 'view' => 'Ver',
+ 'submit' => 'Enviar',
+ 'products' => 'Productos',
+ 'news' => 'Artículos',
+ 'pages' => 'Páginas',
+ 'search' => 'Buscar',
+ 'back_page' => 'Volver',
+ 'telephone' => 'Teléfono',
+ 'created_at' => 'Creado el',
+ 'delete_confirm' => '¿Estás seguro de que deseas eliminarlo?',
- 'delete_confirm' => '¿Estás seguro de que deseas eliminarlo?',
- 'get_success' => 'Obtener con éxito',
- 'saved_success' => 'Guardado con éxito',
- 'updated_success' => 'Actualizado con éxito',
- 'deleted_success' => 'Eliminado con éxito',
+ 'get_success' => 'Obtener con éxito',
+ 'saved_success' => 'Guardado con éxito',
+ 'updated_success' => 'Actualizado con éxito',
+ 'deleted_success' => 'Eliminado con éxito',
+ 'submitted_success' => 'Submitted successfully',
];
diff --git a/innopacks/front/lang/zh_cn/common.php b/innopacks/front/lang/zh_cn/common.php
index 4d8b6e18..f8753f11 100644
--- a/innopacks/front/lang/zh_cn/common.php
+++ b/innopacks/front/lang/zh_cn/common.php
@@ -8,32 +8,33 @@
*/
return [
- 'home' => '首页',
- 'login' => '登录',
- 'register' => '注册',
- 'cancel' => '取消',
- 'confirm' => '确定',
- 'delete' => '删除',
- 'edit' => '编辑',
- 'action' => '操作',
- 'add' => '添加',
- 'text_hint' => '提示',
- 'image' => '图片',
- 'all' => '全部',
- 'status' => '状态',
- 'view' => '查看',
- 'submit' => '提交',
- 'products' => '商品',
- 'news' => '文章',
- 'pages' => '单页',
- 'search' => '搜索',
- 'telephone' => '联系电话',
- 'back_page' => '返回上一页',
- 'created_at' => '创建时间',
+ 'home' => '首页',
+ 'login' => '登录',
+ 'register' => '注册',
+ 'cancel' => '取消',
+ 'confirm' => '确定',
+ 'delete' => '删除',
+ 'edit' => '编辑',
+ 'action' => '操作',
+ 'add' => '添加',
+ 'text_hint' => '提示',
+ 'image' => '图片',
+ 'all' => '全部',
+ 'status' => '状态',
+ 'view' => '查看',
+ 'submit' => '提交',
+ 'products' => '商品',
+ 'news' => '文章',
+ 'pages' => '单页',
+ 'search' => '搜索',
+ 'telephone' => '联系电话',
+ 'back_page' => '返回上一页',
+ 'created_at' => '创建时间',
+ 'delete_confirm' => '确定要删除吗?',
- 'delete_confirm' => '确定要删除吗?',
- 'get_success' => '获取成功',
- 'saved_success' => '保存成功',
- 'updated_success' => '更新成功',
- 'deleted_success' => '删除成功',
+ 'get_success' => '获取成功',
+ 'saved_success' => '保存成功',
+ 'updated_success' => '更新成功',
+ 'deleted_success' => '删除成功',
+ 'submitted_success' => '提交成功',
];
diff --git a/innopacks/front/resources/views/orders/show.blade.php b/innopacks/front/resources/views/orders/show.blade.php
new file mode 100644
index 00000000..4cb37fa0
--- /dev/null
+++ b/innopacks/front/resources/views/orders/show.blade.php
@@ -0,0 +1,97 @@
+@extends('layouts.app')
+@section('body-class', 'page-checkout-success')
+
+@section('content')
+
+
{{ __('front::order.order_number') }} | +{{ __('front::order.order_date') }} | +{{ __('front::order.order_total') }} | +{{ __('front::order.order_status') }} | +
---|---|---|---|
{{ $order->number }} | +{{ $order->created_at->format('Y-m-d') }} | +{{ $order->total_format }} | +{{ $order->status_format }} | +
{{ __('front::order.product') }} | +{{ __('front::order.price') }} | +{{ __('front::order.quantity') }} | +{{ __('front::order.subtotal') }} | +
---|---|---|---|
+
+
+
+
+
+
+
+ {{ $product['name'] }}
+ {{ $product['product_sku'] }}
+ @if ($product['variant_label'])
+ - {{ $product['variant_label'] }}
+ @endif
+
+ |
+ {{ $product['price_format'] }} | +{{ $product['quantity'] }} | +{{ $product['price_format'] }} | +
+ | + | {{ $total['title'] }} | +{{ $total->value_format }} | +
+ | + | {{ __('front::order.order_total') }} | +{{ $order->total_format }} | +