├── .gitignore ├── Block └── Adminhtml │ └── Form │ └── Field │ ├── Currency.php │ ├── PriceFormat.php │ └── SymbolPosition.php ├── Helper └── Data.php ├── LICENSE.txt ├── Model └── System │ └── Config │ └── Backend │ └── PriceFormat.php ├── Observer └── Currency │ └── DisplayOptionsFormingObserver.php ├── Plugin ├── Directory │ └── Model │ │ └── CurrencyPlugin.php └── Framework │ ├── CurrencyPlugin.php │ └── Locale │ └── FormatPlugin.php ├── README.md ├── composer.json ├── etc ├── acl.xml ├── adminhtml │ └── system.xml ├── config.xml ├── di.xml ├── events.xml └── module.xml ├── i18n ├── en_US.csv └── fr_FR.csv └── registration.php /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | .DS_Store -------------------------------------------------------------------------------- /Block/Adminhtml/Form/Field/Currency.php: -------------------------------------------------------------------------------- 1 | localeLists = $localeLists; 41 | } 42 | 43 | /** 44 | * Retrieve allowed currencies 45 | * 46 | * @param string $currencyCode 47 | * @return array|string 48 | */ 49 | protected function getCurrencies($currencyCode = null) 50 | { 51 | if ($this->currencies === null) { 52 | $this->currencies = []; 53 | 54 | foreach ($this->localeLists->getOptionCurrencies() as $currency) { 55 | $this->currencies[$currency['value']] = $currency['label']; 56 | } 57 | } 58 | if ($currencyCode !== null) { 59 | return isset($this->currencies[$currencyCode]) ? $this->currencies[$currencyCode] : null; 60 | } 61 | return $this->currencies; 62 | } 63 | 64 | /** 65 | * Set input name 66 | * 67 | * @param string $value 68 | * @return $this 69 | */ 70 | public function setInputName($value) 71 | { 72 | return $this->setName($value); 73 | } 74 | 75 | /** 76 | * Render block HTML 77 | * 78 | * @return string 79 | */ 80 | public function _toHtml() 81 | { 82 | if (!$this->getOptions()) { 83 | foreach ($this->getCurrencies() as $code => $label) { 84 | $this->addOption($code, addslashes($label)); 85 | } 86 | } 87 | return parent::_toHtml(); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Block/Adminhtml/Form/Field/PriceFormat.php: -------------------------------------------------------------------------------- 1 | currencyRenderer) { 32 | $this->currencyRenderer = $this->getLayout()->createBlock( 33 | \Shopigo\PriceFormat\Block\Adminhtml\Form\Field\Currency::class, 34 | '', 35 | ['data' => ['is_render_to_js_template' => true]] 36 | ); 37 | $this->currencyRenderer->setExtraParams('style="width: 150px;"'); 38 | $this->currencyRenderer->setClass('locale_select'); 39 | } 40 | return $this->currencyRenderer; 41 | } 42 | 43 | /** 44 | * Retrieve symbol position column renderer 45 | * 46 | * @return SymbolPosition 47 | */ 48 | protected function getSymbolPositionRenderer() 49 | { 50 | if (!$this->symbolPositionRenderer) { 51 | $this->symbolPositionRenderer = $this->getLayout()->createBlock( 52 | 'Shopigo\PriceFormat\Block\Adminhtml\Form\Field\SymbolPosition', 53 | '', 54 | ['data' => ['is_render_to_js_template' => true]] 55 | ); 56 | $this->symbolPositionRenderer->setExtraParams('style="width: 100px;"'); 57 | $this->symbolPositionRenderer->setClass('format_type_select'); 58 | } 59 | return $this->symbolPositionRenderer; 60 | } 61 | 62 | /** 63 | * Prepare to render 64 | * 65 | * @return void 66 | */ 67 | protected function _prepareToRender() 68 | { 69 | $this->addColumn( 70 | 'currency', 71 | [ 72 | 'label' => __('Currency'), 73 | 'renderer' => $this->getCurrencyRenderer(), 74 | ] 75 | ); 76 | 77 | $this->addColumn( 78 | 'group', 79 | [ 80 | 'label' => __('Thousand separator'), 81 | ] 82 | ); 83 | 84 | $this->addColumn( 85 | 'decimal', 86 | [ 87 | 'label' => __('Decimal separator'), 88 | ] 89 | ); 90 | 91 | $this->addColumn( 92 | 'position', 93 | [ 94 | 'label' => __('Symbol position'), 95 | 'renderer' => $this->getSymbolPositionRenderer(), 96 | ] 97 | ); 98 | 99 | $this->_addAfter = false; 100 | $this->_addButtonLabel = __('Add Format'); 101 | } 102 | 103 | /** 104 | * Prepare existing row data object 105 | * 106 | * @param \Magento\Framework\DataObject $row 107 | * @return void 108 | */ 109 | protected function _prepareArrayRow(\Magento\Framework\DataObject $row) 110 | { 111 | $optionExtraAttr = []; 112 | $optionExtraAttr['option_' . $this->getCurrencyRenderer()->calcOptionHash($row->getData('currency'))] = 113 | 'selected="selected"'; 114 | $optionExtraAttr['option_' . $this->getSymbolPositionRenderer()->calcOptionHash($row->getData('position'))] = 115 | 'selected="selected"'; 116 | $row->setData( 117 | 'option_extra_attrs', 118 | $optionExtraAttr 119 | ); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /Block/Adminhtml/Form/Field/SymbolPosition.php: -------------------------------------------------------------------------------- 1 | positions === null) { 29 | $this->positions = [ 30 | \Zend_Currency::STANDARD => __('Default'), 31 | \Zend_Currency::LEFT => __('Left'), 32 | \Zend_Currency::RIGHT => __('Right'), 33 | ]; 34 | } 35 | if ($position !== null) { 36 | return isset($this->positions[$position]) ? $this->positions[$position] : null; 37 | } 38 | return $this->positions; 39 | } 40 | 41 | /** 42 | * Set input name 43 | * 44 | * @param string $value 45 | * @return $this 46 | */ 47 | public function setInputName($value) 48 | { 49 | return $this->setName($value); 50 | } 51 | 52 | /** 53 | * Render block HTML 54 | * 55 | * @return string 56 | */ 57 | public function _toHtml() 58 | { 59 | if (!$this->getOptions()) { 60 | foreach ($this->getPositions() as $code => $label) { 61 | $this->addOption($code, addslashes($label)); 62 | } 63 | } 64 | return parent::_toHtml(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Helper/Data.php: -------------------------------------------------------------------------------- 1 | mathRandom = $mathRandom; 36 | parent::__construct($context); 37 | } 38 | 39 | /** 40 | * Generate a storable representation of a value 41 | * 42 | * @param int|float|string|array $value 43 | * @return string 44 | */ 45 | protected function serializeValue($value) 46 | { 47 | if (is_array($value)) { 48 | return serialize($value); 49 | } else { 50 | return ''; 51 | } 52 | } 53 | 54 | /** 55 | * Create a value from a storable representation 56 | * 57 | * @param int|float|string $value 58 | * @return array 59 | */ 60 | protected function unserializeValue($value) 61 | { 62 | if (is_string($value) && !empty($value)) { 63 | return unserialize($value); 64 | } else { 65 | return []; 66 | } 67 | } 68 | 69 | /** 70 | * Check whether value is in form retrieved by _encodeArrayFieldValue() 71 | * 72 | * @param string|array $value 73 | * @return bool 74 | */ 75 | protected function isEncodedArrayFieldValue($value) 76 | { 77 | if (!is_array($value)) { 78 | return false; 79 | } 80 | unset($value['__empty']); 81 | foreach ($value as $row) { 82 | if (!is_array($row) 83 | || !array_key_exists('currency', $row) 84 | || !array_key_exists('group', $row) 85 | || !array_key_exists('decimal', $row) 86 | || !array_key_exists('position', $row) 87 | ) { 88 | return false; 89 | } 90 | } 91 | return true; 92 | } 93 | 94 | /** 95 | * Encode value to be used in \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray 96 | * 97 | * @param array $value 98 | * @return array 99 | */ 100 | protected function encodeArrayFieldValue(array $value) 101 | { 102 | $result = []; 103 | foreach ($value as $row) { 104 | $resultId = $this->mathRandom->getUniqueHash('_'); 105 | $result[$resultId] = $row; 106 | } 107 | return $result; 108 | } 109 | 110 | /** 111 | * Decode value from used in \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray 112 | * 113 | * @param array $value 114 | * @return array 115 | */ 116 | protected function decodeArrayFieldValue(array $value) 117 | { 118 | $result = []; 119 | unset($value['__empty']); 120 | foreach ($value as $row) { 121 | if (!is_array($row) 122 | || !array_key_exists('currency', $row) 123 | || !array_key_exists('group', $row) 124 | || !array_key_exists('decimal', $row) 125 | || !array_key_exists('position', $row) 126 | ) { 127 | continue; 128 | } 129 | $result[] = $row; 130 | } 131 | return $result; 132 | } 133 | 134 | /** 135 | * Check if enabled 136 | * 137 | * @return bool 138 | */ 139 | public function isEnabled() 140 | { 141 | if (!$this->isModuleOutputEnabled()) { 142 | return false; 143 | } 144 | return $this->scopeConfig->isSetFlag( 145 | self::XML_PATH_ENABLED, 146 | ScopeInterface::SCOPE_STORES 147 | ); 148 | } 149 | 150 | /** 151 | * Retrieve price format from config 152 | * 153 | * @param string $currencyCode 154 | * @return string|null 155 | */ 156 | public function getConfigValue($currencyCode) 157 | { 158 | if (empty($currencyCode)) { 159 | return null; 160 | } 161 | 162 | $value = $this->scopeConfig->getValue(self::XML_PATH_CURRENY_FORMAT); 163 | if (empty($value)) { 164 | return null; 165 | } 166 | 167 | $value = $this->unserializeValue($value); 168 | if ($this->isEncodedArrayFieldValue($value)) { 169 | $value = $this->decodeArrayFieldValue($value); 170 | } 171 | 172 | $result = null; 173 | foreach ($value as $row) { 174 | if ($row['currency'] == $currencyCode) { 175 | $result = [ 176 | 'group' => $row['group'], 177 | 'decimal' => $row['decimal'], 178 | 'position' => (int)$row['position'] 179 | ]; 180 | break; 181 | } 182 | } 183 | return $result; 184 | } 185 | 186 | /** 187 | * Make value readable by \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray 188 | * 189 | * @param string|array $value 190 | * @return array 191 | */ 192 | public function makeArrayFieldValue($value) 193 | { 194 | $value = $this->unserializeValue($value); 195 | if (!$this->isEncodedArrayFieldValue($value)) { 196 | $value = $this->encodeArrayFieldValue($value); 197 | } 198 | return $value; 199 | } 200 | 201 | /** 202 | * Make value ready for store 203 | * 204 | * @param string|array $value 205 | * @return string 206 | */ 207 | public function makeStorableArrayFieldValue($value) 208 | { 209 | if ($this->isEncodedArrayFieldValue($value)) { 210 | $value = $this->decodeArrayFieldValue($value); 211 | } 212 | $value = $this->serializeValue($value); 213 | return $value; 214 | } 215 | 216 | /** 217 | * Price post process 218 | * 219 | * @param string $price 220 | * @param string $currencyCode 221 | * @return string 222 | */ 223 | public function postProcess($price, $currencyCode) 224 | { 225 | $currencyOptions = $this->getConfigValue($currencyCode); 226 | if (is_null($currencyOptions)) { 227 | return $price; 228 | } 229 | 230 | // Mapped symbols 231 | $map = ['decimal' => '.', 'group' => ',']; 232 | 233 | // Replace each symbol by their code (e.g. "," will be replaced by "group") 234 | $price = strtr($price, array_flip($map)); 235 | 236 | // Replace all codes by their symbol (e.g. "group" will be replaced by ",") 237 | $price = strtr($price, $currencyOptions); 238 | 239 | return $price; 240 | } 241 | } 242 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Open Software License ("OSL") v. 3.0 3 | 4 | This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: 5 | 6 | Licensed under the Open Software License version 3.0 7 | 8 | 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: 9 | 10 | 1. to reproduce the Original Work in copies, either alone or as part of a collective work; 11 | 12 | 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; 13 | 14 | 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License; 15 | 16 | 4. to perform the Original Work publicly; and 17 | 18 | 5. to display the Original Work publicly. 19 | 20 | 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. 21 | 22 | 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. 23 | 24 | 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. 25 | 26 | 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). 27 | 28 | 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. 29 | 30 | 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. 31 | 32 | 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. 33 | 34 | 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). 35 | 36 | 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. 37 | 38 | 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. 39 | 40 | 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. 41 | 42 | 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. 43 | 44 | 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 45 | 46 | 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. 47 | 48 | 16. Modification of This License. This License is Copyright (C) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. 49 | -------------------------------------------------------------------------------- /Model/System/Config/Backend/PriceFormat.php: -------------------------------------------------------------------------------- 1 | dataHelper = $dataHelper; 42 | parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); 43 | } 44 | 45 | /** 46 | * Process data after load 47 | * 48 | * @return void 49 | */ 50 | protected function _afterLoad() 51 | { 52 | $value = $this->getValue(); 53 | $value = $this->dataHelper->makeArrayFieldValue($value); 54 | $this->setValue($value); 55 | } 56 | 57 | /** 58 | * Prepare data before save 59 | * 60 | * @return void 61 | */ 62 | public function beforeSave() 63 | { 64 | $value = $this->getValue(); 65 | $value = $this->dataHelper->makeStorableArrayFieldValue($value); 66 | $this->setValue($value); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Observer/Currency/DisplayOptionsFormingObserver.php: -------------------------------------------------------------------------------- 1 | dataHelper = $dataHelper; 29 | } 30 | 31 | /** 32 | * Set currency options 33 | * 34 | * @param Observer $observer 35 | * @return $this 36 | */ 37 | public function execute(Observer $observer) 38 | { 39 | if (!$this->dataHelper->isEnabled()) { 40 | return $this; 41 | } 42 | 43 | $event = $observer->getEvent(); 44 | 45 | $currencyCode = $event->getBaseCode(); 46 | if (!empty($currencyCode)) { 47 | $customOptions = $this->dataHelper->getConfigValue($currencyCode); 48 | if (!is_null($customOptions)) { 49 | $options = $event->getCurrencyOptions(); 50 | $options->setData($customOptions + $options->getData()); 51 | } 52 | } 53 | 54 | return $this; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Plugin/Directory/Model/CurrencyPlugin.php: -------------------------------------------------------------------------------- 1 | dataHelper = $dataHelper; 28 | } 29 | 30 | /** 31 | * Set currency options 32 | * 33 | * @param Currency $subject 34 | * @param float $price 35 | * @param array $options 36 | * @return string 37 | */ 38 | public function beforeFormatTxt(Currency $subject, $price, $options = []) 39 | { 40 | if (!$this->dataHelper->isEnabled()) { 41 | return [$price, $options]; 42 | } 43 | 44 | $currencyCode = $subject->getCode(); 45 | if (!empty($currencyCode)) { 46 | $customOptions = $this->dataHelper->getConfigValue($currencyCode); 47 | if (!is_null($customOptions)) { 48 | $options = $customOptions + $options; 49 | } 50 | } 51 | return [$price, $options]; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Plugin/Framework/CurrencyPlugin.php: -------------------------------------------------------------------------------- 1 | dataHelper = $dataHelper; 35 | $this->scopeResolver = $scopeResolver; 36 | } 37 | 38 | /** 39 | * After to currency plugin method in order to modify price format 40 | * 41 | * @param Currency $subject 42 | * @param \Closure $closure 43 | * @param int|float $value 44 | * @param array $options 45 | * @return string 46 | */ 47 | public function aroundToCurrency( 48 | Currency $subject, 49 | \Closure $closure, 50 | $value = null, 51 | array $options = array() 52 | ) { 53 | if (!$this->dataHelper->isEnabled()) { 54 | $result = $closure($value, $options); 55 | return $result; 56 | } 57 | 58 | // Force the usage of the en_US locale in order to avoid formatting problem 59 | $options['locale'] = 'en_US'; 60 | 61 | $result = $closure($value, $options); 62 | 63 | if (!empty($options['currency'])) { 64 | $currencyCode = $options['currency']; 65 | } else { 66 | $currencyCode = $this->scopeResolver->getScope()->getCurrentCurrencyCode(); 67 | } 68 | 69 | if (!empty($currencyCode)) { 70 | return $this->dataHelper->postProcess($result, $currencyCode); 71 | } 72 | return $result; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Plugin/Framework/Locale/FormatPlugin.php: -------------------------------------------------------------------------------- 1 | dataHelper = $dataHelper; 35 | $this->scopeResolver = $scopeResolver; 36 | } 37 | 38 | /** 39 | * Set currency options 40 | * 41 | * @param Format $subject 42 | * @param \Closure $closure 43 | * @param string $localeCode Locale code 44 | * @param string $currencyCode Currency code 45 | * @return array 46 | */ 47 | public function aroundGetPriceFormat( 48 | Format $subject, 49 | \Closure $closure, 50 | $localeCode = null, 51 | $currencyCode = null 52 | ) { 53 | $result = $closure($localeCode, $currencyCode); 54 | 55 | if (!$this->dataHelper->isEnabled()) { 56 | return $result; 57 | } 58 | 59 | if (!$currencyCode) { 60 | $currencyCode = $this->scopeResolver->getScope()->getCurrentCurrencyCode(); 61 | } 62 | 63 | if (!empty($currencyCode)) { 64 | $customOptions = $this->dataHelper->getConfigValue($currencyCode); 65 | if (!is_null($customOptions)) { 66 | $result = [ 67 | 'groupSymbol' => $customOptions['group'], 68 | 'decimalSymbol' => $customOptions['decimal'], 69 | 'position' => $customOptions['position'] 70 | ] + $result; 71 | } 72 | } 73 | return $result; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Shopigo](https://i.imgur.com/7Ctkn7X.png) 2 | 3 | # Magento 2 Price Format extension by Shopigo 4 | 5 | This extension adds a feature which allow to configure the display format of prices and subtotals. 6 | 7 | Price display settings (thousand separator, decimal separator, symbol position) can be configured per currency and per store. 8 | 9 | ![](https://i.imgur.com/zKoA7iq.jpg) 10 | 11 | Example: 12 | 13 | ![](https://i.imgur.com/MBObwN3.jpg) 14 | 15 | ## Requirements 16 | 17 | Magento Open Source Edition 2.2 or 2.3 18 | 19 | ## Installation 20 | 21 | ## Method 1 - Installing via composer 22 | 23 | - Switch to your Magento project root 24 | - Run `composer require shopigo/magento2-extension-price-format` 25 | 26 | ## Method 2 - Installing using archive 27 | 28 | - Download [ZIP Archive](https://github.com/acharrex/magento2-extension-price-format/archive/master.zip) 29 | - Switch to your Magento project root 30 | - Create folder `app/code/Shopigo/PriceFormat` 31 | - Extract zip into path 32 | 33 | ### Enable extension 34 | 35 | - Switch to your Magento project root 36 | - Run the following commands to enable the module and clear static contents generated by Magento: 37 | ``` 38 | php bin/magento module:enable Shopigo_PriceFormat 39 | php bin/magento setup:upgrade 40 | php bin/magento setup:di:compile 41 | php bin/magento setup:static-content:deploy 42 | ``` 43 | 44 | ## How to use it 45 | 46 | - Log into your Magento back-office 47 | - Go to the menu "Stores > Configuration > Shopigo Extensions > Price Format" 48 | - Configure your formats in the field "Price Format" 49 | - Set the parameter "Enabled" to "Yes" 50 | - Flush Magento caches from the menu "System > Tools > Cache Management" 51 | 52 | Note: to customize currency symbols, go to the menu "Stores > Currency > Currency Symbols". 53 | 54 | ## Support 55 | 56 | If you have any issues, open a bug report in GitHub's [issue tracker](https://github.com/acharrex/magento2-extension-price-format/issues). 57 | 58 | ## Change logs 59 | 60 | **Version 1.0.3** (2019-02-07) 61 | - Fix composer.json for Magento 2.3 62 | 63 | **Version 1.0.2** (2018-11-15) 64 | - [Issue #5: Issue in Magento 2.1](https://github.com/acharrex/magento2-extension-price-format/issues/5) 65 | 66 | **Version 1.0.1** (2018-10-09) 67 | - Fix composer.json for Magento 2.2.0-2.2.5 68 | 69 | **Version 1.0.0** (2018-09-04) 70 | - First version 71 | 72 | ## License 73 | 74 | The code is licensed under [Open Software License ("OSL") v. 3.0](http://opensource.org/licenses/osl-3.0.php). 75 | 76 |
Enjoy! -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "shopigo/magento2-extension-price-format", 3 | "description": "Magento 2 Price Format extension by Shopigo", 4 | "require": { 5 | "php": "^7.0", 6 | "magento/module-directory": "*", 7 | "magento/framework": "*" 8 | }, 9 | "type": "magento2-module", 10 | "version": "1.0.3", 11 | "license": [ 12 | "OSL-3.0", 13 | "AFL-3.0" 14 | ], 15 | "autoload": { 16 | "files": [ 17 | "registration.php" 18 | ], 19 | "psr-4": { 20 | "Shopigo\\PriceFormat\\": "" 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /etc/acl.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /etc/adminhtml/system.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | shopigo 16 | Shopigo_PriceFormat::config 17 | 18 | 19 | 20 | 21 | Magento\Config\Model\Config\Source\Yesno 22 | 23 | 24 | 25 | Shopigo\PriceFormat\Block\Adminhtml\Form\Field\PriceFormat 26 | Shopigo\PriceFormat\Model\System\Config\Backend\PriceFormat 27 | 28 | 29 |
30 |
31 |
32 | -------------------------------------------------------------------------------- /etc/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 0 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /etc/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /etc/events.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /i18n/en_US.csv: -------------------------------------------------------------------------------- 1 | "Add Format","Add Format" 2 | "Currency","Currency" 3 | "Decimal separator","Decimal separator" 4 | "Default","Default" 5 | "Left","Left" 6 | "Price Format","Price Format" 7 | "Price Format Section","Price Format Section" 8 | "Right","Right" 9 | "Shopigo Extensions","Shopigo Extensions" 10 | "Symbol position","Symbol position" 11 | "Thousand separator","Thousand separator" -------------------------------------------------------------------------------- /i18n/fr_FR.csv: -------------------------------------------------------------------------------- 1 | "Add Format","Ajouter un format" 2 | "Currency","Devise" 3 | "Decimal separator","Séparateur de décimales" 4 | "Default","Défault" 5 | "Left","Gauche" 6 | "Price Format","Format des prix" 7 | "Price Format Section","Section format des prix" 8 | "Right","Droite" 9 | "Shopigo Extensions","Extensions Shopigo" 10 | "Symbol position","Position du symbole" 11 | "Thousand separator","Séparateur de milliers" -------------------------------------------------------------------------------- /registration.php: -------------------------------------------------------------------------------- 1 |