Installation
composer require masando/edemy-productbundle
Ensure eDemyFramework is installed and configured as a base dependency.
Bundle Registration
Add to config/bundles.php:
Masando\eDemyProductBundle\eDemyProductBundle::class => ['all' => true],
First Use Case: Product CRUD
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
php bin/console make:controller ProductController --resource --entity=Product
Key Files to Review
src/Entity/Product.php (Core model)src/Resources/config/doctrine/Product.orm.yml (Schema)src/Controller/ProductController.php (Default CRUD logic)Product Management
ProductRepository or ProductManager service:
$product = $productManager->create([
'name' => 'Bundle Starter Pack',
'price' => 99.99,
'bundled_items' => [1, 2, 3] // IDs of child products
]);
BundleTrait in child entities:
use Masando\eDemyProductBundle\Traits\BundleTrait;
class ChildProduct {
use BundleTrait;
}
Inventory Integration
Product entity to include stock levels:
// src/Entity/Product.php
use Masando\eDemyProductBundle\Entity\Product as BaseProduct;
class Product extends BaseProduct {
private $stock;
}
API Endpoints
use Symfony\Component\Serializer\Annotation\Groups;
class Product {
#[Groups(['product:read'])]
public $name;
}
ProductEvents (e.g., ProductCreatedEvent) for post-save logic:
// src/EventListener/ProductListener.php
public static function getSubscribedEvents(): array {
return [
ProductEvents::POST_CREATE => 'onProductCreated',
];
}
ProductValidator for custom rules:
use Masando\eDemyProductBundle\Validator\Constraints\Product as Assert;
#[Assert\UniqueBundleItems]
public $bundled_items;
Bundle Relationships
ManyToMany between Product and Bundle. Use ManyToOne from Bundle to Product instead.cascade={"remove"} on bundled_items to prevent accidental deletion of child products.Performance
ProductRepository::findWithBundles() to eager-load relationships:
$products = $repo->findWithBundles(['id' => [1, 2, 3]]);
bundle_id and product_id columns in the join table.Configuration Quirks
config/packages/edemy_product.yaml to set defaults:
edemy_product:
default_stock: 0
bundle_discount_threshold: 3
// config/packages/dev/doctrine.yaml
doctrine:
dbal:
logging: true
profiling: true
ProductEvents and BundleEvents payloads.Custom Bundle Types
BundleType to add dynamic bundle logic:
class CustomBundleType extends BundleType {
public function getDiscountLogic(): callable {
return fn($items) => count($items) * 0.1; // 10% off per item
}
}
services.yaml:
Masando\eDemyProductBundle\BundleType\BundleTypeInterface: '@custom_bundle_type'
Third-Party Integrations
ProductEvents::PRE_CHECKOUT to validate bundle eligibility.ProductManager::exportToErp() for batch processing.Testing
BundleTrait in unit tests:
$product = $this->createMock(Product::class);
$product->method('getBundledItems')->willReturn([$childProduct]);
How can I help you explore Laravel packages today?