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
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.
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 }
Product Management
Use the ShopBundle CRUD endpoints (e.g., /shop/product) for:
ProductType (Symfony form).VichUploaderBundle (configured in vich_uploader.yaml).// Example: Uploading a product image
$product->setImageFile($request->file('image'));
$em->persist($product);
$em->flush();
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);
Order Processing
Use Order entity for checkout flows:
$order = new Order();
$order->setUser($currentUser);
$order->addProduct($product, $quantity);
$em->persist($order);
API Endpoints Leverage Symfony’s serializers for JSON responses:
# config/packages/api_platform.yaml
resources:
- App\Entity\Product
- App\Entity\Order
templates/shop/ for product listings.
{% for product in products %}
<img src="{{ vich_uploader_asset(product.image) }}">
{{ product.name }} - {{ product.price|money }}
{% endfor %}
/shop/management routes with ROLE_ADMIN.Order entity events (e.g., postPersist).Database Schema
doctrine:schema:validate after every migration to catch missing relations.User entity extends ShopBundle's base user class if required.File Uploads
public/medias/) must be writable by the web server.php bin/console vich_uploader:clear_cache
Security
ROLE_ADMIN for /shop/management routes.security:hash-password).Crowdfunding Logic
endDate (e.g., future dates only):
use Symfony\Component\Validator\Constraints as Assert;
/**
* @Assert\GreaterThan("today")
*/
private $endDate;
php bin/console cache:clear
vich_uploader.yaml for correct db_driver (ORM) and metadata mappings.access_control in security.yaml and user roles.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;
}
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
}
}
API Extensions Override serializers for custom data:
# config/packages/api_platform.yaml
formats:
jsonld:
mime_types: ['application/ld+json']
How can I help you explore Laravel packages today?