Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunil Tiwari committed Feb 7, 2022
0 parents commit 1219eae
Show file tree
Hide file tree
Showing 17 changed files with 709 additions and 0 deletions.
70 changes: 70 additions & 0 deletions Controller/Adminhtml/Fileupload/Fileupload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
namespace Sunarc\Orderattachment\Controller\Adminhtml\Fileupload;

use Magento\Framework\Filesystem;
use Magento\MediaStorage\Model\File\UploaderFactory;

class Fileupload extends \Magento\Backend\App\Action
{
protected $filesystem;
protected $fileUploader;
protected $orderHistoryFactory;
protected $session;

public function __construct(
\Magento\Backend\App\Action\Context $context,
Filesystem $filesystem,
UploaderFactory $fileUploader,
\Magento\Sales\Model\Order\Status\HistoryFactory $orderHistoryFactory,
\Magento\Backend\Model\Session $session
) {
$this->filesystem = $filesystem;
$this->fileUploader = $fileUploader;
$this->orderHistoryFactory = $orderHistoryFactory;
$this->session = $session;
$this->mediaDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
return parent::__construct($context);
}

public function execute()
{
// print_r($this->getRequest()->getFiles());
// this folder will be created inside "pub/media" folder
$yourFolderName = 'order_attachment/';

// "upload_custom_file" is the HTML input file name
$yourInputFileName = 'attachment';

try {
$file = $this->getRequest()->getFiles($yourInputFileName);
$fileName = ($file && array_key_exists('name', $file)) ? $file['name'] : null;

if ($file && $fileName) {
$target = $this->mediaDirectory->getAbsolutePath($yourFolderName);

/** @var $uploader \Magento\MediaStorage\Model\File\Uploader */
$uploader = $this->fileUploader->create(['fileId' => $yourInputFileName]);
// set allowed file extensions
$uploader->setAllowedExtensions(['jpg', 'pdf', 'doc', 'png', 'zip']);
// allow folder creation
$uploader->setAllowCreateFolders(true);

// rename file name if already exists
$uploader->setAllowRenameFiles(true);

// upload file in the specified folder
$result = $uploader->save($target);

//echo '<pre>'; print_r($result); exit;
$fileName = $uploader->getUploadedFileName();
$this->session->setFileName($fileName);
if ($result['file']) {
$this->messageManager->addSuccess(__('File has been successfully uploaded.'));
}

}
} catch (\Exception $e) {
$this->messageManager->addError($e->getMessage());
}
}
}
65 changes: 65 additions & 0 deletions Controller/Adminhtml/Order/AddComment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
namespace Sunarc\Orderattachment\Controller\Adminhtml\Order;

class AddComment extends \Magento\Sales\Controller\Adminhtml\Order\AddComment
{
protected $session;

/**
* Add order comment action
*
* @return \Magento\Framework\Controller\ResultInterface
*/
public function execute()
{
$order = $this->_initOrder();
if ($order) {
try {
$data = $this->getRequest()->getPost('history');

if (empty($data['comment']) && $data['status'] == $order->getDataByKey('status')) {
throw new \Magento\Framework\Exception\LocalizedException(
__('The comment is missing. Enter and try again.')
);
}

$order->setStatus($data['status']);
$notify = $data['is_customer_notified'] ?? false;
$visible = $data['is_visible_on_front'] ?? false;

if ($notify && !$this->_authorization->isAllowed(self::ADMIN_SALES_EMAIL_RESOURCE)) {
$notify = false;
}
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$fileName = $objectManager->get('Magento\Backend\Model\Session')->getFileName();
$history = $order->addStatusHistoryComment($data['comment'], $data['status']);
$history->setIsVisibleOnFront($visible);
$history->setIsCustomerNotified($notify);
$history->setAttachment($fileName);
$history->save();

// $this->session->setHistoryId($history->getId());
$comment = trim(strip_tags($data['comment']));

$order->save();
/** @var OrderCommentSender $orderCommentSender */
$orderCommentSender = $this->_objectManager
->create(\Magento\Sales\Model\Order\Email\Sender\OrderCommentSender::class);

$orderCommentSender->send($order, $notify, $comment);

return $this->resultPageFactory->create();
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$response = ['error' => true, 'message' => $e->getMessage()];
} catch (\Exception $e) {
$response = ['error' => true, 'message' => __('We cannot add order history.')];
}
if (is_array($response)) {
$resultJson = $this->resultJsonFactory->create();
$resultJson->setData($response);
return $resultJson;
}
}
return $this->resultRedirectFactory->create()->setPath('sales/*/');
}
}
50 changes: 50 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Sunarc\Orderattachment\Helper;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
/**
* Configuration paths enable module
*/
const CONFIG_PATH_MODULE_ENABLED = 'orderattachment/general/enable';

/**
* @var ScopeConfigInterface
*/
protected $_scopeConfig;

public function __construct(
ScopeConfigInterface $scopeConfig
) {
$this->_scopeConfig = $scopeConfig;
}

