Gaia_Carbon - Version 1.0.1

Version Notes

Initial release version

Download this release

Release Info

Developer Martin Novak
Extension Gaia_Carbon
Version 1.0.1
Comparing to
See all releases


Version 1.0.1

Files changed (45) hide show
  1. app/code/community/Gaia/Carbon/Block/Adminhtml/Sales/Order/Create/Totals/Carbon.php +19 -0
  2. app/code/community/Gaia/Carbon/Block/Adminhtml/Signup/Edit.php +47 -0
  3. app/code/community/Gaia/Carbon/Block/Adminhtml/Signup/Edit/Form.php +76 -0
  4. app/code/community/Gaia/Carbon/Block/Adminhtml/System/Config/Form/Button/Clearlog.php +47 -0
  5. app/code/community/Gaia/Carbon/Block/Adminhtml/System/Config/Form/Button/Showlog.php +47 -0
  6. app/code/community/Gaia/Carbon/Block/Adminhtml/System/Config/Form/Button/Signup.php +47 -0
  7. app/code/community/Gaia/Carbon/Block/Checkout/Carbon.php +83 -0
  8. app/code/community/Gaia/Carbon/Block/Checkout/Totals/Carbon.php +18 -0
  9. app/code/community/Gaia/Carbon/Block/Sales/Order/Carbon.php +57 -0
  10. app/code/community/Gaia/Carbon/Helper/Data.php +279 -0
  11. app/code/community/Gaia/Carbon/Model/Api/Client.php +150 -0
  12. app/code/community/Gaia/Carbon/Model/Api/Request.php +169 -0
  13. app/code/community/Gaia/Carbon/Model/Carbon.php +90 -0
  14. app/code/community/Gaia/Carbon/Model/Checkout/Type/Onepage.php +38 -0
  15. app/code/community/Gaia/Carbon/Model/Geocoder.php +119 -0
  16. app/code/community/Gaia/Carbon/Model/Location.php +71 -0
  17. app/code/community/Gaia/Carbon/Model/Observer.php +89 -0
  18. app/code/community/Gaia/Carbon/Model/Sales/Order/Total/Creditmemo/Carbon.php +50 -0
  19. app/code/community/Gaia/Carbon/Model/Sales/Order/Total/Invoice/Carbon.php +44 -0
  20. app/code/community/Gaia/Carbon/Model/Sales/Quote/Address/Total/Carbon.php +83 -0
  21. app/code/community/Gaia/Carbon/Model/Signup.php +70 -0
  22. app/code/community/Gaia/Carbon/Model/System/Config/Source/Abstract.php +88 -0
  23. app/code/community/Gaia/Carbon/Model/System/Config/Source/Environment.php +23 -0
  24. app/code/community/Gaia/Carbon/Model/System/Config/Source/Mode.php +23 -0
  25. app/code/community/Gaia/Carbon/Model/System/Config/Source/Unit/Weight.php +25 -0
  26. app/code/community/Gaia/Carbon/controllers/Adminhtml/DebugController.php +52 -0
  27. app/code/community/Gaia/Carbon/controllers/Adminhtml/SignupController.php +37 -0
  28. app/code/community/Gaia/Carbon/controllers/AjaxController.php +30 -0
  29. app/code/community/Gaia/Carbon/etc/adminhtml.xml +34 -0
  30. app/code/community/Gaia/Carbon/etc/config.xml +197 -0
  31. app/code/community/Gaia/Carbon/etc/system.xml +162 -0
  32. app/code/community/Gaia/Carbon/sql/carbon_setup/mysql4-install-1.0.0.php +26 -0
  33. app/design/adminhtml/default/default/layout/gaia/carbon.xml +65 -0
  34. app/design/adminhtml/default/default/template/gaia/carbon/sales/order/refunded.phtml +30 -0
  35. app/design/adminhtml/default/default/template/gaia/carbon/sales/order/total.phtml +19 -0
  36. app/design/adminhtml/default/default/template/gaia/carbon/system/config/button.phtml +1 -0
  37. app/design/frontend/base/default/layout/gaia/carbon.xml +81 -0
  38. app/design/frontend/base/default/template/gaia/checkout/cart/totals/carbon.phtml +35 -0
  39. app/design/frontend/base/default/template/gaia/checkout/onepage/carbon.phtml +15 -0
  40. app/etc/modules/Gaia_Carbon.xml +9 -0
  41. package.xml +23 -0
  42. skin/frontend/base/default/gaia/carbon/css/styles.css +98 -0
  43. skin/frontend/base/default/gaia/carbon/images/dark-check-green.png +0 -0
  44. skin/frontend/base/default/gaia/carbon/images/i_question-mark.png +0 -0
  45. skin/frontend/base/default/gaia/carbon/images/lite-green-check.png +0 -0
