How can I getting only the number id of the product in shopify using graphql and laravel app
How can I getting only the number id of the product in shopify using graphql and laravel app
This is my route,
Route::get('/carts/{numericProductID}', 'App\Http\Controllers\ShopifyController@showProductDetails')
->name('showProductDetails');
This is the link to redirect to another page to show/fetch the details of the selected product.
<a href="{{ route('showProductDetails', ['numericProductID' => $product['node']['id']]) }}">View Details</a>
try this
use Shopify;
use Illuminate\Http\Request;
public function showProductDetails(Request $request, $numericProductID)
{
// Build your GraphQL query to fetch the product details
$query = <<<GRAPHQL
{
product(id: $numericProductID) {
id
title
# Add other fields you want to retrieve
}
}
GRAPHQL;
// Make the GraphQL request to Shopify
$response = Shopify::graph($query);
// Parse the response JSON
$productData = json_decode($response->getBody(), true);
// Extract the numeric product ID
$numericID = $productData['data']['product']['id'];
// You can now use $numericID in your view or return it as needed
// For example, return a view with the product details
return view('product_details', ['product' => $productData['data']['product']]);
}
in view file
<a href="{{ route('showProductDetails', ['numericProductID' => $product['id']]) }}">View Details</a>
December 30, 2023
Turbo Multi-language Translator
Make the better internet purchasing globaly
Turbosify SEO Speed Booster
5.0 (7)•Free plan available
Get better conversions by improving store loading speed
Installed
Turbo Multi-language Chat - AI Customer service in one hand
December 30, 2023