Skip to content

Commit 4790b37

Browse files
committed
add README & LICENSE
1 parent 3d0e5c8 commit 4790b37

File tree

3 files changed

+181
-0
lines changed

3 files changed

+181
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) OpenGento
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Model/Document/Operation/CreateFromFile.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function execute(DocumentTypeInterface $documentType, string $file): Docu
4545
{
4646
$destFilePath = $this->fileHelper->getFileDestPath($documentType, $file);
4747
$document = $this->processorFactory->get($documentType->getCode())->execute($documentType, $destFilePath);
48+
$destFilePath = $this->fileHelper->getFilePath($document);
4849
$this->fileHelper->moveFile($file, $destFilePath);
4950

5051
try {

README.md

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# Document Module for Magento 2
2+
3+
[![Latest Stable Version](https://img.shields.io/packagist/v/opengento/module-document.svg?style=flat-square)](https://packagist.org/packages/opengento/module-document)
4+
[![License: MIT](https://img.shields.io/github/license/opengento/magento2-document.svg?style=flat-square)](./LICENSE)
5+
[![Packagist](https://img.shields.io/packagist/dt/opengento/module-document.svg?style=flat-square)](https://packagist.org/packages/opengento/module-document/stats)
6+
[![Packagist](https://img.shields.io/packagist/dm/opengento/module-document.svg?style=flat-square)](https://packagist.org/packages/opengento/module-document/stats)
7+
8+
This module add the many countries to many stores relation and make it available to the storefront.
9+
10+
- [Setup](#setup)
11+
- [Composer installation](#composer-installation)
12+
- [Setup the module](#setup-the-module)
13+
- [Features](#features)
14+
- [Settings](#settings)
15+
- [Documentation](#documentation)
16+
- [Support](#support)
17+
- [Authors](#authors)
18+
- [License](#license)
19+
20+
## Setup
21+
22+
Magento 2 Open Source or Commerce edition is required.
23+
24+
### Composer installation
25+
26+
Run the following composer command:
27+
28+
```
29+
composer require opengento/module-document
30+
```
31+
32+
### Setup the module
33+
34+
Run the following magento command:
35+
36+
```
37+
bin/magento setup:upgrade
38+
```
39+
40+
**If you are in production mode, do not forget to recompile and redeploy the static resources.**
41+
42+
## Features
43+
44+
This module aims to help merchants to manage easily their documents in Magento 2.
45+
Documents are sorted by types and can be manipulated with ease.
46+
47+
- Declare new document types:
48+
- from the back-office
49+
- from xml config files
50+
51+
- Create new documents:
52+
- from the back-office
53+
- from command line
54+
- from a cron job
55+
56+
Documents can be uploaded with a thumbnail. The default thumbnail of the document type can be used.
57+
The thumbnail can be resized in order to optimize the performance.
58+
59+
## Documentation
60+
61+
### How to declare a document type from config file
62+
63+
Create a new file `resource_document_types.xml` in the `etc/` folder of your module:
64+
65+
```xml
66+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:mpbio:document:etc/resource_document_types.xsd">
67+
<documentType code="cert">
68+
<scheduledImport>true</scheduledImport>
69+
<visibility>public</visibility>
70+
<name>Certificates</name>
71+
<fileSourcePath>cert/import/</fileSourcePath>
72+
<fileDestPath>coa/</fileDestPath>
73+
<subPathLength>3</subPathLength>
74+
<filePattern>CERT-*.[pP][dD][fF]</filePattern>
75+
<fileAllowedExtensions>
76+
<extension>pdf</extension>
77+
</fileAllowedExtensions>
78+
<defaultImageFileName>document/image/cert/thumbnail.png</defaultImageFileName>
79+
</documentType>
80+
</config>
81+
```
82+
83+
### How to add a new import file processor
84+
85+
When files are import from command line or cron jobs, you cannot set manually metadata.
86+
The code, name, and pivot field has to be filled and that is what the file import processor do.
87+
If you need to implement your own logic on how a document should be created on the import fly, check the following code:
88+
89+
Implement the interface `\Opengento\Document\Model\Document\ProcessorInterface`:
90+
91+
```php
92+
93+
namespace Vendor\Module\Model\Document\Processor;
94+
95+
use Opengento\Document\Api\Data\DocumentInterface;
96+
use Opengento\Document\Api\Data\DocumentTypeInterface;
97+
use Opengento\Document\Model\Document\Helper\File;
98+
use Opengento\Document\Model\Document\Helper\Format;
99+
use Opengento\Document\Model\Document\ProcessorInterface;
100+
use Opengento\Document\Model\DocumentBuilder;
101+
use function basename;
102+
use function dirname;
103+
104+
final class CustomProcessor implements ProcessorInterface
105+
{
106+
public const CODE = 'custom';
107+
108+
/**
109+
* @var DocumentBuilder
110+
*/
111+
private $documentBuilder;
112+
113+
/**
114+
* @var File
115+
*/
116+
private $fileHelper;
117+
118+
public function __construct(
119+
DocumentBuilder $documentBuilder,
120+
File $fileHelper
121+
) {
122+
$this->documentBuilder = $documentBuilder;
123+
$this->fileHelper = $fileHelper;
124+
}
125+
126+
public function execute(DocumentTypeInterface $documentType, string $filePath): DocumentInterface
127+
{
128+
// $filePath is the path where the file is being moved
129+
// You can change the destination path if you edit the file path value
130+
// with $this->documentBuilder->setFilePath($newDestPath)
131+
// and $this->documentBuilder->setFileName($newFileName)
132+
133+
$fileName = basename($filePath);
134+
$this->documentBuilder->setTypeId($documentType->getId());
135+
$this->documentBuilder->setCode(Format::formatCode($fileName));
136+
$this->documentBuilder->setName(Format::formatName($fileName));
137+
$this->documentBuilder->setFileName($fileName);
138+
$this->documentBuilder->setFilePath(dirname($this->fileHelper->getRelativeFilePath($filePath)));
139+
140+
return $this->documentBuilder->create();
141+
}
142+
}
143+
```
144+
145+
## Support
146+
147+
Raise a new [request](https://github.com/opengento/magento2-document/issues) to the issue tracker.
148+
149+
## Authors
150+
151+
- **Opengento Community** - *Lead* - [![Twitter Follow](https://img.shields.io/twitter/follow/opengento.svg?style=social)](https://twitter.com/opengento)
152+
- **Thomas Klein** - *Maintainer* - [![GitHub followers](https://img.shields.io/github/followers/thomas-kl1.svg?style=social)](https://github.com/thomas-kl1)
153+
- **Contributors** - *Contributor* - [![GitHub contributors](https://img.shields.io/github/contributors/opengento/magento2-document.svg?style=flat-square)](https://github.com/opengento/magento2-document/graphs/contributors)
154+
155+
## License
156+
157+
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) details.
158+
159+
***That's all folks!***

0 commit comments

Comments
 (0)