Install Dependencies
Add to composer.json:
"require": {
"birko/minishop-najnakup": "dev-main",
"birko/najnakup": "dev-main"
}
Run composer update.
Register Bundle
In AppKernel.php, add:
new Birko\MiniShopNajnakupBundle\MiniShopNajnakupBundle(),
new Birko\CoreNajnakupBundle\CoreNajnakupBundle(),
Configure Routing
Add to app/config/routing.yml:
core_najnakup:
resource: "@MiniShopNajnakupBundle/Resources/config/routing.yml"
prefix: /najnakup
Configure Package
In app/config/config.yml:
minishop_najnakup:
prices: ['normal'] # Supported price types
key: "your_najnakup_api_key" # Required for API calls
First Use Case Trigger a price update via CLI:
php artisan najnakup:update-prices
Price Synchronization
NajnakupService to fetch and update product prices:
$service = $this->get('minishop_najnakup.service');
$service->syncPrices(); // Fetches and updates prices for configured types
app/Console/Kernel.php):
$schedule->command('najnakup:update-prices')->daily();
Product Integration
MiniShop\ProductBundle\Entity\Product to include Najnakup metadata:
/**
* @ORM\Column(type="array", nullable=true)
*/
private $najnakupPrices = [];
NajnakupPriceUpdater to attach price logic:
$updater = new NajnakupPriceUpdater($product, $priceType);
$updater->updateFromNajnakup();
API-Driven Updates
NajnakupClient:
$this->app->bind('najnakup.client', function() {
return new CustomNajnakupClient('custom_endpoint');
});
Event Listeners
najnakup.price.updated to react to changes:
public function onPriceUpdated(PriceUpdatedEvent $event) {
// Log, notify, or trigger side effects
}
services.yml:
services:
app.najnakup.listener:
class: AppBundle\Listener\NajnakupListener
tags:
- { name: kernel.event_listener, event: najnakup.price.updated, method: onPriceUpdated }
API Key Management
config.yml is insecure. Use Laravel’s .env:
minishop_najnakup:
key: "%env('NAJNAKUP_API_KEY')%"
.env to version control.Price Type Mismatches
prices config matches Najnakup’s API response structure. Default ['normal'] may need expansion (e.g., ['promo', 'sale']).Rate Limiting
use Symfony\Component\HttpKernel\Exception\RateLimitedHttpException;
try {
$response = $client->request('GET', '/prices');
} catch (RateLimitedHttpException $e) {
sleep(2 ** $attempt); // Exponential backoff
retry();
}
Database Locking
$entityManager->beginTransaction();
try {
foreach ($products as $product) {
$product->setNajnakupPrice($newPrice);
$entityManager->persist($product);
}
$entityManager->flush();
$entityManager->commit();
} catch (\Exception $e) {
$entityManager->rollback();
throw $e;
}
Enable API Logging
Add to config/services.yml:
monolog:
handlers:
najnakup:
type: stream
path: "%kernel.logs_dir%/najnakup.log"
level: debug
Log API requests/responses in NajnakupClient:
$this->logger->debug('Najnakup API Request', ['url' => $url, 'data' => $data]);
Validate Responses Use a custom validator for Najnakup’s API schema:
$validator = new NajnakupResponseValidator();
if (!$validator->isValid($response)) {
throw new \RuntimeException('Invalid Najnakup response: ' . $validator->getErrors());
}
Test Locally Mock the API client for testing:
$this->app->bind('najnakup.client', function() {
return new MockNajnakupClient([
'products' => ['test_product' => ['price' => 999]]
]);
});
Custom Price Calculators
Override NajnakupPriceCalculator to implement business logic:
class CustomNajnakupPriceCalculator extends NajnakupPriceCalculator {
protected function calculateDiscount($basePrice, $najnakupPrice) {
return $basePrice * 0.9; // 10% discount
}
}
Bind in services.yml:
services:
minishop_najnakup.price_calculator:
class: AppBundle\Calculator\CustomNajnakupPriceCalculator
Webhook Support Extend the bundle to handle Najnakup webhooks:
public function handleWebhook(Request $request) {
$payload = json_decode($request->getContent(), true);
$this->dispatchEvent(new NajnakupWebhookEvent($payload));
}
Add route:
najnakup_webhook:
path: /najnakup/webhook
defaults: { _controller: AppBundle\Controller\NajnakupWebhookController::handle }
Multi-Currency Support
Extend NajnakupService to handle currency conversion:
public function syncPrices($currency = 'EUR') {
$this->client->setCurrency($currency);
// ... rest of sync logic
}
How can I help you explore Laravel packages today?