opengento / module-document
This module aims to help merchants to manage easily their documents in Magento 2.
Fund package maintenance!
www.helloasso.com/associations/opengento/formulaires/1
Installs: 5 257
Dependents: 4
Suggesters: 0
Security: 0
Stars: 6
Watchers: 11
Forks: 2
Open Issues: 2
Type:magento2-module
Requires
- ext-dom: *
- magento/framework: ^103.0
- magento/module-backend: ^102.0
- magento/module-cache-invalidate: ^100.4
- magento/module-config: ^101.0
- magento/module-page-cache: ^100.0
- magento/module-ui: ^101.0
Requires (Dev)
- magento/magento-coding-standard: ^5
- magento/marketplace-eqp: ^4.0
- roave/security-advisories: dev-master
Suggests
- opengento/module-document-product-link: This module aims to help merchants to link their documents to products in Magento 2.
- opengento/module-document-product-search: This module aims to make documents searchable with product keywords in Magento 2.
- opengento/module-document-restrict: This module aims to restrict documents by type in Magento 2.
- opengento/module-document-search: This module aims to make documents searchable for customers in Magento 2.
- opengento/module-document-widget: This module aims to help merchants to manage easily their documents on the Magento 2 storefront.
README
This module aims to help merchants to manage easily their documents in Magento 2.
Setup
Magento 2 Open Source or Commerce edition is required.
Composer installation
Run the following composer command:
composer require opengento/module-document
Setup the module
Run the following magento command:
bin/magento setup:upgrade
If you are in production mode, do not forget to recompile and redeploy the static resources.
Features
This module aims to help merchants to manage easily their documents in Magento 2.
Documents are sorted by types and can be manipulated with ease.
-
Declare new document types:
- from the back-office
- from xml config files
-
Create new documents:
- from the back-office
- from command line
- from a cron job
Documents can be uploaded with a thumbnail. The default thumbnail of the document type can be used.
The thumbnail can be resized in order to optimize the performance.
Documentation
How to declare a document type from config file
Create a new file resource_document_types.xml
in the etc/
folder of your module:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:opengento:document:etc/resource_document_types.xsd"> <documentType code="cert"> <scheduledImport>true</scheduledImport> <visibility>public</visibility> <name>Certificates</name> <fileSourcePath>cert/import/</fileSourcePath> <fileDestPath>coa/</fileDestPath> <subPathLength>3</subPathLength> <filePattern>CERT-*.[pP][dD][fF]</filePattern> <fileAllowedExtensions> <extension>pdf</extension> </fileAllowedExtensions> <defaultImageFileName>document/image/cert/thumbnail.png</defaultImageFileName> </documentType> </config>
How to add a new import file processor
When files are import from command line or cron jobs, you cannot set manually metadata.
The code, name, and pivot field has to be filled and that is what the file import processor do.
If you need to implement your own logic on how a document should be created on the import fly, check the following code:
Implement the interface \Opengento\Document\Model\Document\ProcessorInterface
:
namespace Vendor\Module\Model\Document\Processor; use Opengento\Document\Api\Data\DocumentInterface; use Opengento\Document\Api\Data\DocumentTypeInterface; use Opengento\Document\Model\Document\Filesystem\File; use Opengento\Document\Model\Document\Filesystem\Format; use Opengento\Document\Model\Document\ProcessorInterface; use Opengento\Document\Model\DocumentBuilder; use function basename; use function dirname; final class CustomProcessor implements ProcessorInterface { public const CODE = 'custom'; /** * @var DocumentBuilder */ private $documentBuilder; /** * @var File */ private $fileHelper; public function __construct( DocumentBuilder $documentBuilder, File $fileHelper ) { $this->documentBuilder = $documentBuilder; $this->fileHelper = $fileHelper; } public function execute(DocumentTypeInterface $documentType, string $filePath): DocumentInterface { // $filePath is the path where the source file is currently saved. // You can change the destination path if want to. // Edit the file path value with $this->documentBuilder->setFilePath($newDestPath). // You can also rename the file with $this->documentBuilder->setFileName($newFileName) $destFilePath = $this->fileHelper->getFileDestPath($documentType, $filePath); $fileName = basename($destFilePath); $this->documentBuilder->setTypeId($documentType->getId()); $this->documentBuilder->setCode(Format::formatCode($fileName)); $this->documentBuilder->setName(Format::formatName($fileName)); $this->documentBuilder->setFileName($fileName); $this->documentBuilder->setFilePath(dirname($this->fileHelper->getRelativeFilePath($destFilePath))); return $this->documentBuilder->create(); } }
Support
Raise a new request to the issue tracker.
Authors
License
This project is licensed under the MIT License - see the LICENSE details.
That's all folks!