blackboxcode/pando-product-provider-bundle
Installation Add the bundle via Composer:
composer require blackboxcode/pando-product-provider-bundle
Enable the bundle in config/bundles.php:
BlackBoxCode\PandoProductProviderBundle\PandoProductProviderBundle::class => ['all' => true],
Configuration Publish the default config:
php artisan vendor:publish --provider="BlackBoxCode\PandoProductProviderBundle\PandoProductProviderBundle" --tag="config"
Update config/pando_product_provider.php with your Pando API credentials and endpoints.
First Use Case Fetch a product by ID in a controller:
use BlackBoxCode\PandoProductProviderBundle\Service\PandoProductService;
public function showProduct(PandoProductService $pandoService, $productId)
{
$product = $pandoService->getProduct($productId);
return view('product.show', compact('product'));
}
Product Data Fetching
Use the PandoProductService to retrieve products, categories, or variants:
// Get a single product
$product = $pandoService->getProduct($id);
// Get a list of products (with optional filters)
$products = $pandoService->getProducts(['category' => 'electronics', 'limit' => 10]);
Integration with Laravel Models
Extend a Laravel model (e.g., Product) to sync with Pando:
class Product extends Model
{
public function syncWithPando()
{
$pandoData = app(PandoProductService::class)->getProduct($this->pando_id);
$this->update($pandoData);
}
}
Event-Driven Updates Listen for Pando webhooks (if supported) to trigger model updates:
// In EventServiceProvider
protected $listen = [
'BlackBoxCode\PandoProductProviderBundle\Events\PandoProductUpdated' => [
ProductUpdatedListener::class,
],
];
Caching Strategies Cache responses to reduce API calls:
$products = Cache::remember("pando_products_{$category}", now()->addHours(1), function () use ($pandoService, $category) {
return $pandoService->getProducts(['category' => $category]);
});
Custom API Endpoints Extend the provider to support non-standard Pando endpoints:
// Create a custom service
class CustomPandoService extends PandoProductService
{
public function getCustomData($endpoint, $params = [])
{
return $this->client->get($endpoint, $params);
}
}
Bulk Operations Use chunking for large datasets:
$pandoService->getProductsInBulk($category, 100, function ($products) {
Product::insert($products);
});
Localization Handling
Map Pando’s localized fields to Laravel’s json columns:
$product->localized_fields = $pandoService->getLocalizedFields($productId);
$product->save();
API Rate Limits
try {
return $this->client->get('/products');
} catch (RateLimitException $e) {
sleep($e->getRetryAfter());
return $this->client->get('/products');
}
Data Mismatches
$mappedProduct = (new PandoToLaravelMapper())->map($pandoData);
Webhook Verification
if (!Hash::check($request->header('X-Signature'), $request->getContent())) {
abort(403);
}
Idempotency
Product::upsert($pandoData, ['pando_id'], ['name', 'price']);
Enable API Logging Configure the HTTP client to log requests/responses:
'pando' => [
'logging' => true,
'log_path' => storage_path('logs/pando.log'),
],
Mock the Service for Testing
Use Laravel’s Mockery to isolate tests:
$mock = Mockery::mock(PandoProductService::class);
$mock->shouldReceive('getProduct')->andReturn($fakeProduct);
Handle Deprecated Endpoints
Custom Providers
Implement PandoProductProviderInterface for alternative data sources:
class CustomPandoProvider implements PandoProductProviderInterface
{
public function getProduct($id)
{
// Custom logic
}
}
Event Dispatching Extend the bundle to dispatch events after sync operations:
// In PandoProductService
event(new ProductSynced($product));
Queue Background Jobs Offload heavy syncs to queues:
SyncPandoProducts::dispatch($categoryId)->onQueue('pando');
How can I help you explore Laravel packages today?