├── Controller
└── Cancelorder
│ └── Index.php
├── Helper
└── Data.php
├── README.md
├── composer.json
├── etc
├── adminhtml
│ └── system.xml
├── config.xml
├── email_templates.xml
├── frontend
│ └── routes.xml
└── module.xml
├── media
├── admin_config.png
└── order-history.gif
├── registration.php
└── view
└── frontend
├── email
└── cancelOrderEmail.html
├── layout
├── customer_account_index.xml
├── email_product_list.xml
└── sales_order_history.xml
└── templates
├── order
├── history.phtml
└── recent.phtml
└── product.phtml
/Controller/Cancelorder/Index.php:
--------------------------------------------------------------------------------
1 | priceHelper = $priceHelper;
43 | $this->resultPageFactory = $resultPageFactory;
44 | $this->_order = $order;
45 | $this->_customerSession = $customerSession;
46 | $this->transportBuilder = $transportBuilder;
47 | $this->helper = $helper;
48 | $this->collectionFactory = $collectionFactory;
49 | $this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);
50 |
51 | return parent::__construct($context);
52 | }
53 |
54 | public function execute()
55 | {
56 | $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
57 | $orderId = $this->getRequest()->getParam('orderid');
58 | $order = $this->_order->load($orderId);
59 | $productId = [];
60 | foreach ($order->getAllItems() as $item) {
61 | $productId[] = $item->getProductId();
62 | }
63 | $productCollection = $this->collectionFactory->create();
64 | $productCollection->addAttributeToSelect('*')->addFieldToFilter('entity_id', array('in' => $productId));
65 | $products = [];
66 | foreach ($productCollection as $product) {
67 | $products[] = $product;
68 |
69 | }
70 | $post['collectionProduct'] = $products;
71 | if($order->canCancel()){
72 | $order->cancel();
73 | $order->save();
74 | $this->messageManager->addSuccess(__('Order has been canceled successfully.'));
75 | $post['store_id'] = $order->getStore()->getStoreId();
76 | $post['store_name'] = $order->getStore()->getName();
77 | $post['site_name'] = $order->getStore()->getWebsite()->getName();
78 | $post['entity_id'] = $order->getEntity_id();
79 | $post['base_grand_total'] = $this->priceHelper->currency($order->getBase_grand_total(), true, false);
80 | $post['created_at'] = $order->getCreated_at();
81 | $post['customer_lastname'] = $order->getCustomer_lastname();
82 | $post['orderid'] = $order->getIncrement_id();
83 | $customerData = $this->_customerSession->getCustomer();
84 | $senderName = $customerData->getName();
85 | $senderEmail = $customerData->getEmail();
86 | $sender = [
87 | 'name' => $senderName,
88 | 'email' => $this->helper->getEmailSender(),
89 | ];
90 | if($this->helper->getEmailSender()){
91 | if($this->helper->getEmailSeller()){
92 | $transport = $this->transportBuilder->setTemplateIdentifier('cancel_order_email_template')
93 | ->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $post['store_id']])
94 | ->setTemplateVars($post)
95 | ->setFrom($sender)
96 | ->addTo($senderEmail)
97 | ->addCc($this->helper->getEmailSeller())
98 | ->getTransport();
99 | }else {
100 | $transport = $this->transportBuilder->setTemplateIdentifier('cancel_order_email_template')
101 | ->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $post['store_id']])
102 | ->setTemplateVars($post)
103 | ->setFrom($sender)
104 | ->addTo($senderEmail)
105 | ->getTransport();
106 | }
107 |
108 | try {
109 | $transport->sendMessage();
110 | } catch (\Exception $e) {
111 | $this->logger->critical($e->getMessage());
112 | }
113 |
114 | }
115 |
116 | } else {
117 | $this->messageManager->addError(__('Order cannot be canceled.'));
118 | }
119 |
120 | $resultRedirect->setUrl($this->_redirect->getRefererUrl());
121 |
122 | return $resultRedirect;
123 | }
124 | }
--------------------------------------------------------------------------------
/Helper/Data.php:
--------------------------------------------------------------------------------
1 | configModule = $this->getConfig(strtolower($this->_getModuleName()));
24 | }
25 |
26 | public function getConfig($cfg='')
27 | {
28 | if($cfg) return $this->scopeConfig->getValue( $cfg, \Magento\Store\Model\ScopeInterface::SCOPE_STORE );
29 | return $this->scopeConfig;
30 | }
31 |
32 | public function getConfigModule($cfg='', $value=null)
33 | {
34 | $values = $this->configModule;
35 | if( !$cfg ) return $values;
36 | $config = explode('/', $cfg);
37 | $end = count($config) - 1;
38 | foreach ($config as $key => $vl) {
39 | if( isset($values[$vl]) ){
40 | if( $key == $end ) {
41 | $value = $values[$vl];
42 | }else {
43 | $values = $values[$vl];
44 | }
45 | }
46 |
47 | }
48 | return $value;
49 | }
50 |
51 | public function isEnabled()
52 | {
53 | return $this->getConfigModule('general/enabled');
54 | }
55 |
56 | public function getEmailSender()
57 | {
58 | return $this->getConfigModule('general/email_sender');
59 | }
60 |
61 | public function getEmailSeller()
62 | {
63 | return $this->getConfigModule('general/email_seller');
64 | }
65 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://shopify.pxf.io/VyL446)
2 |
3 | ## Magento 2 Cancel Order by Customer
4 | This module is allow user can cancel order in frontend.
5 |
6 | ### Description
7 | In many cases, customers order a product on a website but change their mind and don't want to buy that product anymore. To cancel an order, they have to contact the website administrator and have to wait for customer service to process the request.
8 |
9 |
10 | **Cancel order extension** allows Magento website to integrate the order cancellation feature right on the user interface. Customers can fully control the orders they have paid on the website.
11 |
12 | ### Features
13 |
14 | - Customers automatically cancel orders quickly
15 |
16 | - Notify admin about canceled orders
17 |
18 | - Send order cancellation confirmation to customer's email.
19 |
20 | - Convenient management in the backend
21 |
22 | - Simple steps to install and use but bring great features
23 |
24 | - User-friendly interface
25 |
26 | [](https://packagist.org/packages/magepow/cancelorder)
27 | [](https://packagist.org/packages/magepow/cancelorder)
28 | [](https://packagist.org/packages/magepow/cancelorder)
29 |
30 | ## 2. How to install Magento 2 Cancel Order extension Free
31 | ### ✓ Install Magepow Cancel Order via composer (recommend)
32 | Run the following command in Magento 2 root folder:
33 |
34 | ```
35 | composer require magepow/cancelorder
36 | php bin/magento setup:upgrade
37 | php bin/magento setup:static-content:deploy -f
38 | ```
39 |
40 | ## 3. How does Cancel order work for Magento?
41 |
42 | In Store > Configuration > Magepow > Cancel Order
43 |
44 | 
45 |
46 | ### This Is Result In Frontend
47 | 
48 |
49 | If this project help you reduce time to develop, you can give me a cup of coffee :)
50 |
51 | [](https://www.paypal.com/paypalme/alopay)
52 |
53 |
54 | **[Our Magento 2 Extensions](https://magepow.com/magento-2-extensions.html)**
55 |
56 | * [Magento 2 Recent Sales Notification](https://magepow.com/magento-2-recent-order-notification.html)
57 |
58 | * [Magento 2 Categories Extension](https://magepow.com/magento-categories-extension.html)
59 |
60 | * [Magento 2 Sticky Cart](https://magepow.com/magento-sticky-cart.html)
61 |
62 | * [Magento 2 Ajax Contact](https://magepow.com/magento-ajax-contact-form.html)
63 |
64 | * [Magento 2 Lazy Load](https://magepow.com/magento-lazy-load.html)
65 |
66 | * [Magento 2 Mutil Translate](https://magepow.com/magento-multi-translate.html)
67 |
68 | * [Magento 2 Instagram Integration](https://magepow.com/magento-2-instagram.html)
69 |
70 | * [Magento 2 Lookbook Pin Products](https://magepow.com/lookbook-pin-products.html)
71 |
72 | * [Magento 2 Product Slider](https://magepow.com/magento-product-slider.html)
73 |
74 | * [Magento 2 Product Banner](https://magepow.com/magento-2-banner-slider.html)
75 |
76 | **[Our Magento 2 services](https://magepow.com/magento-services.html)**
77 |
78 | * [PSD to Magento 2 Theme Conversion](https://alothemes.com/psd-to-magento-theme-conversion.html)
79 |
80 | * [Magento 2 Speed Optimization Service](https://magepow.com/magento-speed-optimization-service.html)
81 |
82 | * [Magento 2 Security Patch Installation](https://magepow.com/magento-security-patch-installation.html)
83 |
84 | * [Magento 2 Website Maintenance Service](https://magepow.com/website-maintenance-service.html)
85 |
86 | * [Magento 2 Professional Installation Service](https://magepow.com/professional-installation-service.html)
87 |
88 | * [Magento 2 Upgrade Service](https://magepow.com/magento-upgrade-service.html)
89 |
90 | * [Magento 2 Customization Service](https://magepow.com/customization-service.html)
91 |
92 | * [Hire Magento 2 Developer](https://magepow.com/hire-magento-developer.html)
93 |
94 | **[Our Magento 2 Themes](https://alothemes.com/)**
95 |
96 | * [Expert Multipurpose Responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/expert-premium-responsive-magento-2-and-1-support-rtl-magento-2-/21667789)
97 |
98 | * [Gecko Premium Responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/gecko-responsive-magento-2-theme-rtl-supported/24677410)
99 |
100 | * [Milano Fashion Responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/milano-fashion-responsive-magento-1-2-theme/12141971)
101 |
102 | * [Electro 2 Responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/electro2-premium-responsive-magento-2-rtl-supported/26875864)
103 |
104 | * [Electro Responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/electro-responsive-magento-1-2-theme/17042067)
105 |
106 | * [Pizzaro Food responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/pizzaro-food-responsive-magento-1-2-theme/19438157)
107 |
108 | * [Biolife organic responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/biolife-organic-food-magento-2-theme-rtl-supported/25712510)
109 |
110 | * [Market responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/market-responsive-magento-2-theme/22997928)
111 |
112 | * [Kuteshop responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/kuteshop-multipurpose-responsive-magento-1-2-theme/12985435)
113 |
114 | * [Bencher - Responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/bencher-responsive-magento-1-2-theme/15787772)
115 |
116 | * [Supermarket Responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/supermarket-responsive-magento-1-2-theme/18447995)
117 |
118 | **[Our Shopify Themes](https://themeforest.net/user/alotheme)**
119 |
120 | * [Dukamarket - Multipurpose Shopify Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/dukamarket-multipurpose-shopify-theme/36158349)
121 |
122 | * [Ohey - Multipurpose Shopify Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/ohey-multipurpose-shopify-theme/34624195)
123 |
124 | * [Flexon - Multipurpose Shopify Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/flexon-multipurpose-shopify-theme/33461048)
125 |
126 | **[Our Shopify App](https://apps.shopify.com/partners/maggicart)**
127 |
128 | * [Magepow Infinite Scroll](https://apps.shopify.com/magepow-infinite-scroll)
129 |
130 | * [Magepow Promotionbar](https://apps.shopify.com/magepow-promotionbar)
131 |
132 | * [Magepow Size Chart](https://apps.shopify.com/magepow-size-chart)
133 |
134 | **[Our WordPress Theme](https://themeforest.net/user/alotheme/portfolio)**
135 |
136 | * [SadesMarket - Multipurpose WordPress Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/sadesmarket-multipurpose-wordpress-theme/35369933)
137 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "magepow/cancelorder",
3 | "description": "Customer Cancel Order magento2",
4 | "require": {
5 | "magepow/core": "^1.0.0"
6 | },
7 | "type": "magento2-module",
8 | "license": [
9 | "MIT"
10 | ],
11 | "authors": [
12 | {
13 | "name": "Magepow",
14 | "email": "support@magepow.com",
15 | "homepage": "https://www.magepow.com",
16 | "role": "Technical Support"
17 | }
18 | ],
19 | "autoload": {
20 | "psr-4": {
21 | "Magepow\\CancelOrder\\": ""
22 | },
23 | "files": [
24 | "registration.php"
25 | ]
26 | }
27 | }
--------------------------------------------------------------------------------
/etc/adminhtml/system.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 | 19 | # 20 | {{var orderid}} 21 |
22 |We're writing to let you know that your order has been successfully canceled. In most cases, you pay for items when we ship them to you, so you won't be charged for items that are canceled.*
27 |31 | 32 | # 33 | {{var orderid}} 34 |
35 |36 | 37 | {{var created_at}} 38 |
39 |= $block->escapeHtml(__('Order #')) ?> | 21 |= $block->escapeHtml(__('Date')) ?> | 22 | = $block->getChildHtml('extra.column.header') ?> 23 |= $block->escapeHtml(__('Order Total')) ?> | 24 |= $block->escapeHtml(__('Status')) ?> | 25 |= $block->escapeHtml(__('Action')) ?> | 26 |
---|---|---|---|---|
= $block->escapeHtml($_order->getRealOrderId()) ?> | 32 |= /* @noEscape */ $block->formatDate($_order->getCreatedAt()) ?> | 33 | getChildBlock('extra.container'); ?> 34 | 35 | setOrder($_order); ?> 36 | = $extra->getChildHtml() ?> 37 | 38 |= /* @noEscape */ $_order->formatPrice($_order->getGrandTotal()) ?> | 39 |= $block->escapeHtml($_order->getStatusLabel()) ?> | 40 |41 | canCancel() && $helper->isEnabled()): ?> 42 | = /* @escapeNotVerified */ __('Cancel Order') ?> 43 | 44 | 45 | = $block->escapeHtml(__('View Order')) ?> 46 | 47 | helper(\Magento\Sales\Helper\Reorder::class)->canReorder($_order->getEntityId())) : ?> 48 | 52 | = $block->escapeHtml(__('Reorder')) ?> 53 | 54 | 55 | | 56 |
= $block->escapeHtml(__('Order #')) ?> | 34 |= $block->escapeHtml(__('Date')) ?> | 35 |= $block->escapeHtml(__('Ship To')) ?> | 36 |= $block->escapeHtml(__('Order Total')) ?> | 37 |= $block->escapeHtml(__('Status')) ?> | 38 |= $block->escapeHtml(__('Action')) ?> | 39 |
---|---|---|---|---|---|
= $block->escapeHtml($_order->getRealOrderId()) ?> | 45 |= $block->escapeHtml($block->formatDate($_order->getCreatedAt())) ?> | 46 |= $_order->getShippingAddress() ? $block->escapeHtml($_order->getShippingAddress()->getName()) : " " ?> | 47 |= /* @noEscape */ $_order->formatPrice($_order->getGrandTotal()) ?> | 48 |= $block->escapeHtml($_order->getStatusLabel()) ?> | 49 |50 | canCancel() && $helper->isEnabled()) : ?> 51 | = /* @escapeNotVerified */ __('Cancel Order') ?> 52 | 53 | 54 | = $block->escapeHtml(__('View Order')) ?> 55 | 56 | helper(\Magento\Sales\Helper\Reorder::class) 57 | ->canReorder($_order->getEntityId()) 58 | ) : ?> 59 | 63 | = $block->escapeHtml(__('Reorder')) ?> 64 | 65 | 66 | | 67 |