At BitBag we do believe in open source. However, we are able to do it just because of our awesome clients, who are kind enough to share some parts of our work with the community. Therefore, if you feel like there is a possibility for us working together, feel free to reach us out. You will find out more about our professional services, technologies and contact details at https://bitbag.io/.
This plugin allows you to create new products by bundling existing products together.
-
Require plugin with composer:
composer require bitbag/product-bundle-plugin
-
Add plugin dependencies to your
config/bundles.php
file:return [ ... BitBag\SyliusProductBundlePlugin\BitBagSyliusProductBundlePlugin::class => ['all' => true ], ];
-
Import required config in your
config/packages/_sylius.yaml
file:# config/packages/_sylius.yaml imports: ... - { resource: "@BitBagSyliusProductBundlePlugin/Resources/config/config.yml" }
-
Import routing in your
config/routes.yaml
file:# config/routes.yaml ... bitbag_sylius_product_bundle_plugin: resource: "@BitBagSyliusProductBundlePlugin/Resources/config/routing.yml"
-
Extend
Product
(including Doctrine mapping):<?php declare(strict_types=1); namespace App\Entity\Product; use BitBag\SyliusProductBundlePlugin\Entity\ProductBundlesAwareInterface; use BitBag\SyliusProductBundlePlugin\Entity\ProductBundlesAwareTrait; use Sylius\Component\Core\Model\Product as BaseProduct; class Product extends BaseProduct implements ProductBundlesAwareInterface { use ProductBundlesAwareTrait; }
Mapping (XML):
<?xml version="1.0" encoding="UTF-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd" > <entity name="App\Entity\Product\Product" table="sylius_product"> <one-to-one field="productBundle" target-entity="BitBag\SyliusProductBundlePlugin\Entity\ProductBundleInterface" mapped-by="product"> <cascade> <cascade-all/> </cascade> </one-to-one> </entity> </doctrine-mapping>
-
Extend
OrderItem
(including Doctrine mapping):<?php declare(strict_types=1); namespace App\Entity\Order; use BitBag\SyliusProductBundlePlugin\Entity\OrderItemInterface; use BitBag\SyliusProductBundlePlugin\Entity\ProductBundleOrderItemsAwareTrait; use Sylius\Component\Core\Model\OrderItem as BaseOrderItem; class OrderItem extends BaseOrderItem implements OrderItemInterface { use ProductBundleOrderItemsAwareTrait; public function __construct() { parent::__construct(); $this->init(); } }
Mapping (XML):
<?xml version="1.0" encoding="UTF-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd" > <entity name="App\Entity\Order\OrderItem" table="sylius_order_item"> <one-to-many field="productBundleOrderItems" target-entity="BitBag\SyliusProductBundlePlugin\Entity\ProductBundleOrderItem" mapped-by="orderItem" > <cascade> <cascade-all/> </cascade> </one-to-many> </entity> </doctrine-mapping>
-
Add configuration for extended product, order item and product variant repository:
# config/packages/_sylius.yaml sylius_product: resources: product: classes: model: App\Entity\Product\Product product_variant: classes: repository: BitBag\SyliusProductBundlePlugin\Repository\ProductVariantRepository sylius_order: resources: order_item: classes: model: App\Entity\Order\OrderItem
-
Add 'Create/Bundle' to product grid configuration:
# config/packages/_sylius.yaml sylius_grid: grids: sylius_admin_product: actions: main: create: links: bundle: label: bitbag_sylius_product_bundle.ui.bundle icon: plus route: bitbag_product_bundle_admin_product_create_bundle
-
Finish the installation by updating the database schema and installing assets:
$ bin/console doctrine:migrations:diff $ bin/console doctrine:migrations:migrate
$ composer install
$ cd tests/Application
$ yarn install
$ yarn build
$ bin/console assets:install public -e test
$ bin/console doctrine:schema:create -e test
$ bin/console server:run 127.0.0.1:8080 -d public -e test
$ open http://localhost:8080
$ vendor/bin/behat
Learn more about our contribution workflow on http://docs.sylius.org/en/latest/contributing/.