FranciscoPrado_PrecoParcelado - Version 1.0.0.0

Version Notes

Primeira versão do módulo Preço Parcelado.

Download this release

Release Info

Developer Francisco Prado
Extension FranciscoPrado_PrecoParcelado
Version 1.0.0.0
Comparing to
See all releases


Version 1.0.0.0

app/code/community/FranciscoPrado/PrecoParcelado/Helper/Data.php ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FranciscoPrado_PrecoParcelado_Helper_Data extends Mage_Core_Helper_Abstract {
4
+
5
+ const XML_PATH_ACTIVE = 'sales/franciscoprado_precoparcelado/active';
6
+ const XML_PATH_SHOW_TABLE = 'sales/franciscoprado_precoparcelado/show_table';
7
+ const XML_PATH_TABLE_TITLE = 'sales/franciscoprado_precoparcelado/table_title';
8
+ const XML_PATH_SHOW_PRICE_IN_PARCELS = 'sales/franciscoprado_precoparcelado/show_price_in_parcels';
9
+ const XML_PATH_MIN_PARCEL_VALUE = 'sales/franciscoprado_precoparcelado/min_quote_value';
10
+ const XML_PATH_MAX_NUMBER_MONTHS = 'sales/franciscoprado_precoparcelado/max_number_months';
11
+ const XML_PATH_INTEREST_VALUE = 'sales/franciscoprado_precoparcelado/interest_value';
12
+ const XML_PATH_USE_COMPOUND = 'sales/franciscoprado_precoparcelado/use_compound';
13
+ const XML_PATH_TEXT_PATTERN = 'sales/franciscoprado_precoparcelado/text_pattern';
14
+ const XML_PATH_TABLE_TEXT_PATTERN = 'sales/franciscoprado_precoparcelado/text_table_pattern';
15
+
16
+ public function isModuleEnabled($moduleName = null) {
17
+ if ((int) Mage::getStoreConfig(self::XML_PATH_ACTIVE, Mage::app()->getStore()) != 1) {
18
+ return false;
19
+ }
20
+ return parent::isModuleEnabled($moduleName);
21
+ }
22
+
23
+ public function showTable($store = null) {
24
+ return Mage::getStoreConfig(self::XML_PATH_SHOW_TABLE, $store);
25
+ }
26
+
27
+ public function getTableTitle($store = null) {
28
+ return Mage::getStoreConfig(self::XML_PATH_TABLE_TITLE, $store);
29
+ }
30
+
31
+ public function showPriceInParcels($store = null) {
32
+ return Mage::getStoreConfig(self::XML_PATH_SHOW_PRICE_IN_PARCELS, $store);
33
+ }
34
+
35
+ public function getMinParcelValue($store = null) {
36
+ return (int) Mage::getStoreConfig(self::XML_PATH_MIN_PARCEL_VALUE, $store);
37
+ }
38
+
39
+ public function getMaxNumberMonths($store = null) {
40
+ return (int) Mage::getStoreConfig(self::XML_PATH_MAX_NUMBER_MONTHS, $store);
41
+ }
42
+
43
+ public function getInterest($store = null) {
44
+ return (int) Mage::getStoreConfig(self::XML_PATH_INTEREST_VALUE, $store);
45
+ }
46
+
47
+ public function useCompound($store = null) {
48
+ return (int) Mage::getStoreConfig(self::XML_PATH_USE_COMPOUND, $store);
49
+ }
50
+
51
+ public function getText($store = null) {
52
+ return Mage::getStoreConfig(self::XML_PATH_TEXT_PATTERN, $store);
53
+ }
54
+
55
+ public function getTableText($store = null) {
56
+ return Mage::getStoreConfig(self::XML_PATH_TABLE_TEXT_PATTERN, $store);
57
+ }
58
+
59
+ public function getSimpleInterest($value, $interest, $parcels) {
60
+ $interest = $interest / 100;
61
+ $m = $value * (1 + $interest * $parcels);
62
+ $parcelValue = $m / $parcels;
63
+
64
+ return $parcelValue;
65
+ }
66
+
67
+ public function getCompoundInterest($value, $interest, $parcels) {
68
+ $interest = $interest / 100;
69
+ $parcelValue = $value * pow((1 + $interest), $parcels);
70
+ $parcelValue = $parcelValue / $parcels;
71
+
72
+ return $parcelValue;
73
+ }
74
+
75
+ public function getPrice($value) {
76
+ if ($this->isModuleEnabled() && $this->showPriceInParcels()) {
77
+
78
+ if ($value > $this->getMinParcelValue()) {
79
+ $finalText = '';
80
+
81
+ for ($i = 2; $i <= $this->getMaxNumberMonths(); $i++) {
82
+ if ($this->useCompound()) {
83
+ $parcel = $this->getCompoundInterest($value, $this->getInterest(), $i);
84
+ } else {
85
+ $parcel = $this->getSimpleInterest($value, $this->getInterest(), $i);
86
+ }
87
+
88
+ if ($parcel >= $this->getMinParcelValue()) {
89
+ $price = Mage::helper('core')->currency($parcel, true, false);
90
+ $replaceText = str_replace('{parcelas}', $i, $this->getText());
91
+ $finalText = str_replace('{preco}', $price, $replaceText);
92
+ }
93
+ }
94
+
95
+ $returnHtml = sprintf('<span class="precoparcelado-parcels">%s</span>', $finalText);
96
+
97
+ return $returnHtml;
98
+ }
99
+ }
100
+
101
+ return null;
102
+ }
103
+
104
+ }
app/code/community/FranciscoPrado/PrecoParcelado/etc/config.xml ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <FranciscoPrado_PrecoParcelado>
5
+ <version>1.0.0.0</version>
6
+ </FranciscoPrado_PrecoParcelado>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <franciscoprado_precoparcelado>
11
+ <class>FranciscoPrado_PrecoParcelado_Model</class>
12
+ </franciscoprado_precoparcelado>
13
+ </models>
14
+ <helpers>
15
+ <franciscoprado_precoparcelado>
16
+ <class>FranciscoPrado_PrecoParcelado_Helper</class>
17
+ </franciscoprado_precoparcelado>
18
+ </helpers>
19
+ </global>
20
+ <frontend>
21
+ <layout>
22
+ <updates>
23
+ <franciscoprado_precoparcelado module="franciscoprado_precoparcelado">
24
+ <file>franciscoprado_precoparcelado.xml</file>
25
+ </franciscoprado_precoparcelado>
26
+ </updates>
27
+ </layout>
28
+ <routers>
29
+ <franciscoprado_precoparcelado>
30
+ <use>standard</use>
31
+             <args>
32
+              <module>FranciscoPrado_PrecoParcelado</module>
33
+                 <frontName>precoparcelado</frontName>
34
+ </args>
35
+ </franciscoprado_precoparcelado>
36
+ </routers>
37
+ <translate>
38
+ <modules>
39
+ <FranciscoPrado_PrecoParcelado>
40
+ <files>
41
+ <default>FranciscoPrado_PrecoParcelado.csv</default>
42
+ </files>
43
+ </FranciscoPrado_PrecoParcelado>
44
+ </modules>
45
+ </translate>
46
+ </frontend>
47
+ <adminhtml>
48
+ <translate>
49
+ <modules>
50
+ <FranciscoPrado_PrecoParcelado>
51
+ <files>
52
+ <default>FranciscoPrado_PrecoParcelado.csv</default>
53
+ </files>
54
+ </FranciscoPrado_PrecoParcelado>
55
+ </modules>
56
+ </translate>
57
+ </adminhtml>
58
+ <default>
59
+ <sales>
60
+ <franciscoprado_precoparcelado>
61
+ <active>1</active>
62
+ <show_table>1</show_table>
63
+ <table_title>Valor das Parcelas</table_title>
64
+ <show_price_in_parcels>1</show_price_in_parcels>
65
+ <min_quote_value>50</min_quote_value>
66
+ <max_number_months>12</max_number_months>
67
+ <interest_value>1</interest_value>
68
+ <use_compound>1</use_compound>
69
+ <text_pattern>ou em {parcelas} vezes de {preco}</text_pattern>
70
+ <text_table_pattern>{parcelas}x de</text_table_pattern>
71
+ </franciscoprado_precoparcelado>
72
+ </sales>
73
+ </default>
74
+ </config>
app/code/community/FranciscoPrado/PrecoParcelado/etc/system.xml ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <sales module="sales">
5
+ <groups>
6
+ <franciscoprado_precoparcelado>
7
+ <label>Preço Parcelado</label>
8
+ <sort_order>10</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+ <fields>
13
+ <active>
14
+ <label>Enable</label>
15
+ <sort_order>10</sort_order>
16
+ <frontend_type>select</frontend_type>
17
+ <source_model>adminhtml/system_config_source_yesno</source_model>
18
+ <show_in_default>1</show_in_default>
19
+ <show_in_website>1</show_in_website>
20
+ <show_in_store>0</show_in_store>
21
+ </active>
22
+ <show_price_in_parcels>
23
+ <label>Show Price In Parcels</label>
24
+ <sort_order>20</sort_order>
25
+ <frontend_type>select</frontend_type>
26
+ <source_model>adminhtml/system_config_source_yesno</source_model>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>1</show_in_website>
29
+ <show_in_store>0</show_in_store>
30
+ <comment>
31
+ Ativa a exibição do texto quando inserido no template, usando como base o valor do campo Padrão de Texto.
32
+ </comment>
33
+ </show_price_in_parcels>
34
+ <show_table>
35
+ <label>Show Parcel Table</label>
36
+ <sort_order>30</sort_order>
37
+ <frontend_type>select</frontend_type>
38
+ <source_model>adminhtml/system_config_source_yesno</source_model>
39
+ <show_in_default>1</show_in_default>
40
+ <show_in_website>1</show_in_website>
41
+ <show_in_store>0</show_in_store>
42
+ <comment>
43
+ Exibirá uma tabela com a projeção das parcelas, mês a mês, ao lado do produto.
44
+ </comment>
45
+ </show_table>
46
+ <table_title>
47
+ <label>Table Title</label>
48
+ <frontend_type>text</frontend_type>
49
+ <sort_order>40</sort_order>
50
+ <show_in_default>1</show_in_default>
51
+ <show_in_website>1</show_in_website>
52
+ <show_in_store>0</show_in_store>
53
+ </table_title>
54
+ <min_quote_value>
55
+ <label>Minimal Value of the Parcel</label>
56
+ <frontend_type>text</frontend_type>
57
+ <sort_order>50</sort_order>
58
+ <show_in_default>1</show_in_default>
59
+ <show_in_website>1</show_in_website>
60
+ <show_in_store>0</show_in_store>
61
+ <validate>validate-greater-than-zero</validate>
62
+ </min_quote_value>
63
+ <max_number_months>
64
+ <label>Maximum Number of Months</label>
65
+ <frontend_type>text</frontend_type>
66
+ <sort_order>60</sort_order>
67
+ <show_in_default>1</show_in_default>
68
+ <show_in_website>1</show_in_website>
69
+ <show_in_store>0</show_in_store>
70
+ <validate>validate-greater-than-zero</validate>
71
+ </max_number_months>
72
+ <interest_value>
73
+ <label>Interest Value</label>
74
+ <frontend_type>text</frontend_type>
75
+ <sort_order>70</sort_order>
76
+ <show_in_default>1</show_in_default>
77
+ <show_in_website>1</show_in_website>
78
+ <show_in_store>0</show_in_store>
79
+ <validate>validate-zero-or-greater</validate>
80
+ </interest_value>
81
+ <use_compound>
82
+ <label>Use Compound Interest?</label>
83
+ <sort_order>80</sort_order>
84
+ <frontend_type>select</frontend_type>
85
+ <source_model>adminhtml/system_config_source_yesno</source_model>
86
+ <show_in_default>1</show_in_default>
87
+ <show_in_website>1</show_in_website>
88
+ <show_in_store>0</show_in_store>
89
+ <comment>
90
+ Se Sim, usará fórmula de juros compostos. Se Não, usará a de juros simples.
91
+ </comment>
92
+ </use_compound>
93
+ <text_pattern>
94
+ <label>Text Pattern</label>
95
+ <frontend_type>text</frontend_type>
96
+ <sort_order>90</sort_order>
97
+ <show_in_default>1</show_in_default>
98
+ <show_in_website>1</show_in_website>
99
+ <show_in_store>0</show_in_store>
100
+ <comment>
101
+ Insira {parcelas} para exibir o número de parcelas, e {preco} para exibir o seu valor.
102
+ </comment>
103
+ </text_pattern>
104
+ <text_table_pattern>
105
+ <label>Table Text Pattern</label>
106
+ <frontend_type>text</frontend_type>
107
+ <sort_order>100</sort_order>
108
+ <show_in_default>1</show_in_default>
109
+ <show_in_website>1</show_in_website>
110
+ <show_in_store>0</show_in_store>
111
+ <comment>
112
+ O {parcelas} é necessário e substituirá pela quantidade de parcelas na apresentação.
113
+ </comment>
114
+ </text_table_pattern>
115
+ </fields>
116
+ </franciscoprado_precoparcelado>
117
+ </groups>
118
+ </sales>
119
+ </sections>
120
+ </config>
app/design/frontend/base/default/layout/franciscoprado_precoparcelado.xml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <catalog_product_view>
4
+ <reference name="head">
5
+ <action method="addItem">
6
+ <type>skin_css</type>
7
+ <script>css/precoparcelado.css</script>
8
+ <params><![CDATA[media="all"]]></params>
9
+ </action>
10
+ </reference>
11
+ <reference name="head">
12
+ <action method="addItem">
13
+ <type>skin_js</type>
14
+ <script>js/precoparcelado.js</script>
15
+ <params><![CDATA[name="precoparcelado"]]></params>
16
+ </action>
17
+ </reference>
18
+ <reference name="product.info.extrahint">
19
+ <block type="core/template" name="precoparcelado.table" template="precoparcelado/table.phtml" before="-" />
20
+ </reference>
21
+ <reference name="content">
22
+ <block type="core/template" name="precoparcelado.jsdata" template="precoparcelado/jsdata.phtml" before="-" />
23
+ </reference>
24
+ </catalog_product_view>
25
+ </layout>
app/design/frontend/base/default/template/precoparcelado/jsdata.phtml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /* Suporte JS para preços configuráveis */
4
+
5
+ $helper = Mage::helper('franciscoprado_precoparcelado');
6
+ $isActive = $helper->isModuleEnabled();
7
+ $showTable = $helper->showTable();
8
+ $minParcel = Mage::helper('franciscoprado_precoparcelado')->getMinParcelValue();
9
+ $maxNumberMonths = Mage::helper('franciscoprado_precoparcelado')->getMaxNumberMonths();
10
+ $useCompound = Mage::helper('franciscoprado_precoparcelado')->useCompound();
11
+ $interest = Mage::helper('franciscoprado_precoparcelado')->getInterest();
12
+ $text = Mage::helper('franciscoprado_precoparcelado')->getText();
13
+ $tableText = Mage::helper('franciscoprado_precoparcelado')->getTableText();
14
+
15
+ if ($isActive): ?>
16
+ <script>
17
+ /* preco parcelado */
18
+ var showTable = <?php echo $showTable ? 'true' : 'false'; ?>;
19
+ var minParcel = <?php echo $minParcel ?>;
20
+ var maxNumberMonths = <?php echo $maxNumberMonths ?>;
21
+ var useCompound = <?php echo $useCompound ? 'true' : 'false' ?>;
22
+ var interest = <?php echo $interest ?>;
23
+ var ppText = '<?php echo $text ?>';
24
+ var ppTableText = '<?php echo $tableText ?>';
25
+ var ppId = '<?php echo Mage::registry('current_product')->getId() ?>';
26
+ </script>
27
+ <?php endif; ?>
app/design/frontend/base/default/template/precoparcelado/table.phtml ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $helper = Mage::helper('franciscoprado_precoparcelado');
4
+ $isActive = $helper->isModuleEnabled();
5
+ $showTable = $helper->showTable();
6
+
7
+ if ($isActive && $showTable):
8
+ $maxNumberMonths = $helper->getMaxNumberMonths();
9
+ $minParcelValue = $helper->getMinParcelValue();
10
+ $interest = $helper->getInterest();
11
+ $productPrice = Mage::registry('current_product')->getPrice();
12
+
13
+ ?>
14
+ <table class="precoparcelado-table">
15
+ <thead>
16
+ <tr>
17
+ <th colspan="2"><?php echo $helper->getTableTitle() ?></th>
18
+ </tr>
19
+ </thead>
20
+ <tbody>
21
+ <?php
22
+ if ($productPrice > $minParcelValue):
23
+ for ($i = 2; $i <= $maxNumberMonths; $i++):
24
+
25
+ if ($helper->useCompound()):
26
+ $parcel = $helper->getCompoundInterest($productPrice, $interest, $i);
27
+ else:
28
+ $parcel = $helper->getSimpleInterest($productPrice, $interest, $i);
29
+ endif;
30
+
31
+ $tableText = str_replace('{parcelas}', $i, $helper->getTableText());
32
+ $parcelPrice = Mage::helper('core')->currency($parcel, true, false);
33
+
34
+ if ($parcel >= $minParcelValue):
35
+ ?>
36
+ <tr>
37
+ <td><?php echo $tableText ?></td>
38
+ <td><?php echo $parcelPrice ?></td>
39
+ <tr>
40
+ <?php
41
+ endif;
42
+ endfor;
43
+ endif;
44
+ ?>
45
+ </tbody>
46
+ </table>
47
+ <?php
48
+ endif;
app/etc/modules/FranciscoPrado_PrecoParcelado.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <FranciscoPrado_PrecoParcelado>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </FranciscoPrado_PrecoParcelado>
8
+ </modules>
9
+ </config>
app/locale/pt_BR/FranciscoPrado_PrecoParcelado.csv ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ "Parcels Value", "Valor das Parcelas"
2
+ "Show Parcel Table", "Mostrar Tabela de Parcelas"
3
+ "Table Title", "Título da Tabela"
4
+ "Show Price In Parcels", "Mostrar Preço em Parcela"
5
+ "Minimal Value of the Parcel", "Valor Mínimo da Parcela"
6
+ "Maximum Number of Months", "Número Máximo de Meses"
7
+ "Interest Value", "Valor do Juros"
8
+ "Use Compound Interest?", "Usar Juros Compostos?"
9
+ "Text Pattern", "Padrão do Texto"
10
+ "Table Text Pattern", "Padrão do Texto da Tabela"
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>FranciscoPrado_PrecoParcelado</name>
4
+ <version>1.0.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Extens&#xE3;o para exibir o pre&#xE7;o do produto em parcelas.</summary>
10
+ <description>Extens&#xE3;o para exibir o pre&#xE7;o do produto em parcelas. &#xC9; poss&#xED;vel alterar a configura&#xE7;&#xE3;o, como o tipo de exibi&#xE7;&#xE3;o (em tabelas e ao lado do pre&#xE7;o), taxa de juros, f&#xF3;rmula de juros, valor m&#xED;nimo da parcela, n&#xFA;mero de meses, entre outros.</description>
11
+ <notes>Primeira vers&#xE3;o do m&#xF3;dulo Pre&#xE7;o Parcelado.</notes>
12
+ <authors><author><name>Francisco Prado</name><user>fr_prado</user><email>franciscontato@gmail.com</email></author></authors>
13
+ <date>2014-07-18</date>
14
+ <time>18:49:07</time>
15
+ <contents><target name="magecommunity"><dir name="FranciscoPrado"><dir name="PrecoParcelado"><dir name="Helper"><file name="Data.php" hash="16d18971431f3704effdcb7169b996a9"/></dir><dir name="etc"><file name="config.xml" hash="c070d790f9c5c3dd0ac5e5d02fa3fcfb"/><file name="system.xml" hash="c1fe5af2a805155827a2d2e25c1d2ce4"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="franciscoprado_precoparcelado.xml" hash="87ff7075401208ff78a9d8bc115a9970"/></dir><dir name="template"><dir name="precoparcelado"><file name="jsdata.phtml" hash="dc3f3dcd822fb2389324eae6e23cccc2"/><file name="table.phtml" hash="5375174d15dc910bf48cff5f55c88eed"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="FranciscoPrado_PrecoParcelado.xml" hash="ff2352dd5dcf370b98b77782ac230e5f"/></dir></target><target name="magelocale"><dir name="pt_BR"><file name="FranciscoPrado_PrecoParcelado.csv" hash="aa2537735fc8e2225a78db58767e719a"/></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="css"><file name="precoparcelado.css" hash="8b127443908efc0529ff9953e4d1402e"/></dir><dir name="js"><file name="precoparcelado.js" hash="de65fa886a758dfb00caafba5b577bed"/></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>
skin/frontend/base/default/css/precoparcelado.css ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .precoparcelado-table {
2
+ width: 200px;
3
+ }
4
+
5
+ .precoparcelado-table thead th {
6
+ border: solid 1px;
7
+ text-align: center;
8
+ }
9
+
10
+ .precoparcelado-table tbody td {
11
+ border: solid 1px;
12
+ }
skin/frontend/base/default/js/precoparcelado.js ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ $pp = jQuery.noConflict();
2
+
3
+ $pp(document).ready(function() {
4
+
5
+ Number.prototype.formatMoney = function(c, d, t) {
6
+ var n = this,
7
+ c = isNaN(c = Math.abs(c)) ? 2 : c,
8
+ d = d == undefined ? "." : d,
9
+ t = t == undefined ? "," : t,
10
+ s = n < 0 ? "-" : "",
11
+ i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
12
+ j = (j = i.length) > 3 ? j % 3 : 0;
13
+
14
+ return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
15
+ };
16
+
17
+ var getSimpleInterest = function(value, interest, parcels) {
18
+ interest = interest / 100;
19
+ var m = value * (1 + interest * parcels);
20
+ var parcelValue = m / parcels;
21
+
22
+ return parcelValue;
23
+ };
24
+
25
+ var getCompoundInterest = function(value, interest, parcels) {
26
+ interest = interest / 100;
27
+ var parcelValue = value * Math.pow((1 + interest), parcels);
28
+ var parcelValue = parcelValue / parcels;
29
+
30
+ return parcelValue;
31
+ };
32
+
33
+ var getPrice = function(value) {
34
+ if (value > minParcel) {
35
+ var finalText = '';
36
+ var ppDecimalSymbol = optionsPrice.priceFormat.decimalSymbol;
37
+ var ppCurrencyFormat = optionsPrice.priceFormat.pattern.replace('%s', '');
38
+ var ppGroupSymbol = optionsPrice.priceFormat.groupSymbol;
39
+ var finalText = '';
40
+ var tableText = '';
41
+
42
+ for (var i = 2; i <= maxNumberMonths; i++) {
43
+ var parcel = 0;
44
+
45
+ if (useCompound) {
46
+ parcel = getCompoundInterest(value, interest, i);
47
+ } else {
48
+ parcel = getSimpleInterest(value, interest, i);
49
+ }
50
+
51
+ if (parcel >= minParcel) {
52
+ var parcelToCurrency = ppCurrencyFormat + (parcel).formatMoney(2, ppDecimalSymbol, ppGroupSymbol);
53
+ finalText = ppText.replace('{preco}', parcelToCurrency);
54
+ finalText = finalText.replace('{parcelas}', i);
55
+
56
+ if (showTable) {
57
+ tableText += '<tr>';
58
+ tableText += '<td>' + ppTableText.replace('{parcelas}', i) + '</td>';
59
+ tableText += '<td>' + parcelToCurrency + '</td>';
60
+ tableText += '</tr>';
61
+ }
62
+ }
63
+ }
64
+
65
+ $pp('.precoparcelado-parcels').html(finalText);
66
+ $pp('.precoparcelado-table tbody').html(tableText);
67
+ }
68
+
69
+ return null;
70
+ };
71
+
72
+ var onPriceChange = function(e) {
73
+ var ppTotalPrice = $pp('#product-price-' + ppId + ' span').html();
74
+ var ppCurrencyFormat = optionsPrice.priceFormat.pattern.replace('%s', '');
75
+ var ppDecimalSymbol = optionsPrice.priceFormat.decimalSymbol;
76
+ var ppGroupSymbol = optionsPrice.priceFormat.groupSymbol;
77
+ var ppCurrent = new Number(
78
+ ppTotalPrice.replace(ppCurrencyFormat, '').replace(ppDecimalSymbol, '.').replace(ppGroupSymbol, ''));
79
+
80
+ getPrice(ppCurrent);
81
+ };
82
+
83
+ $pp('*[name^=super_attribute], *[name^=options]').on('change', onPriceChange);
84
+
85
+ });