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

Productbundle Laravel Package

edemy/productbundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require masando/edemy-productbundle
    

    Ensure eDemyFramework is installed and configured as a base dependency.

  2. Bundle Registration Add to config/bundles.php:

    Masando\eDemyProductBundle\eDemyProductBundle::class => ['all' => true],
    
  3. First Use Case: Product CRUD

    • Run migrations:
      php bin/console doctrine:migrations:diff
      php bin/console doctrine:migrations:migrate
      
    • Scaffold a basic product controller:
      php bin/console make:controller ProductController --resource --entity=Product
      
  4. 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)

Implementation Patterns

Core Workflows

  1. Product Management

    • Create: Use ProductRepository or ProductManager service:
      $product = $productManager->create([
          'name' => 'Bundle Starter Pack',
          'price' => 99.99,
          'bundled_items' => [1, 2, 3] // IDs of child products
      ]);
      
    • Bundle Logic: Leverage BundleTrait in child entities:
      use Masando\eDemyProductBundle\Traits\BundleTrait;
      
      class ChildProduct {
          use BundleTrait;
      }
      
  2. Inventory Integration

    • Extend Product entity to include stock levels:
      // src/Entity/Product.php
      use Masando\eDemyProductBundle\Entity\Product as BaseProduct;
      
      class Product extends BaseProduct {
          private $stock;
      }
      
  3. API Endpoints

    • Use Symfony Serializer for bundle responses:
      use Symfony\Component\Serializer\Annotation\Groups;
      
      class Product {
          #[Groups(['product:read'])]
          public $name;
      }
      

Integration Tips

  • Event Listeners: Subscribe to ProductEvents (e.g., ProductCreatedEvent) for post-save logic:
    // src/EventListener/ProductListener.php
    public static function getSubscribedEvents(): array {
        return [
            ProductEvents::POST_CREATE => 'onProductCreated',
        ];
    }
    
  • Validation: Extend ProductValidator for custom rules:
    use Masando\eDemyProductBundle\Validator\Constraints\Product as Assert;
    
    #[Assert\UniqueBundleItems]
    public $bundled_items;
    

Gotchas and Tips

Common Pitfalls

  1. Bundle Relationships

    • Circular References: Avoid bidirectional ManyToMany between Product and Bundle. Use ManyToOne from Bundle to Product instead.
    • Cascading Deletes: Disable cascade={"remove"} on bundled_items to prevent accidental deletion of child products.
  2. Performance

    • N+1 Queries: Use ProductRepository::findWithBundles() to eager-load relationships:
      $products = $repo->findWithBundles(['id' => [1, 2, 3]]);
      
    • Indexing: Add indexes to bundle_id and product_id columns in the join table.
  3. Configuration Quirks

    • Default Values: Override config/packages/edemy_product.yaml to set defaults:
      edemy_product:
          default_stock: 0
          bundle_discount_threshold: 3
      

Debugging Tips

  • Doctrine Events: Enable SQL logging for bundle operations:
    // config/packages/dev/doctrine.yaml
    doctrine:
        dbal:
            logging: true
            profiling: true
    
  • Symfony Profiler: Use the toolbar to inspect ProductEvents and BundleEvents payloads.

Extension Points

  1. Custom Bundle Types

    • Extend 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
          }
      }
      
    • Register in services.yaml:
      Masando\eDemyProductBundle\BundleType\BundleTypeInterface: '@custom_bundle_type'
      
  2. Third-Party Integrations

    • Payment Gateways: Hook into ProductEvents::PRE_CHECKOUT to validate bundle eligibility.
    • ERP Systems: Use ProductManager::exportToErp() for batch processing.
  3. Testing

    • Mock BundleTrait in unit tests:
      $product = $this->createMock(Product::class);
      $product->method('getBundledItems')->willReturn([$childProduct]);
      
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware