├── .github ├── FUNDING.yml ├── issue_template.md └── workflows │ └── php.yml ├── Block ├── Adminhtml │ └── System │ │ └── Config │ │ └── Form │ │ └── Field │ │ └── MiscScript.php └── Checkout │ └── Success.php ├── Helper └── Data.php ├── Model └── Config │ └── Backend │ └── Serialized │ └── MiscScriptArraySerialized.php ├── README.md ├── composer.json ├── etc ├── acl.xml ├── adminhtml │ └── system.xml └── module.xml ├── i18n └── en_US.csv ├── registration.php └── view ├── adminhtml ├── requirejs-config.js ├── templates │ └── system │ │ └── config │ │ └── form │ │ └── field │ │ └── array.phtml └── web │ └── js │ └── checkout-success-misc-script.js └── frontend ├── layout └── checkout_onepage_success.xml └── templates └── checkout └── misc-script.phtml /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | #github: [srenon] 4 | custom: ['https://paypal.me/magepal'] 5 | -------------------------------------------------------------------------------- /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | #### Magento version #: 7 | 8 | #### Edition (EE, CE, OS, etc): 9 | 10 | #### Expected behavior: 11 | 12 | #### Actual behavior: 13 | 14 | #### Steps to reproduce: 15 | 16 | #### Preconditions 17 | 18 | 19 | 20 | 21 | 37 | -------------------------------------------------------------------------------- /.github/workflows/php.yml: -------------------------------------------------------------------------------- 1 | name: PHPCS 2 | on: [push] 3 | jobs: 4 | build: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@master 8 | - name: PHPCS 9 | run: docker run --rm -v $PWD:/code:ro domw/phpcs phpcs --colors --standard=Magento2 --report=full,summary,gitblame --extensions=php,phtml ./ 10 | - name: compatibility 11 | run: docker run --rm -v $PWD:/code:ro domw/phpcompatibility phpcs --standard=PHPCompatibility --runtime-set testVersion 5.6-7.4 --colors --warning-severity=0 --report=full,summary --extensions=php,phtml ./ 12 | -------------------------------------------------------------------------------- /Block/Adminhtml/System/Config/Form/Field/MiscScript.php: -------------------------------------------------------------------------------- 1 | helper = $helper; 41 | parent::__construct($context, $data); 42 | } 43 | 44 | /** 45 | * Initialise columns for 'Store Locations' 46 | * Label is name of field 47 | * Class is storefront validation action for field 48 | * 49 | * @return void 50 | */ 51 | protected function _construct() 52 | { 53 | $this->addColumn( 54 | 'is_enabled', 55 | [ 56 | 'label' => __('Is Enabled'), 57 | 'class' => '', 58 | 'type' => 'checkbox' 59 | ] 60 | ); 61 | $this->addColumn( 62 | 'title', 63 | [ 64 | 'label' => __('Title/Description'), 65 | 'class' => 'validate-no-empty', 66 | 'type' => 'text' 67 | ] 68 | ); 69 | $this->addColumn( 70 | 'scripts', 71 | [ 72 | 'label' => __('Scripts'), 73 | 'class' => 'validate-no-empty greater-than-equals-to-0', 74 | 'type' => 'textarea' 75 | ] 76 | ); 77 | $this->_addAfter = false; 78 | parent::_construct(); 79 | } 80 | 81 | /** 82 | * @return string 83 | */ 84 | public function getTemplateButtonList() 85 | { 86 | $html = ''; 87 | 88 | foreach ($this->helper->getTemplateVariableKey() as $key) { 89 | $html .= sprintf( 90 | '<%s style="%s" data-mage-init=\\\'%s\\\' type="button">%s', 91 | 'button', 92 | 'margin:3px;', 93 | '{"checkoutSuccessMiscScript":{"textareaId":"<%- _id %>_scripts"}}', 94 | $key 95 | ); 96 | } 97 | 98 | return $html; 99 | } 100 | 101 | /** 102 | * Add a column to array-grid 103 | * 104 | * @param string $name 105 | * @param array $params 106 | * @return void 107 | */ 108 | public function addColumn($name, $params) 109 | { 110 | $this->_columns[$name] = [ 111 | 'label' => $this->_getParam($params, 'label', 'Column'), 112 | 'size' => $this->_getParam($params, 'size', false), 113 | 'style' => $this->_getParam($params, 'style'), 114 | 'class' => $this->_getParam($params, 'class'), 115 | 'type' => $this->_getParam($params, 'type', 'text'), 116 | 'renderer' => false, 117 | ]; 118 | if (!empty($params['renderer']) && $params['renderer'] instanceof AbstractBlock) { 119 | $this->_columns[$name]['renderer'] = $params['renderer']; 120 | } 121 | } 122 | 123 | /** 124 | * @param string $columnName 125 | * @return mixed|string 126 | * @throws LocalizedException 127 | */ 128 | public function renderCellTemplate($columnName) 129 | { 130 | if (empty($this->_columns[$columnName])) { 131 | throw new LocalizedException(__('Wrong column name specified.')); 132 | } 133 | $column = $this->_columns[$columnName]; 134 | $inputName = $this->_getCellInputElementName($columnName); 135 | 136 | if ($column['renderer']) { 137 | return str_replace(["\n", "\t", "\r"], '', $column['renderer']->setInputName( 138 | $inputName 139 | )->setInputId( 140 | $this->_getCellInputElementId('<%- _id %>', $columnName) 141 | )->setColumnName( 142 | $columnName 143 | )->setColumn( 144 | $column 145 | )->toHtml()); 146 | } 147 | 148 | if ($column['type'] == 'text') { 149 | return ''; 168 | } elseif ($column['type'] == 'checkbox') { 169 | return ''; 188 | } else { 189 | return ''; 206 | } 207 | } 208 | } 209 | -------------------------------------------------------------------------------- /Block/Checkout/Success.php: -------------------------------------------------------------------------------- 1 | helper = $helper; 59 | $this->checkoutSession = $checkoutSession; 60 | $this->orderRepository = $orderRepository; 61 | parent::__construct($context, $data); 62 | } 63 | 64 | /** 65 | * @return string 66 | */ 67 | protected function _toHtml() 68 | { 69 | if (!$this->helper->isEnabled()) { 70 | return ''; 71 | } 72 | 73 | return parent::_toHtml(); 74 | } 75 | 76 | /** 77 | * @return OrderInterface 78 | */ 79 | protected function getOrder() 80 | { 81 | if (!$this->order) { 82 | $this->order = $this->orderRepository->get($this->checkoutSession->getLastOrderId()); 83 | } 84 | 85 | return $this->order; 86 | } 87 | 88 | /** 89 | * @param $order 90 | * @return $this 91 | */ 92 | public function setOrder($order) 93 | { 94 | $this->order = $order; 95 | return $this; 96 | } 97 | 98 | /** 99 | * @return array 100 | */ 101 | protected function getTemplateArray() 102 | { 103 | $order = $this->getOrder(); 104 | 105 | $this->helper->setVariableData('order_id', $order->getIncrementId()); 106 | $this->helper->setVariableData('total', $this->helper->formatPrice($order->getBaseGrandTotal())); 107 | $this->helper->setVariableData('sub_total', $this->helper->formatPrice($order->getBaseSubtotal())); 108 | $this->helper->setVariableData('shipping', $this->helper->formatPrice($order->getBaseShippingAmount())); 109 | $this->helper->setVariableData('tax', $this->helper->formatPrice($order->getTaxAmount())); 110 | $this->helper->setVariableData('coupon_code', $order->getCouponCode() ?: ''); 111 | $this->helper->setVariableData('discount', $this->helper->formatPrice($order->getDiscountAmount())); 112 | 113 | return $this->helper->getTemplateVariable(); 114 | } 115 | 116 | /** 117 | * @param $string 118 | * @return mixed 119 | */ 120 | protected function processTemplate($string) 121 | { 122 | if (empty($this->templateArray)) { 123 | $template = $this->getTemplateArray(); 124 | 125 | $this->templateArray = str_replace(array_keys($template), array_values($template), $string); 126 | } 127 | 128 | return $this->templateArray; 129 | } 130 | 131 | /** 132 | * @return mixed 133 | */ 134 | public function getActiveScripts() 135 | { 136 | $html = ''; 137 | 138 | $scripts = $this->helper->getScripts(); 139 | 140 | if (is_array($scripts)) { 141 | foreach ($scripts as $script) { 142 | if (array_key_exists('is_enabled', $script) 143 | && $script['is_enabled'] == 'checked' 144 | && array_key_exists('scripts', $script) 145 | ) { 146 | $html .= $script['scripts']; 147 | } 148 | } 149 | } 150 | 151 | return $this->processTemplate($html); 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /Helper/Data.php: -------------------------------------------------------------------------------- 1 | null, 21 | 'total' => null, 22 | 'sub_total' => null, 23 | 'shipping' => null, 24 | 'tax' => null, 25 | 'coupon_code' => null, 26 | 'discount' => null, 27 | ]; 28 | 29 | const TEMPLATE_START = '{{'; 30 | const TEMPLATE_END = '}}'; 31 | 32 | /** 33 | * @var JsonHelper 34 | */ 35 | protected $jsonHelper; 36 | 37 | /** 38 | * @param Context $context 39 | * @param JsonHelper $jsonHelper 40 | */ 41 | public function __construct( 42 | Context $context, 43 | JsonHelper $jsonHelper 44 | ) { 45 | parent::__construct($context); 46 | $this->jsonHelper = $jsonHelper; 47 | } 48 | 49 | /** 50 | * Whether is active 51 | * 52 | * @return bool 53 | */ 54 | public function isEnabled() 55 | { 56 | return $this->scopeConfig->isSetFlag(self::XML_PATH_ACTIVE, ScopeInterface::SCOPE_STORE); 57 | } 58 | 59 | /** 60 | * Customer dashboard active 61 | * 62 | * @return bool 63 | */ 64 | public function getScripts() 65 | { 66 | $json = $this->scopeConfig->getValue( 67 | 'magepal_checkout/misc_script/scripts', 68 | ScopeInterface::SCOPE_STORE 69 | ); 70 | 71 | return $this->jsonHelper->jsonDecode($json); 72 | } 73 | 74 | /** 75 | * Format Price 76 | * 77 | * @param $price 78 | * @return float 79 | */ 80 | public function formatPrice($price) 81 | { 82 | return (float)sprintf('%.2F', $price); 83 | } 84 | 85 | /** 86 | * @return array 87 | */ 88 | public function getVariables() 89 | { 90 | return $this->variables; 91 | } 92 | 93 | /** 94 | * @param $key 95 | * @param $value 96 | * @return $this 97 | */ 98 | public function setVariableData($key, $value) 99 | { 100 | if (array_key_exists($key, $this->variables)) { 101 | $this->variables[$key] = $value; 102 | } 103 | 104 | return $this; 105 | } 106 | 107 | /** 108 | * @return array 109 | */ 110 | public function getTemplateVariableKey() 111 | { 112 | $keys = []; 113 | 114 | foreach ($this->getVariables() as $key => $val) { 115 | $keys[] = self::TEMPLATE_START . $key . self::TEMPLATE_END; 116 | } 117 | 118 | return $keys; 119 | } 120 | 121 | /** 122 | * @return array 123 | */ 124 | public function getTemplateVariable() 125 | { 126 | $values = []; 127 | 128 | foreach ($this->getVariables() as $key => $val) { 129 | $values[self::TEMPLATE_START . $key . self::TEMPLATE_END] = $val; 130 | } 131 | 132 | return $values; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /Model/Config/Backend/Serialized/MiscScriptArraySerialized.php: -------------------------------------------------------------------------------- 1 | getValue(); 22 | if (is_array($values)) { 23 | foreach ($values as &$value) { 24 | if (!array_key_exists('is_enabled', $value)) { 25 | $value['is_enabled'] = ''; 26 | } 27 | } 28 | } 29 | 30 | $this->setValue($values); 31 | return $this; 32 | } 33 | 34 | /** 35 | * @return $this 36 | */ 37 | public function beforeSave() 38 | { 39 | $values = $this->getValue(); 40 | 41 | if (is_array($values)) { 42 | foreach ($values as &$value) { 43 | if (is_array($value)) { 44 | if (!array_key_exists('is_enabled', $value)) { 45 | $value['is_enabled'] = ''; 46 | } else { 47 | $value['is_enabled'] = 'checked'; 48 | } 49 | } 50 | } 51 | 52 | $this->setValue($values); 53 | } 54 | 55 | parent::beforeSave(); 56 | return $this; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Magento App Store 2 | 3 | # Add Miscellaneous HTML and Scripts to Magento2 Checkout Success Page 4 | 5 | [![Total Downloads](https://poser.pugx.org/magepal/magento2-checkout-success-misc-script/downloads)](https://www.magepal.com/order-confirmation-miscellaneous-scripts-for-magento-2.html) 6 | [![Latest Stable Version](https://poser.pugx.org/magepal/magento2-checkout-success-misc-script/v/stable)](https://www.magepal.com/order-confirmation-miscellaneous-scripts-for-magento-2.html) 7 | [![GitHub stars](https://img.shields.io/github/stars/magepal/magento2-checkout-success-misc-script.svg)](https://www.magepal.com/order-confirmation-miscellaneous-scripts-for-magento-2.html) 8 | [![GitHub forks](https://img.shields.io/github/forks/magepal/magento2-checkout-success-misc-script.svg)](https://www.magepal.com/order-confirmation-miscellaneous-scripts-for-magento-2.html) 9 | 10 | Magento2 - Edit Order Email 11 | 12 | Add miscellaneous HTML and scripts quickly and easily to your Magento2 checkout success page. Ideal for testing new page styling of your order confirmation page, adding new static blocks or other customization to your checkout page. 13 | 14 | Easily preview and make changes using our [Preview Order Confirmation Page](https://www.magepal.com/magento2/extensions/preview-order-confirmation-page-for-magento-2.html) extension without having to placing a new order or modifying Magento's core source code. 15 | 16 | Design beautiful order confirmation page with our new [Enhanced Success Page](https://www.magepal.com/magento2/extensions/enhanced-success-page.html) extension. 17 | 18 | ![success page miscellaneous html and scripts](https://image.ibb.co/gZcjAx/Success_Page_Miscellaneous_HTML_and_Scripts_by_magepal.gif) 19 | 20 | ### Order Variables 21 | 22 | - Order ID 23 | - Total 24 | - Sub Total 25 | - Shipping Cost 26 | - Tax 27 | - Coupon Code 28 | - Discount 29 | 30 | ### Documentation 31 | 32 | - [How to Installing Order Confirmation Miscellaneous HTML and Scripts](https://www.magepal.com/help/docs/success-page-miscellaneous-scripts-magento-2/#installation) 33 | 34 | - [How to Configure Add Miscellaneous HTML and Scripts to Checkout Success Page](https://www.magepal.com/help/docs/success-page-miscellaneous-scripts-magento-2/#configuration) 35 | 36 | ## Installation using Composer (recommended) 37 | 38 | ``` 39 | composer require magepal/magento2-checkout-success-misc-script 40 | ``` 41 | 42 | Contribution 43 | --- 44 | Want to contribute to this extension? The quickest way is to open a [pull request on GitHub](https://help.github.com/articles/using-pull-requests). 45 | 46 | Support 47 | --- 48 | If you encounter any problems or bugs, please open an issue on [GitHub](https://github.com/magepal/magento2-reindex/issues). 49 | 50 | Need help setting up or want to customize this extension to meet your business needs? Please email support@magepal.com and if we like your idea we will add this feature for free or at a discounted rate. 51 | 52 | Magento 2 Extensions 53 | --- 54 | - [Custom SMTP](https://www.magepal.com/magento2/extensions/custom-smtp.html) 55 | - [Catalog Hover Image for Magento](https://www.magepal.com/magento2/extensions/catalog-hover-image-for-magento.html) 56 | - [Enhanced Success Page for Magento 2](https://www.magepal.com/magento2/extensions/enhanced-success-page.html) 57 | - [Enhanced Transactional Emails for Magento 2](https://www.magepal.com/magento2/extensions/enhanced-transactional-emails.html) 58 | - [Google Tag Manager](https://www.magepal.com/magento2/extensions/google-tag-manager.html) 59 | - [Enhanced E-commerce](https://www.magepal.com/magento2/extensions/enhanced-ecommerce-for-google-tag-manager.html) 60 | - [Admin Reindex](https://www.magepal.com/magento2/extensions/reindex.html) 61 | - [Custom Shipping Method](https://www.magepal.com/magento2/extensions/custom-shipping-rates-for-magento-2.html) 62 | - [Preview Order Confirmation](https://www.magepal.com/magento2/extensions/preview-order-confirmation-page-for-magento-2.html) 63 | - [Guest to Customer](https://www.magepal.com/magento2/extensions/guest-to-customer.html) 64 | - [Admin Form Fields Manager](https://www.magepal.com/magento2/extensions/admin-form-fields-manager-for-magento-2.html) 65 | - [Customer Dashboard Links Manager](https://www.magepal.com/magento2/extensions/customer-dashboard-links-manager-for-magento-2.html) 66 | - [Lazy Loader](https://www.magepal.com/magento2/extensions/lazy-load.html) 67 | - [Order Confirmation Page Miscellaneous Scripts](https://www.magepal.com/magento2/extensions/order-confirmation-miscellaneous-scripts-for-magento-2.html) 68 | - [HTML Minifier for Magento2](https://www.magepal.com/magento2/extensions/html-minifier.html) 69 | 70 | © MagePal LLC. | [www.magepal.com](https://www.magepal.com) 71 | 72 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magepal/magento2-checkout-success-misc-script", 3 | "description": "Add Miscellaneous HTML and JavaScript codes to Magento2 checkout confirmation page", 4 | "keywords": [ 5 | "magento 2", 6 | "checkout tags", 7 | "success page", 8 | "magento2 scripts", 9 | "checkout success page java scripts", 10 | "order confirmation page javascript", 11 | "magento2 order confirmation tracking", 12 | "add js to confirmation page", 13 | "success page js" 14 | ], 15 | "require": { 16 | "php": "~7.2.0|~7.3.0|~7.4.0|~8.1.0|~8.2.0|~8.3.0|~8.4.0", 17 | "magento/module-backend": "100.0.*|100.1.*|100.2.*|101.0.*|102.0.*", 18 | "magento/framework": "100.0.*|100.1.*|101.0.*|102.0.*|103.0.*", 19 | "magepal/magento2-core": ">=1.1.10" 20 | }, 21 | "suggest": { 22 | "magepal/magento2-preview-checkout-success-page":"Preview checkout success page from admin" 23 | }, 24 | "type": "magento2-module", 25 | "version": "1.2.5", 26 | "license": [ 27 | "proprietary" 28 | ], 29 | "homepage": "https://www.magepal.com/", 30 | "support": { 31 | "email": "support@magepal.com", 32 | "issues": "https://github.com/magepal/magento2-checkout-success-misc-script/issues/" 33 | }, 34 | "authors": [ 35 | { 36 | "name": "Renon Stewart", 37 | "email": "renon@magepal.com", 38 | "homepage": "https://www.magepal.com/", 39 | "role": "Leader" 40 | } 41 | ], 42 | "autoload": { 43 | "files": [ 44 | "registration.php" 45 | ], 46 | "psr-4": { 47 | "MagePal\\CheckoutSuccessMiscScript\\": "" 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /etc/acl.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /etc/adminhtml/system.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | magepal 17 | MagePal_PreviewCheckoutSuccessPage::config_magepal_checkoutsuccessmiscscript 18 | 19 | 20 | 1 21 | 22 | 24 | Copyright © 2024 MagePal, LLC 25 | Documentation 26 | Support 27 | Latest Version 28 | Extension Detail 29 | More Extensions 30 | 31 |
32 | Design beautiful order confirmation page with our new Enhanced Success Page extension. 33 |
34 |
35 | ]]> 36 |
37 | 38 | 39 | MagePal\Core\Block\Adminhtml\System\Config\Composer\Version 40 | 41 | 42 | 43 | Magento\Config\Model\Config\Source\Yesno 44 | 45 | 46 | 47 | MagePal\CheckoutSuccessMiscScript\Block\Adminhtml\System\Config\Form\Field\MiscScript 48 | MagePal\CheckoutSuccessMiscScript\Model\Config\Backend\Serialized\MiscScriptArraySerialized 49 | 50 | 1 51 | 52 | 53 |
54 |
55 |
56 |
57 | -------------------------------------------------------------------------------- /etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /i18n/en_US.csv: -------------------------------------------------------------------------------- 1 | "Module Version","Module Version" 2 | "Composer Version","Composer Version" 3 | "Version","Version" 4 | "Enable","Enable" 5 | "HTML and Scripts","HTML and Scripts" 6 | "Is Enabled","Is Enabled" 7 | "Title/Description","Title/Description" 8 | "Scripts","Scripts" 9 | "Add","Add" 10 | -------------------------------------------------------------------------------- /registration.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | getHtmlId() ? $block->getHtmlId() : '_' . uniqid(); 15 | $_colspan = $block->isAddAfter() ? 2 : 1; 16 | ?> 17 | 18 |
19 |
20 | 21 | 22 | 23 | getColumns() as $columnName => $column) : ?> 24 | 25 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | 35 | 43 | 44 | 45 | 46 |
escapeHtml($column['label']) ?> 29 | escapeHtml(__('Action')); ?> 30 |
36 | 42 |
47 |
48 | 51 | 52 | 154 |
155 | -------------------------------------------------------------------------------- /view/adminhtml/web/js/checkout-success-misc-script.js: -------------------------------------------------------------------------------- 1 | define([ 2 | 'jquery' 3 | ], function ($) { 4 | 5 | return{ 6 | checkoutSuccessMiscScript: function (options, element) { 7 | $(element).on('click', this.processTemplateVar.bind(this, options.textareaId, element)); 8 | }, 9 | processTemplateVar: function (textareaId, element) { 10 | 11 | var $textarea = $('#' + textareaId); 12 | 13 | var startCursorPos = $textarea.prop('selectionStart'); 14 | var endCursorPos = $textarea.prop('selectionEnd'); 15 | var v = $textarea.val(); 16 | 17 | if (endCursorPos > startCursorPos) { 18 | v = v.slice(0, startCursorPos) + v.slice(endCursorPos); 19 | } 20 | 21 | var textBefore = v.substring(0, startCursorPos); 22 | var textAfter = v.substring(startCursorPos, v.length); 23 | $textarea.val(textBefore + $(element).text() + textAfter); 24 | } 25 | } 26 | 27 | }); -------------------------------------------------------------------------------- /view/frontend/layout/checkout_onepage_success.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /view/frontend/templates/checkout/misc-script.phtml: -------------------------------------------------------------------------------- 1 | 12 | getActiveScripts(); ?> 13 | --------------------------------------------------------------------------------