dzangocart/subscription-bundle
Installation Add the bundle via Composer:
composer require dzangocart/subscription-bundle:dev-master
Register the bundle in config/bundles.php (Symfony 4+) or AppKernel.php (Symfony 2/3):
Dzangocart\SubscriptionBundle\DzangocartSubscriptionBundle::class => ['all' => true],
Load Fixtures Import essential fixtures (units, periods) for subscription management:
php bin/console doctrine:fixtures:load --fixtures=DzangocartSubscriptionBundle:Fixtures
(Note: Replace doctrine with propel if using Propel ORM as per the README.)
Declare Subscription Entities Annotate your product entity to mark it as subscription-capable:
use Dzangocart\SubscriptionBundle\Annotation\Subscription;
/**
* @Subscription()
*/
class Product {}
First Use Case: Display a Pricing Page Use the bundle’s built-in Twig templates to render a pricing table:
{{ render(controller('DzangocartSubscriptionBundle:Plan:pricing')) }}
Defining Plans Create pricing plans via Doctrine entities (or Propel models) with annotations:
use Dzangocart\SubscriptionBundle\Entity\Plan;
class MyPlan extends Plan {
// Customize plan properties (e.g., name, price, features)
}
Load plans via fixtures or manually via the admin interface (if implemented).
Linking to DzangoCart Integrate with DzangoCart’s API for payment processing:
$subscription = $this->get('dzangocart.subscription.manager')->createSubscription(
$planId,
$customerEmail,
$dzangoCartCustomerId
);
Feature Management
Attach features to plans (e.g., "Premium Support") using the Feature entity:
$plan->addFeature($featureEntity);
$entityManager->persist($plan);
$entityManager->flush();
Subscription Lifecycle
SubscriptionManager:
$this->get('dzangocart.subscription.manager')->cancelSubscription($subscriptionId);
Twig Integration Display subscription status or plans in templates:
{% for plan in plans %}
<div class="plan">
<h3>{{ plan.name }}</h3>
<p>{{ plan.price }} {{ plan.period.unit }}</p>
<a href="{{ path('dzangocart_subscription_subscribe', {'id': plan.id}) }}">Subscribe</a>
</div>
{% endfor %}
PlanType for plan selection forms.dzangocart.subscription.created or dzangocart.subscription.cancelled events for custom logic.ORM Dependency
config/packages/doctrine.yaml is properly set up if using Doctrine.Resources/config/doctrine/ if using Propel or custom ORM.Fixtures Overwrite
propel:fixtures:load or doctrine:fixtures:load multiple times may duplicate data (e.g., units like "month").--append flag or clean fixtures before loading:
php bin/console doctrine:fixtures:load --append --fixtures=DzangocartSubscriptionBundle:Fixtures
DzangoCart API Credentials
config.yml is insecure.parameter_bag or environment variables:
# config/packages/dzangocart_subscription.yaml
dzangocart_subscription:
api_key: '%env(DZANGO_CART_API_KEY)%'
Missing Configuration
DzangocartSubscriptionBundle/Resources/config/services.yaml for default parameters or extend the bundle’s configuration.Twig Template Overrides
pricing.html.twig) are not documented for customization.templates/bundles/dzangocartsubscription/:
mkdir -p templates/bundles/dzangocartsubscription
cp vendor/dzangocart/subscription-bundle/Resources/views/Plan/pricing.html.twig templates/bundles/dzangocartsubscription/
Subscription Not Saving:
@Subscription annotation is on the correct entity.SubscriptionManager service is properly bound in services.yaml:
Dzangocart\SubscriptionBundle\Manager\SubscriptionManager: ~
DzangoCart API Errors:
Custom Plan Logic
Extend the Plan entity or override the PlanType form to add custom fields (e.g., trial period):
class CustomPlanType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('trialDays', IntegerType::class);
}
}
Webhook Handling
Implement a custom subscriber for DzangoCart webhooks (e.g., subscription.activated):
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class DzangoCartWebhookSubscriber implements EventSubscriberInterface {
public static function getSubscribedEvents() {
return [
'dzangocart.subscription.activated' => 'onSubscriptionActivated',
];
}
public function onSubscriptionActivated(SubscriptionEvent $event) {
// Custom logic (e.g., send welcome email)
}
}
Multi-Currency Support
Override the bundle’s PriceCalculator service to support dynamic currencies:
# config/services.yaml
Dzangocart\SubscriptionBundle\Calculator\PriceCalculator:
arguments:
$currencyService: '@app.custom_currency_service'
How can I help you explore Laravel packages today?