diff --git a/beike/Admin/Http/Controllers/ProductController.php b/beike/Admin/Http/Controllers/ProductController.php index cad4155e..e2222802 100644 --- a/beike/Admin/Http/Controllers/ProductController.php +++ b/beike/Admin/Http/Controllers/ProductController.php @@ -19,16 +19,16 @@ class ProductController extends Controller public function index(Request $request) { - $requestData = $request->all(); - $productList = ProductRepo::list($requestData); - $products = ProductResource::collection($productList); + $requestData = $request->all(); + $productList = ProductRepo::list($requestData); + $products = ProductResource::collection($productList); $productsFormat = $products->jsonSerialize(); $data = [ - 'categories' => CategoryRepo::flatten(locale()), + 'categories' => CategoryRepo::flatten(locale()), 'products_format' => $productsFormat, - 'products' => $products, - 'type' => 'products', + 'products' => $products, + 'type' => 'products', ]; $data = hook_filter('admin.product.index.data', $data); diff --git a/beike/Admin/Http/Resources/ProductResource.php b/beike/Admin/Http/Resources/ProductResource.php index 96414eac..b75a0cab 100644 --- a/beike/Admin/Http/Resources/ProductResource.php +++ b/beike/Admin/Http/Resources/ProductResource.php @@ -27,12 +27,12 @@ class ProductResource extends JsonResource 'price_formatted' => currency_format($masterSku->price), 'active' => $this->active, 'position' => $this->position, - 'url' => shop_route('products.show', $this->id), + 'url' => $this->url, 'created_at' => time_format($this->created_at), 'deleted_at' => $this->deleted_at ? time_format($this->deleted_at) : '', 'url_edit' => admin_route('products.edit', $this->id), ]; - return $data; + return hook_filter('resource.product', $data); } } diff --git a/beike/Models/Product.php b/beike/Models/Product.php index e1fc3502..fd924ed2 100644 --- a/beike/Models/Product.php +++ b/beike/Models/Product.php @@ -76,7 +76,10 @@ class Product extends Base public function getUrlAttribute() { - return shop_route('products.show', ['product' => $this]); + $url = shop_route('products.show', ['product' => $this]); + $filters = hook_filter('model.product.url', ['url' => $url, 'product' => $this]); + + return $filters['url'] ?? ''; } public function getImageAttribute() diff --git a/beike/Shop/Http/Resources/ProductSimple.php b/beike/Shop/Http/Resources/ProductSimple.php index c7442946..febc4359 100644 --- a/beike/Shop/Http/Resources/ProductSimple.php +++ b/beike/Shop/Http/Resources/ProductSimple.php @@ -37,12 +37,12 @@ class ProductSimple extends JsonResource $images = $this->images ?? []; } - return [ + $data = [ 'id' => $this->id, 'sku_id' => $masterSku->id, 'name' => $name, 'name_format' => $name, - 'url' => shop_route('products.show', ['product' => $this]), + 'url' => $this->url, 'price' => $masterSku->price, 'origin_price' => $masterSku->origin_price, 'price_format' => currency_format($masterSku->price), @@ -54,5 +54,7 @@ class ProductSimple extends JsonResource return image_resize($item, 400, 400); }, $images), ]; + + return hook_filter('resource.product.simple', $data); } }