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

Wooapubundle Laravel Package

ederribeiro/wooapubundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation

    composer require ederribeiro/wooapubundle "~1.*"
    

    Add the bundle to AppKernel.php:

    new Woo\ApuBundle\WooApuBundle(),
    

    Configure credentials in parameters.yml.dist:

    woo_apu:
        consumer_key: "your_woocommerce_consumer_key"
        consumer_secret: "your_woocommerce_consumer_secret"
        shop: "https://your-store.com"
    
  2. First Use Case Inject the client service into a controller/service:

    use Symfony\Component\DependencyInjection\ContainerInterface;
    
    class ProductController
    {
        public function __construct(ContainerInterface $container)
        {
            $this->client = $container->get("wooapu.client");
        }
    
        public function fetchProducts()
        {
            $response = $this->client->get('/products');
            return json_decode($response->getBody(), true);
        }
    }
    

Implementation Patterns

Core Workflows

  1. REST API Calls Use the client for standard WooCommerce API operations:

    // Fetch products
    $products = $this->client->get('/products')->getBody();
    
    // Create an order
    $orderData = ['payment_method' => 'bacs', 'billing' => [...]];
    $order = $this->client->post('/orders', $orderData)->getBody();
    
  2. Dependency Injection Prefer constructor injection for testability:

    class OrderService
    {
        public function __construct(private WooApuClient $client) {}
    }
    
  3. Error Handling Validate responses with HTTP status checks:

    $response = $this->client->get('/products');
    if ($response->getStatusCode() !== 200) {
        throw new \RuntimeException('Failed to fetch products');
    }
    
  4. Pagination Handle paginated endpoints:

    $page = 1;
    $perPage = 10;
    $response = $this->client->get("/products?page=$page&per_page=$perPage");
    

Integration Tips

  • Symfony Forms: Bind WooCommerce product data to Symfony forms for admin UIs.
  • Event Listeners: Subscribe to WooCommerce webhooks (e.g., order_created) via the API.
  • Caching: Cache frequent API calls (e.g., product catalog) using Symfony’s cache system.

Gotchas and Tips

Pitfalls

  1. Authentication Failures

    • Issue: Invalid consumer_key/consumer_secret throws 401 Unauthorized.
    • Fix: Double-check credentials in parameters.yml and regenerate keys in WooCommerce → Settings → Advanced → REST API.
  2. Rate Limiting

    • Issue: WooCommerce may throttle requests (default: 60 calls/hour).
    • Fix: Implement exponential backoff or use a queue system (e.g., Symfony Messenger).
  3. Legacy Symfony Kernel

    • Issue: Bundle assumes Symfony 2.x/3.x (AppKernel). For Symfony 4/5, use config/bundles.php instead of AppKernel.php.
  4. Deprecated Methods

    • Issue: The bundle lacks type hints and modern PHP practices (e.g., no PSR-15 HTTP clients).
    • Fix: Extend the client class or wrap it in a modern interface (e.g., Psr\Http\Client\ClientInterface).

Debugging

  • Enable Debug Mode: Add debug: true to parameters.yml for verbose API logs.
  • Check Headers: Inspect raw responses with:
    $headers = $response->getHeaders();
    

Extension Points

  1. Custom Endpoints Extend the client to support non-standard routes:

    $this->client->setBaseUri('https://custom-endpoint.com');
    
  2. Middleware Add request/response middleware:

    $client->getEmitter()->addSubscriber(new CustomMiddleware());
    
  3. Testing Mock the client in tests:

    $mockClient = $this->createMock(WooApuClient::class);
    $mockClient->method('get')->willReturn(new Response(200, [], json_encode([])));
    $this->container->set('wooapu.client', $mockClient);
    

Configuration Quirks

  • HTTPS Requirement: Ensure shop URL uses https://; WooCommerce REST API rejects HTTP.
  • Parameter Overrides: Use environment variables for sensitive data:
    woo_apu:
        consumer_key: "%env(WOOCOMMERCE_KEY)%"
    
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.
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
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