Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Minishop Najnakup Laravel Package

birko/minishop-najnakup

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install Dependencies Add to composer.json:

    "require": {
        "birko/minishop-najnakup": "dev-main",
        "birko/najnakup": "dev-main"
    }
    

    Run composer update.

  2. Register Bundle In AppKernel.php, add:

    new Birko\MiniShopNajnakupBundle\MiniShopNajnakupBundle(),
    new Birko\CoreNajnakupBundle\CoreNajnakupBundle(),
    
  3. Configure Routing Add to app/config/routing.yml:

    core_najnakup:
        resource: "@MiniShopNajnakupBundle/Resources/config/routing.yml"
        prefix: /najnakup
    
  4. Configure Package In app/config/config.yml:

    minishop_najnakup:
        prices: ['normal']  # Supported price types
        key: "your_najnakup_api_key"  # Required for API calls
    
  5. First Use Case Trigger a price update via CLI:

    php artisan najnakup:update-prices
    

Implementation Patterns

Core Workflows

  1. Price Synchronization

    • Use NajnakupService to fetch and update product prices:
      $service = $this->get('minishop_najnakup.service');
      $service->syncPrices(); // Fetches and updates prices for configured types
      
    • Schedule via Laravel’s task scheduler (app/Console/Kernel.php):
      $schedule->command('najnakup:update-prices')->daily();
      
  2. Product Integration

    • Extend MiniShop\ProductBundle\Entity\Product to include Najnakup metadata:
      /**
       * @ORM\Column(type="array", nullable=true)
       */
      private $najnakupPrices = [];
      
    • Use NajnakupPriceUpdater to attach price logic:
      $updater = new NajnakupPriceUpdater($product, $priceType);
      $updater->updateFromNajnakup();
      
  3. API-Driven Updates

    • Override default API calls by binding a custom NajnakupClient:
      $this->app->bind('najnakup.client', function() {
          return new CustomNajnakupClient('custom_endpoint');
      });
      
  4. Event Listeners

    • Listen for najnakup.price.updated to react to changes:
      public function onPriceUpdated(PriceUpdatedEvent $event) {
          // Log, notify, or trigger side effects
      }
      
    • Register in services.yml:
      services:
          app.najnakup.listener:
              class: AppBundle\Listener\NajnakupListener
              tags:
                  - { name: kernel.event_listener, event: najnakup.price.updated, method: onPriceUpdated }
      

Gotchas and Tips

Pitfalls

  1. API Key Management

    • Hardcoding keys in config.yml is insecure. Use Laravel’s .env:
      minishop_najnakup:
          key: "%env('NAJNAKUP_API_KEY')%"
      
    • Never commit .env to version control.
  2. Price Type Mismatches

    • Ensure prices config matches Najnakup’s API response structure. Default ['normal'] may need expansion (e.g., ['promo', 'sale']).
  3. Rate Limiting

    • Najnakup’s API may throttle requests. Implement retries with exponential backoff:
      use Symfony\Component\HttpKernel\Exception\RateLimitedHttpException;
      
      try {
          $response = $client->request('GET', '/prices');
      } catch (RateLimitedHttpException $e) {
          sleep(2 ** $attempt); // Exponential backoff
          retry();
      }
      
  4. Database Locking

    • Bulk updates can cause deadlocks. Use transactions:
      $entityManager->beginTransaction();
      try {
          foreach ($products as $product) {
              $product->setNajnakupPrice($newPrice);
              $entityManager->persist($product);
          }
          $entityManager->flush();
          $entityManager->commit();
      } catch (\Exception $e) {
          $entityManager->rollback();
          throw $e;
      }
      

Debugging Tips

  1. 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]);
    
  2. 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());
    }
    
  3. Test Locally Mock the API client for testing:

    $this->app->bind('najnakup.client', function() {
        return new MockNajnakupClient([
            'products' => ['test_product' => ['price' => 999]]
        ]);
    });
    

Extension Points

  1. 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
    
  2. 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 }
    
  3. Multi-Currency Support Extend NajnakupService to handle currency conversion:

    public function syncPrices($currency = 'EUR') {
        $this->client->setCurrency($currency);
        // ... rest of sync logic
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours