The Product Attachments extension for Magento 2 equips product pages with a special attachments block where you can upload numerous documents such as user guides, extra images, pdf, certificates, licenses and many others.
It also has API support SOAP and REST for creating,updating,deleting and get attachments. It also has support for get product API to get attachments by product.
For Manage Attachment/Icon: Catalog->Product Attachments
For Settings: Stores->Configuration->MagePrince->Product Attachment
Please donate if you enjoy my extension.
Manual Installation
- Copy the content of the repo to the app/code/Prince/Productattach
- Run command: php bin/magento setup:upgrade
- Run command: php bin/magento setup:static-content:deploy
- Now flush cache: php bin/magento cache:flush
Install By Composer
- Go to the Magento folder and run the command: composer require mageprince/magento2-productattachment
- Enable the extension and clear static view files: php bin/magento module:enable Prince_Productattach --clear-static-content
- Register the extension php bin/magento setup:upgrade
- Recompile your Magento project php bin/magento setup:di:compile
Want to contribute to this extension? The quickest way is to open a pull request on GitHub.
If you encounter any problems or bugs, please open an issue on GitHub.
METHOD: POST
URL: http:https://< your store url >/rest/V1/productattach/addupdate
BODY:
(json encoded)
{
"productattachTable": {
"productAttachId": "0",
"name": "testname",
"description": "test desc",
"file": "testfile.pdf",
"url": "",
"store": "0,1",
"customerGroup": "0,1,2,3",
"products": "1,2,3",
"active": "1"
},
"filename": "testfile.pdf",
"fileContent": "JVBERi0xLjYNJeLjz9MN....CiUlRU9GDQo="
}
(json encoded)
{
"productattachTable": {
"productAttachId": "10",
"name": "testname",
"description": "test desc",
},
"filename": "",
"fileContent": ""
}
Note: Keep only field which you want to update except "filename" and "fileContent"
### Deleting an attachment record
**METHOD**: DELETE
**URL**: http:https://< your store url >/rest/V1/productattach/delete/< attachment id >
# API (SOAP) examples
**Creating a new attachment record**
<soap:Envelope xmlns:soap="http:https://www.w3.org/2003/05/soap-envelope" xmlns:all="http:https://magetest:8000/index.php/soap/all?services=princeProductattachV1">
<soap:Header/>
<soap:Body>
<all:princeProductattachV1UpdateInsertAttachmentRequest>
<productattachTable>
<productAttachId>0</productAttachId>
<name>testname</name>
<description>test desc</description>
<file>testfile.pdf</file>
<url></url>
<store>0,1</store>
<customerGroup>0,1,2,3</customerGroup>
<products>1</products>
<active>1</active>
</productattachTable>
<filename>testfile.pdf</filename>
<fileContent><![CDATA[JVBERi0xLjYNJeLjz9MN....CiUlRU9GDQo=]]></fileContent>
</all:princeProductattachV1UpdateInsertAttachmentRequest>
</soap:Body>
</soap:Envelope>
**Updating an attachment record** (same as the previous one, except for the given id in the productAttachId element)
<soap:Envelope xmlns:soap="http:https://www.w3.org/2003/05/soap-envelope" xmlns:all="http:https://magetest:8000/index.php/soap/all?services=princeProductattachV1">
<soap:Header/>
<soap:Body>
<all:princeProductattachV1UpdateInsertAttachmentRequest>
<productattachTable>
<productAttachId>9</productAttachId>
<name>testname</name>
<description>test desc</description>
<file>testfile.pdf</file>
<url></url>
<store>0,1</store>
<customerGroup>0,1,2,3</customerGroup>
<products>1</products>
<active>1</active>
</productattachTable>
<filename>testfile.pdf</filename>
<fileContent><![CDATA[JVBERi0xLjYNJeLjz9MN....CiUlRU9GDQo=]]></fileContent>
</all:princeProductattachV1UpdateInsertAttachmentRequest>
</soap:Body>
</soap:Envelope>
**Deleting an attachment record**
<soap:Envelope xmlns:soap="http:https://www.w3.org/2003/05/soap-envelope" xmlns:all="http:https://magetest:8000/index.php/soap/all?services=princeProductattachV1">
<soap:Header/>
<soap:Body>
<all:princeProductattachV1DeleteAttachmentRequest>
<int>9</int>
</all:princeProductattachV1DeleteAttachmentRequest>
</soap:Body>
</soap:Envelope>