Install via Composer:
composer require astina/tradedoubler-bundle:dev-master
(Note: Use dev-master as the package is archived and no stable releases exist.)
Enable the Bundle:
Add to app/AppKernel.php:
new Astina\Bundle\TradedoublerBundle\AstinaTradedoublerBundle(),
Configure config.yml:
astina_tradedoubler:
api_token: "your_tradedoubler_api_token"
feed_id: "your_feed_id"
trackback:
organization: "your_org_id"
event_id: "your_event_id"
redirect_default_url: "http://your-shop.com"
First Use Case: Push a single product to Tradedoubler via CLI:
php app/console astina:tradedoubler:populate
(Requires implementing ProductSourceInterface—see Implementation Patterns.)
Define a Product Source Service:
Implement ProductSourceInterface to fetch products from your database:
// src/Acme/ShopBundle/Service/ProductSource.php
use Astina\Bundle\TradedoublerBundle\Client\ProductSourceInterface;
class ProductSource implements ProductSourceInterface
{
public function getProducts()
{
return ProductCollection::fromArray($this->fetchFromDb());
}
}
Register the Service:
services:
my_product_source:
class: Acme\ShopBundle\Service\ProductSource
tags:
- { name: astina_tradedoubler.product_source }
Update config.yml:
astina_tradedoubler:
product_source: my_product_source
Trigger Sync:
php app/console astina:tradedoubler:populate
(Logs output to var/log/dev.log by default.)
Event-Driven Updates:
Hook into Symfony events (e.g., kernel.request) to push updates incrementally:
$client->updateProduct($productId, $updatedProduct);
Bulk Operations:
Use ProductCollection for batch processing:
$collection = new ProductCollection([$product1, $product2]);
$client->createProducts($collection);
Error Handling: Wrap API calls in try-catch:
try {
$client->createProducts($collection);
} catch (\Astina\Bundle\TradedoublerBundle\Exception\TradedoublerException $e) {
$this->logger->error($e->getMessage());
}
XML Reports:
Enable the mailer by configuring astina_tradedoubler.xml_report in config.yml:
astina_tradedoubler:
xml_report:
enabled: true
email: "reports@example.com"
Deprecated Dependencies:
Timeout Issues:
Client constructor).$client = new Client($config, ['timeout' => 60]);
Product ID Mismatches:
product_id in ProductCollection.$collection->validateUniqueIds();
Logging Quirks:
TradedoublerException messages are automatically logged (v1.2.5+).var/log/dev.log for API errors.Enable API Debugging:
Set debug: true in config:
astina_tradedoubler:
debug: true
(Logs raw API requests/responses.)
Validate XML Output:
Use jms/serializer to inspect serialized payloads:
$serializer = $this->container->get('jms_serializer');
$xml = $serializer->serialize($product, 'xml');
Test Locally:
Mock the Client for unit tests:
$client = $this->createMock(\Astina\Bundle\TradedoublerBundle\Client\Client::class);
$client->method('createProducts')->willReturn(true);
Custom Fields:
Extend Product model to add Tradedoubler-specific attributes:
class CustomProduct extends \Astina\Bundle\TradedoublerBundle\Model\Product
{
protected $customField;
public function setCustomField($value) { $this->customField = $value; }
public function getCustomField() { return $this->customField; }
}
Override Serialization:
Replace the jms/serializer configuration for custom formats:
jms_serializer:
metadata:
directories:
AcmeShop:
namespace_prefix: "Acme\\ShopBundle\\Model"
path: "%kernel.root_dir%/config/serializer/AcmeShop"
Add Webhooks:
Implement a PostSyncEventListener to trigger actions after sync:
use Astina\Bundle\TradedoublerBundle\Event\PostSyncEvent;
class MyListener
{
public function onPostSync(PostSyncEvent $event)
{
if ($event->isSuccess()) {
// Send Slack notification, etc.
}
}
}
Register as a service with the kernel.event_listener tag.
How can I help you explore Laravel packages today?