ikoncept/product-manager-adapter
最新稳定版本:0.1.0
Composer 安装命令:
composer require ikoncept/product-manager-adapter
包简介
Usage in conjunction with the product register api
README 文档
README
Installation
You can install the package via composer:
composer require ikoncept/product-manager-adapter
php artisan vendor:publish --tag="product-manager-adapter-config"
This is the contents of the published config file:
return [ 'api_key' => env('PRODUCT_MANAGER_ADAPTER_KEY'), 'endpoint' => env('PRODUCT_MANAGER_ADAPTER_ENDPOINT', 'https://products.malmsten.com') ];
Usage
Routes
This package comes with a couple of different controller methods to make interacting with the products api easier.
Note You need to register the routes yourself
Recommended public routes
// Get a tree node by ID. Usually when retrieving navigation on the front end Route::get('/tree-nodes/{id}', [TreeNodeController::class, 'show']); // Get a tree node via slug, usefull when retrieving a tree node from an url parameter Route::get('/tree-nodes/{slug}/slug', [TreeNodeSlugsController::class, 'show']); // Get a product with a specific SKU Route::get('/products/{sku}', [ProductController::class, 'show']);
Recommended private routes
// Get a list of all available product trees Route::get('/product-trees', [ProductTreeController::class, 'index']); // Get a tree representation of a specific node Route::get('/node-trees/{id}', [NodeTreeController::class, 'index']);
Specifying language
The product api has support for multiple languages. The required language is set via the X-LOCALE header. See below example
const payload = { params: { include: 'content', }, headers: { 'X-LOCALE': this.$i18n.locale, }, } const { data } = await this.$axios.get('/api/products', payload)
Filter out products for the active product tree
To prevent products from other trees to be included in various api calls the X-PRODUCT-TREES header can be used:
const payload = { params: { include: 'content', }, headers: { 'X-PRODUCT-TREES': 3 }, } const { data } = await this.$axios.get('/api/products', payload)
Complete example using the search filter:
const payload = { params: { include: 'content', number: 10, 'filter[nodeIds]': this.nodeRootIds.join(','), 'filter[search]': this.searchQuery, }, headers: { 'X-LOCALE': this.$i18n.locale, 'X-PRODUCT-TREES': this.$store.getters['nav/productTreeRootIds'].join(',') }, } const { data } = await this.$axios.get('/api/products', payload)
Testing
composer test
统计信息
- 总下载量: 63
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-14