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

Shop Bundle Laravel Package

c975l/shop-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require c975l/shop-bundle
    php bin/console make:migration
    php bin/console doctrine:migrations:migrate
    

    Create required directories:

    mkdir -p public/{medias,downloads} private
    echo "public/{medias,downloads}/ private/" >> .gitignore
    
  2. User Setup

    php bin/console make:user
    php bin/console make:security:form-login
    

    Add an admin user:

    php bin/console security:hash-password
    

    Assign ROLE_ADMIN to the user in your User entity.

  3. First Use Case Validate schema:

    php bin/console doctrine:schema:validate
    

    Add basic security config to config/packages/security.yaml:

    access_control:
        - { path: ^/shop/management, roles: ROLE_ADMIN }
    

Implementation Patterns

Core Workflows

  1. Product Management Use the ShopBundle CRUD endpoints (e.g., /shop/product) for:

    • Creating/editing products via ProductType (Symfony form).
    • Uploading media with VichUploaderBundle (configured in vich_uploader.yaml).
    // Example: Uploading a product image
    $product->setImageFile($request->file('image'));
    $em->persist($product);
    $em->flush();
    
  2. Crowdfunding Integration Extend Product entity to include crowdfunding fields (e.g., targetAmount, endDate).

    // In ProductType.php
    $builder->add('targetAmount', MoneyType::class);
    $builder->add('endDate', DateType::class);
    
  3. Order Processing Use Order entity for checkout flows:

    $order = new Order();
    $order->setUser($currentUser);
    $order->addProduct($product, $quantity);
    $em->persist($order);
    
  4. API Endpoints Leverage Symfony’s serializers for JSON responses:

    # config/packages/api_platform.yaml
    resources:
        - App\Entity\Product
        - App\Entity\Order
    

Integration Tips

  • Frontend: Use Twig templates in templates/shop/ for product listings.
    {% for product in products %}
        <img src="{{ vich_uploader_asset(product.image) }}">
        {{ product.name }} - {{ product.price|money }}
    {% endfor %}
    
  • Admin Panel: Secure /shop/management routes with ROLE_ADMIN.
  • Payments: Integrate with Stripe/PayPal via Order entity events (e.g., postPersist).

Gotchas and Tips

Pitfalls

  1. Database Schema

    • Run doctrine:schema:validate after every migration to catch missing relations.
    • Ensure User entity extends ShopBundle's base user class if required.
  2. File Uploads

    • Media paths (public/medias/) must be writable by the web server.
    • Clear VichUploader cache after manual file deletions:
      php bin/console vich_uploader:clear_cache
      
  3. Security

    • Always validate ROLE_ADMIN for /shop/management routes.
    • Hash passwords before storing (use security:hash-password).
  4. Crowdfunding Logic

    • Implement custom validation for endDate (e.g., future dates only):
      use Symfony\Component\Validator\Constraints as Assert;
      
      /**
       * @Assert\GreaterThan("today")
       */
      private $endDate;
      

Debugging

  • Missing Routes: Clear cache after adding new routes:
    php bin/console cache:clear
    
  • Upload Errors: Check vich_uploader.yaml for correct db_driver (ORM) and metadata mappings.
  • Permission Issues: Verify access_control in security.yaml and user roles.

Extension Points

  1. Custom Fields Extend Product entity with traits or interfaces:

    namespace App\Entity;
    
    use Doctrine\ORM\Mapping as ORM;
    use ShopBundle\Entity\Product as BaseProduct;
    
    #[ORM\Entity]
    class Product extends BaseProduct
    {
        #[ORM\Column]
        private $customField;
    }
    
  2. Event Listeners Hook into Order lifecycle for custom logic:

    // src/EventListener/OrderListener.php
    public function postPersist(Order $order, EventArgs $args)
    {
        if ($order->isCrowdfunding()) {
            // Trigger crowdfunding logic
        }
    }
    
  3. API Extensions Override serializers for custom data:

    # config/packages/api_platform.yaml
    formats:
        jsonld:
            mime_types: ['application/ld+json']
    
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