wp_price_decimal - Version 1.4.0

Version Notes

+ trim decimal zero to the right, ~ fix: exclude cart

Download this release

Release Info

Developer Magento Core Team
Extension wp_price_decimal
Version 1.4.0
Comparing to
See all releases


Code changes from version 1.3.1 to 1.4.0

app/code/community/WP/PriceDecimal/Block/About.php CHANGED
@@ -13,8 +13,8 @@ class WP_PriceDecimal_Block_About
13
  */
14
  public function render(Varien_Data_Form_Element_Abstract $element)
15
  {
16
- $html = <<<HTML
17
- <div style="background:url('http://www.webandpeople.com/template/public/images/logo.gif') no-repeat scroll 14px 14px #EAF0EE;border:1px solid #CCCCCC;margin-bottom:10px;padding:10px 5px 5px 164px;">
18
  <p>
19
  <b style="font-size:12px;">WebAndPeople</b>, a family of niche sites, provides small businesses with everything they need to start selling online.
20
  </p>
@@ -34,6 +34,169 @@ class WP_PriceDecimal_Block_About
34
  </p>
35
  </div>
36
  HTML;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  return $html;
38
  }
39
  }
13
  */
14
  public function render(Varien_Data_Form_Element_Abstract $element)
15
  {
16
+ $default = <<<HTML
17
+ <div style="background-color:#EAF0EE;border:1px solid #CCCCCC;margin-bottom:10px;padding:20px;">
18
  <p>
19
  <b style="font-size:12px;">WebAndPeople</b>, a family of niche sites, provides small businesses with everything they need to start selling online.
20
  </p>
34
  </p>
35
  </div>
36
  HTML;
37
+ $default = json_encode($default);
38
+ $html = '<div id="wp_aboutus_content"></div>
39
+
40
+ <script type="text/javascript"> //<![CDATA[
41
+
42
+ /* JSON-P implementation for Prototype.js somewhat by Dan Dean (http://www.dandean.com)
43
+ *
44
+ * *HEAVILY* based on Tobie Langel\'s version: http://gist.github.com/145466.
45
+ * Might as well just call this an iteration.
46
+ *
47
+ * This version introduces:
48
+ * - Support for predefined callbacks (Necessary for OAuth signed requests, by @rboyce)
49
+ * - Partial integration with Ajax.Responders (Thanks to @sr3d for the kick in this direction)
50
+ * - Compatibility with Prototype 1.7 (Thanks to @soung3 for the bug report)
51
+ * - Will not break if page lacks a <head> element
52
+ *
53
+ * See examples in README for usage
54
+ *
55
+ * VERSION 1.1.2
56
+ *
57
+ * new Ajax.JSONRequest(url, options);
58
+ * - url (String): JSON-P endpoint url.
59
+ * - options (Object): Configuration options for the request.
60
+ */
61
+ Ajax.JSONRequest = Class.create(Ajax.Base, (function() {
62
+ var id = 0, head = document.getElementsByTagName(\'head\')[0] || document.body;
63
+ return {
64
+ initialize: function($super, url, options) {
65
+ $super(options);
66
+ this.options.url = url;
67
+ this.options.callbackParamName = this.options.callbackParamName || \'callback\';
68
+ this.options.timeout = this.options.timeout || 10; // Default timeout: 10 seconds
69
+ this.options.invokeImmediately = (!Object.isUndefined(this.options.invokeImmediately)) ? this.options.invokeImmediately : true ;
70
+
71
+ if (!Object.isUndefined(this.options.parameters) && Object.isString(this.options.parameters)) {
72
+ this.options.parameters = this.options.parameters.toQueryParams();
73
+ }
74
+
75
+ if (this.options.invokeImmediately) {
76
+ this.request();
77
+ }
78
+ },
79
+
80
+ /**
81
+ * Ajax.JSONRequest#_cleanup() -> undefined
82
+ * Cleans up after the request
83
+ **/
84
+ _cleanup: function() {
85
+ if (this.timeout) {
86
+ clearTimeout(this.timeout);
87
+ this.timeout = null;
88
+ }
89
+ if (this.transport && Object.isElement(this.transport)) {
90
+ this.transport.remove();
91
+ this.transport = null;
92
+ }
93
+ },
94
+
95
+ /**
96
+ * Ajax.JSONRequest#request() -> undefined
97
+ * Invokes the JSON-P request lifecycle
98
+ **/
99
+ request: function() {
100
+
101
+ // Define local vars
102
+ var response = new Ajax.JSONResponse(this);
103
+ var key = this.options.callbackParamName,
104
+ name = \'_prototypeJSONPCallback_\' + (id++),
105
+ complete = function() {
106
+ if (Object.isFunction(this.options.onComplete)) {
107
+ this.options.onComplete.call(this, response);
108
+ }
109
+ Ajax.Responders.dispatch(\'onComplete\', this, response);
110
+ }.bind(this);
111
+
112
+ // If the callback parameter is already defined, use that
113
+ if (this.options.parameters[key] !== undefined) {
114
+ name = this.options.parameters[key];
115
+ }
116
+ // Otherwise, add callback as a parameter
117
+ else {
118
+ this.options.parameters[key] = name;
119
+ }
120
+
121
+ // Build request URL
122
+ this.options.parameters[key] = name;
123
+ var url = this.options.url + ((this.options.url.include(\'?\') ? \'&\' : \'?\') + Object.toQueryString(this.options.parameters));
124
+
125
+ // Define callback function
126
+ window[name] = function(json) {
127
+ this._cleanup(); // Garbage collection
128
+ window[name] = undefined;
129
+
130
+ response.status = 200;
131
+ response.statusText = "OK";
132
+ response.setResponseContent(json);
133
+
134
+ if (Object.isFunction(this.options.onSuccess)) {
135
+ this.options.onSuccess.call(this, response);
136
+ }
137
+ Ajax.Responders.dispatch(\'onSuccess\', this, response);
138
+
139
+ complete();
140
+
141
+ }.bind(this);
142
+
143
+ this.transport = new Element(\'script\', { type: \'text/javascript\', src: url });
144
+
145
+ if (Object.isFunction(this.options.onCreate)) {
146
+ this.options.onCreate.call(this, response);
147
+ }
148
+ Ajax.Responders.dispatch(\'onCreate\', this);
149
+
150
+ head.appendChild(this.transport);
151
+
152
+ this.timeout = setTimeout(function() {
153
+ this._cleanup();
154
+ window[name] = Prototype.emptyFunction;
155
+ if (Object.isFunction(this.options.onFailure)) {
156
+ response.status = 504;
157
+ response.statusText = "Gateway Timeout";
158
+ this.options.onFailure.call(this, response);
159
+ }
160
+ complete();
161
+ }.bind(this), this.options.timeout * 1000);
162
+ },
163
+ toString: function() { return "[object Ajax.JSONRequest]"; }
164
+ };
165
+ })());
166
+
167
+ Ajax.JSONResponse = Class.create({
168
+ initialize: function(request) {
169
+ this.request = request;
170
+ },
171
+ request: undefined,
172
+ status: 0,
173
+ statusText: \'\',
174
+ responseJSON: undefined,
175
+ responseText: undefined,
176
+ setResponseContent: function(json) {
177
+ this.responseJSON = json;
178
+ this.responseText = Object.toJSON(json);
179
+ },
180
+ getTransport: function() {
181
+ if (this.request) return this.request.transport;
182
+ },
183
+ toString: function() { return "[object Ajax.JSONResponse]"; }
184
+ });
185
+
186
+ window.onload = function(){
187
+ var html = ' . $default . ';
188
+
189
+ new Ajax.JSONRequest(\'http://web-experiment.info/about-us.php\', {
190
+ callbackParamName: "jsoncallback",
191
+ onComplete: function(response) {
192
+ if (response.responseJSON && response.responseJSON.html) {
193
+ html = response.responseJSON.html;
194
+ }
195
+ Element.replace(\'wp_aboutus_content\', html);
196
+ }
197
+ });
198
+ };
199
+ //]]></script>';
200
  return $html;
201
  }
202
  }
app/code/community/WP/PriceDecimal/Helper/Data.php CHANGED
@@ -6,13 +6,14 @@ class WP_PriceDecimal_Helper_Data extends Mage_Core_Helper_Abstract
6
  {
7
  $config = Mage::getStoreConfig('price_decimal/general');
8
  $moduleName = Mage::app()->getRequest()->getModuleName();
9
- $controllerName = Mage::app()->getRequest()->getControllerName();
10
 
11
  $skeep = !$config['enabled'];
12
- if ($moduleName == 'checkout' && $config['exclude_cart']) $skeep = true;
 
13
  if ($moduleName == 'admin') $skeep = true; // --- if Backand skeep
14
 
15
- $precision = 0;
16
  if (isset($config['precision']) && ($config['precision'] + 0) >= 0)
17
  $precision = $config['precision'] + 0;
18
 
@@ -21,4 +22,17 @@ class WP_PriceDecimal_Helper_Data extends Mage_Core_Helper_Abstract
21
  'precision' => $precision,
22
  );
23
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  }
6
  {
7
  $config = Mage::getStoreConfig('price_decimal/general');
8
  $moduleName = Mage::app()->getRequest()->getModuleName();
9
+ $id = Mage::app()->getRequest()->getParam('id', '');
10
 
11
  $skeep = !$config['enabled'];
12
+
13
+ if ($moduleName == 'checkout' && $config['exclude_cart'] && !$id) $skeep = true;
14
  if ($moduleName == 'admin') $skeep = true; // --- if Backand skeep
15
 
16
+ $precision = 0;
17
  if (isset($config['precision']) && ($config['precision'] + 0) >= 0)
18
  $precision = $config['precision'] + 0;
19
 
22
  'precision' => $precision,
23
  );
24
  }
25
+
26
+ public static function trimZeroRight($price, $precision)
27
+ {
28
+ if (!Mage::getStoreConfig('price_decimal/general/trim_zero_right'))
29
+ return $precision;
30
+ $xPrice = sprintf("%." . $precision . "F", $price);
31
+ $decimal = strrchr($xPrice, '.');
32
+ $c1 = strlen($decimal);
33
+ $decimal = rtrim($decimal, '0');
34
+ $c2 = strlen($decimal);
35
+ $xPrecision = $precision - ($c1 - $c2);
36
+ return $xPrecision;
37
+ }
38
  }
app/code/community/WP/PriceDecimal/Model/Currency.php CHANGED
@@ -13,6 +13,7 @@ class WP_PriceDecimal_Model_Currency extends Mage_Directory_Model_Currency
13
  {
14
  $params = Mage::helper('pricedecimal')->getParams();
15
  if ($params['skeep']) return parent::format($price, $options, $includeContainer, $addBrackets);
16
- return $this->formatPrecision($price, $params['precision'], $options, $includeContainer, $addBrackets);
 
17
  }
18
  }
13
  {
14
  $params = Mage::helper('pricedecimal')->getParams();
15
  if ($params['skeep']) return parent::format($price, $options, $includeContainer, $addBrackets);
16
+ $params['precision'] = Mage::helper('pricedecimal')->trimZeroRight($price, $params['precision']);
17
+ return $formatPrice = $this->formatPrecision($price, $params['precision'], $options, $includeContainer, $addBrackets);
18
  }
19
  }
app/code/community/WP/PriceDecimal/etc/config.xml CHANGED
@@ -2,9 +2,18 @@
2
  <config>
3
  <modules>
4
  <WP_PriceDecimal>
5
- <version>1.3.1</version>
6
  </WP_PriceDecimal>
7
  </modules>
 
 
 
 
 
 
 
 
 
8
  <global>
9
  <helpers>
10
  <pricedecimal>
@@ -53,9 +62,10 @@
53
  <price_decimal>
54
  <general>
55
  <enabled>1</enabled>
 
56
  <precision>0</precision>
57
- <exclude_cart>0</exclude_cart>
58
- <version>1.3.1</version>
59
  </general>
60
  </price_decimal>
61
  </default>
2
  <config>
3
  <modules>
4
  <WP_PriceDecimal>
5
+ <version>1.4.0</version>
6
  </WP_PriceDecimal>
7
  </modules>
8
+ <frontend>
9
+ <layout>
10
+ <updates>
11
+ <pricedecimal>
12
+ <file>webandpeople/pricedecimal.xml</file>
13
+ </pricedecimal>
14
+ </updates>
15
+ </layout>
16
+ </frontend>
17
  <global>
18
  <helpers>
19
  <pricedecimal>
62
  <price_decimal>
63
  <general>
64
  <enabled>1</enabled>
65
+ <exclude_cart>1</exclude_cart>
66
  <precision>0</precision>
67
+ <trim_zero_right>0</trim_zero_right>
68
+ <version>1.4.0</version>
69
  </general>
70
  </price_decimal>
71
  </default>
app/code/community/WP/PriceDecimal/etc/system.xml CHANGED
@@ -33,28 +33,37 @@
33
  <show_in_website>1</show_in_website>
34
  <show_in_store>1</show_in_store>
35
  </enabled>
 
 
 
 
 
 
 
 
 
 
36
  <precision translate="label comment">
37
  <label>Precision</label>
38
  <comment>Number of decimal (e.g. 0, 1, 2). </comment>
39
  <frontend_type>text</frontend_type>
40
- <sort_order>3</sort_order>
41
  <show_in_default>1</show_in_default>
42
  <show_in_website>1</show_in_website>
43
  <show_in_store>1</show_in_store>
44
  </precision>
45
- <exclude_cart translate="label comment">
46
- <label>Exclude Checkout</label>
47
- <comment>Select "Yes" to leave decimal price in the shopping cart (e.g. due to taxes)</comment>
48
  <frontend_type>select</frontend_type>
49
  <source_model>adminhtml/system_config_source_yesno</source_model>
50
- <sort_order>5</sort_order>
51
  <show_in_default>1</show_in_default>
52
  <show_in_website>1</show_in_website>
53
  <show_in_store>1</show_in_store>
54
- </exclude_cart>
55
- <version translate="label comment">
56
  <label>Extension Release</label>
57
- <comment/>
58
  <frontend_type>label</frontend_type>
59
  <sort_order>100</sort_order>
60
  <show_in_default>1</show_in_default>
33
  <show_in_website>1</show_in_website>
34
  <show_in_store>1</show_in_store>
35
  </enabled>
36
+ <exclude_cart translate="label comment">
37
+ <label>Exclude Checkout</label>
38
+ <comment>Select "Yes" to disable this extension in the shopping cart (e.g. due to taxes)</comment>
39
+ <frontend_type>select</frontend_type>
40
+ <source_model>adminhtml/system_config_source_yesno</source_model>
41
+ <sort_order>5</sort_order>
42
+ <show_in_default>1</show_in_default>
43
+ <show_in_website>1</show_in_website>
44
+ <show_in_store>1</show_in_store>
45
+ </exclude_cart>
46
  <precision translate="label comment">
47
  <label>Precision</label>
48
  <comment>Number of decimal (e.g. 0, 1, 2). </comment>
49
  <frontend_type>text</frontend_type>
50
+ <sort_order>10</sort_order>
51
  <show_in_default>1</show_in_default>
52
  <show_in_website>1</show_in_website>
53
  <show_in_store>1</show_in_store>
54
  </precision>
55
+ <trim_zero_right translate="label comment">
56
+ <label>Trim decimal zeros to the right</label>
57
+ <comment>e.g. 3.3400 to 3.34, 0.2000 to 0.2 if param Precision = 4</comment>
58
  <frontend_type>select</frontend_type>
59
  <source_model>adminhtml/system_config_source_yesno</source_model>
60
+ <sort_order>15</sort_order>
61
  <show_in_default>1</show_in_default>
62
  <show_in_website>1</show_in_website>
63
  <show_in_store>1</show_in_store>
64
+ </trim_zero_right>
65
+ <version translate="label">
66
  <label>Extension Release</label>
 
67
  <frontend_type>label</frontend_type>
68
  <sort_order>100</sort_order>
69
  <show_in_default>1</show_in_default>
app/design/frontend/default/default/layout/webandpeople/pricedecimal.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <default>
4
+ <reference name="head">
5
+ <action ifconfig="price_decimal/general/trim_zero_right" method="addJs"><script>webandpeople/pricedecimal/trim_zero_right.js</script></action>
6
+ </reference>
7
+ </default>
8
+ </layout>
js/webandpeople/pricedecimal/trim_zero_right.js ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ document.observe("dom:loaded", function() {
2
+ if (typeof(Product) != 'undefined' && typeof(Product.OptionsPrice) != 'undefined') {
3
+ Product.OptionsPrice.prototype.formatPrice = function(price) {
4
+ var precision = wpTrimZeroRight(price, this.priceFormat.precision);
5
+ this.priceFormat.precision = precision;
6
+ this.priceFormat.requiredPrecision = precision;
7
+ return formatCurrency(price, this.priceFormat);
8
+ };
9
+ if (typeof(optionsPrice) != 'undefined') {
10
+ optionsPrice.reload(); // --- FIX: for magento 1.4.x.x
11
+ }
12
+ }
13
+
14
+ });
15
+
16
+ function wpTrimZeroRight(price, precision) {
17
+ var format = {
18
+ 'pattern': '%s',
19
+ 'precision': precision,
20
+ 'requiredPrecision': precision,
21
+ 'decimalSymbol': '.',
22
+ 'groupSymbol': '',
23
+ 'groupLength': 0,
24
+ 'integerRequired': 1
25
+ };
26
+ var xPrice = formatCurrency(price, format);
27
+ var decimal = '';
28
+ var pointPos = xPrice.lastIndexOf('.');
29
+ if (pointPos !== -1) decimal = xPrice.substr(pointPos);
30
+ var c1 = decimal.length;
31
+ decimal = decimal.replace(new RegExp("[0]+$", "g"), "");
32
+ var c2 = decimal.length;
33
+ var xPrecision = precision - (c1 - c2);
34
+ return xPrecision;
35
+ }
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>wp_price_decimal</name>
4
- <version>1.3.1</version>
5
  <stability>stable</stability>
6
  <license uri="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 Unported License</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Decimal price (WebAndPeople.com)</summary>
10
  <description>Decimal price (WebAndPeople.com)</description>
11
- <notes>~ conf. product price update, disabled in backand by default</notes>
12
- <authors><author><name>WebAndPeople</name><user>auto-converted</user><email>design@webandpeople.com</email></author><author><name>y.gerassimenko</name><user>auto-converted</user><email>y.gerassimenko@webandpeople.com</email></author></authors>
13
- <date>2011-11-04</date>
14
- <time>13:00:22</time>
15
- <contents><target name="mageweb"><dir name="app"><dir name="code"><dir name="community"><dir name="WP"><dir name="PriceDecimal"><dir name="Block"><file name="About.php" hash="5c0719ff5bda0feb45cde267e28b3714"/></dir><dir name="Helper"><file name="Data.php" hash="aea28646aee55b7a21bb90c52df0b14d"/></dir><dir name="Model"><file name="Currency.php" hash="bae33697c942d87dc36ce1cc99a92813"/><file name="Locale.php" hash="d66eb5e2e8b0fc14202f699d94b2c26e"/></dir><dir name="etc"><file name="config.xml" hash="e1d1ffa2739cdeb0c6759aa1be2a0cd7"/><file name="system.xml" hash="527c2e7bb956a0292ac23c497f9fd873"/></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="WP_PriceDecimal.xml" hash="9b870760e423ab063bd152305552564c"/></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies/>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>wp_price_decimal</name>
4
+ <version>1.4.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 Unported License</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Decimal price (WebAndPeople.com)</summary>
10
  <description>Decimal price (WebAndPeople.com)</description>
11
+ <notes>+ trim decimal zero to the right, ~ fix: exclude cart</notes>
12
+ <authors><author><name>WebAndPeople</name><user>auto-converted</user><email>design@webandpeople.com</email></author><author><name>Yura Gerassimenko</name><user>auto-converted</user><email>y.gerassimenko@webandpeople.com</email></author></authors>
13
+ <date>2012-02-29</date>
14
+ <time>12:34:31</time>
15
+ <contents><target name="magecommunity"><dir name="WP"><dir name="PriceDecimal"><dir name="Block"><file name="About.php" hash="e64d4b64438c4b31258d3d37849a72cf"/></dir><dir name="Helper"><file name="Data.php" hash="91104b07553625a02be163e75a9ae62d"/></dir><dir name="Model"><file name="Currency.php" hash="90e0a2a555054ea5b6b3976b41e6818c"/><file name="Locale.php" hash="d66eb5e2e8b0fc14202f699d94b2c26e"/></dir><dir name="etc"><file name="config.xml" hash="773208fc7b5822eef94de53385ca7b25"/><file name="system.xml" hash="753085ff1ea0365aa6647aeee9a3a61d"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="WP_PriceDecimal.xml" hash="9b870760e423ab063bd152305552564c"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><dir name="webandpeople"><file name="pricedecimal.xml" hash="bc44be7e61f49d7012e0a71036ac1fec"/></dir></dir></dir></dir></dir></target><target name="mageweb"><dir name="js"><dir name="webandpeople"><dir name="pricedecimal"><file name="trim_zero_right.js" hash="53fcc4c36d0ff2bc0729beb78158cb92"/></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies/>
18
  </package>