PHP code example of sharpapi / laravel-ecommerce-product-categories

1. Go to this page and download the library: Download sharpapi/laravel-ecommerce-product-categories library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sharpapi / laravel-ecommerce-product-categories example snippets




namespace App\Http\Controllers;

use GuzzleHttp\Exception\GuzzleException;
use SharpAPI\EcommerceProductCategories\EcommerceProductCategoriesService;

class ProductController extends Controller
{
    protected EcommerceProductCategoriesService $productCategoriesService;

    public function __construct(EcommerceProductCategoriesService $productCategoriesService)
    {
        $this->productCategoriesService = $productCategoriesService;
    }

    /**
     * @throws GuzzleException
     */
    public function getProductCategories(string $productName)
    {
        $statusUrl = $this->productCategoriesService->productCategories(
            $productName,
            'English',   // optional language
            5,   // optional maximum quantity
            'Tech-savvy',   // optional voice tone
            'Electronics, Gadgets'   // optional context
        );
        
        $result = $this->productCategoriesService->fetchResults($statusUrl);

        return response()->json($result->getResultJson());
    }
}

use GuzzleHttp\Exception\ClientException;

try {
    $statusUrl = $this->productCategoriesService->productCategories('Sony PlayStation 5', 'English', 5);
} catch (ClientException $e) {
    echo $e->getMessage();
}
bash
php artisan vendor:publish --tag=sharpapi-ecommerce-product-categories