public function getAdminTemplate()
{
$enabledModule = $this->_scopeConfig->getValue(self::CONFIG_PATH_MODULE_ENABLED, ScopeInterface::SCOPE_STORE);

if ($enabledModule) {
$template = 'Sunarc_Orderattachment::order/view/history.phtml';
} else {
$template = 'Magento_Sales::order/view/history.phtml';
}

return $template;
}
public function getFrontendTemplate()
{
$enabledModule = $this->_scopeConfig->getValue(self::CONFIG_PATH_MODULE_ENABLED, ScopeInterface::SCOPE_STORE);

if ($enabledModule) {
$template = 'Sunarc_Orderattachment::order/order_comments.phtml';
} else {
$template = 'Magento_Sales::order/order_comments.phtml';
}

return $template;
}
}
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
![image](https://user-images.githubusercontent.com/45708520/152330764-01e40664-832a-47fd-8141-d2249e2e36a3.png)

# Magento 2 Order Attachment Extension by Sunarc

The OrderAttachment extension for Magento 2 is a great solution for those users who want to attach media in their order notes section

## Installation
Via Composer

```bash
composer require sunarctech/orderattachment
```
## Key Features
- This module helps us attach media files in order notes section in admin side.
- Attachment will show in both frontend side and admin side.
- Easy to use and user friendly.


## Extension Requirments
###### Php Version
- 5.5 - 8.0

###### Magento Version
- 2.1 to 2.4

## Created by SunArc Technologies
We are the leading Software Development Company providing end-to-end IT services & solutions to our esteemed customers in multiple industries and domains for the past 18+ years? Give us a call.

https://sunarctechnologies.com/ <br>
info@sunarctechnologies.com <br>
+91-8764025209

## 🛒 Marketplace By SunArc Technologies
We developed a broad range of Magento Extensions for E-Com merchants, The objective is to provide premium Extensions to increase the efficiency of the Magento E-stores
[Suncart Marketplace](https://www.suncartstore.com/)

## License
The OSL-3.0 & AFL-3.0 License. Please see [LICENSE](LICENSE) for more information.
35 changes: 35 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "sunarctech/orderattachment",
"description": "Order attachment for magento2",
"keywords": [
"magento2",
"order attachment",
"order attachment admin panel",
"sunarc"
],
"version": "1.0.0",
"require": {
"php": "~5.5.0|~5.6.0|~7.0.0|7.0.1|7.0.2|7.0.4|~7.0.6|~7.1.0|~7.2.0|~7.3.0|~7.4.0"
},
"type": "magento2-module",
"license": [
"OSL-3.0",
"AFL-3.0"
],
"authors": [
{
"name": "Rajneesh Vyas",
"email": "rajneesh.vyas@sunarctechnologies.com",
"homepage": "http://sunarctechnologies.com/",
"role": "Leader"
}
],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Sunarc\\Orderattachment\\": ""
}
}
}
32 changes: 32 additions & 0 deletions etc/acl.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<!--
/**
* Sunarc_Orderattachment extension
* NOTICE OF LICENSE
*
* This source file is subject to the SunArc Technologies License
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://sunarctechnologies.com/end-user-agreement/
*
* @category Sunarc
* @package Sunarc_Orderattachment
* @copyright Copyright (c) 2017
* @license
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
<resources>
<resource id="Magento_Backend::admin">
<resource id="Magento_Backend::stores">
<resource id="Magento_Backend::stores_settings">
<resource id="Magento_Config::config">
<resource id="Sunarc_Orderattachment::orderattachment_config" title="Orderattachment"/>
</resource>
</resource>
</resource>
</resource>
</resources>
</acl>
</config>
24 changes: 24 additions & 0 deletions etc/adminhtml/routes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<!--
/**
* Sunarc_SplitorderByShippingMethod extension
* NOTICE OF LICENSE
*
* This source file is subject to the SunArc Technologies License
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://sunarctechnologies.com/end-user-agreement/
*
* @category Sunarc
* @package Sunarc_SplitorderByShippingMethod
* @copyright Copyright (c) 2017
* @license
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
<route id="orderattachment" frontName="orderattachment">
<module name="Sunarc_Orderattachment"/>
</route>
</router>
</config>
51 changes: 51 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0"?>
<!--
/**
* Sunarc_Splitorderpro
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* Sunarc_Splitorderpro
*
* @category Sunarc_Splitorderpro
* @package Sunarc_Splitorderpro
* @copyright Copyright (c) 2014 Zowta LLC (http://www.sunarctechnologies.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Sunarc_Splitorderpro Team support@sunarctechnologies.com
*
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="sunarc" translate="label" sortOrder="100">
<label>Sunarc</label>
</tab>
<section id="orderattachment" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<class>separator-top</class>
<label>Order Attachment</label>
<tab>sunarc</tab>
<resource>Sunarc_Orderattachment::orderattachment_config</resource>
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>General Configurations</label>
<field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Enable Orderattachment</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</section>
</system>
</config>
7 changes: 7 additions & 0 deletions etc/db_schema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="sales_order_status_history">
<column xsi:type="text" name="attachment" nullable="true" comment="Order Attachment"/>
</table>
</schema>
3 changes: 3 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Sales\Controller\Adminhtml\Order\AddComment" type="Sunarc\Orderattachment\Controller\Adminhtml\Order\AddComment" />
</config>
6 changes: 6 additions & 0 deletions etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Sunarc_Orderattachment" setup_version="1.0.0">
</module>
</config>
Loading

0 comments on commit 1219eae

Please sign in to comment.