A plugin to create, group and associate documents with products
- Create type of documents
- Easily customize which documents to display from the product configuration page
- Document are automatically displayed on the product's store page and downloaded there
-
run
composer require asdoria/sylius-product-document-plugin
-
Add the bundle in
config/bundles.php
. You must put it ABOVESyliusGridBundle
Asdoria\SyliusProductDocumentPlugin\AsdoriaSyliusProductDocumentPlugin::class => ['all' => true],
[...]
Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
- Import routes in
config/routes.yaml
asdoria_product_document:
resource: "@AsdoriaSyliusProductDocumentPlugin/Resources/config/routing.yaml"
- Import config in
config/packages/_sylius.yaml
imports:
- { resource: "@AsdoriaSyliusProductDocumentPlugin/Resources/config/app/config.yaml"}
- In
src/Entity/Product/Product.php
. Import the following classes, traits and methods.
use Asdoria\SyliusProductDocumentPlugin\Model\Aware\ProductDocumentsAwareInterface;
use Asdoria\SyliusProductDocumentPlugin\Model\ProductDocumentInterface;
use Asdoria\SyliusProductDocumentPlugin\Traits\ProductDocumentsTrait;
use Sylius\Component\Product\Model\ProductTranslationInterface;
class Product extends BaseProduct implements ProductDocumentsAwareInterface
{
use ProductDocumentsTrait;
public function __construct()
{
parent::__construct();
$this->initializeProductDocumentsCollection();
}
/**
* @param ProductDocumentInterface $productDocument
*/
public function addProductDocument(ProductDocumentInterface $productDocument): void
{
if (!$this->hasProductDocument($productDocument)) {
$productDocument->setProduct($this);
$this->productDocuments->add($productDocument);
}
}
/**
* @param ProductDocumentInterface $productDocument
*/
public function removeProductDocument(ProductDocumentInterface $productDocument): void
{
if ($this->hasProductDocument($productDocument)) {
$productDocument->setProduct(null);
$this->productDocuments->removeElement($productDocument);
}
}
}
-
run
php bin/console do:mi:mi
to update the database schema` -
Gaufrette is no longer used by Sylius in favour of Flysystem. If you want to use Gaufrette in your project, you need to set:
asdoria_sylius_product_document: filesystem: adapter: gaufrette
in your
config/packages/_sylius.yaml
file.
You can see the result for the user here with a cap: here.
If you want to try to create documents, go on the admin authentication page and connect with:
Login: asdoria
Password: asdoria
Then go on "Document Type" in the back office and follow usage lines below.
Note that we have developed several other open source plugins for Sylius, whose demos and documentation are listed on the following page.
- In the back office, under
Catalog
, enterDocument Types
. Create a type of document using a unique code. - Go to a product's edit page, then click the
Documents
tab in the sidebar. Here you can add documents type then upload which document you wish to display for each.