Merge pull request #277 from ControlPanel-gg/product_linking
Fixed a bug where products where only fetched using node and not egg,…
This commit is contained in:
commit
451913f015
|
@ -76,14 +76,20 @@ class ProductController extends Controller
|
|||
|
||||
/**
|
||||
* @param Node $node
|
||||
* @param Egg $egg
|
||||
* @return Collection|JsonResponse
|
||||
*/
|
||||
public function getProductsBasedOnNode(Node $node)
|
||||
public function getProductsBasedOnNode(Egg $egg, Node $node)
|
||||
{
|
||||
if (is_null($node->id)) return response()->json('Node ID is required', '400');
|
||||
if (is_null($egg->id) || is_null($node->id)) return response()->json('node and egg id is required', '400');
|
||||
|
||||
return Product::query()->whereHas('nodes', function (Builder $builder) use ($node) {
|
||||
return Product::query()
|
||||
->whereHas('nodes', function (Builder $builder) use ($node) {
|
||||
$builder->where('id', '=', $node->id);
|
||||
})->get();
|
||||
})
|
||||
->whereHas('eggs', function (Builder $builder) use ($egg) {
|
||||
$builder->where('id', '=', $egg->id);
|
||||
})
|
||||
->get();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -362,7 +362,7 @@
|
|||
this.products = [];
|
||||
this.selectedProduct = 'null';
|
||||
|
||||
let response = await axios.get(`{{route('products.products.node')}}/${this.selectedNode}`)
|
||||
let response = await axios.get(`{{route('products.products.node')}}/${this.selectedEgg}/${this.selectedNode}`)
|
||||
.catch(console.error)
|
||||
|
||||
this.fetchedProducts = true;
|
||||
|
|
|
@ -58,7 +58,7 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () {
|
|||
#routes made for server create page to fetch product info
|
||||
Route::get('/products/nodes/egg/{egg?}', [FrontProductController::class, 'getNodesBasedOnEgg'])->name('products.nodes.egg');
|
||||
Route::get('/products/locations/egg/{egg?}', [FrontProductController::class, 'getLocationsBasedOnEgg'])->name('products.locations.egg');
|
||||
Route::get('/products/products/node/{node?}', [FrontProductController::class, 'getProductsBasedOnNode'])->name('products.products.node');
|
||||
Route::get('/products/products/{egg?}/{node?}', [FrontProductController::class, 'getProductsBasedOnNode'])->name('products.products.node');
|
||||
|
||||
#payments
|
||||
Route::get('checkout/{paypalProduct}', [PaymentController::class, 'checkOut'])->name('checkout');
|
||||
|
|
Loading…
Reference in a new issue