Trendyr_Trendyrshare - Version 1.0.0

Version Notes

This is tested to run with the default checkout setup.

Download this release

Release Info

Developer Steve Barbera
Extension Trendyr_Trendyrshare
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/Trendyr/Trendyrshare/Block/Sales/Order/Total.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Trendyr_Trendyrshare_Block_Sales_Order_Total extends Mage_Core_Block_Template
3
+ {
4
+ /**
5
+ * Get label cell tag properties
6
+ *
7
+ * @return string
8
+ */
9
+ public function getLabelProperties()
10
+ {
11
+ return $this->getParentBlock()->getLabelProperties();
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
+ * Get value cell tag properties
36
+ *
37
+ * @return string
38
+ */
39
+ public function getValueProperties()
40
+ {
41
+ return $this->getParentBlock()->getValueProperties();
42
+ }
43
+
44
+ /**
45
+ * Initialize reward points totals
46
+ *
47
+ * @return Enterprise_Reward_Block_Sales_Order_Total
48
+ */
49
+ public function initTotals()
50
+ {
51
+
52
+ if ((float) $this->getOrder()->getBaseTrendyrshareAmount()) {
53
+ $source = $this->getSource();
54
+ $value = $source->getTrendyrshareAmount();
55
+
56
+ $this->getParentBlock()->addTotal(new Varien_Object(array(
57
+ 'code' => 'trendyrshare',
58
+ 'strong' => false,
59
+ 'label' => Mage::helper('trendyrshare')->formatTrendyrshare($value),
60
+ 'value' => $source instanceof Mage_Sales_Model_Order_Creditmemo ? - $value : $value
61
+ )));
62
+ }
63
+
64
+ return $this;
65
+ }
66
+ }
app/code/local/Trendyr/Trendyrshare/Block/Template.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Trendyr_Trendyrshare_Block_Template extends Mage_Core_Block_Template
3
+ {
4
+ public function fetchView($fileName)
5
+ {
6
+ //ignores file name, just uses a simple include with template name
7
+ $path = Mage::getModuleDir('', 'Trendyr_Trendyrshare').'/templates';
8
+ $file = pathinfo($fileName);
9
+ $file = $file['filename'].'.'.$file['extension'];
10
+ $path = $path.'/'.$file;
11
+ include($path);
12
+ }
13
+ }
app/code/local/Trendyr/Trendyrshare/Helper/Data.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Trendyr_Trendyrshare_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+ public function formatTrendyrshare($amount){
6
+ return Mage::helper('trendyrshare')->__('Trendyr Discount');
7
+ }
8
+
9
+ }
app/code/local/Trendyr/Trendyrshare/Model/Observer.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Trendyr_Trendyrshare_Model_Observer
3
+ {
4
+ public function invoiceSaveAfter(Varien_Event_Observer $observer)
5
+ {
6
+ $invoice = $observer->getEvent()->getInvoice();
7
+ if ($invoice->getBaseTrendyrshareAmount()) {
8
+ $order = $invoice->getOrder();
9
+ $order->setTrendyrshareAmountInvoiced($order->getTrendyrshareAmountInvoiced() + $invoice->getTrendyrshareAmount());
10
+ $order->setBaseTrendyrshareAmountInvoiced($order->getBaseTrendyrshareAmountInvoiced() + $invoice->getBaseTrendyrshareAmount());
11
+ }
12
+ return $this;
13
+ }
14
+ public function creditmemoSaveAfter(Varien_Event_Observer $observer)
15
+ {
16
+ /* @var $creditmemo Mage_Sales_Model_Order_Creditmemo */
17
+ $creditmemo = $observer->getEvent()->getCreditmemo();
18
+ if ($creditmemo->getTrendyrshareAmount()) {
19
+ $order = $creditmemo->getOrder();
20
+ $order->setTrendyrshareAmountRefunded($order->getTrendyrshareAmountRefunded() + $creditmemo->getTrendyrshareAmount());
21
+ $order->setBaseTrendyrshareAmountRefunded($order->getBaseTrendyrshareAmountRefunded() + $creditmemo->getBaseTrendyrshareAmount());
22
+ }
23
+ return $this;
24
+ }
25
+
26
+
27
+ /*
28
+ public function block_inject_cart_totals(Varien_Event_Observer $observer)
29
+ {
30
+ //http://www.magentocommerce.com/boards/viewthread/197627/#t247757
31
+
32
+ $block = $observer->getEvent()->getBlock();
33
+
34
+ if ($block->getId() == 'mage_checkout_block_cart_totals')
35
+ {
36
+ $extendBlock = Mage::app()->getLayout()->createBlock('Mage_Core_Block_Text');
37
+
38
+ $extendBlock->setText('<h1>This is a Test</h1>');
39
+ Mage::app()->getLayout()->getBlock('content')->append($extendBlock, 'block_td');
40
+ return $this;
41
+ }
42
+ }
43
+ */
44
+
45
+ public function updatePaypalTotal($evt)
46
+ {
47
+ $cart = $evt->getPaypalCart();
48
+ $cart->updateTotal(Mage_Paypal_Model_Cart::TOTAL_SUBTOTAL,$cart->getSalesEntity()->getTrendyrshareAmount());
49
+ }
50
+
51
+ }
app/code/local/Trendyr/Trendyrshare/Model/Sales/Order/Total/Creditmemo/Trendyr.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Trendyr_Trendyrshare_Model_Sales_Order_Total_Creditmemo_Trendyrshare extends Mage_Sales_Model_Order_Creditmemo_Total_Abstract
3
+ {
4
+ public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
5
+ {
6
+ $order = $creditmemo->getOrder();
7
+ $trendyrshareAmountLeft = $order->getTrendyrshareAmountInvoiced() - $order->getTrendyrshareAmountRefunded();
8
+ $basetrendyrshareAmountLeft = $order->getBaseTrendyrshareAmountInvoiced() - $order->getBaseTrendyrshareAmountRefunded();
9
+ if ($basetrendyrshareAmountLeft > 0) {
10
+ $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $trendyrshareAmountLeft);
11
+ $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $basetrendyrshareAmountLeft);
12
+ $creditmemo->setTrendyrshareAmount($trendyrshareAmountLeft);
13
+ $creditmemo->setBaseTrendyrshareAmount($basetrendyrshareAmountLeft);
14
+ }
15
+ return $this;
16
+ }
17
+ }
app/code/local/Trendyr/Trendyrshare/Model/Sales/Order/Total/Invoice/Trendyr.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Trendyr_Trendyrshare_Model_Sales_Order_Total_Invoice_Trendyrshare extends Mage_Sales_Model_Order_Invoice_Total_Abstract
3
+ {
4
+ public function collect(Mage_Sales_Model_Order_Invoice $invoice)
5
+ {
6
+ $order = $invoice->getOrder();
7
+ $trendyrshareAmountLeft = $order->getTrendyrshareAmount() - $order->getTrendyrshareAmountInvoiced();
8
+ $baseTrendyrshareAmountLeft = $order->getBaseTrendyrshareAmount() - $order->getBaseTrendyrshareAmountInvoiced();
9
+ if (abs($baseTrendyrshareAmountLeft) < $invoice->getBaseGrandTotal()) {
10
+ $invoice->setGrandTotal($invoice->getGrandTotal() + $trendyrshareAmountLeft);
11
+ $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseTrendyrshareAmountLeft);
12
+ } else {
13
+ $trendyrshareAmountLeft = $invoice->getGrandTotal() * -1;
14
+ $baseTrendyrshareAmountLeft = $invoice->getBaseGrandTotal() * -1;
15
+
16
+ $invoice->setGrandTotal(0);
17
+ $invoice->setBaseGrandTotal(0);
18
+ }
19
+
20
+ $invoice->setTrendyrshareAmount($trendyrshareAmountLeft);
21
+ $invoice->setBaseTrendyrshareAmount($baseTrendyrshareAmountLeft);
22
+ return $this;
23
+ }
24
+ }
app/code/local/Trendyr/Trendyrshare/Model/Sales/Quote/Address/Total/Trendyrshare.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Trendyr_Trendyrshare_Model_Sales_Quote_Address_Total_Trendyrshare extends Mage_Sales_Model_Quote_Address_Total_Abstract{
3
+ protected $_code = 'trendyrshare';
4
+
5
+ public function collect(Mage_Sales_Model_Quote_Address $address)
6
+ {
7
+ parent::collect($address);
8
+
9
+ $this->_setAmount(0);
10
+ $this->_setBaseAmount(0);
11
+
12
+ $items = $this->_getAddressItems($address);
13
+ if (!count($items)) {
14
+ return $this; //this makes only address type shipping to come through
15
+ }
16
+
17
+ $quote = $address->getQuote();
18
+
19
+
20
+ $exist_amount = $quote->getTrendyrshareAmount();
21
+ $trendyrshare = Trendyr_Trendyrshare_Model_Trendyrshare::getTrendyrshare();
22
+ $balance = $trendyrshare - $exist_amount;
23
+
24
+ // $balance = $trendyrshare;
25
+
26
+ //$this->_setAmount($balance);
27
+ //$this->_setBaseAmount($balance);
28
+
29
+ $address->setTrendyrshareAmount($balance);
30
+ $address->setBaseTrendyrshareAmount($balance);
31
+
32
+ $quote->setTrendyrshareAmount($balance);
33
+
34
+ $address->setGrandTotal($address->getGrandTotal() + $address->getTrendyrshareAmount());
35
+ $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseTrendyrshareAmount());
36
+
37
+ }
38
+
39
+ public function fetch(Mage_Sales_Model_Quote_Address $address)
40
+ {
41
+ $amt = $address->getTrendyrshareAmount();
42
+ if($address->getTrendyrshareAmount() == 0){return $this;}
43
+ $address->addTotal(array(
44
+ 'code'=>$this->getCode(),
45
+ 'title'=>Mage::helper('trendyrshare')->__('Trendyr Discount'),
46
+ 'value'=> $amt
47
+ ));
48
+ return $this;
49
+ }
50
+ }
app/code/local/Trendyr/Trendyrshare/Model/Trendyrshare.php ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Trendyr_Trendyrshare_Model_Trendyrshare extends Varien_Object{
5
+
6
+
7
+ public static function getTrendyrshare()
8
+ {
9
+
10
+
11
+ //if there's not a merch key, shut it down.
12
+ if(!$merchant_public_key = self::get_merch_key()){return false;}
13
+
14
+ //prep an array of cart items for Trendyr
15
+ $checkout_items = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
16
+ $trendyr_product_data = self::prep_trendyr_products($merchant_public_key, $checkout_items);
17
+
18
+
19
+ //make the call to Trendyr, get back an array of data about the transaction
20
+ $trendyr_data = self::trendyr_curl($trendyr_product_data, $_SESSION['trendyr']['transaction_social_key']);
21
+
22
+ return -($trendyr_data->discount_amount);
23
+ }
24
+
25
+ private function trendyr_curl($trendyr_product_data, $social_key = null)
26
+ {
27
+
28
+
29
+ $trendyr_url = 'http://sandbox.trendyr.com'; //dev url
30
+
31
+ //is there a social key? make a url choice based on that.
32
+ $social_key ?
33
+ $url = $trendyr_url.'/transaction/update/'.$social_key :
34
+ $url = $trendyr_url.'/transaction/create';
35
+
36
+ $trendyr_product_data_string = http_build_query($trendyr_product_data);
37
+
38
+ //kick off a cURL
39
+ $ch = curl_init();
40
+ curl_setopt($ch,CURLOPT_URL, $url);
41
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
42
+ curl_setopt($ch,CURLOPT_POSTFIELDS, $trendyr_product_data_string);
43
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
44
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 8);
45
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
46
+
47
+ $result = curl_exec($ch);
48
+ $result = json_decode($result);
49
+
50
+ //make sure the return is good to go, else kill it.
51
+ if(curl_getinfo($ch, CURLINFO_HTTP_CODE) != 200)
52
+ {
53
+ unset($_SESSION['trendyr']);
54
+ return false;
55
+
56
+ } //Trendyr data unavilable.
57
+ curl_close($ch);
58
+
59
+ //save the terndyr social key in post for later use if needed
60
+
61
+ $max_discount = number_format($result->max_discount_amount, 2);
62
+ $current_discount = number_format($result->discount_amount, 2);
63
+
64
+ $_SESSION['trendyr']['max_savings'] = $max_discount;
65
+
66
+ !$_SESSION['trendyr']['transaction_social_key'] ? $_SESSION['trendyr']['transaction_social_key'] = $result->transaction_social_key : null;
67
+
68
+ //determin the right message for the modal button
69
+ self::prep_trendyr_btn_msg($max_discount, $current_discount);
70
+
71
+ //the server sends back some JSON, change it to an object then return it.
72
+
73
+ return $result;
74
+
75
+ }
76
+
77
+ private function prep_trendyr_btn_msg($max, $current)
78
+ {
79
+ $btn_message = '';
80
+ $btn_code = '';
81
+
82
+ if($current == 0)
83
+ {
84
+ $btn_message = 'Save $'.number_Format($max, 2) .' by social sharing!';
85
+ $btn_code = 0;
86
+ }
87
+
88
+ else if ($max != $current) {
89
+
90
+ $dif = number_format(($max - $current), 2);
91
+ $btn_message = 'Save another $'.$dif.' instantly!';
92
+ $btn_code = 1;
93
+
94
+ } else {
95
+
96
+ $btn_message = 'Max savings applied!';
97
+ $btn_code = 2;
98
+ }
99
+
100
+ $_SESSION['trendyr']['btn_msg_text'] = $btn_message;
101
+ $_SESSION['trendyr']['btn_msg_code'] = $btn_code;
102
+ }
103
+
104
+ private function prep_trendyr_products($merchant_public_key, $checkout_items)
105
+ {
106
+
107
+ //before getting into the products, stick the merch key on the array
108
+ $trendyr_product_data['merchant_public_key'] = $merchant_public_key;
109
+
110
+
111
+ //iterate over the products, add them to the array with details.
112
+ $i = 0;
113
+ foreach($checkout_items as $item)
114
+ {
115
+ $_product = Mage::getModel('catalog/product')->load($item->getProductId());
116
+ $product_image_url = Mage::getModel('catalog/product_media_config')->getMediaUrl( $_product->getImage());
117
+
118
+ $trendyr_product_data['products'][$i]['product_sku'] = $_product->getSku();
119
+ $trendyr_product_data['products'][$i]['product_name'] = $_product->getName();
120
+ $trendyr_product_data['products'][$i]['product_url'] = $_product->getProductUrl();
121
+ $trendyr_product_data['products'][$i]['product_quantity'] = $item->getQty();
122
+ $trendyr_product_data['products'][$i]['product_price'] = $_product->getPrice();
123
+ $trendyr_product_data['products'][$i]['product_description'] = $_product->getDescription();
124
+ $trendyr_product_data['products'][$i]['product_image_url'] = $product_image_url;
125
+
126
+ //$trendyr_product_data['products'][$i]['major_category'] = // add this later
127
+ //$trendyr_product_data['products'][$i]['minor_category'] = // add this later
128
+
129
+ $i++;
130
+
131
+ }
132
+ return $trendyr_product_data;
133
+ }
134
+
135
+
136
+ private function get_merch_key()
137
+ {
138
+ //read in the Trendyr social key from admin config
139
+ $resource = Mage::getSingleton('core/resource');
140
+ $read_connection = $resource->getConnection('core_read');
141
+ $table_name = $resource->getTableName('trendyrshare');
142
+
143
+ $q = "SELECT merchantkey from $table_name";
144
+ $r = $read_connection->fetchAll($q);
145
+
146
+ return $r[0]['merchantkey'];
147
+
148
+ }
149
+
150
+ public static function canApply($address){
151
+ //put here your business logic to check if trendyrshare should be applied or not
152
+ //if($address->getAddressType() == 'billing'){
153
+ return true;
154
+ //}
155
+
156
+ }
157
+ }
app/code/local/Trendyr/Trendyrshare/controllers/IndexController.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Trendyr_Trendyrshare_IndexController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+
6
+ public function indexAction()
7
+ {
8
+
9
+ $this->loadLayout();
10
+ $block = $this->getLayout()->createBlock('trendyrshare/template')
11
+ ->setTemplate('form_block_action.phtml');
12
+
13
+ $this->_addContent($block);
14
+ $this->renderLayout();
15
+
16
+
17
+
18
+ /*
19
+
20
+ $this->loadLayout();
21
+
22
+ //create a text block with the name of "example-block"
23
+ $block = $this->getLayout()
24
+ ->createBlock('core/text', 'Trendyr_Trendyrshare-block')
25
+ ->setText('<h1>Trendyr Configuration</h1>');
26
+
27
+ $this->_addContent($block);
28
+
29
+ $this->renderLayout();
30
+ */
31
+
32
+
33
+
34
+ }
35
+ }
36
+
37
+
38
+
app/code/local/Trendyr/Trendyrshare/etc/config.xml ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Trendyr_Trendyrshare>
5
+ <version>1.0</version>
6
+ </Trendyr_Trendyrshare>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <trendyrshare>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>Trendyr_Trendyrshare</module>
14
+ <frontName>trendyrshare</frontName>
15
+ </args>
16
+ </trendyrshare>
17
+ </routers>
18
+ <layout>
19
+ <updates>
20
+ <trendyrshare>
21
+ <file>trendyrshare.xml</file>
22
+ </trendyrshare>
23
+ </updates>
24
+ </layout>
25
+ </frontend>
26
+
27
+
28
+
29
+ <admin>
30
+ <routers>
31
+ <trendyrshare>
32
+ <use>admin</use>
33
+ <args>
34
+ <module>Trendyr_Trendyrshare</module>
35
+ <frontName>trendyrshare</frontName>
36
+ </args>
37
+ </trendyrshare>
38
+ </routers>
39
+ </admin>
40
+ <adminhtml>
41
+ <menu>
42
+ <menu1 translate="title" module="Trendyrshare">
43
+ <title>Trendyr</title>
44
+ <sort_order>9999</sort_order>
45
+ <children>
46
+ <menuitem1 module="Trendyrshare">
47
+ <title>Configure</title>
48
+ <action>trendyrshare/index</action>
49
+ </menuitem1>
50
+ </children>
51
+ </menu1>
52
+ </menu>
53
+ <acl>
54
+ <resources>
55
+ <admin>
56
+ <children>
57
+ <menu1 translate="title" module="Trendyrshare">
58
+ <title>Trendyr Configure</title>
59
+ <sort_order>60</sort_order>
60
+ <children>
61
+ <menuitem1>
62
+ <title>Menu item 1</title>
63
+ </menuitem1>
64
+ </children>
65
+ </menu1>
66
+ </children>
67
+ </admin>
68
+ </resources>
69
+ </acl>
70
+ </adminhtml>
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+ <global>
79
+ <helpers>
80
+ <Trendyrshare>
81
+ <class>Trendyr_Trendyrshare_Helper</class>
82
+ </Trendyrshare>
83
+ </helpers>
84
+
85
+ <sales>
86
+ <quote>
87
+ <totals>
88
+ <trendyrshare>
89
+ <class>trendyrshare/sales_quote_address_total_trendyrshare</class>
90
+ </trendyrshare>
91
+ </totals>
92
+ </quote>
93
+ <order_invoice>
94
+ <totals>
95
+ <trendyrshare>
96
+ <class>trendyrshare/sales_order_total_invoice_trendyrshare</class>
97
+ </trendyrshare>
98
+ </totals>
99
+ </order_invoice>
100
+ <order_creditmemo>
101
+ <totals>
102
+ <trendyrshare>
103
+ <class>trendyrshare/sales_order_total_creditmemo_trendyrshare</class>
104
+ </trendyrshare>
105
+ </totals>
106
+ </order_creditmemo>
107
+ </sales>
108
+ <events>
109
+ <paypal_prepare_line_items>
110
+ <observers>
111
+ <paypal_prepare_line_items>
112
+ <class>trendyrshare/observer</class>
113
+ <method>updatePaypalTotal</method>
114
+ </paypal_prepare_line_items>
115
+ </observers>
116
+ </paypal_prepare_line_items>
117
+ <sales_order_invoice_save_after>
118
+ <observers>
119
+ <sales_order_invoice_save_after>
120
+ <class>trendyrshare/observer</class>
121
+ <method>invoiceSaveAfter</method>
122
+ </sales_order_invoice_save_after>
123
+ </observers>
124
+ </sales_order_invoice_save_after>
125
+ <sales_order_creditmemo_save_after>
126
+ <observers>
127
+ <sales_order_creditmemo_save_after>
128
+ <class>trendyrshare/observer</class>
129
+ <method>creditmemoSaveAfter</method>
130
+ </sales_order_creditmemo_save_after>
131
+ </observers>
132
+ </sales_order_creditmemo_save_after>
133
+ </events>
134
+ <fieldsets>
135
+ <sales_convert_quote_address>
136
+ <trendyrshare_amount><to_order>*</to_order></trendyrshare_amount>
137
+ <base_trendyrshare_amount><to_order>*</to_order></base_trendyrshare_amount>
138
+ </sales_convert_quote_address>
139
+ </fieldsets>
140
+ <pdf>
141
+ <totals>
142
+ <trendyrshare translate="title">
143
+ <title>Trendyrshare</title>
144
+ <source_field>trendyrshare_amount</source_field>
145
+ <font_size>7</font_size>
146
+ <display_zero>0</display_zero>
147
+ <sort_order>650</sort_order>
148
+ <amount_prefix>-</amount_prefix>
149
+ </trendyrshare>
150
+ </totals>
151
+ </pdf>
152
+ <models>
153
+ <trendyrshare>
154
+ <class>Trendyr_Trendyrshare_Model</class>
155
+ <resourceModel>trendyrshare_mysql4</resourceModel>
156
+ </trendyrshare>
157
+ <trendyrshare_mysql4>
158
+ <class>Trendyr_Trendyrshare_Model_Mysql4</class>
159
+ <entities>
160
+ <trendyrshare>
161
+ <table>trendyrshare</table>
162
+ </trendyrshare>
163
+ </entities>
164
+ </trendyrshare_mysql4>
165
+ </models>
166
+ <resources>
167
+ <trendyrshare_setup>
168
+ <setup>
169
+ <module>Trendyr_Trendyrshare</module>
170
+ </setup>
171
+ <connection>
172
+ <use>core_setup</use>
173
+ </connection>
174
+ </trendyrshare_setup>
175
+ <trendyrshare_write>
176
+ <connection>
177
+ <use>core_write</use>
178
+ </connection>
179
+ </trendyrshare_write>
180
+ <trendyrshare_read>
181
+ <connection>
182
+ <use>core_read</use>
183
+ </connection>
184
+ </trendyrshare_read>
185
+ </resources>
186
+ <blocks>
187
+ <trendyrshare>
188
+ <class>Trendyr_Trendyrshare_Block</class>
189
+ </trendyrshare>
190
+ </blocks>
191
+ <helpers>
192
+ <trendyrshare>
193
+ <class>Trendyr_Trendyrshare_Helper</class>
194
+ </trendyrshare>
195
+ </helpers>
196
+ </global>
197
+ <default>
198
+ <sales>
199
+ <totals_sort>
200
+ <trendyrshare>15</trendyrshare>
201
+ </totals_sort>
202
+ </sales>
203
+ </default>
204
+ </config>
app/code/local/Trendyr/Trendyrshare/sql/trendyrshare_setup/mysql4-install-1.0.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+
7
+ $installer->run("
8
+
9
+ DROP TABLE IF EXISTS {$this->getTable('trendyrshare')};
10
+
11
+ CREATE TABLE {$this->getTable('trendyrshare')} (
12
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
13
+ `jsmode` varcar(255) NOT NULL default '',
14
+ `tcopy` text,
15
+ `merchantkey` varchar(255) NOT NULL default '',
16
+ PRIMARY KEY (`id`)
17
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
18
+
19
+ ");
20
+
21
+ $installer->run("INSERT INTO {$this->getTable('trendyrshare')} (merchantkey) VALUES ('');");
22
+ $installer->run("INSERT INTO {$this->getTable('trendyrshare')} (jsmode) VALUES ('https://api.trendyr.com/trendyr.js');");
23
+
24
+ $installer->run("
25
+
26
+ ALTER TABLE `".$this->getTable('sales/order')."` ADD `trendyrshare_amount_refunded` DECIMAL( 10, 2 ) NOT NULL;
27
+ ALTER TABLE `".$this->getTable('sales/order')."` ADD `base_trendyrshare_amount_refunded` DECIMAL( 10, 2 ) NOT NULL;
28
+
29
+ ALTER TABLE `".$this->getTable('sales/invoice')."` ADD `trendyrshare_amount` DECIMAL( 10, 2 ) NOT NULL;
30
+ ALTER TABLE `".$this->getTable('sales/invoice')."` ADD `base_trendyrshare_amount` DECIMAL( 10, 2 ) NOT NULL;
31
+
32
+ ALTER TABLE `".$this->getTable('sales/quote_address')."` ADD `trendyrshare_amount` DECIMAL( 10, 2 ) NOT NULL;
33
+ ALTER TABLE `".$this->getTable('sales/quote_address')."` ADD `base_trendyrshare_amount` DECIMAL( 10, 2 ) NOT NULL;
34
+
35
+ ALTER TABLE `".$this->getTable('sales/creditmemo')."` ADD `trendyrshare_amount` DECIMAL( 10, 2 ) NOT NULL;
36
+ ALTER TABLE `".$this->getTable('sales/creditmemo')."` ADD `base_trendyrshare_amount` DECIMAL( 10, 2 ) NOT NULL;
37
+
38
+ ");
39
+
40
+
41
+ $installer->endSetup();
42
+
app/code/local/Trendyr/Trendyrshare/templates/form_block_action.phtml ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Get the resource model
4
+ */
5
+ $resource = Mage::getSingleton('core/resource');
6
+
7
+ /**
8
+ * Retrieve the read connection
9
+ */
10
+
11
+ $trendyr_url_debug = 'https://sandbox.trendyr.com/trendyr.js';
12
+ $trendyr_url_live = 'https://api.trendyr.com/trendyr.js';
13
+
14
+ $read_connection = $resource->getConnection('core_read');
15
+ $table_name = $resource->getTableName('trendyrshare');
16
+
17
+ if($_POST['update'] == 1)
18
+ {
19
+ //check if key exists in the db already.
20
+
21
+ $write_connection = $resource->getConnection('core_write');
22
+
23
+ if($_POST['merchantkey'])
24
+ {
25
+ $binds = array('merchantkey'=>$_POST['merchantkey']);
26
+ $q = "UPDATE $table_name SET merchantkey=:merchantkey WHERE id=1";
27
+ $write_connection->query($q, $binds);
28
+ }
29
+
30
+ if($_POST['jsmode'])
31
+ {
32
+
33
+ $jsmode = $_POST['jsmode'];
34
+ $q = "UPDATE $table_name SET jsmode='$jsmode' WHERE id=1";
35
+ $write_connection->query($q);
36
+
37
+ }
38
+
39
+ $binds = array('tcopy'=>$_POST['tcopy']);
40
+ $q = "UPDATE $table_name SET tcopy=:tcopy WHERE id=1";
41
+ $write_connection->query($q, $binds);
42
+
43
+ }
44
+
45
+ //setup the form
46
+ $q = "SELECT * from $table_name";
47
+ $r = $read_connection->fetchAll($q);
48
+
49
+ $merchantkey = $r[0]['merchantkey'];
50
+ $jsmode = $r[0]['jsmode'];
51
+ $tcopy = $r[0]['tcopy'];
52
+ $url = Mage::helper("adminhtml")->getUrl('*/*/index');
53
+
54
+
55
+ function solve_dd($jsmode, $trendyr_url_debug, $trendyr_url_live)
56
+ {
57
+ //why I can't get at the url variables, I'm not sure so im passing them as args for now
58
+
59
+ $output = '';
60
+ $op_live = '<option value="'.$trendyr_url_live.'">Live</option>';
61
+ $op_debug = '<option value="'.$trendyr_url_debug.'">Debug</option>';
62
+
63
+ if($jsmode == $trendyr_url_debug)
64
+ {
65
+ $output = 'foo'.$op_debug.$op_live;
66
+
67
+ } else {
68
+ $output = 'bar'.$op_live.$op_debug;
69
+ }
70
+
71
+ return $output;
72
+ }
73
+
74
+
75
+ ?>
76
+ <h1>Trendyr</h1>
77
+ <div>
78
+ <form action="<?=$url?>" method="post">
79
+ Merchant Key: <input name="merchantkey" value="<?=$merchantkey?>">
80
+ <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" /><br/><br/>
81
+ Trendyr Mode: <input name="update" type="hidden" value="1" />
82
+ <select name="jsmode">
83
+ <?=solve_dd($jsmode, $trendyr_url_debug, $trendyr_url_live);?>
84
+ </select><br/><br/>
85
+ Modal legal copy:<br/>
86
+ <textarea name="tcopy" cols="40" rows="5"><?=$tcopy?></textarea><br/>
87
+ <input type="submit" value="save"/>
88
+ </form>
89
+ </div>
app/code/local/Trendyr/Trendyrshare/templates/resources/trendyr.js ADDED
File without changes
app/code/local/Trendyr/Trendyrshare/templates/resources/trendyr_background.png ADDED
Binary file
app/code/local/Trendyr/Trendyrshare/templates/resources/trendyr_fish.png ADDED
Binary file
app/design/frontend/default/default/layout/trendyrshare.xml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <checkout_onepage_success>
4
+ <reference name="content">
5
+ <!-- <action method="setTemplate"><template>trendyrshare/on_success.phtml</template></action> -->
6
+ <block type="page/html" name="checkout.trendyr" template="trendyrshare/on_success.phtml"/>
7
+ </reference>
8
+ </checkout_onepage_success>
9
+ <checkout_cart_index>
10
+ <reference name="content">
11
+ <!-- adds the Trendyr button to the top -->
12
+ <block before="-" type="page/html" name="checkout.cart.trendyr" template="trendyrshare/cart_trendyr_button.phtml"/>
13
+ </reference>
14
+ </checkout_cart_index>
15
+ </layout>
app/design/frontend/default/default/template/trendyrshare/cart_trendyr_button.phtml ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if($_SESSION['trendyr']) :?>
2
+ <?php
3
+ $resource = Mage::getSingleton('core/resource');
4
+ $read_connection = $resource->getConnection('core_read');
5
+ $table_name = $resource->getTableName('trendyrshare');
6
+ $q = "SELECT * from $table_name";
7
+ $r = $read_connection->fetchAll($q);
8
+ $jsmode = $r[0]['jsmode'];
9
+ ?>
10
+
11
+ <script type="text/javascript" src="<?=$jsmode?>"></script>
12
+
13
+
14
+ <?php if($_SESSION['trendyr']['btn_msg_code'] != 2) : ?>
15
+ <?php
16
+ //get the notes val from the db
17
+
18
+
19
+ $tcopy = $r[0]['tcopy'];
20
+ $tcopy = preg_replace("@\"@", '\"', $tcopy); //get rid of any double quote issues.
21
+
22
+ ?>
23
+ <script type="text/javascript">
24
+ //Load the Trendyr Javascript Library
25
+ window.onload = function(){
26
+ //Add any addtional notices or notes to the modal window
27
+ var notes = "<?=$tcopy?>";
28
+
29
+ //Instantiate the Trendyr Javascript Library
30
+ //Include the Transaction Social Key
31
+ var trendyr = new Trendyr("<?=$_SESSION['trendyr']['transaction_social_key']?>", notes);
32
+ trendyr.createButton();
33
+ //When the window is closed refresh the window
34
+ trendyr.onClose(function(result){
35
+ window.location.reload();
36
+ });
37
+ };
38
+ </script>
39
+ <div href="#" id="Trendyr-Button"></div>
40
+ <?php endif; ?>
41
+
42
+ <?php endif; ?>
app/design/frontend/default/default/template/trendyrshare/on_success.phtml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if($_SESSION['trendyr']) : ?>
2
+ <?php
3
+ $resource = Mage::getSingleton('core/resource');
4
+ $read_connection = $resource->getConnection('core_read');
5
+ $table_name = $resource->getTableName('trendyrshare');
6
+ $q = "SELECT * from $table_name";
7
+ $r = $read_connection->fetchAll($q);
8
+ $jsmode = $r[0]['jsmode'];
9
+
10
+ ?>
11
+ <script type="text/javascript" src="<?=$jsmode?>"></script>
12
+ <script>
13
+ var trendyr = new Trendyr('<?=$_SESSION['trendyr']['transaction_social_key']?>');
14
+ trendyr.transactionComplete();
15
+ </script>
16
+ <?php unset($_SESSION['trendyr']); ?>
17
+ <?php endif;?>
app/etc/modules/Trendyr_Trendyrshare.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Trendyr_Trendyrshare>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Trendyr_Trendyrshare>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Trendyr_Trendyrshare</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.apache.org/licenses/LICENSE-2.0.html">APACHE V2</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>This extension allows a checkout to use the Trendyr service.</summary>
10
+ <description>This extension allows a checkout to use the Trendyr service.</description>
11
+ <notes>This is tested to run with the default checkout setup.</notes>
12
+ <authors><author><name>Trendyr</name><user>trendyr</user><email>info@trendyr.com</email></author></authors>
13
+ <date>2012-08-07</date>
14
+ <time>15:13:42</time>
15
+ <contents><target name="magelocal"><dir name="Trendyr"><dir name="Trendyrshare"><dir name="Block"><dir name="Sales"><dir name="Order"><file name="Total.php" hash="411a319e2b492a22544bef8809802b7a"/></dir></dir><file name="Template.php" hash="ab50f42f19119b08b0a29559bf13e115"/></dir><dir name="Helper"><file name="Data.php" hash="5ff36855d52b16de7cf6ac9c29469c3e"/></dir><dir name="Model"><file name="Observer.php" hash="21afccea7c98498c73a8cc708b239755"/><dir name="Sales"><dir name="Order"><dir name="Total"><dir name="Creditmemo"><file name="Trendyr.php" hash="46790941ddf158f1a34a180e35a8205a"/></dir><dir name="Invoice"><file name="Trendyr.php" hash="2a313d89b5ee0ccc004153555b70aac9"/></dir></dir></dir><dir name="Quote"><dir name="Address"><dir name="Total"><file name="Trendyrshare.php" hash="4914701d5fa568a1267b738836c3cca6"/></dir></dir></dir></dir><file name="Trendyrshare.php" hash="46f13f65280452f31d03ffea760d032c"/></dir><dir name="controllers"><file name="IndexController.php" hash="db00d66bd927109405c922694e8a2218"/></dir><dir name="etc"><file name="config.xml" hash="14229c1257a637cc7c0846de73b811c5"/></dir><dir name="sql"><dir name="trendyrshare_setup"><file name="mysql4-install-1.0.php" hash="6838031d37e0fac933c27a6378f7e99f"/></dir></dir><dir name="templates"><file name="form_block_action.phtml" hash="915b9844a6488c83ac5f46e4ec4c04a6"/><dir name="resources"><file name="trendyr.js" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="trendyr_background.png" hash="c7d74d45f01e20bafc11e8d16fa0ce87"/><file name="trendyr_fish.png" hash="fab6eefa84f91e0af3e9d86904bdaa3e"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="trendyrshare.xml" hash="0b8577cc69cf51735414180da439df24"/></dir><dir name="template"><dir name="trendyrshare"><file name="cart_trendyr_button.phtml" hash="1338073a019aa8d07bdff1a5970bb582"/><file name="on_success.phtml" hash="94f5e49d2ac1234a8574a23e33fceb1a"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Trendyr_Trendyrshare.xml" hash="8ba423b88e654a90e0b9fb4a695aa7f9"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>