Manual Installation
1. Install the Plugin via Composer
composer require sylius/product-bundle-plugin
2. Enable the Bundle
# config/bundles.php
return [
...
Sylius\ProductBundlePlugin\SyliusProductBundlePlugin::class => ['all' => true],
];
3. Import Configuration
# config/packages/_sylius.yaml
imports:
...
- { resource: "@SyliusProductBundlePlugin/config/config.yaml" }
4. Import routes
# config/routes.yaml
...
sylius_product_bundle:
resource: "@SyliusProductBundlePlugin/config/routes.yaml"
5. Extend the OrderItem
entity
OrderItem
entity<?php
// src/Entity/Order/OrderItem.php
declare(strict_types=1);
namespace App\Entity\Order;
use Doctrine\ORM\Mapping as ORM;
use Sylius\ProductBundlePlugin\Entity\OrderItemInterface;
use Sylius\ProductBundlePlugin\Entity\ProductBundleOrderItemsAwareTrait;
use Sylius\Component\Core\Model\OrderItem as BaseOrderItem;
#[ORM\Entity]
#[ORM\Table(name: 'sylius_order_item')]
class OrderItem extends BaseOrderItem implements OrderItemInterface
{
use ProductBundleOrderItemsAwareTrait;
public function __construct()
{
parent::__construct();
$this->initializeProductBundleOrderItems();
}
}
Register the OrderItem
entity
# config/packages/_sylius.yaml
sylius_order:
resources:
...
order_item:
classes:
model: App\Entity\Order\OrderItem
6. Extend the Product
entity
Product
entity<?php
// src/Entity/Product/Product.php
declare(strict_types=1);
namespace App\Entity\Product;
use Doctrine\ORM\Mapping as ORM;
use Sylius\ProductBundlePlugin\Entity\ProductBundlesAwareTrait;
use Sylius\ProductBundlePlugin\Entity\ProductInterface;
use Sylius\Component\Core\Model\Product as BaseProduct;
#[ORM\Entity]
#[ORM\Table(name: 'sylius_product')]
class Product extends BaseProduct implements ProductInterface
{
use ProductBundlesAwareTrait;
}
Register the Product
entity
# config/packages/_sylius.yaml
sylius_product:
resources:
...
product:
classes:
model: App\Entity\Product\Product
7. Import plugin assets
// assets/admin/entrypoint.js
...
import '@vendor/sylius/product-bundle-plugin/assets/admin/entrypoint'
// assets/shop/entrypoint.js
...
import '@vendor/sylius/product-bundle-plugin/assets/shop/entrypoint'
8. Install and build assets
bin/console assets:install
yarn install
yarn encore dev # or yarn encore prod
9. Run Doctrine Migrations
The plugin comes with database changes. Run:
bin/console doctrine:migrations:migrate # add `-e prod` for production
10. Clear the Symfony Cache
Finally, clear the Symfony cache to ensure changes are applied:
bin/console cache:clear
Last updated
Was this helpful?