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
|
@ -58,13 +58,13 @@ class ProductController extends Controller
|
||||||
/** @var Location $location */
|
/** @var Location $location */
|
||||||
$location = $node->location;
|
$location = $node->location;
|
||||||
|
|
||||||
if (!$locations->contains('id' , $location->id)){
|
if (!$locations->contains('id', $location->id)) {
|
||||||
$nodeIds = $nodes->map(function ($node){
|
$nodeIds = $nodes->map(function ($node) {
|
||||||
return $node->id;
|
return $node->id;
|
||||||
});
|
});
|
||||||
|
|
||||||
$location->nodes = $location->nodes()
|
$location->nodes = $location->nodes()
|
||||||
->whereIn('id' , $nodeIds)
|
->whereIn('id', $nodeIds)
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$locations->add($location);
|
$locations->add($location);
|
||||||
|
@ -76,14 +76,20 @@ class ProductController extends Controller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Node $node
|
* @param Node $node
|
||||||
|
* @param Egg $egg
|
||||||
* @return Collection|JsonResponse
|
* @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()
|
||||||
$builder->where('id', '=', $node->id);
|
->whereHas('nodes', function (Builder $builder) use ($node) {
|
||||||
})->get();
|
$builder->where('id', '=', $node->id);
|
||||||
|
})
|
||||||
|
->whereHas('eggs', function (Builder $builder) use ($egg) {
|
||||||
|
$builder->where('id', '=', $egg->id);
|
||||||
|
})
|
||||||
|
->get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -362,7 +362,7 @@
|
||||||
this.products = [];
|
this.products = [];
|
||||||
this.selectedProduct = 'null';
|
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)
|
.catch(console.error)
|
||||||
|
|
||||||
this.fetchedProducts = true;
|
this.fetchedProducts = true;
|
||||||
|
|
|
@ -58,7 +58,7 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () {
|
||||||
#routes made for server create page to fetch product info
|
#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/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/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
|
#payments
|
||||||
Route::get('checkout/{paypalProduct}', [PaymentController::class, 'checkOut'])->name('checkout');
|
Route::get('checkout/{paypalProduct}', [PaymentController::class, 'checkOut'])->name('checkout');
|
||||||
|
|
Loading…
Reference in a new issue