app/code/community/Gaia/Carbon/Block/Adminhtml/Sales/Order/Create/Totals/Carbon.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Description of class...
4
+ *
5
+ * @category Gaia
6
+ * @package Gaia_Carbon
7
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
8
+ */
9
+
10
+ class Gaia_Carbon_Block_Adminhtml_Sales_Order_Create_Totals_Carbon
11
+ extends Mage_Adminhtml_Block_Sales_Order_Create_Totals_Default
12
+ {
13
+ /**
14
+ * Use your own template if necessary
15
+ * See "sales/order/create/totals/default.phtml" for example
16
+ */
17
+ // protected $_template = 'gaia/carbon/sales/order/create/totals/carbon.phtml';
18
+
19
+ }
app/code/community/Gaia/Carbon/Block/Adminhtml/Signup/Edit.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * @category Gaia
5
+ * @package Gaia_Carbon
6
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
7
+ */
8
+ class Gaia_Carbon_Block_Adminhtml_Signup_Edit
9
+ extends Mage_Adminhtml_Block_Widget_Form_Container
10
+ {
11
+
12
+ protected $_blockGroup = 'carbon';
13
+ protected $_controller = 'adminhtml_signup';
14
+
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+ $this->removeButton('delete');
19
+ $this->removeButton('back');
20
+ $this->removeButton('reset');
21
+ $this->_updateButton('save', 'label', Mage::helper('carbon')->__('Sign Up'));
22
+ }
23
+
24
+ /**
25
+ * Getter for form header text
26
+ *
27
+ * @return string
28
+ */
29
+ public function getHeaderText()
30
+ {
31
+ return Mage::helper('carbon')->__('Sign Up');
32
+ }
33
+
34
+ /**
35
+ * Get form action URL
36
+ *
37
+ * @return string
38
+ */
39
+ public function getFormActionUrl()
40
+ {
41
+ if ($this->hasFormActionUrl()) {
42
+ return $this->getData('form_action_url');
43
+ }
44
+ return $this->getUrl('*/' . $this->_controller . '/signup');
45
+ }
46
+
47
+ }
app/code/community/Gaia/Carbon/Block/Adminhtml/Signup/Edit/Form.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * @category Gaia
5
+ * @package Gaia_Carbon
6
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
7
+ */
8
+ class Gaia_Carbon_Block_Adminhtml_Signup_Edit_Form
9
+ extends Mage_Adminhtml_Block_Widget_Form
10
+ {
11
+
12
+ protected function _prepareForm()
13
+ {
14
+ $form = new Varien_Data_Form(
15
+ array(
16
+ 'id' => 'edit_form',
17
+ 'action' => $this->getUrl('*/*/signup'),
18
+ 'method' => 'post',
19
+ 'enctype' => 'multipart/form-data',
20
+ )
21
+ );
22
+
23
+ $this->setForm($form);
24
+ $form_data = Mage::registry('carbon_signup_form_data');
25
+
26
+ $fieldset = $form->addFieldset('login', array(
27
+ 'legend' => Mage::helper('carbon')->__('Name & Contact Details')
28
+ ));
29
+
30
+ $fieldset->addField('title', 'text', array(
31
+ 'name' => 'title',
32
+ 'label' => Mage::helper('carbon')->__('Title'),
33
+ 'required' => false,
34
+ ));
35
+
36
+ $fieldset->addField('name', 'text', array(
37
+ 'name' => 'name',
38
+ 'label' => Mage::helper('carbon')->__('Full Name'),
39
+ 'required' => true,
40
+ ));
41
+
42
+ $fieldset->addField('email', 'text', array(
43
+ 'name' => 'email',
44
+ 'label' => Mage::helper('carbon')->__('Email Address'),
45
+ 'required' => true,
46
+ 'class' => 'validate-email'
47
+ ));
48
+
49
+ $fieldset->addField('phone', 'text', array(
50
+ 'name' => 'phone',
51
+ 'label' => Mage::helper('carbon')->__('Phone'),
52
+ 'required' => false,
53
+ 'class' => 'validate-digits'
54
+ ));
55
+
56
+ $fieldset->addField('mobile', 'text', array(
57
+ 'name' => 'mobile',
58
+ 'label' => Mage::helper('carbon')->__('Mobile'),
59
+ 'required' => false,
60
+ 'class' => 'validate-digits'
61
+ ));
62
+
63
+ $fieldset->addField('company', 'text', array(
64
+ 'name' => 'company',
65
+ 'label' => Mage::helper('carbon')->__('Company Name'),
66
+ 'required' => false
67
+ ));
68
+
69
+ if ($form_data) {
70
+ $form->setValues($form_data);
71
+ }
72
+ $form->setUseContainer(true);
73
+ return parent::_prepareForm();
74
+ }
75
+
76
+ }
app/code/community/Gaia/Carbon/Block/Adminhtml/System/Config/Form/Button/Clearlog.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gaia
5
+ * @package Gaia_Carbon
6
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
7
+ */
8
+ class Gaia_Carbon_Block_Adminhtml_System_Config_Form_Button_Clearlog
9
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
10
+ {
11
+ /*
12
+ * Set template
13
+ */
14
+ protected function _construct()
15
+ {
16
+ parent::_construct();
17
+ $this->setTemplate('gaia/carbon/system/config/button.phtml');
18
+ }
19
+
20
+ /**
21
+ * Return element html
22
+ *
23
+ * @param Varien_Data_Form_Element_Abstract $element
24
+ * @return string
25
+ */
26
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
27
+ {
28
+ return $this->_toHtml();
29
+ }
30
+
31
+ /**
32
+ * Generate button html
33
+ *
34
+ * @return string
35
+ */
36
+ public function getButtonHtml()
37
+ {
38
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')
39
+ ->setData(array(
40
+ 'id' => 'clear_button',
41
+ 'label' => $this->helper('adminhtml')->__('Clear Log File'),
42
+ 'onclick' => "window.location = '".$this->getUrl('acarbon/adminhtml_debug/clearlog')."';"
43
+ ));
44
+
45
+ return $button->toHtml();
46
+ }
47
+ }
app/code/community/Gaia/Carbon/Block/Adminhtml/System/Config/Form/Button/Showlog.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gaia
5
+ * @package Gaia_Carbon
6
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
7
+ */
8
+ class Gaia_Carbon_Block_Adminhtml_System_Config_Form_Button_Showlog
9
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
10
+ {
11
+ /*
12
+ * Set template
13
+ */
14
+ protected function _construct()
15
+ {
16
+ parent::_construct();
17
+ $this->setTemplate('gaia/carbon/system/config/button.phtml');
18
+ }
19
+
20
+ /**
21
+ * Return element html
22
+ *
23
+ * @param Varien_Data_Form_Element_Abstract $element
24
+ * @return string
25
+ */
26
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
27
+ {
28
+ return $this->_toHtml();
29
+ }
30
+
31
+ /**
32
+ * Generate button html
33
+ *
34
+ * @return string
35
+ */
36
+ public function getButtonHtml()
37
+ {
38
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')
39
+ ->setData(array(
40
+ 'id' => 'showlog_button',
41
+ 'label' => $this->helper('adminhtml')->__('Show Log File Content'),
42
+ 'onclick' => "window.open('".$this->getUrl('acarbon/adminhtml_debug/showlog')."');"
43
+ ));
44
+
45
+ return $button->toHtml();
46
+ }
47
+ }
app/code/community/Gaia/Carbon/Block/Adminhtml/System/Config/Form/Button/Signup.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gaia
5
+ * @package Gaia_Carbon
6
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
7
+ */
8
+ class Gaia_Carbon_Block_Adminhtml_System_Config_Form_Button_Signup
9
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
10
+ {
11
+ /*
12
+ * Set template
13
+ */
14
+ protected function _construct()
15
+ {
16
+ parent::_construct();
17
+ $this->setTemplate('gaia/carbon/system/config/button.phtml');
18
+ }
19
+
20
+ /**
21
+ * Return element html
22
+ *
23
+ * @param Varien_Data_Form_Element_Abstract $element
24
+ * @return string
25
+ */
26
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
27
+ {
28
+ return $this->_toHtml();
29
+ }
30
+
31
+ /**
32
+ * Generate button html
33
+ *
34
+ * @return string
35
+ */
36
+ public function getButtonHtml()
37
+ {
38
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')
39
+ ->setData(array(
40
+ 'id' => 'showlog_button',
41
+ 'label' => $this->helper('adminhtml')->__('Sign Up - Register for production API key'),
42
+ 'onclick' => "window.open('".$this->getUrl('acarbon/adminhtml_signup')."');"
43
+ ));
44
+
45
+ return $button->toHtml();
46
+ }
47
+ }
app/code/community/Gaia/Carbon/Block/Checkout/Carbon.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Description of class...
5
+ *
6
+ * @category Gaia
7
+ * @package Gaia_Carbon
8
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
9
+ */
10
+ class Gaia_Carbon_Block_Checkout_Carbon
11
+ extends Mage_Checkout_Block_Onepage_Abstract
12
+ {
13
+ const CARBON_URL = 'gaiapartnership.com/services/page7/carbon_offsets.html';
14
+ protected $_carbonCopy = 'The Gaia Partnership\'s CO2counter automatically calculates the carbon emissions from the transportation of your goods. The small cost of offsetting is then shown in within the cart.';
15
+
16
+ public function isEnabled()
17
+ {
18
+ return Mage::helper('carbon')->isEnabled();
19
+ }
20
+
21
+ public function isOptional()
22
+ {
23
+ return Mage::helper('carbon')->getApplyMode()
24
+ === Gaia_Carbon_Model_System_Config_Source_Mode::OPTIONAL;
25
+ }
26
+
27
+ public function isCarbonSelected()
28
+ {
29
+ return Mage::getSingleton('checkout/session')->getCustomerPaysForCarbon() == true;
30
+ }
31
+
32
+ public function getCarbonDescription()
33
+ {
34
+ return $this->_carbonCopy;
35
+ }
36
+
37
+ public function getCarbonAmount()
38
+ {
39
+ if ($amount = $this->getQuote()->getCarbonAmount()) {
40
+ return $this->formatCurrency($amount);
41
+ }
42
+ return '';
43
+ }
44
+
45
+ public function getCarbonUrl()
46
+ {
47
+ if (Mage::app()->getStore()->isCurrentlySecure()) {
48
+ return 'https://'.self::CARBON_URL;
49
+ }
50
+ return 'http://'.self::CARBON_URL;
51
+ }
52
+
53
+ /**
54
+ * Gets currency code (by order store)
55
+ *
56
+ * @return string
57
+ */
58
+ public function getStoreCurrencyCode()
59
+ {
60
+ return $this->getQuote()->getStoreCurrencyCode();
61
+ }
62
+
63
+ /**
64
+ * Gets symbol for store currency code
65
+ *
66
+ * @return string
67
+ */
68
+ public function getCurrencySymbol()
69
+ {
70
+ return Mage::app()->getLocale()->currency($this->getStoreCurrencyCode())->getSymbol();
71
+ }
72
+
73
+ /**
74
+ * Format currency
75
+ *
76
+ * @param float $price
77
+ * @return string
78
+ */
79
+ public function formatCurrency($price)
80
+ {
81
+ return Mage::helper('core')->currency($price);
82
+ }
83
+ }
app/code/community/Gaia/Carbon/Block/Checkout/Totals/Carbon.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Description of class...
4
+ *
5
+ * @category Gaia
6
+ * @package Gaia_Carbon
7
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
8
+ */
9
+
10
+ class Gaia_Carbon_Block_Checkout_Totals_Carbon
11
+ extends Mage_Checkout_Block_Total_Default
12
+ {
13
+ /**
14
+ * Use your own template if necessary
15
+ * See "checkout/total/default.phtml" for example
16
+ */
17
+ // protected $_template = 'gaia/carbon/checkout/total/carbon.phtml';
18
+ }
app/code/community/Gaia/Carbon/Block/Sales/Order/Carbon.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Description of class...
4
+ *
5
+ * @category Gaia
6
+ * @package Gaia_Carbon
7
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
8
+ */
9
+
10
+ class Gaia_Carbon_Block_Sales_Order_Carbon
11
+ extends Mage_Core_Block_Template
12
+ {
13
+
14
+ /**
15
+ * Get order store object
16
+ *
17
+ * @return Mage_Sales_Model_Order
18
+ */
19
+ public function getOrder()
20
+ {
21
+ return $this->getParentBlock()->getOrder();
22
+ }
23
+
24
+ /**
25
+ * Get totals source object
26
+ *
27
+ * @return Mage_Sales_Model_Order
28
+ */
29
+ public function getSource()
30
+ {
31
+ return $this->getParentBlock()->getSource();
32
+ }
33
+
34
+ /**
35
+ * Initialize fee totals
36
+ *
37
+ * @return Gaia_Carbon_Block_Sales_Order_Carbon
38
+ */
39
+ public function initTotals()
40
+ {
41
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
42
+
43
+ if ((float) $this->getOrder()->getBaseCarbonAmount()) {
44
+ $source = $this->getSource();
45
+ $value = $source->getCarbonAmount();
46
+
47
+ $this->getParentBlock()->addTotal(new Varien_Object(array(
48
+ 'code' => 'carbon',
49
+ 'strong' => false,
50
+ 'label' => Mage::helper('carbon')->__('Carbon Offset'),
51
+ 'value' => $value
52
+ )));
53
+ }
54
+
55
+ return $this;
56
+ }
57
+ }
app/code/community/Gaia/Carbon/Helper/Data.php ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Description of class...
5
+ *
6
+ * @category Gaia
7
+ * @package Gaia_Carbon
8
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
9
+ */
10
+ class Gaia_Carbon_Helper_Data
11
+ extends Mage_Core_Helper_Abstract
12
+ {
13
+ const LOG_FILENAME = 'gaia-carbon.log';
14
+
15
+ const SANDBOX_KEY = '2';
16
+ const SANDBOX_HASH = 'sandbox';
17
+
18
+ const XPATH_ACTIVE = 'carbon/general/active';
19
+ const XPATH_ENVIRONMENT = 'carbon/general/environment';
20
+ const XPATH_APIKEY = 'carbon/general/api_key';
21
+ const XPATH_APIHASH = 'carbon/general/api_hash';
22
+ const XPATH_SIG_APIKEY = 'carbon/general/api_sigkey';
23
+ const XPATH_SIG_APIHASH = 'carbon/general/api_sighash';
24
+ const XPATH_MODE = 'carbon/general/mode';
25
+ const XPATH_WEIGHTUNIT = 'carbon/general/weight_unit';
26
+ const XPATH_LOG_ACTIVE = 'carbon/log/active';
27
+ const XPATH_LOG_VERBOSE = 'carbon/log/verbose';
28
+
29
+ /**
30
+ * Is this plugin enabled?
31
+ *
32
+ * @param mixed $store
33
+ * @return bool
34
+ */
35
+ public function isEnabled($store = null)
36
+ {
37
+ return Mage::getStoreConfigFlag(self::XPATH_ACTIVE, $store);
38
+ }
39
+
40
+ /**
41
+ * Is this sandbox or production?
42
+ *
43
+ * @param mixed $store
44
+ * @return boolean
45
+ */
46
+ public function isSandbox($store = null)
47
+ {
48
+ return Mage::getStoreConfig(self::XPATH_ENVIRONMENT, $store)
49
+ === Gaia_Carbon_Model_System_Config_Source_Environment::SANDBOX;
50
+ }
51
+
52
+ /**
53
+ * Returns carbon offset apply mode
54
+ *
55
+ * @param mixed $store
56
+ * @return string
57
+ */
58
+ public function getApplyMode($store = null)
59
+ {
60
+ return Mage::getStoreConfig(self::XPATH_MODE, $store);
61
+ }
62
+
63
+ /**
64
+ * Returns Gaia API key
65
+ *
66
+ * @param mixed $store
67
+ * @return string
68
+ */
69
+ public function getApiKey($store = null)
70
+ {
71
+ if ($this->isSandbox($store)) {
72
+ return self::SANDBOX_KEY;
73
+ }
74
+ return Mage::getStoreConfig(self::XPATH_APIKEY, $store);
75
+ }
76
+
77
+ /**
78
+ * Returns Gaia Api hash
79
+ *
80
+ * @param mixed $store
81
+ * @return string
82
+ */
83
+ public function getApiHash($store = null)
84
+ {
85
+ if ($this->isSandbox($store)) {
86
+ return self::SANDBOX_HASH;
87
+ }
88
+ return Mage::getStoreConfig(self::XPATH_APIHASH, $store);
89
+ }
90
+
91
+ /**
92
+ * Returns Gaia API key
93
+ *
94
+ * @param mixed $store
95
+ * @return string
96
+ */
97
+ public function getSigApiKey($store = null)
98
+ {
99
+ return Mage::getStoreConfig(self::XPATH_SIG_APIKEY, $store);
100
+ }
101
+
102
+ /**
103
+ * Returns Gaia Api hash
104
+ *
105
+ * @param mixed $store
106
+ * @return string
107
+ */
108
+ public function getSigApiHash($store = null)
109
+ {
110
+ return Mage::getStoreConfig(self::XPATH_SIG_APIHASH, $store);
111
+ }
112
+
113
+ /**
114
+ * Returns product weight unit from configuration
115
+ *
116
+ * @param mixed $store
117
+ * @return string
118
+ */
119
+ public function getWeightUnit($store = null)
120
+ {
121
+ return Mage::getStoreConfig(self::XPATH_WEIGHTUNIT, $store);
122
+ }
123
+
124
+ /**
125
+ * Is logging enabled?
126
+ *
127
+ * @param mixed $store
128
+ * @return boolean
129
+ */
130
+ public function isLogEnabled($store = null)
131
+ {
132
+ return Mage::getStoreConfigFlag(self::XPATH_LOG_ACTIVE, $store);
133
+ }
134
+
135
+ /**
136
+ * Is verbose log option enabled?
137
+ *
138
+ * @param mixed $store
139
+ * @return boolean
140
+ */
141
+ public function isLogVerbose($store = null)
142
+ {
143
+ return Mage::getStoreConfigFlag(self::XPATH_LOG_VERBOSE, $store);
144
+ }
145
+
146
+ /**
147
+ * Wrapper for Magentos' own log function
148
+ *
149
+ * @param mixed $data
150
+ * @param boolean $verbose
151
+ * @param int $store
152
+ */
153
+ public function log($log, $verbose = false, $store = null)
154
+ {
155
+ if ($this->isLogEnabled($store)) {
156
+ if ($verbose === false || ($verbose && $this->isLogVerbose($store))) {
157
+ Mage::log($log, null, self::LOG_FILENAME, true);
158
+ }
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Gets shipping origin address from configuration
164
+ *
165
+ * @param mixed $store
166
+ * @return string
167
+ */
168
+ public function getOriginAddress($store = null)
169
+ {
170
+ $return = array(
171
+ Mage::getStoreConfig('shipping/origin/street_line1', $store),
172
+ Mage::getStoreConfig('shipping/origin/street_line2', $store),
173
+ Mage::getStoreConfig('shipping/origin/city', $store),
174
+ $this->getRegionName(Mage::getStoreConfig('shipping/origin/region_id', $store)),
175
+ Mage::getStoreConfig('shipping/origin/postcode', $store),
176
+ Mage::getStoreConfig('shipping/origin/country_id', $store),
177
+ );
178
+ return implode(',', array_filter($return));
179
+ }
180
+
181
+ /**
182
+ * Gets shipping origin street from configuration
183
+ *
184
+ * @param mixed $store
185
+ * @return string
186
+ */
187
+ public function getOriginStreet($store = null)
188
+ {
189
+ $return = array(
190
+ Mage::getStoreConfig('shipping/origin/street_line1', $store),
191
+ Mage::getStoreConfig('shipping/origin/street_line2', $store),
192
+ );
193
+ return implode(',', array_filter($return));
194
+ }
195
+
196
+ /**
197
+ * Gets shipping origin city from configuration
198
+ *
199
+ * @param mixed $store
200
+ * @return string
201
+ */
202
+ public function getOriginCity($store = null)
203
+ {
204
+ return trim(Mage::getStoreConfig('shipping/origin/city', $store));
205
+ }
206
+
207
+ /**
208
+ * Gets shipping origin state from configuration
209
+ *
210
+ * @param mixed $store
211
+ * @return string
212
+ */
213
+ public function getOriginState($store = null)
214
+ {
215
+ return $this->getRegionName(Mage::getStoreConfig('shipping/origin/region_id', $store));
216
+ }
217
+
218
+
219
+ /**
220
+ * Returns region name
221
+ *
222
+ * @param mixed $region
223
+ * @return string
224
+ */
225
+ public function getRegionName($region)
226
+ {
227
+ if (is_numeric($region)) {
228
+ return Mage::getModel('directory/region')->load($region)->getName();
229
+ }
230
+ return trim($region);
231
+ }
232
+
233
+ /**
234
+ * Gets shipping origin postal code from configuration
235
+ *
236
+ * @param mixed $store
237
+ * @return string
238
+ */
239
+ public function getOriginPostcode($store = null)
240
+ {
241
+ return trim(Mage::getStoreConfig('shipping/origin/postcode', $store));
242
+ }
243
+
244
+ /**
245
+ * Gets shipping origin country id from configuration
246
+ *
247
+ * @param mixed $store
248
+ * @return string
249
+ */
250
+ public function getOriginCountryId($store = null)
251
+ {
252
+ return trim(Mage::getStoreConfig('shipping/origin/country_id', $store));
253
+ }
254
+
255
+ /**
256
+ * Converts given weight from configured unit to kilograms
257
+ *
258
+ * @param float $value Weight to convert
259
+ * @return float Converted weight in kilograms
260
+ */
261
+ public function getWeightInKilograms($value, $currentUnit = null)
262
+ {
263
+ $value = floatval($value);
264
+ $currentUnit = $currentUnit ? $currentUnit : $this->getWeightUnit();
265
+ //from units as specified in configuration
266
+ switch($currentUnit) {
267
+ case Gaia_Carbon_Model_System_Config_Source_Unit_Weight::GRAMS:
268
+ return $value * 0.001;
269
+
270
+ case Gaia_Carbon_Model_System_Config_Source_Unit_Weight::OUNCES:
271
+ return $value * 0.0283495;
272
+
273
+ case Gaia_Carbon_Model_System_Config_Source_Unit_Weight::POUNDS:
274
+ return $value * 0.453592;
275
+
276
+ default: return $value;
277
+ }
278
+ }
279
+ }
app/code/community/Gaia/Carbon/Model/Api/Client.php ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @method Gaia_Carbon_Model_Api_Client setMethod()
5
+ * @method string getMethod()
6
+ *
7
+ * @category Gaia
8
+ * @package Gaia_Carbon
9
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
10
+ */
11
+ class Gaia_Carbon_Model_Api_Client
12
+ extends Mage_Core_Model_Abstract
13
+ {
14
+ /**
15
+ * The Carbon Offset API URL
16
+ */
17
+ const SERVICE_URL_SANDBOX = "http://test.co2counter.com.au/api/api3.php";
18
+
19
+ const SERVICE_URL_PRODUCTION = "http://co2counter.com.au/api/api3.php";
20
+ const SIGNUP_URL_PRODUCTION = "http://co2counter.com.au/api/api3.register.php";
21
+
22
+ /**
23
+ * The supported methods of communication with Gaia API
24
+ */
25
+ const METHOD_JSON = 'json';
26
+
27
+ /**
28
+ * The API connector http client
29
+ *
30
+ * @var Varien_Http_Client
31
+ */
32
+ protected $_client = null;
33
+
34
+
35
+ public function _construct() {
36
+ parent::_construct();
37
+ $this->_initialize();
38
+ }
39
+
40
+ /**
41
+ * Prepare client for use and set default properties
42
+ *
43
+ * @return \Gaia_Carbon_Model_Api_Client
44
+ */
45
+ protected function _initialize()
46
+ {
47
+ return $this->_prepareClient()->setMethod(self::METHOD_JSON);
48
+ }
49
+
50
+ /**
51
+ *
52
+ * @return \Gaia_Carbon_Model_Api_Client
53
+ */
54
+ protected function _prepareClient()
55
+ {
56
+ if (!$this->_client) {
57
+ $this->_client = new Varien_Http_Client();
58
+ $this->_client->setConfig(array('maxredirects' => 0, 'timeout' => 30));
59
+ }
60
+ return $this;
61
+ }
62
+
63
+ /**
64
+ * Calls API to calculate carbon offset charges for given request
65
+ *
66
+ * @param array $request
67
+ * @return array
68
+ */
69
+ public function calculate($request)
70
+ {
71
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
72
+
73
+ if (!$this->_client) {
74
+ return false;
75
+ }
76
+ try {
77
+
78
+ $this->_client
79
+ ->setUri($this->_prepareServiceUrl())
80
+ ->setParameterGet('json', Mage::helper('core')->jsonEncode($request));
81
+ /**
82
+ * Getting response via raw body and decoding coz of a bug in Zend yielding
83
+ * exception when ->getBody() is used to decode and return response
84
+ */
85
+ Mage::helper('carbon')->log('API Request/Response', true);
86
+ Mage::helper('carbon')->log(Mage::helper('core')->jsonEncode($request), true);
87
+ $rawBody = $this->_client->request(Varien_Http_Client::POST)->getRawBody();
88
+ Mage::helper('carbon')->log($rawBody, true);
89
+ return Mage::helper('core')->jsonDecode($rawBody, Zend_Json::TYPE_ARRAY);
90
+ } catch (Exception $e) {
91
+ Mage::logException($e);
92
+ return false;
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Signup - new client via API
98
+ *
99
+ * @param array $data
100
+ * @return boolean
101
+ */
102
+ public function signup($data)
103
+ {
104
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
105
+
106
+ if (!$this->_client) {
107
+ Mage::throwException('Something went wrong - missing API client class.');
108
+ }
109
+ $this->_client
110
+ ->setUri($this->_prepareSignupUrl())
111
+ ->setParameterGet('json', Mage::helper('core')->jsonEncode($data));
112
+ /**
113
+ * Getting response via raw body and decoding coz of a bug in Zend yielding
114
+ * exception when ->getBody() is used to decode and return response
115
+ */
116
+ Mage::helper('carbon')->log('API Request/Response', true);
117
+ Mage::helper('carbon')->log(Mage::helper('core')->jsonEncode($data), true);
118
+ $rawBody = $this->_client->request(Varien_Http_Client::POST)->getRawBody();
119
+ Mage::helper('carbon')->log($rawBody, true);
120
+ $response = Mage::helper('core')->jsonDecode($rawBody, Zend_Json::TYPE_ARRAY);
121
+ if (isset($response['co2counter']['status'])) {
122
+ if ($response['co2counter']['status'] == 1) {
123
+ Mage::throwException('Signup failed: '.reset($response['co2counter']));
124
+ }
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Gets service URL for current environment
130
+ *
131
+ * @return string
132
+ */
133
+ protected function _prepareServiceUrl()
134
+ {
135
+ if (Mage::helper('carbon')->isSandbox()) {
136
+ return self::SERVICE_URL_SANDBOX;
137
+ }
138
+ return self::SERVICE_URL_PRODUCTION;
139
+ }
140
+
141
+ /**
142
+ * Gets production signup URL
143
+ *
144
+ * @return string
145
+ */
146
+ protected function _prepareSignupUrl()
147
+ {
148
+ return self::SIGNUP_URL_PRODUCTION;
149
+ }
150
+ }
app/code/community/Gaia/Carbon/Model/Api/Request.php ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @method Gaia_Carbon_Model_Api_Request setMethod()
5
+ * @method Gaia_Carbon_Model_Api_Request setIsSale()
6
+ *
7
+ * @method string getMethod()
8
+ * @method boolean getIsSale()
9
+ *
10
+ * @category Gaia
11
+ * @package Gaia_Carbon
12
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
13
+ */
14
+ class Gaia_Carbon_Model_Api_Request
15
+ extends Mage_Core_Model_Abstract
16
+ {
17
+ /**
18
+ * The origin (from) location
19
+ *
20
+ * @var Gaia_Carbon_Model_Location
21
+ */
22
+ protected $_origin;
23
+
24
+ /**
25
+ * The destination (to) location
26
+ *
27
+ * @var Gaia_Carbon_Model_Location
28
+ */
29
+ protected $_destination;
30
+
31
+ /**
32
+ * The request items (all products in cart)
33
+ */
34
+ protected $_items;
35
+
36
+
37
+ public function _construct() {
38
+ parent::_construct();
39
+ $this->_origin = Mage::getModel('carbon/location');
40
+ $this->_destination = Mage::getModel('carbon/location');
41
+ }
42
+
43
+ /**
44
+ * Set order items
45
+ *
46
+ * @param mixed $items
47
+ * @return \Gaia_Carbon_Model_Api_Request
48
+ */
49
+ public function setItems($items)
50
+ {
51
+ $this->_items = $items;
52
+ return $this;
53
+ }
54
+
55
+ /**
56
+ * Set origin location for request
57
+ *
58
+ * @param Gaia_Carbon_Model_Location $origin
59
+ * @return \Gaia_Carbon_Model_Api_Request
60
+ */
61
+ public function setOrigin(Gaia_Carbon_Model_Location $origin)
62
+ {
63
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
64
+
65
+ $this->_origin = $origin;
66
+ return $this;
67
+ }
68
+
69
+ /**
70
+ * Set destination location for request
71
+ *
72
+ * @param Gaia_Carbon_Model_Location $destination
73
+ * @return \Gaia_Carbon_Model_Api_Request
74
+ */
75
+ public function setDestination(Gaia_Carbon_Model_Location $destination)
76
+ {
77
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
78
+
79
+ $this->_destination = $destination;
80
+ return $this;
81
+ }
82
+
83
+ /**
84
+ * Calculate carbon offset charges for given request
85
+ *
86
+ * @return array|boolean false on failure
87
+ */
88
+ public function calculate()
89
+ {
90
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
91
+
92
+ if (!$this->_validate()) {
93
+ Mage::helper('carbon')->log('Not a valid API request.');
94
+ return false;
95
+ }
96
+ try {
97
+ $request = $this->_prepareRequest();
98
+ $api = Mage::getModel('carbon/api_client');
99
+ /* @var $api Gaia_Carbon_Model_Api_Client */
100
+ return $api->calculate($request);
101
+ } catch (Exception $e) {
102
+ Mage::logException($e);
103
+ }
104
+ return false;
105
+ }
106
+
107
+ protected function _prepareRequest()
108
+ {
109
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
110
+
111
+ return array(
112
+ 'key' => Mage::helper('carbon')->getApiKey(),
113
+ 'hash' => Mage::helper('carbon')->getApiHash(),
114
+ 'orn' => '3333',
115
+ 'mass_kg' => Mage::helper('carbon')
116
+ ->getWeightInKilograms($this->_getCombinedProductWeight()),
117
+ 'sale' => $this->getIsSale() ? true : false,
118
+ 'currency' => $this->getCurrency(),
119
+ 'cust_notes' => $this->getCustNotes(),
120
+ 'cust_email' => $this->getCustEmail(),
121
+ 'output' => 'full',
122
+ 'hops' => array( 0 => array(
123
+ 'type' => 'latlong',
124
+ 'lat1' => $this->_origin->getLatitude(),
125
+ 'lon1' => $this->_origin->getLongitude(),
126
+ 'lat2' => $this->_destination->getLatitude(),
127
+ 'lon2' => $this->_destination->getLongitude(),
128
+ 'freight_type' => 'GeneralRoad',
129
+ 'seq' => 0)
130
+ )
131
+ );
132
+ }
133
+
134
+ /**
135
+ * Returns combined weight of items on order
136
+ *
137
+ * @return float
138
+ */
139
+ protected function _getCombinedProductWeight()
140
+ {
141
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
142
+
143
+ $weight = 0;
144
+ foreach ($this->_items as $item) {
145
+ if ($item->getParentItem() || $item->getIsVirtual()) {
146
+ continue;
147
+ }
148
+ if ($item->getProduct() && $item->getProduct()->isVirtual()) {
149
+ continue;
150
+ }
151
+ $weight += $item->getWeight() * $item->getQty();
152
+ }
153
+ return $weight;
154
+ }
155
+
156
+ /**
157
+ * Validate request before making the call to carbon service
158
+ *
159
+ * @return boolean
160
+ */
161
+ protected function _validate()
162
+ {
163
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
164
+
165
+ return
166
+ $this->_origin->validate() &&
167
+ $this->_destination->validate();
168
+ }
169
+ }
app/code/community/Gaia/Carbon/Model/Carbon.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * @category Gaia
5
+ * @package Gaia_Carbon
6
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
7
+ */
8
+ class Gaia_Carbon_Model_Carbon extends Varien_Object
9
+ {
10
+
11
+ /**
12
+ * Retrieve Carbon Amount
13
+ *
14
+ * @static
15
+ * @param Mage_Sales_Model_Quote_Address $address
16
+ * @param boolean $sale
17
+ * @return float
18
+ */
19
+ public static function getCarbon($address, $sale = false)
20
+ {
21
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
22
+
23
+ try {
24
+ $originLocation = Mage::getModel('carbon/location');
25
+ /* @var $originLocation Gaia_Carbon_Model_Location */
26
+ $originLocation
27
+ ->setStreet(Mage::helper('carbon')->getOriginStreet())
28
+ ->setCity(Mage::helper('carbon')->getOriginCity())
29
+ ->setState(Mage::helper('carbon')->getOriginState())
30
+ ->setPostcode(Mage::helper('carbon')->getOriginPostcode())
31
+ ->setCountry(Mage::helper('carbon')->getOriginCountryId());
32
+ $originLocation->geocode();
33
+
34
+ $destinationLocation = Mage::getModel('carbon/location');
35
+ $destinationLocation
36
+ ->setStreet($address->getStreetFull())
37
+ ->setCity($address->getCity())
38
+ ->setState($address->getRegion())
39
+ ->setPostcode($address->getPostcode())
40
+ ->setCountry($address->getCountryId());
41
+ $destinationLocation->geocode();
42
+
43
+ //get carbon charges for trip
44
+ $request = Mage::getModel('carbon/api_request');
45
+ /* @var $request Gaia_Carbon_Model_Api_Request */
46
+ $response = $request
47
+ ->setOrigin($originLocation)
48
+ ->setDestination($destinationLocation)
49
+ ->setItems($address->getAllVisibleItems())
50
+ ->setCustNotes($address->getName())
51
+ ->setCustEmail($address->getEmail())
52
+ ->setCurrency($address->getQuote()->getStoreCurrencyCode())
53
+ ->setIsSale($sale)
54
+ ->calculate();
55
+ if ($response && isset($response['co2counter']['offset_post_gst'])) {
56
+ return (float)$response['co2counter']['offset_post_gst'];
57
+ }
58
+
59
+ } catch (Exception $e) {
60
+ Mage::logException($e);
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Check if carbon can be applied
66
+ *
67
+ * @static
68
+ * @param Mage_Sales_Model_Quote_Address $address
69
+ * @return bool
70
+ */
71
+ public static function canApply($address)
72
+ {
73
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
74
+
75
+ if (!Mage::helper('carbon')->isEnabled()) {
76
+ return false; //module is disabled
77
+ }
78
+ switch (Mage::helper('carbon')->getApplyMode()) {
79
+ case Gaia_Carbon_Model_System_Config_Source_Mode::MANDATORY:
80
+ return true; // module enabled and carbon set to mandatory
81
+ case Gaia_Carbon_Model_System_Config_Source_Mode::OPTIONAL:
82
+ if (Mage::getSingleton('checkout/session')->getCustomerPaysForCarbon() == true) {
83
+ return true; // module enabled and customer choose to pay for carbon
84
+ }
85
+ break;
86
+ }
87
+ return false;
88
+ }
89
+
90
+ }
app/code/community/Gaia/Carbon/Model/Checkout/Type/Onepage.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gaia
5
+ * @package Gaia_Carbon
6
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
7
+ */
8
+ class Gaia_Carbon_Model_Checkout_Type_Onepage
9
+ extends Mage_Checkout_Model_Type_Onepage
10
+ {
11
+ /**
12
+ * Specify quote shipping method
13
+ *
14
+ * @param string $shippingMethod
15
+ * @return array
16
+ */
17
+ public function saveShippingMethod($shippingMethod)
18
+ {
19
+ $this->saveCarbonOffset();
20
+ return parent::saveShippingMethod($shippingMethod);
21
+ }
22
+
23
+ /**
24
+ * Save carbon offset customer selection
25
+ *
26
+ * @return \Gaia_Carbon_Model_Checkout_Type_Onepage
27
+ */
28
+ public function saveCarbonOffset()
29
+ {
30
+ $carbon = Mage::app()->getRequest()->getParam('add-carbon', null);
31
+ if ($carbon) {
32
+ $this->_checkoutSession->setCustomerPaysForCarbon(true);
33
+ } else {
34
+ $this->_checkoutSession->unsCustomerPaysForCarbon();
35
+ }
36
+ return $this;
37
+ }
38
+ }
app/code/community/Gaia/Carbon/Model/Geocoder.php ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @method Gaia_Carbon_Model_Geocoder setMethod()
5
+ * @method Gaia_Carbon_Model_Geocoder setAddress()
6
+ *
7
+ * @method string getMethod()
8
+ * @method string getAddress()
9
+ *
10
+ * @category Gaia
11
+ * @package Gaia_Carbon
12
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
13
+ */
14
+ class Gaia_Carbon_Model_Geocoder
15
+ extends Mage_Core_Model_Abstract
16
+ {
17
+ /**
18
+ * The geocoding service URL (google API)
19
+ */
20
+ const SERVICE_URL = "http://maps.googleapis.com/maps/api/geocode/";
21
+
22
+ /**
23
+ * The supported methods of communication with google API
24
+ */
25
+ const METHOD_JSON = 'json'; //preferred and used by default
26
+ const METHOD_XML = 'xml'; //not implemented (future use)
27
+
28
+ /**
29
+ * The HTTP Client
30
+ *
31
+ * @var Varien_Http_Client
32
+ */
33
+ protected $_client = null;
34
+
35
+ public function _construct() {
36
+ parent::_construct();
37
+ $this->_initialize();
38
+ }
39
+
40
+ /**
41
+ * Initialize Geocoder
42
+ *
43
+ * @return \Gaia_Carbon_Model_Geocoder
44
+ */
45
+ protected function _initialize()
46
+ {
47
+ return $this->_prepareClient()->setMethod(self::METHOD_JSON);
48
+ }
49
+
50
+ /**
51
+ * Initializes http client to communicate with Google Api
52
+ *
53
+ * @return \Gaia_Carbon_Model_Geocoder
54
+ */
55
+ protected function _prepareClient()
56
+ {
57
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
58
+
59
+ if(!$this->_client) {
60
+ $this->_client = new Varien_Http_Client();
61
+ $this->_client->setConfig(array('maxredirects' => 0, 'timeout' => 30));
62
+ }
63
+ return $this;
64
+ }
65
+
66
+ /**
67
+ * Returns latitude and longitude of geocoded address
68
+ *
69
+ * @return array or false on failure
70
+ */
71
+ public function geocode()
72
+ {
73
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
74
+
75
+ if (!$this->_validate()) {
76
+ return false;
77
+ }
78
+ try {
79
+ $this->_client
80
+ ->setUri(self::SERVICE_URL.$this->getMethod())
81
+ ->setParameterGet('address', $this->getAddress())
82
+ ->setParameterGet('sensor', 'false');
83
+ /**
84
+ * Getting response via raw body and decoding coz of a bug in Zend yielding
85
+ * exception when ->getBody() is used to decode and return response
86
+ */
87
+ $rawBody = $this->_client->request(Varien_Http_Client::GET)->getRawBody();
88
+ $response = Mage::helper('core')->jsonDecode($rawBody, Zend_Json::TYPE_ARRAY);
89
+
90
+ $lat = $lng = false;
91
+ if (isset($response['results'][0]['geometry']['location']['lat'])) {
92
+ $lat = (string)$response['results'][0]['geometry']['location']['lat'];
93
+ }
94
+ if (isset($response['results'][0]['geometry']['location']['lng'])) {
95
+ $lng = (string)$response['results'][0]['geometry']['location']['lng'];
96
+ }
97
+ return array('lat' => $lat, 'lng' => $lng);
98
+ } catch (Exception $e) {
99
+ Mage::logException($e);
100
+ return false;
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Validate request before making the call to geocoder service
106
+ *
107
+ * @return boolean
108
+ */
109
+ protected function _validate()
110
+ {
111
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
112
+
113
+ if (!$this->getAddress()) {
114
+ Mage::helper('carbon')->log(__METHOD__.': validation failed - missing address.');
115
+ return false;
116
+ }
117
+ return true;
118
+ }
119
+ }
app/code/community/Gaia/Carbon/Model/Location.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @method Gaia_Carbon_Model_Api_Location setStreet()
5
+ * @method Gaia_Carbon_Model_Api_Location setCity()
6
+ * @method Gaia_Carbon_Model_Api_Location setState()
7
+ * @method Gaia_Carbon_Model_Api_Location setPostcode()
8
+ * @method Gaia_Carbon_Model_Api_Location setCountry()
9
+ * @method Gaia_Carbon_Model_Api_Location setLatitude()
10
+ * @method Gaia_Carbon_Model_Api_Location setLongitude()
11
+ *
12
+ * @method string getStreet()
13
+ * @method string getCity()
14
+ * @method string getState()
15
+ * @method string getPostcode()
16
+ * @method string getCountry()
17
+ * @method string getLatitude()
18
+ * @method string getLongitude()
19
+ *
20
+ *
21
+ * @category Gaia
22
+ * @package Gaia_Carbon
23
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
24
+ */
25
+ class Gaia_Carbon_Model_Location
26
+ extends Varien_Object
27
+ {
28
+ /**
29
+ * Tries to geocode location address
30
+ *
31
+ * @throws Exception If geocoding fails
32
+ * @return \Gaia_Carbon_Model_Location
33
+ */
34
+ public function geocode()
35
+ {
36
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
37
+
38
+ $geo = Mage::getModel('carbon/geocoder');
39
+ /* @var $geo Gaia_Carbon_Model_Geocoder */
40
+ $address = $this->getAddressAsString();
41
+ $geoData = $geo->setAddress($address)->geocode();
42
+ if (!is_array($geoData)) {
43
+ Mage::throwException(__METHOD__.': failed to geocode location address ('.$address.')');
44
+ }
45
+ $this->setLatitude($geoData['lat'])->setLongitude($geoData['lng']);
46
+ return $this;
47
+ }
48
+
49
+ /**
50
+ * Gets location address as string
51
+ *
52
+ * @return string
53
+ */
54
+ public function getAddressAsString()
55
+ {
56
+ $data = array_filter(array(
57
+ $this->getStreet(),
58
+ $this->getCity(),
59
+ $this->getState(),
60
+ $this->getPostcode(),
61
+ $this->getCountry()
62
+ ));
63
+
64
+ return implode(', ', $data);
65
+ }
66
+
67
+ public function validate()
68
+ {
69
+ return strlen($this->getAddressAsString());
70
+ }
71
+ }
app/code/community/Gaia/Carbon/Model/Observer.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * @category Gaia
5
+ * @package Gaia_Carbon
6
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
7
+ */
8
+
9
+ class Gaia_Carbon_Model_Observer
10
+ {
11
+
12
+ /**
13
+ * Send sale request to carbon API when an order is placed
14
+ *
15
+ * @param Varien_Event_Observer $observer
16
+ * @return Gaia_Carbon_Model_Observer
17
+ */
18
+ public function orderPlaceAfter(Varien_Event_Observer $observer)
19
+ {
20
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
21
+
22
+ $order = $observer->getEvent()->getOrder();
23
+ /* @var $order Mage_Sales_Model_Order */
24
+ if ($order->getCarbonAmount()) {
25
+ $quote = Mage::getModel('sales/quote')->load($order->getQuoteId());
26
+ /* @var $quote Mage_Sales_Model_Quote */
27
+ Gaia_Carbon_Model_Carbon::getCarbon($quote->getShippingAddress(), true);
28
+ }
29
+ return $this;
30
+ }
31
+
32
+ /**
33
+ * Set carbon amount invoiced to the order
34
+ *
35
+ * @param Varien_Event_Observer $observer
36
+ * @return Gaia_Carbon_Model_Observer
37
+ */
38
+ public function invoiceSaveAfter(Varien_Event_Observer $observer)
39
+ {
40
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
41
+
42
+ $invoice = $observer->getEvent()->getInvoice();
43
+
44
+ if ($invoice->getBaseCarbonAmount()) {
45
+ $order = $invoice->getOrder();
46
+ $order->setCarbonAmountInvoiced($order->getCarbonAmountInvoiced() + $invoice->getCarbonAmount());
47
+ $order->setBaseCarbonAmountInvoiced($order->getBaseCarbonAmountInvoiced() + $invoice->getBaseCarbonAmount());
48
+ }
49
+
50
+ return $this;
51
+ }
52
+
53
+ /**
54
+ * Set carbon amount refunded to the order
55
+ *
56
+ * @param Varien_Event_Observer $observer
57
+ * @return Gaia_Carbon_Model_Observer
58
+ */
59
+ public function creditmemoSaveAfter(Varien_Event_Observer $observer)
60
+ {
61
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
62
+
63
+ $creditmemo = $observer->getEvent()->getCreditmemo();
64
+
65
+ if ($creditmemo->getCarbonAmount()) {
66
+ $order = $creditmemo->getOrder();
67
+ $order->setCarbonAmountRefunded($order->getCarbonAmountRefunded() + $creditmemo->getCarbonAmount());
68
+ $order->setBaseCarbonAmountRefunded($order->getBaseCarbonAmountRefunded() + $creditmemo->getBaseCarbonAmount());
69
+ }
70
+
71
+ return $this;
72
+ }
73
+
74
+ /**
75
+ * Update PayPal Total
76
+ *
77
+ * @param Varien_Event_Observer $observer
78
+ * @return Gaia_Carbon_Model_Observer
79
+ */
80
+ public function updatePaypalTotal(Varien_Event_Observer $observer)
81
+ {
82
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
83
+
84
+ $cart = $observer->getEvent()->getPaypalCart();
85
+ $cart->updateTotal(Mage_Paypal_Model_Cart::TOTAL_SUBTOTAL, $cart->getSalesEntity()->getCarbonAmount());
86
+ return $this;
87
+ }
88
+
89
+ }
app/code/community/Gaia/Carbon/Model/Sales/Order/Total/Creditmemo/Carbon.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * @category Gaia
6
+ * @package Gaia_Carbon
7
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
8
+ */
9
+ class Gaia_Carbon_Model_Sales_Order_Total_Creditmemo_Carbon
10
+ extends Mage_Sales_Model_Order_Creditmemo_Total_Abstract
11
+ {
12
+
13
+ /**
14
+ * Collect credit memo total
15
+ *
16
+ * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
17
+ * @return Gaia_Carbon_Model_Sales_Order_Total_Creditmemo_Carbon
18
+ */
19
+ public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
20
+ {
21
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
22
+
23
+ $order = $creditmemo->getOrder();
24
+
25
+ if ($order->getCarbonAmountInvoiced() > 0) {
26
+
27
+ $carbonAmountLeft = $order->getCarbonAmountInvoiced() - $order->getCarbonAmountRefunded();
28
+ $baseCarbonAmountLeft = $order->getBaseCarbonAmountInvoiced() - $order->getBaseCarbonAmountRefunded();
29
+
30
+ if ($baseCarbonAmountLeft > 0) {
31
+ $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $carbonAmountLeft);
32
+ $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseCarbonAmountLeft);
33
+ $creditmemo->setCarbonAmount($carbonAmountLeft);
34
+ $creditmemo->setBaseCarbonAmount($baseCarbonAmountLeft);
35
+ }
36
+ } else {
37
+
38
+ $carbonAmount = $order->getCarbonAmountInvoiced();
39
+ $basecarbonAmount = $order->getBaseCarbonAmountInvoiced();
40
+
41
+ $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $carbonAmount);
42
+ $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $basecarbonAmount);
43
+ $creditmemo->setCarbonAmount($carbonAmount);
44
+ $creditmemo->setBaseCarbonAmount($basecarbonAmount);
45
+ }
46
+
47
+ return $this;
48
+ }
49
+
50
+ }
app/code/community/Gaia/Carbon/Model/Sales/Order/Total/Invoice/Carbon.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * @category Gaia
5
+ * @package Gaia_Carbon
6
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
7
+ */
8
+ class Gaia_Carbon_Model_Sales_Order_Total_Invoice_Carbon
9
+ extends Mage_Sales_Model_Order_Invoice_Total_Abstract
10
+ {
11
+
12
+ /**
13
+ * Collect invoice total
14
+ *
15
+ * @param Mage_Sales_Model_Order_Invoice $invoice
16
+ * @return Gaia_Carbon_Model_Sales_Order_Total_Invoice_Carbon
17
+ */
18
+ public function collect(Mage_Sales_Model_Order_Invoice $invoice)
19
+ {
20
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
21
+
22
+ $order = $invoice->getOrder();
23
+
24
+ $carbonAmountLeft = $order->getCarbonAmount() - $order->getCarbonAmountInvoiced();
25
+ $baseCarbonAmountLeft = $order->getBaseCarbonAmount() - $order->getBaseCarbonAmountInvoiced();
26
+
27
+ if (abs($baseCarbonAmountLeft) < $invoice->getBaseGrandTotal()) {
28
+ $invoice->setGrandTotal($invoice->getGrandTotal() + $carbonAmountLeft);
29
+ $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseCarbonAmountLeft);
30
+ } else {
31
+ $carbonAmountLeft = $invoice->getGrandTotal() * -1;
32
+ $baseCarbonAmountLeft = $invoice->getBaseGrandTotal() * -1;
33
+
34
+ $invoice->setGrandTotal(0);
35
+ $invoice->setBaseGrandTotal(0);
36
+ }
37
+
38
+ $invoice->setCarbonAmount($carbonAmountLeft);
39
+ $invoice->setBaseCarbonAmount($baseCarbonAmountLeft);
40
+
41
+ return $this;
42
+ }
43
+
44
+ }
app/code/community/Gaia/Carbon/Model/Sales/Quote/Address/Total/Carbon.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * @category Gaia
5
+ * @package Gaia_Carbon
6
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
7
+ */
8
+ class Gaia_Carbon_Model_Sales_Quote_Address_Total_Carbon
9
+ extends Mage_Sales_Model_Quote_Address_Total_Abstract
10
+ {
11
+
12
+ protected $_code = 'carbon';
13
+
14
+ /**
15
+ * Collect carbon amount for address
16
+ *
17
+ * @param Mage_Sales_Model_Quote_Address $address
18
+ * @return Gaia_Carbon_Model_Sales_Quote_Address_Total_Carbon
19
+ */
20
+ public function collect(Mage_Sales_Model_Quote_Address $address)
21
+ {
22
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
23
+
24
+ parent::collect($address);
25
+
26
+ $this->_setAmount(0);
27
+ $this->_setBaseAmount(0);
28
+
29
+ $items = $this->_getAddressItems($address);
30
+ if (!count($items)) {
31
+ return $this;
32
+ }
33
+
34
+ $quote = $address->getQuote();
35
+
36
+ if (Gaia_Carbon_Model_Carbon::canApply($address)) {
37
+ $exist_amount = $quote->getCarbonAmount();
38
+ $carbon = Gaia_Carbon_Model_Carbon::getCarbon($address);
39
+ $balance = $carbon - $exist_amount;
40
+
41
+ $address->setCarbonAmount($balance);
42
+ $address->setBaseCarbonAmount($balance);
43
+
44
+ $quote->setCarbonAmount($balance);
45
+
46
+ $address->setGrandTotal($address->getGrandTotal() + $address->getCarbonAmount());
47
+ $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseCarbonAmount());
48
+ }
49
+
50
+ return $this;
51
+ }
52
+
53
+ /**
54
+ * Add carbon information to address
55
+ *
56
+ * @param Mage_Sales_Model_Quote_Address $address
57
+ * @return Gaia_Carbon_Model_Sales_Quote_Address_Total_Carbon
58
+ */
59
+ public function fetch(Mage_Sales_Model_Quote_Address $address)
60
+ {
61
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
62
+
63
+ if (Gaia_Carbon_Model_Carbon::canApply($address)) {
64
+ $amount = $address->getCarbonAmount();
65
+ if (!$amount) {
66
+ return $this;
67
+ }
68
+ $address->addTotal(array(
69
+ 'code' => $this->getCode(),
70
+ 'title' => $this->_getTitle(),
71
+ 'value' => $amount
72
+ ));
73
+ }
74
+ return $this;
75
+ }
76
+
77
+ protected function _getTitle()
78
+ {
79
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
80
+ return Mage::helper('carbon')->__('Carbon Offset');
81
+ }
82
+
83
+ }
app/code/community/Gaia/Carbon/Model/Signup.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @method Gaia_Carbon_Model_Signup setSignupData()
5
+ * @method array getSignupData()
6
+ *
7
+ * @category Gaia
8
+ * @package Gaia_Carbon
9
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
10
+ */
11
+ class Gaia_Carbon_Model_Signup
12
+ extends Varien_Object
13
+ {
14
+ /**
15
+ * Customer sign up action via the API
16
+ *
17
+ * @return array|boolean on failure
18
+ * @throws exception
19
+ */
20
+ public function signup()
21
+ {
22
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
23
+
24
+ if (!$this->_validate()) {
25
+ Mage::throwException('Not a valid request. Please check entered data and try again.');
26
+ }
27
+ $request = $this->_prepareRequest();
28
+ $api = Mage::getModel('carbon/api_client');
29
+ /* @var $api Gaia_Carbon_Model_Api_Client */
30
+ $api->signup($request);
31
+ }
32
+
33
+ /**
34
+ * Prepares API request array from available data
35
+ *
36
+ * @return array
37
+ */
38
+ protected function _prepareRequest()
39
+ {
40
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
41
+ $data = $this->getSignupData();
42
+ return array(
43
+ 'key' => Mage::helper('carbon')->getSigApiKey(),
44
+ 'hash' => Mage::helper('carbon')->getSigApiHash(),
45
+ 'name' => trim($data['name']),
46
+ 'email' => trim($data['email']),
47
+ 'output' => 'full',
48
+ 'title' => trim($data['title']),
49
+ 'phoneOffice' => trim($data['phone']),
50
+ 'mobile' => trim($data['mobile']),
51
+ 'companyName' => trim($data['company'])
52
+ );
53
+ }
54
+
55
+ /**
56
+ * Validate request before making the call to carbon signup service
57
+ *
58
+ * @return boolean
59
+ */
60
+ protected function _validate()
61
+ {
62
+ Mage::helper('carbon')->log('ENTERING: '.__METHOD__, true);
63
+ $data = $this->getSignupData();
64
+
65
+ return
66
+ !empty($data) && is_array($data) &&
67
+ array_key_exists('name', $data) && strlen(trim($data['name'])) &&
68
+ array_key_exists('email', $data) && strlen(trim($data['email']));
69
+ }
70
+ }
app/code/community/Gaia/Carbon/Model/System/Config/Source/Abstract.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Description of class...
4
+ *
5
+ * @category Gaia
6
+ * @package Gaia_Carbon
7
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
8
+ */
9
+ abstract class Gaia_Carbon_Model_System_Config_Source_Abstract
10
+ {
11
+
12
+ /**
13
+ * The array of options in the configuration item.
14
+ *
15
+ * This array's keys are the values used in the database etc. and the
16
+ * values of this array are used as labels on the frontend.
17
+ *
18
+ * @var array
19
+ */
20
+ protected $_options;
21
+
22
+ public function __construct()
23
+ {
24
+ $this->_setupOptions();
25
+ }
26
+
27
+ /**
28
+ * Sets up the $_options array with the correct values.
29
+ *
30
+ * This function is called in the constructor.
31
+ *
32
+ * @return Gaia_Carbon_Model_System_Config_Source_Abstract
33
+ */
34
+ protected abstract function _setupOptions();
35
+
36
+ /**
37
+ * Gets all the options in the key => value type array.
38
+ *
39
+ * @return array
40
+ */
41
+ public function getOptions($please_select = false)
42
+ {
43
+ $options = $this->_options;
44
+ if ($please_select) {
45
+ $options = array(null => '--Please Select--') + $options;
46
+ }
47
+ return $options;
48
+ }
49
+
50
+ /**
51
+ * Converts the options into a format suitable for use in the admin area.
52
+ *
53
+ * @return array
54
+ */
55
+ public function toOptionArray()
56
+ {
57
+ return $this->_toOptionArray($this->_options);
58
+ }
59
+
60
+ protected function _toOptionArray($input)
61
+ {
62
+ $array = array();
63
+
64
+ foreach ($input as $key => $value) {
65
+ $array[] = array(
66
+ 'value' => $key,
67
+ 'label' => $value,
68
+ );
69
+ }
70
+
71
+ return $array;
72
+ }
73
+
74
+ /**
75
+ * Looks up an option by key and gets the label.
76
+ *
77
+ * @param mixed $value
78
+ * @return mixed
79
+ */
80
+ public function getOptionLabel($value)
81
+ {
82
+ if (array_key_exists($value, $this->_options)) {
83
+ return $this->_options[$value];
84
+ }
85
+ return null;
86
+ }
87
+
88
+ }
app/code/community/Gaia/Carbon/Model/System/Config/Source/Environment.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Description of class...
4
+ *
5
+ * @category Gaia
6
+ * @package Gaia_Carbon
7
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
8
+ */
9
+ class Gaia_Carbon_Model_System_Config_Source_Environment
10
+ extends Gaia_Carbon_Model_System_Config_Source_Abstract
11
+ {
12
+
13
+ const SANDBOX = '0';
14
+ const PRODUCTION = '5';
15
+
16
+ protected function _setupOptions()
17
+ {
18
+ $this->_options = array(
19
+ self::SANDBOX => Mage::helper('carbon')->__('Sandbox'),
20
+ self::PRODUCTION => Mage::helper('carbon')->__('Production'),
21
+ );
22
+ }
23
+ }
app/code/community/Gaia/Carbon/Model/System/Config/Source/Mode.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Description of class...
4
+ *
5
+ * @category Gaia
6
+ * @package Gaia_Carbon
7
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
8
+ */
9
+ class Gaia_Carbon_Model_System_Config_Source_Mode
10
+ extends Gaia_Carbon_Model_System_Config_Source_Abstract
11
+ {
12
+
13
+ const OPTIONAL = '0';
14
+ const MANDATORY = '5';
15
+
16
+ protected function _setupOptions()
17
+ {
18
+ $this->_options = array(
19
+ self::OPTIONAL => Mage::helper('carbon')->__('Optional'),
20
+ self::MANDATORY => Mage::helper('carbon')->__('Mandatory'),
21
+ );
22
+ }
23
+ }
app/code/community/Gaia/Carbon/Model/System/Config/Source/Unit/Weight.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * @category Gaia
5
+ * @package Gaia_Carbon
6
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
7
+ */
8
+ class Gaia_Carbon_Model_System_Config_Source_Unit_Weight
9
+ extends Gaia_Carbon_Model_System_Config_Source_Abstract
10
+ {
11
+ const GRAMS = 'Grams';
12
+ const KILOGRAMS = 'Kilograms';
13
+ const OUNCES = 'Ounces';
14
+ const POUNDS = 'Pounds';
15
+
16
+ protected function _setupOptions()
17
+ {
18
+ $this->_options = array(
19
+ self::GRAMS => 'Grams',
20
+ self::KILOGRAMS => 'Kilograms',
21
+ self::OUNCES => 'Ounces',
22
+ self::POUNDS => 'Pounds',
23
+ );
24
+ }
25
+ }
app/code/community/Gaia/Carbon/controllers/Adminhtml/DebugController.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gaia
5
+ * @package Gaia_Carbon
6
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
7
+ */
8
+ class Gaia_Carbon_Adminhtml_DebugController
9
+ extends Mage_Adminhtml_Controller_Action
10
+ {
11
+ public function showlogAction()
12
+ {
13
+ try {
14
+ $logDir = Mage::getBaseDir('var') . DS . 'log';
15
+ $logFile = $logDir . DS . Gaia_Carbon_Helper_Data::LOG_FILENAME;
16
+
17
+ if (!is_dir($logDir)) {
18
+ echo 'Log folder does not exist.';
19
+ return;
20
+ }
21
+ if (!file_exists($logFile)) {
22
+ echo 'Log file does not exist.';
23
+ return;
24
+ }
25
+ $contents = file_get_contents($logFile);
26
+ echo nl2br($contents);
27
+ } catch (Exception $ex) {
28
+ Mage::logException($ex);
29
+ echo 'Error occured when fetching Gaia Carbon Offset log file. See Magento exception log for more details.';
30
+ }
31
+ }
32
+
33
+ public function clearlogAction()
34
+ {
35
+ $logFile = Mage::getBaseDir('var') . DS . 'log' . DS . Gaia_Carbon_Helper_Data::LOG_FILENAME;
36
+ if (file_exists($logFile)) {
37
+ try {
38
+ if(unlink($logFile)) {
39
+ $this->_getSession()->addSuccess($this->__('Log file deleted.'));
40
+ } else {
41
+ $this->_getSession()->addError($this->__('Unable to delete log file.'));
42
+ }
43
+ } catch (Exception $ex) {
44
+ Mage::logException($ex);
45
+ $this->_getSession()->addError($this->__('Error occured when trying to delete Gaia Carbon Offset log file. See Magento exception log for more details.'));
46
+ }
47
+ } else {
48
+ $this->_getSession()->addNotice($this->__('Gaia Carbon Offset log file does not exist.'));
49
+ }
50
+ $this->_redirect('adminhtml/system_config/edit/section/carbon');
51
+ }
52
+ }
app/code/community/Gaia/Carbon/controllers/Adminhtml/SignupController.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gaia
5
+ * @package Gaia_Carbon
6
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
7
+ */
8
+ class Gaia_Carbon_Adminhtml_SignupController
9
+ extends Mage_Adminhtml_Controller_Action
10
+ {
11
+ public function indexAction()
12
+ {
13
+ $this->loadLayout()->renderLayout();
14
+ }
15
+
16
+ public function signupAction()
17
+ {
18
+ if ($data = $this->getRequest()->getPost()) {
19
+ Mage::register('carbon_signup_form_data', $data, true);
20
+ try {
21
+ $signup = Mage::getModel('carbon/signup');
22
+ $signup->setSignupData($data)->signup();
23
+ $this->_getSession()->addSuccess($this->__('You have successfully signed up. Please check your nominated email address for further details.'));
24
+ } catch (Exception $e) {
25
+ Mage::helper('carbon')->log($e->getMessage());
26
+ $this->_getSession()->addError($this->__($e->getMessage()));
27
+ $this->_redirect('*/*/');
28
+ return;
29
+ }
30
+ } else {
31
+ $this->_getSession()->addError($this->__('Please fill in all required fields.'));
32
+ $this->_redirect('*/*/');
33
+ return;
34
+ }
35
+ $this->_redirectUrl(Mage::helper('adminhtml')->getUrl('adminhtml/system_config/edit/section/carbon'));
36
+ }
37
+ }
app/code/community/Gaia/Carbon/controllers/AjaxController.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Description of class...
4
+ *
5
+ * @category Gaia
6
+ * @package Gaia_Carbon
7
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
8
+ */
9
+ class Gaia_Carbon_AjaxController
10
+ extends Mage_Core_Controller_Front_Action
11
+ {
12
+ public function addcarbonAction()
13
+ {
14
+ try {
15
+ $status = (boolean)$this->getRequest()->getPost('status');
16
+ Mage::getSingleton('checkout/session')->setCustomerPaysForCarbon($status);
17
+ Mage::getSingleton('checkout/session')->getQuote()
18
+ ->setTotalsCollectedFlag(false)
19
+ ->collectTotals();
20
+
21
+ $block = Mage::app()->getLayout()
22
+ ->createBlock('checkout/cart_totals', 'checkout.cart.totals')
23
+ ->setTemplate('checkout/cart/totals.phtml');
24
+
25
+ echo $block->toHtml();
26
+ } catch (Exception $e) {
27
+
28
+ }
29
+ }
30
+ }
app/code/community/Gaia/Carbon/etc/adminhtml.xml ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Description of class...
5
+ *
6
+ * @category Gaia
7
+ * @package Gaia_Carbon
8
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
9
+ */
10
+ -->
11
+ <config>
12
+ <acl>
13
+ <resources>
14
+ <all>
15
+ <title>Allow Everything</title>
16
+ </all>
17
+ <admin>
18
+ <children>
19
+ <system>
20
+ <children>
21
+ <config>
22
+ <children>
23
+ <carbon translate="title" module="carbon">
24
+ <title>Carbon Offset</title>
25
+ </carbon>
26
+ </children>
27
+ </config>
28
+ </children>
29
+ </system>
30
+ </children>
31
+ </admin>
32
+ </resources>
33
+ </acl>
34
+ </config>
app/code/community/Gaia/Carbon/etc/config.xml ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /**
4
+ * @category Gaia
5
+ * @package Gaia_Carbon
6
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
7
+ */
8
+ -->
9
+ <config>
10
+ <modules>
11
+ <Gaia_Carbon>
12
+ <version>1.0.1</version>
13
+ </Gaia_Carbon>
14
+ </modules>
15
+ <global>
16
+ <models>
17
+ <carbon>
18
+ <class>Gaia_Carbon_Model</class>
19
+ <resourceModel>carbon_mysql4</resourceModel>
20
+ </carbon>
21
+ <checkout>
22
+ <rewrite>
23
+ <type_onepage>Gaia_Carbon_Model_Checkout_Type_Onepage</type_onepage>
24
+ </rewrite>
25
+ </checkout>
26
+ </models>
27
+ <resources>
28
+ <carbon_setup>
29
+ <setup>
30
+ <module>Gaia_Carbon</module>
31
+ <class>Mage_Eav_Model_Entity_Setup</class>
32
+ </setup>
33
+ <connection>
34
+ <use>core_setup</use>
35
+ </connection>
36
+ </carbon_setup>
37
+ <carbon_mysql4>
38
+ <class>Gaia_Carbon_Model_Mysql4</class>
39
+ </carbon_mysql4>
40
+ <carbon_write>
41
+ <connection>
42
+ <use>core_write</use>
43
+ </connection>
44
+ </carbon_write>
45
+ <carbon_read>
46
+ <connection>
47
+ <use>core_read</use>
48
+ </connection>
49
+ </carbon_read>
50
+ </resources>
51
+ <blocks>
52
+ <carbon>
53
+ <class>Gaia_Carbon_Block</class>
54
+ </carbon>
55
+ </blocks>
56
+ <helpers>
57
+ <carbon>
58
+ <class>Gaia_Carbon_Helper</class>
59
+ </carbon>
60
+ </helpers>
61
+ <sales>
62
+ <quote>
63
+ <totals>
64
+ <carbon>
65
+ <class>carbon/sales_quote_address_total_carbon</class>
66
+ <renderer>carbon/checkout_totals_carbon</renderer>
67
+ <admin_renderer>carbon/adminhtml_sales_order_create_totals_carbon</admin_renderer>
68
+ </carbon>
69
+ </totals>
70
+ </quote>
71
+ <order_invoice>
72
+ <totals>
73
+ <carbon>
74
+ <class>carbon/sales_order_total_invoice_carbon</class>
75
+ </carbon>
76
+ </totals>
77
+ </order_invoice>
78
+ <order_creditmemo>
79
+ <totals>
80
+ <carbon>
81
+ <class>carbon/sales_order_total_creditmemo_carbon</class>
82
+ </carbon>
83
+ </totals>
84
+ </order_creditmemo>
85
+ </sales>
86
+ <events>
87
+ <paypal_prepare_line_items>
88
+ <observers>
89
+ <gaia_carbon_paypal_prepare_line_items>
90
+ <class>carbon/observer</class>
91
+ <method>updatePaypalTotal</method>
92
+ </gaia_carbon_paypal_prepare_line_items>
93
+ </observers>
94
+ </paypal_prepare_line_items>
95
+ <sales_order_place_after>
96
+ <observers>
97
+ <gaia_carbon_sales_order_place_after>
98
+ <class>carbon/observer</class>
99
+ <method>orderPlaceAfter</method>
100
+ </gaia_carbon_sales_order_place_after>
101
+ </observers>
102
+ </sales_order_place_after>
103
+ <sales_order_invoice_save_after>
104
+ <observers>
105
+ <gaia_carbon_sales_order_invoice_save_after>
106
+ <class>carbon/observer</class>
107
+ <method>invoiceSaveAfter</method>
108
+ </gaia_carbon_sales_order_invoice_save_after>
109
+ </observers>
110
+ </sales_order_invoice_save_after>
111
+ <sales_order_creditmemo_save_after>
112
+ <observers>
113
+ <gaia_carbon_sales_order_creditmemo_save_after>
114
+ <class>carbon/observer</class>
115
+ <method>creditmemoSaveAfter</method>
116
+ </gaia_carbon_sales_order_creditmemo_save_after>
117
+ </observers>
118
+ </sales_order_creditmemo_save_after>
119
+ </events>
120
+ <fieldsets>
121
+ <sales_convert_quote_address>
122
+ <carbon_amount>
123
+ <to_order>*</to_order>
124
+ </carbon_amount>
125
+ <base_carbon_amount>
126
+ <to_order>*</to_order>
127
+ </base_carbon_amount>
128
+ </sales_convert_quote_address>
129
+ </fieldsets>
130
+ <pdf>
131
+ <totals>
132
+ <carbon translate="title">
133
+ <title>Carbon Offset</title>
134
+ <source_field>carbon_amount</source_field>
135
+ <font_size>7</font_size>
136
+ <display_zero>0</display_zero>
137
+ <sort_order>650</sort_order>
138
+ <amount_prefix></amount_prefix>
139
+ </carbon>
140
+ </totals>
141
+ </pdf>
142
+ </global>
143
+ <frontend>
144
+ <layout>
145
+ <updates>
146
+ <carbon>
147
+ <file>gaia/carbon.xml</file>
148
+ </carbon>
149
+ </updates>
150
+ </layout>
151
+ <routers>
152
+ <carbon>
153
+ <use>standard</use>
154
+ <args>
155
+ <module>Gaia_Carbon</module>
156
+ <frontName>carbon</frontName>
157
+ </args>
158
+ </carbon>
159
+ </routers>
160
+ </frontend>
161
+ <admin>
162
+ <routers>
163
+ <carbon>
164
+ <use>admin</use>
165
+ <args>
166
+ <module>Gaia_Carbon</module>
167
+ <frontName>acarbon</frontName>
168
+ </args>
169
+ </carbon>
170
+ </routers>
171
+ </admin>
172
+ <adminhtml>
173
+ <layout>
174
+ <updates>
175
+ <carbon>
176
+ <file>gaia/carbon.xml</file>
177
+ </carbon>
178
+ </updates>
179
+ </layout>
180
+ </adminhtml>
181
+ <default>
182
+ <sales>
183
+ <totals_sort>
184
+ <carbon>15</carbon>
185
+ </totals_sort>
186
+ </sales>
187
+ <carbon>
188
+ <general>
189
+ <mode><![CDATA[0]]></mode>
190
+ <api_key><![CDATA[]]></api_key>
191
+ <api_hash><![CDATA[]]></api_hash>
192
+ <api_sigkey><![CDATA[2]]></api_sigkey>
193
+ <api_sighash><![CDATA[register_only_$$qw.123]]></api_sighash>
194
+ </general>
195
+ </carbon>
196
+ </default>
197
+ </config>
app/code/community/Gaia/Carbon/etc/system.xml ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Description of class...
5
+ *
6
+ * @category Gaia
7
+ * @package Gaia_Carbon
8
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
9
+ */
10
+ -->
11
+ <config>
12
+ <sections>
13
+ <carbon translate="label" module="carbon">
14
+ <label>Carbon Offset</label>
15
+ <tab>sales</tab>
16
+ <frontend_type>text</frontend_type>
17
+ <sort_order>365</sort_order>
18
+ <show_in_default>1</show_in_default>
19
+ <show_in_website>1</show_in_website>
20
+ <show_in_store>1</show_in_store>
21
+ <groups>
22
+ <general>
23
+ <label>General Settings</label>
24
+ <frontend_type>text</frontend_type>
25
+ <sort_order>10</sort_order>
26
+ <show_in_default>1</show_in_default>
27
+ <show_in_website>1</show_in_website>
28
+ <show_in_store>1</show_in_store>
29
+ <fields>
30
+ <signup translate="label">
31
+ <frontend_type>button</frontend_type>
32
+ <frontend_model>carbon/adminhtml_system_config_form_button_signup</frontend_model>
33
+ <sort_order>5</sort_order>
34
+ <show_in_default>1</show_in_default>
35
+ <show_in_website>0</show_in_website>
36
+ <show_in_store>0</show_in_store>
37
+ </signup>
38
+ <active translate="label">
39
+ <label>Enabled</label>
40
+ <frontend_type>select</frontend_type>
41
+ <source_model>adminhtml/system_config_source_yesno</source_model>
42
+ <sort_order>10</sort_order>
43
+ <show_in_default>1</show_in_default>
44
+ <show_in_website>1</show_in_website>
45
+ <show_in_store>1</show_in_store>
46
+ </active>
47
+ <environment>
48
+ <label>Environment</label>
49
+ <frontend_type>select</frontend_type>
50
+ <source_model>carbon/system_config_source_environment</source_model>
51
+ <sort_order>15</sort_order>
52
+ <show_in_default>1</show_in_default>
53
+ <show_in_website>1</show_in_website>
54
+ <show_in_store>1</show_in_store>
55
+ <comment>
56
+ <![CDATA[
57
+ <strong>Sandbox</strong> The offset pricing is random and therefore false. It cannot be used in a live environment.<br/>
58
+ <strong>Production</strong> The true pricing, guidance and assistance are available by registering for the API key above.
59
+ ]]>
60
+ </comment>
61
+ </environment>
62
+ <api_key>
63
+ <label>API Key</label>
64
+ <frontend_type>text</frontend_type>
65
+ <sort_order>20</sort_order>
66
+ <show_in_default>1</show_in_default>
67
+ <show_in_website>1</show_in_website>
68
+ <show_in_store>1</show_in_store>
69
+ <depends>
70
+ <environment><![CDATA[5]]></environment>
71
+ </depends>
72
+ </api_key>
73
+ <api_hash>
74
+ <label>API Hash</label>
75
+ <frontend_type>text</frontend_type>
76
+ <sort_order>30</sort_order>
77
+ <show_in_default>1</show_in_default>
78
+ <show_in_website>1</show_in_website>
79
+ <show_in_store>1</show_in_store>
80
+ <depends>
81
+ <environment><![CDATA[5]]></environment>
82
+ </depends>
83
+ </api_hash>
84
+ <mode>
85
+ <label>Mode</label>
86
+ <frontend_type>select</frontend_type>
87
+ <source_model>carbon/system_config_source_mode</source_model>
88
+ <sort_order>40</sort_order>
89
+ <show_in_default>1</show_in_default>
90
+ <show_in_website>1</show_in_website>
91
+ <show_in_store>1</show_in_store>
92
+ <comment>
93
+ <![CDATA[
94
+ <strong>Optional</strong> Customer can choose to pay carbon offset charges.<br/>
95
+ <strong>Mandatory</strong> Carbon offset charges are automatically added to every order.
96
+ ]]>
97
+ </comment>
98
+ </mode>
99
+ <weight_unit>
100
+ <label>Weight Unit</label>
101
+ <frontend_type>select</frontend_type>
102
+ <source_model>carbon/system_config_source_unit_weight</source_model>
103
+ <sort_order>50</sort_order>
104
+ <show_in_default>1</show_in_default>
105
+ <show_in_website>1</show_in_website>
106
+ <show_in_store>1</show_in_store>
107
+ <comment>
108
+ <![CDATA[
109
+ Weight unit as used in the system for all magento products.
110
+ ]]>
111
+ </comment>
112
+ </weight_unit>
113
+ </fields>
114
+ </general>
115
+ <log>
116
+ <label>Debug</label>
117
+ <frontend_type>text</frontend_type>
118
+ <sort_order>20</sort_order>
119
+ <show_in_default>1</show_in_default>
120
+ <show_in_website>1</show_in_website>
121
+ <show_in_store>1</show_in_store>
122
+ <fields>
123
+ <active translate="label">
124
+ <label>Enabled</label>
125
+ <frontend_type>select</frontend_type>
126
+ <source_model>adminhtml/system_config_source_yesno</source_model>
127
+ <sort_order>10</sort_order>
128
+ <show_in_default>1</show_in_default>
129
+ <show_in_website>1</show_in_website>
130
+ <show_in_store>1</show_in_store>
131
+ </active>
132
+ <verbose translate="label">
133
+ <label>Verbose</label>
134
+ <frontend_type>select</frontend_type>
135
+ <source_model>adminhtml/system_config_source_yesno</source_model>
136
+ <sort_order>20</sort_order>
137
+ <show_in_default>1</show_in_default>
138
+ <show_in_website>1</show_in_website>
139
+ <show_in_store>1</show_in_store>
140
+ </verbose>
141
+ <show_log translate="label">
142
+ <frontend_type>button</frontend_type>
143
+ <frontend_model>carbon/adminhtml_system_config_form_button_showlog</frontend_model>
144
+ <sort_order>30</sort_order>
145
+ <show_in_default>1</show_in_default>
146
+ <show_in_website>0</show_in_website>
147
+ <show_in_store>0</show_in_store>
148
+ </show_log>
149
+ <clear_log translate="label">
150
+ <frontend_type>button</frontend_type>
151
+ <frontend_model>carbon/adminhtml_system_config_form_button_clearlog</frontend_model>
152
+ <sort_order>40</sort_order>
153
+ <show_in_default>1</show_in_default>
154
+ <show_in_website>0</show_in_website>
155
+ <show_in_store>0</show_in_store>
156
+ </clear_log>
157
+ </fields>
158
+ </log>
159
+ </groups>
160
+ </carbon>
161
+ </sections>
162
+ </config>
app/code/community/Gaia/Carbon/sql/carbon_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ set_time_limit(0);
4
+
5
+ /* @var $this Mage_Eav_Model_Entity_Setup */
6
+ /* @var $installer Mage_Eav_Model_Entity_Setup */
7
+
8
+ $installer = $this;
9
+ $installer->startSetup();
10
+
11
+ $installer->run("
12
+ ALTER TABLE {$this->getTable('sales/quote_address')} ADD `carbon_amount` DECIMAL( 10, 2 ) NOT NULL;
13
+ ALTER TABLE {$this->getTable('sales/quote_address')} ADD `base_carbon_amount` DECIMAL( 10, 2 ) NOT NULL;
14
+ ALTER TABLE {$this->getTable('sales/order')} ADD `carbon_amount` DECIMAL( 10, 2 ) NOT NULL;
15
+ ALTER TABLE {$this->getTable('sales/order')} ADD `base_carbon_amount` DECIMAL( 10, 2 ) NOT NULL;
16
+ ALTER TABLE {$this->getTable('sales/order')} ADD `carbon_amount_invoiced` DECIMAL( 10, 2 ) NOT NULL;
17
+ ALTER TABLE {$this->getTable('sales/order')} ADD `base_carbon_amount_invoiced` DECIMAL( 10, 2 ) NOT NULL;
18
+ ALTER TABLE {$this->getTable('sales/order')} ADD `carbon_amount_refunded` DECIMAL( 10, 2 ) NOT NULL;
19
+ ALTER TABLE {$this->getTable('sales/order')} ADD `base_carbon_amount_refunded` DECIMAL( 10, 2 ) NOT NULL;
20
+ ALTER TABLE {$this->getTable('sales/invoice')} ADD `carbon_amount` DECIMAL( 10, 2 ) NOT NULL;
21
+ ALTER TABLE {$this->getTable('sales/invoice')} ADD `base_carbon_amount` DECIMAL( 10, 2 ) NOT NULL;
22
+ ALTER TABLE {$this->getTable('sales/creditmemo')} ADD `carbon_amount` DECIMAL( 10, 2 ) NOT NULL;
23
+ ALTER TABLE {$this->getTable('sales/creditmemo')} ADD `base_carbon_amount` DECIMAL( 10, 2 ) NOT NULL;
24
+ ");
25
+
26
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/gaia/carbon.xml ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Description of class...
5
+ *
6
+ * @category Gaia
7
+ * @package Gaia_Carbon
8
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
9
+ */
10
+ -->
11
+ <layout version="0.1.0">
12
+ <adminhtml_sales_order_view>
13
+ <reference name="order_totals">
14
+ <block type="adminhtml/sales_order_totals_item" name="carbon" template="gaia/carbon/sales/order/total.phtml" />
15
+ <block type="adminhtml/sales_order_totals_item" name="carbon.refunded" template="gaia/carbon/sales/order/refunded.phtml">
16
+ <action method="setDisplayArea"><area>footer</area></action>
17
+ <action method="setAfterCondition"><condition>last</condition></action>
18
+ </block>
19
+ </reference>
20
+ </adminhtml_sales_order_view>
21
+
22
+ <adminhtml_sales_order_invoice_new>
23
+ <reference name="invoice_totals">
24
+ <block type="adminhtml/sales_order_totals_item" name="carbon" template="gaia/carbon/sales/order/total.phtml" />
25
+ </reference>
26
+ </adminhtml_sales_order_invoice_new>
27
+
28
+ <adminhtml_sales_order_invoice_updateqty>
29
+ <reference name="invoice_totals">
30
+ <block type="adminhtml/sales_order_totals_item" name="carbon" template="gaia/carbon/sales/order/total.phtml" />
31
+ </reference>
32
+ </adminhtml_sales_order_invoice_updateqty>
33
+
34
+ <adminhtml_sales_order_invoice_view>
35
+ <reference name="invoice_totals">
36
+ <block type="adminhtml/sales_order_totals_item" name="carbon" template="gaia/carbon/sales/order/total.phtml" />
37
+ </reference>
38
+ </adminhtml_sales_order_invoice_view>
39
+
40
+ <adminhtml_sales_order_creditmemo_new>
41
+ <reference name="creditmemo_totals">
42
+ <block type="adminhtml/sales_order_totals_item" name="carbon" template="gaia/carbon/sales/order/total.phtml" />
43
+ </reference>
44
+ </adminhtml_sales_order_creditmemo_new>
45
+
46
+ <adminhtml_sales_order_creditmemo_updateqty>
47
+ <reference name="creditmemo_totals">
48
+ <block type="adminhtml/sales_order_totals_item" name="carbon" template="gaia/carbon/sales/order/total.phtml" />
49
+ </reference>
50
+ </adminhtml_sales_order_creditmemo_updateqty>
51
+
52
+ <adminhtml_sales_order_creditmemo_view>
53
+ <reference name="creditmemo_totals">
54
+ <block type="adminhtml/sales_order_totals_item" name="carbon.refunded" template="gaia/carbon/sales/order/refunded.phtml">
55
+ <action method="setDisplayArea"><area>footer</area></action>
56
+ </block>
57
+ </reference>
58
+ </adminhtml_sales_order_creditmemo_view>
59
+
60
+ <carbon_adminhtml_signup_index>
61
+ <reference name="content">
62
+ <block type="carbon/adminhtml_signup_edit" name="carbon_signup" />
63
+ </reference>
64
+ </carbon_adminhtml_signup_index>
65
+ </layout>
app/design/adminhtml/default/default/template/gaia/carbon/sales/order/refunded.phtml ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Description of class...
4
+ *
5
+ * @category Gaia
6
+ * @package Gaia_Carbon
7
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
8
+ */
9
+ ?>
10
+
11
+ <?php if($this->getSource() instanceof Mage_Sales_Model_Order): ?>
12
+
13
+ <?php if ((float)$this->getSource()->getCarbonAmountRefunded() > 0): ?>
14
+ <tr>
15
+ <td class="label"><strong><?php echo Mage::helper('carbon')->__('Carbon offset refunded to customer') ?></strong></td>
16
+ <td><strong><?php echo $this->getSource()->getCarbonAmountRefunded(); ?></strong></td>
17
+ </tr>
18
+ <?php endif; ?>
19
+
20
+ <?php else: ?>
21
+
22
+ <?php if ((float)$this->getSource()->getCarbonAmount()): ?>
23
+ <tr>
24
+ <td class="label"><strong><?php echo Mage::helper('carbon')->__('Carbon Offset Refunded') ?></strong></td>
25
+ <td><strong><?php echo $this->getSource()->getCarbonAmount(); ?></strong></td>
26
+ </tr>
27
+ <?php endif; ?>
28
+
29
+ <?php endif; ?>
30
+
app/design/adminhtml/default/default/template/gaia/carbon/sales/order/total.phtml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Description of class...
4
+ *
5
+ * @category Gaia
6
+ * @package Gaia_Carbon
7
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
8
+ */
9
+ ?>
10
+ <?php $this->setPriceDataObject($this->getSource()) ?>
11
+
12
+ <?php if ((float) $this->getSource()->getCarbonAmount()): ?>
13
+ <tr>
14
+ <td class="label"><?php echo Mage::helper('carbon')->__('Carbon') ?></td>
15
+ <td>
16
+ <?php echo $this->displayPrices($this->getSource()->getBaseCarbonAmount(), $this->getSource()->getCarbonAmount()); ?>
17
+ </td>
18
+ </tr>
19
+ <?php endif; ?>
app/design/adminhtml/default/default/template/gaia/carbon/system/config/button.phtml ADDED
@@ -0,0 +1 @@
 
1
+ <?php echo $this->getButtonHtml() ?>
app/design/frontend/base/default/layout/gaia/carbon.xml ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Description of class...
5
+ *
6
+ * @category Gaia
7
+ * @package Gaia_Carbon
8
+ * @author CZ Digital Team <martin.novak@czdigital.com.au>
9
+ */
10
+ -->
11
+ <layout version="0.1.0">
12
+ <checkout_cart_index>
13
+ <reference name="head">
14
+ <action method="addCss"><stylesheet>gaia/carbon/css/styles.css</stylesheet></action>
15
+ </reference>
16
+ <reference name="checkout.cart.totals">
17
+ <block type="carbon/checkout_carbon" name="cart.carbon.offset" template="gaia/checkout/cart/totals/carbon.phtml"/>
18
+ </reference>
19
+ </checkout_cart_index>
20
+ <checkout_onepage_index>
21
+ <reference name="head">
22
+ <action method="addCss"><stylesheet>gaia/carbon/css/styles.css</stylesheet></action>
23
+ </reference>
24
+ <reference name="checkout.onepage.shipping_method">
25
+ <block type="carbon/checkout_carbon" name="checkout.carbon.offset" template="gaia/checkout/onepage/carbon.phtml"/>
26
+ </reference>
27
+ </checkout_onepage_index>
28
+ <checkout_onepage_shippingmethod>
29
+ <reference name="root">
30
+ <block type="carbon/checkout_carbon" name="checkout.carbon.offset" template="gaia/checkout/onepage/carbon.phtml"/>
31
+ </reference>
32
+ </checkout_onepage_shippingmethod>
33
+
34
+ <sales_order_view>
35
+ <reference name="order_totals">
36
+ <block type="carbon/sales_order_carbon" name="carbon" />
37
+ </reference>
38
+ </sales_order_view>
39
+ <sales_order_print>
40
+ <reference name="order_totals">
41
+ <block type="carbon/sales_order_carbon" name="carbon" />
42
+ </reference>
43
+ </sales_order_print>
44
+ <sales_email_order_items>
45
+ <reference name="order_totals">
46
+ <block type="carbon/sales_order_carbon" name="carbon" />
47
+ </reference>
48
+ </sales_email_order_items>
49
+
50
+ <sales_order_invoice>
51
+ <reference name="invoice_totals">
52
+ <block type="carbon/sales_order_carbon" name="carbon" />
53
+ </reference>
54
+ </sales_order_invoice>
55
+ <sales_order_printinvoice>
56
+ <reference name="invoice_totals">
57
+ <block type="carbon/sales_order_carbon" name="carbon" />
58
+ </reference>
59
+ </sales_order_printinvoice>
60
+ <sales_email_order_invoice_items>
61
+ <reference name="invoice_totals">
62
+ <block type="carbon/sales_order_carbon" name="carbon" />
63
+ </reference>
64
+ </sales_email_order_invoice_items>
65
+
66
+ <sales_order_creditmemo>
67
+ <reference name="creditmemo_totals">
68
+ <block type="carbon/sales_order_carbon" name="carbon" />
69
+ </reference>
70
+ </sales_order_creditmemo>
71
+ <sales_order_printcreditmemo>
72
+ <reference name="creditmemo_totals">
73
+ <block type="carbon/sales_order_carbon" name="carbon" />
74
+ </reference>
75
+ </sales_order_printcreditmemo>
76
+ <sales_email_order_creditmemo_items>
77
+ <reference name="creditmemo_totals">
78
+ <block type="carbon/sales_order_carbon" name="carbon" />
79
+ </reference>
80
+ </sales_email_order_creditmemo_items>
81
+ </layout>
app/design/frontend/base/default/template/gaia/checkout/cart/totals/carbon.phtml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php /** @var $this Gaia_Carbon_Block_Checkout_Carbon **/ ?>
2
+ <?php if($this->isEnabled() && $this->isOptional()): ?>
3
+ <div class="cart-carbon">
4
+ <input class="css-checkbox" type="checkbox" name="add-carbon" id="add-carbon" title="<?php echo $this->__('Offset Carbon') ?>" onclick="addCarbon(this)" <?php if($this->isCarbonSelected()) {echo 'checked=\"checked\"';}?> />
5
+ <label class="css-label" for="add-carbon"><?php echo $this->__("Offset Carbon") ?></label>
6
+ <a class="question-mark tip" target="_blank" href="<?php echo $this->getCarbonUrl() ?>">
7
+ <span><?php echo $this->__($this->getCarbonDescription()) ?></span>
8
+ </a>
9
+ <br/><span id="loading" style="display:none;"><?php echo $this->__('Please wait ...')?></span>
10
+ </div>
11
+ <?php endif; ?>
12
+ <script type="text/javascript">
13
+ //<![CDATA[
14
+ var carbon_url = '<?php echo $this->getUrl('carbon/ajax/addcarbon', array('_secure' => Mage::app()->getStore()->isCurrentlySecure())); ?>';
15
+ function addCarbon(checkbox) {
16
+ checkbox.disable();
17
+ $('loading').show();
18
+ var curStatus = 0;
19
+ if (checkbox.checked) {
20
+ curStatus = 1;
21
+ }
22
+ new Ajax.Request(carbon_url, {
23
+ parameters: {
24
+ status: curStatus
25
+ },
26
+ onComplete: function(resp){
27
+ Element.replace('shopping-cart-totals-table', resp.responseText);
28
+ $('loading').hide();
29
+ checkbox.enable();
30
+ },
31
+ method: 'post'
32
+ });
33
+ }
34
+ //]]
35
+ </script>
app/design/frontend/base/default/template/gaia/checkout/onepage/carbon.phtml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php /** @var $this Gaia_Carbon_Block_Checkout_Carbon **/ ?>
2
+ <?php if($this->isEnabled() && $this->isOptional()): ?>
3
+ <div class="checkout-carbon">
4
+ <li class="control">
5
+ <input class="css-checkbox" type="checkbox" name="add-carbon" id="add-carbon" value="1" title="<?php echo $this->__('Carbon Offset') ?>" <?php if($this->isCarbonSelected()) {echo 'checked=\"checked\"';}?> />
6
+ <label class="css-label" for="add-carbon"><?php echo $this->__('Add Carbon Offset') . ' ' . $this->getCarbonAmount() ?></label>
7
+ </li>
8
+ <span class="carbon-copy">
9
+ <?php echo $this->__($this->getCarbonDescription()) ?>
10
+ Information on the offset programme can be found <a target="_blank" title="carbon offset" href="<?php echo $this->getCarbonUrl()?>">here.</a>
11
+ </span>
12
+ </div>
13
+ <?php endif; ?>
14
+
15
+
app/etc/modules/Gaia_Carbon.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Gaia_Carbon>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Gaia_Carbon>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Gaia_Carbon</name>
4
+ <version>1.0.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Allows your customers to negate the carbon emissions from the shipping of their order.</summary>
10
+ <description>&lt;p&gt;Effectively, by including the offsetting option, customers can choose to negate the carbon dioxide that goes into the atmosphere from the process of shipping their order. At the checkout, customers will see an option to offset the shipment. By selecting this box, the amount of carbon is automatically calculated and the offset fee is added to their shipping cost &#x2013; usually well under a $1.00.&#xD;
11
+ &lt;/p&gt;&#xD;
12
+ &lt;p&gt;&#xD;
13
+ The unique CO2counter technology allows the offset certificate to be automatically generated as a PDF and emailed to the customer if required. The fee is used to invest in projects that prevent or remove greenhouse gas emissions from the atmosphere.&#xD;
14
+ &lt;/p&gt;&#xD;
15
+ &lt;p /&gt;&lt;a href="http://gaiapartnership.com/"&gt;The Gaia Partnership&lt;/a&gt; have arrangements in place with Climate Friendly to purchase offsets in the Tasmanian Native Forest Protection Project. For details of the offsets please read more &lt;a href="http://gaiapartnership.com/services/page7/carbon_offsets.html"&gt;here&lt;/a&gt;.</description>
16
+ <notes>Initial release version</notes>
17
+ <authors><author><name>Martin Novak</name><user>czdigital</user><email>martin.novak@czdigital.com.au</email></author></authors>
18
+ <date>2014-07-19</date>
19
+ <time>00:45:13</time>
20
+ <contents><target name="mageetc"><dir name="modules"><file name="Gaia_Carbon.xml" hash="5fb5b9d7165f07b9efc27a6076528ae3"/></dir></target><target name="magecommunity"><dir name="Gaia"><dir name="Carbon"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><dir name="Create"><dir name="Totals"><file name="Carbon.php" hash="97422040bfeb8dd09a97f3c407b8fc76"/></dir></dir></dir></dir><dir name="Signup"><dir name="Edit"><file name="Form.php" hash="6a04b6552f1851785ffc344ecb300453"/></dir><file name="Edit.php" hash="ab1388630916888414defa05c9a3b6fc"/></dir><dir name="System"><dir name="Config"><dir name="Form"><dir name="Button"><file name="Clearlog.php" hash="caeb679b325a25c4e3149f7aa86f4ce4"/><file name="Showlog.php" hash="e54f3ab832b6f256d8d8e62780fd9982"/><file name="Signup.php" hash="98633f8c8d0d3744591f4aa61dfce9f8"/></dir></dir></dir></dir></dir><dir name="Checkout"><file name="Carbon.php" hash="342775b082c23f84665632a1c949c842"/><dir name="Totals"><file name="Carbon.php" hash="e4fd64b3f26f1d39cdc8e07701de127b"/></dir></dir><dir name="Sales"><dir name="Order"><file name="Carbon.php" hash="45791e2639291312065df87d1bccf33b"/></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="0328006066524d876b3e26ca3ed646b7"/></dir><dir name="Model"><dir name="Api"><file name="Client.php" hash="eca55d0a86cd239cbc3876e34b44e5c5"/><file name="Request.php" hash="d21cf6544af9514b734354c3f12620bb"/></dir><file name="Carbon.php" hash="3fa38ffb86a60d0dadfbf7c34df98942"/><dir name="Checkout"><dir name="Type"><file name="Onepage.php" hash="777e01b62a4e73950405f02eed860a44"/></dir></dir><file name="Geocoder.php" hash="11cebfa03c95a3fe9c980821e9c0ae44"/><file name="Location.php" hash="a49f414a1c21445bce12878a9248d6bd"/><file name="Observer.php" hash="d7a2af7c0826175a8eb0db2812bb2943"/><dir name="Sales"><dir name="Order"><dir name="Total"><dir name="Creditmemo"><file name="Carbon.php" hash="bae40fab1e654a80c1b9dd28ec0d39ab"/></dir><dir name="Invoice"><file name="Carbon.php" hash="e0a52561fb5e466bece46a7ec25b3088"/></dir></dir></dir><dir name="Quote"><dir name="Address"><dir name="Total"><file name="Carbon.php" hash="15e88a492f42007b24c0c6f9dceeecd0"/></dir></dir></dir></dir><file name="Signup.php" hash="15180ec5daee8619bf0e7ebe3f1087a1"/><dir name="System"><dir name="Config"><dir name="Source"><file name="Abstract.php" hash="7b5e813f582f9f7fcf3270f2069a6103"/><file name="Environment.php" hash="12353a36a4c11e0afa5fb30ee6f3f354"/><file name="Mode.php" hash="fb931085bacde582ba0f959fbff1671a"/><dir name="Unit"><file name="Weight.php" hash="dfb923da8fc7bd2edef9f02d6fe0e96c"/></dir></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="DebugController.php" hash="bcb77882d3c1862c72cfa1f430d6df5b"/><file name="SignupController.php" hash="a814d0a3b06b8eb5fffc912d999800c3"/></dir><file name="AjaxController.php" hash="fdd4d006b555d8b264af8479b3fe7319"/></dir><dir name="etc"><file name="adminhtml.xml" hash="9d98fd4c0e773be0379c671a5ff028de"/><file name="config.xml" hash="a95353a63f955cbe83e47175cfc746e6"/><file name="system.xml" hash="45c4b2e6351881bbb2af3aa8875ee378"/></dir><dir name="sql"><dir name="carbon_setup"><file name="mysql4-install-1.0.0.php" hash="1d0a91c77bdf251a978afe8952b6030b"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="gaia"><file name="carbon.xml" hash="0d5a29dc3eb92f00b55a83b1b77bcbc8"/></dir></dir><dir name="template"><dir name="gaia"><dir name="carbon"><dir name="sales"><dir name="order"><file name="refunded.phtml" hash="514414422156a0820ff42772e175671d"/><file name="total.phtml" hash="837d56a1da872a10e73a22e6339f27f3"/></dir></dir><dir name="system"><dir name="config"><file name="button.phtml" hash="fb5ab610c535e7a268195d806abbe0bd"/></dir></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="gaia"><file name="carbon.xml" hash="637dc6367809d07f5be596974fd0b9e7"/></dir></dir><dir name="template"><dir name="gaia"><dir name="checkout"><dir name="cart"><dir name="totals"><file name="carbon.phtml" hash="075639674cb23fee204596ab3df23917"/></dir></dir><dir name="onepage"><file name="carbon.phtml" hash="18e788f2474dffc15bf6b016aa78bf09"/></dir></dir></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="gaia"><dir name="carbon"><dir name="css"><file name="styles.css" hash="f755f5aac98a6f797f963c5a33450a83"/></dir><dir name="images"><file name="dark-check-green.png" hash="75a9f9a93361f6098b6b55ce7cf301c1"/><file name="i_question-mark.png" hash="23201b7ac207eebd9be0776ea44098a4"/><file name="lite-green-check.png" hash="ad9fa0672515826b63c07aef3fc0b07b"/></dir></dir></dir></dir></dir></dir></target></contents>
21
+ <compatible/>
22
+ <dependencies><required><php><min>5.2.13</min><max>6.0.0</max></php></required></dependencies>
23
+ </package>
skin/frontend/base/default/gaia/carbon/css/styles.css ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ input[type=checkbox].css-checkbox {
3
+ position: absolute;
4
+ overflow: hidden;
5
+ clip: rect(0 0 0 0);
6
+ height:1px;
7
+ width:1px;
8
+ margin:-1px;
9
+ padding:0;
10
+ border:0;
11
+ }
12
+
13
+ input[type=checkbox].css-checkbox + label.css-label {
14
+ padding-left:20px;
15
+ height:15px;
16
+ display:inline-block;
17
+ line-height:15px;
18
+ background-repeat:no-repeat;
19
+ background-position: 0 0;
20
+ font-size:15px;
21
+ vertical-align:middle;
22
+ cursor:pointer;
23
+ }
24
+
25
+ input[type=checkbox].css-checkbox:checked + label.css-label {
26
+ background-position: 0 -15px;
27
+ }
28
+
29
+ .css-label{
30
+ background-image: url('../images/lite-green-check.png');
31
+ /**background-image: url('../images/dark-check-green.png');}**/
32
+ }
33
+ .cart-carbon{
34
+ float: right;
35
+ margin: 15px;
36
+ }
37
+
38
+ .checkout-carbon {
39
+ background: none repeat scroll 0 0 #F9F3E3;
40
+ border: 1px solid #BBAFA0;
41
+ color: #F18200;
42
+ width: 95%;
43
+ padding: 15px;
44
+ }
45
+
46
+ .carbon-copy {
47
+ display: block;
48
+ padding-top: 10px;
49
+ font-style: italic;
50
+ font-size: .8em;
51
+ }
52
+
53
+ .tip {
54
+ position: relative;
55
+ text-decoration: none;
56
+ }
57
+
58
+ .tip span {display: none;}
59
+
60
+ .tip:hover span {
61
+ display: block;
62
+ position: absolute;
63
+ padding: .5em;
64
+ content: attr(title);
65
+ width: 250px;
66
+ text-align: center;
67
+ height: auto;
68
+ bottom: 15px;
69
+ background: rgba(0,0,0,.8);
70
+ -moz-border-radius:10px;
71
+ -webkit-border-radius:10px;
72
+ border-radius:10px;
73
+ color: #fff;
74
+ font-size: .86em;
75
+ }
76
+
77
+ .tip:hover span:after {
78
+ position: absolute;
79
+ display: block;
80
+ content: "";
81
+ border-color: rgba(0,0,0,.8) transparent transparent transparent;
82
+ border-style: solid;
83
+ border-width: 10px;
84
+ height:0;
85
+ width:0;
86
+ position:absolute;
87
+ bottom: -16px;
88
+ left:1em;
89
+ }
90
+
91
+ .question-mark {
92
+ background: url("../images/i_question-mark.png") no-repeat scroll 0 0 rgba(0, 0, 0, 0);
93
+ display: inline-block;
94
+ height: 16px;
95
+ margin: 0 0 1px;
96
+ vertical-align: middle;
97
+ width: 16px;
98
+ }
skin/frontend/base/default/gaia/carbon/images/dark-check-green.png ADDED
Binary file
skin/frontend/base/default/gaia/carbon/images/i_question-mark.png ADDED
Binary file
skin/frontend/base/default/gaia/carbon/images/lite-green-check.png ADDED
Binary file