Version Notes
Need to clear cache after installation
Download this release
Release Info
Developer | Smion Li |
Extension | Referboard_Retailer |
Version | 1.0.3 |
Comparing to | |
See all releases |
Version 1.0.3
- app/code/community/Referboard/Retailer/Block/Retailer.php +12 -0
- app/code/community/Referboard/Retailer/Block/Test.php +11 -0
- app/code/community/Referboard/Retailer/Helper/Common.php +91 -0
- app/code/community/Referboard/Retailer/Helper/Data.php +14 -0
- app/code/community/Referboard/Retailer/Model/Data.php +43 -0
- app/code/community/Referboard/Retailer/Model/Observer.php +132 -0
- app/code/community/Referboard/Retailer/Model/Resource/Data.php +19 -0
- app/code/community/Referboard/Retailer/Model/Resource/Data/Collection.php +14 -0
- app/code/community/Referboard/Retailer/etc/config.xml +142 -0
- app/code/community/Referboard/Retailer/etc/system.xml +58 -0
- app/code/community/Referboard/Retailer/sql/referboard_retailer_setup/install-1.0.0.php +71 -0
- app/code/community/Referboard/Retailer/sql/referboard_retailer_setup/install-1.0.3.php +76 -0
- app/design/frontend/base/default/layout/referboard_retailer.xml +26 -0
- app/design/frontend/base/default/template/referboard_retailer/button.phtml +11 -0
- app/design/frontend/base/default/template/referboard_retailer/header.phtml +6 -0
- app/design/frontend/base/default/template/referboard_retailer/index.phtml +63 -0
- app/etc/modules/Referboard_Retailer.xml +35 -0
- lib/Referboard/Referboard_Plugin_Class.php +507 -0
- package.xml +18 -0
app/code/community/Referboard/Retailer/Block/Retailer.php
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by PhpStorm.
|
4 |
+
* User: opentopmedia-dev5
|
5 |
+
* Date: 15/11/16
|
6 |
+
* Time: 3:29 PM
|
7 |
+
*/
|
8 |
+
|
9 |
+
class Referboard_Retailer_Block_Retailer extends Mage_Core_Block_Template
|
10 |
+
{
|
11 |
+
|
12 |
+
}
|
app/code/community/Referboard/Retailer/Block/Test.php
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by Smion Li.
|
4 |
+
* User: opentop_smionli
|
5 |
+
* Date: 2016/11/16
|
6 |
+
* Time: 14:29
|
7 |
+
*/
|
8 |
+
|
9 |
+
class Referboard_Retailer_Block_Test extends Mage_Core_Block_Template{
|
10 |
+
|
11 |
+
}
|
app/code/community/Referboard/Retailer/Helper/Common.php
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by Smion Li.
|
4 |
+
* User: opentop_smionli
|
5 |
+
* Date: 2016/11/16
|
6 |
+
* Time: 15:03
|
7 |
+
*/
|
8 |
+
require_once(Mage::getBaseDir('lib') . '/Referboard/Referboard_Plugin_Class.php');
|
9 |
+
|
10 |
+
|
11 |
+
class Referboard_Retailer_Helper_Common extends Mage_Core_Helper_Abstract
|
12 |
+
{
|
13 |
+
|
14 |
+
public $api_key;
|
15 |
+
public $referboard;
|
16 |
+
public function __construct()
|
17 |
+
{
|
18 |
+
$this->api_key = Mage::getStoreConfig('referboard_retailer_options/section/api_key');
|
19 |
+
|
20 |
+
if (!empty( $this->api_key)) {
|
21 |
+
/**
|
22 |
+
* Only generate button when there is an api key
|
23 |
+
*/
|
24 |
+
$this->referboard = new Referboard_Plugin_Class($this->api_key);
|
25 |
+
}
|
26 |
+
}
|
27 |
+
|
28 |
+
public function generateReferbutton($product)
|
29 |
+
{
|
30 |
+
|
31 |
+
if (isset($this->referboard) && isset($product)) {
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Firstly need to capture request data
|
35 |
+
*/
|
36 |
+
|
37 |
+
$referboard_params = $this->referboard->captureReferboardParams($_REQUEST,'cookie');
|
38 |
+
|
39 |
+
if(!empty($referboard_params['rf_product']) && $referboard_params['buyer_history'] ==0) {
|
40 |
+
/**
|
41 |
+
* Try to get referboard params in request data, or
|
42 |
+
* If user still has a cookies period
|
43 |
+
*/
|
44 |
+
$_SESSION['referboard'] = $referboard_params;
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Only generate reerboard refer button when there is api key and product is available
|
49 |
+
*/
|
50 |
+
$price = !empty($product->getFinalPrice())?$product->getFinalPrice():$product->getPrice();
|
51 |
+
|
52 |
+
$image_list = [];
|
53 |
+
|
54 |
+
foreach ($product->getMediaGalleryImages() as $image) {
|
55 |
+
$image_list[] = $image->getUrl();
|
56 |
+
}
|
57 |
+
|
58 |
+
|
59 |
+
$data = [];
|
60 |
+
$data['product_id'] = $product->getId();
|
61 |
+
$data['product_title'] = $product->getName();
|
62 |
+
$data['product_desc'] = $product->getDescription();
|
63 |
+
$data['product_image'] = Mage::getModel('catalog/product_media_config')->getMediaUrl($product->getImage());;
|
64 |
+
$data['product_image_list'] = $image_list;
|
65 |
+
$data['product_price'] = $price;
|
66 |
+
$data['product_price_type'] = Mage::app()->getStore()->getCurrentCurrencyCode();;
|
67 |
+
$data['product_url'] = $product->getProductUrl();
|
68 |
+
$data['product_retailer_id'] = $this->api_key;
|
69 |
+
|
70 |
+
// return $data;
|
71 |
+
return $this->referboard->generateReferButtonCode($data,'full');
|
72 |
+
|
73 |
+
}
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Home Page Tracking Code
|
78 |
+
* @param array $data
|
79 |
+
* @return bool|string false | output string
|
80 |
+
*/
|
81 |
+
public function generateHomePageCode(array $data = [],$type='all'){
|
82 |
+
|
83 |
+
if(isset($this->referboard))
|
84 |
+
{
|
85 |
+
return $this->referboard->generateHomePageCode([],'all');
|
86 |
+
}else{
|
87 |
+
return '';
|
88 |
+
}
|
89 |
+
}
|
90 |
+
|
91 |
+
}
|
app/code/community/Referboard/Retailer/Helper/Data.php
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by PhpStorm.
|
4 |
+
* User: opentopmedia-dev5
|
5 |
+
* Date: 16/11/16
|
6 |
+
* Time: 11:57 AM
|
7 |
+
*/
|
8 |
+
|
9 |
+
class Referboard_Retailer_Helper_Data extends Mage_Core_Helper_Abstract
|
10 |
+
{
|
11 |
+
public function test(){
|
12 |
+
return 'test_val';
|
13 |
+
}
|
14 |
+
}
|
app/code/community/Referboard/Retailer/Model/Data.php
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by Smion Li.
|
4 |
+
* User: opentop_smionli
|
5 |
+
* Date: 2016/11/16
|
6 |
+
* Time: 16:48
|
7 |
+
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Class Referboard_Retailer_Model_Data
|
11 |
+
* @author smion@referboard.com
|
12 |
+
*/
|
13 |
+
class Referboard_Retailer_Model_Data extends Mage_Core_Model_Abstract {
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Define resource model
|
17 |
+
*/
|
18 |
+
protected function _construct()
|
19 |
+
{
|
20 |
+
$this->_init('referboard_retailer/data','id');
|
21 |
+
}
|
22 |
+
|
23 |
+
public function getTest(){
|
24 |
+
$resource = $this->_getResource();
|
25 |
+
echo get_class($resource);
|
26 |
+
}
|
27 |
+
|
28 |
+
/**
|
29 |
+
* If object is new adds creation date
|
30 |
+
* @return Referboard_Retailer_Model_Data
|
31 |
+
*/
|
32 |
+
protected function _beforeSave()
|
33 |
+
{
|
34 |
+
parent::_beforeSave();
|
35 |
+
|
36 |
+
if($this->isObjectNew()){
|
37 |
+
$this->setData('created', date("Y-m-d H:i:s"));
|
38 |
+
}
|
39 |
+
|
40 |
+
$this->setData('modified', date("Y-m-d H:i:s"));
|
41 |
+
return $this;
|
42 |
+
}
|
43 |
+
}
|
app/code/community/Referboard/Retailer/Model/Observer.php
ADDED
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once(Mage::getBaseDir('lib') . '/Referboard/Referboard_Plugin_Class.php');
|
3 |
+
class Referboard_Retailer_Model_Observer
|
4 |
+
{
|
5 |
+
|
6 |
+
|
7 |
+
public function saveOrder($observer)
|
8 |
+
{
|
9 |
+
|
10 |
+
$order = $observer->getOrder();
|
11 |
+
|
12 |
+
$session_data = isset($_SESSION['referboard'])?$_SESSION['referboard']:null;
|
13 |
+
|
14 |
+
if(!empty($order) && !empty($session_data))
|
15 |
+
{
|
16 |
+
/**
|
17 |
+
* Only save order details when there is an order, and referboard session
|
18 |
+
*/
|
19 |
+
|
20 |
+
$order_id = $order->getIncrementId();
|
21 |
+
|
22 |
+
$total_amount = $order->getBaseGrandTotal()-$order->getShippingAmount();
|
23 |
+
|
24 |
+
$rf_postback_data = [
|
25 |
+
'id' => $session_data['rf_product'],
|
26 |
+
'amount' => $total_amount,
|
27 |
+
'currency' => Mage::getStoreConfig('referboard_retailer_options/section/price_currency'),
|
28 |
+
'cid' => $session_data['rf_user'],
|
29 |
+
'rkey' => Mage::getStoreConfig('referboard_retailer_options/section/api_key'),
|
30 |
+
'email' => $order->getCustomerEmail(),
|
31 |
+
'buyer_ip' => !empty($session_data['rf_buyer_ip'])?$session_data['rf_buyer_ip']:$_SERVER['REMOTE_ADDR'],
|
32 |
+
'buyer_history' => 0,
|
33 |
+
'tid' => $order_id,
|
34 |
+
'extra' => 'freetext'
|
35 |
+
];
|
36 |
+
|
37 |
+
$session_data_json = json_encode($rf_postback_data);
|
38 |
+
|
39 |
+
$data_model = Mage::getModel("referboard_retailer/data");
|
40 |
+
$data_model->load($order_id);
|
41 |
+
|
42 |
+
if(!$data_model->getId()){
|
43 |
+
$data_model = Mage::getModel("referboard_retailer/data");
|
44 |
+
$data = array(
|
45 |
+
'id' => $order_id,
|
46 |
+
'json_data' => $session_data_json
|
47 |
+
);
|
48 |
+
|
49 |
+
$data_model->setData($data);
|
50 |
+
$data_model->isObjectNew(true);
|
51 |
+
$data_model->save();
|
52 |
+
}else{
|
53 |
+
$data = $data_model->getData();
|
54 |
+
}
|
55 |
+
|
56 |
+
}
|
57 |
+
|
58 |
+
|
59 |
+
}
|
60 |
+
|
61 |
+
|
62 |
+
/**
|
63 |
+
*
|
64 |
+
* Send order details to referboard for saving transaction sale
|
65 |
+
* @param $observer
|
66 |
+
*/
|
67 |
+
public function sendOrderToReferboard($observer)
|
68 |
+
{
|
69 |
+
|
70 |
+
$api_key = Mage::getStoreConfig('referboard_retailer_options/section/api_key');
|
71 |
+
|
72 |
+
if(!empty($api_key))
|
73 |
+
{
|
74 |
+
/**
|
75 |
+
* Only if retailer has set up api key, and then we need to check referboard call back
|
76 |
+
*/
|
77 |
+
|
78 |
+
/**
|
79 |
+
* First need to get invoice details
|
80 |
+
*/
|
81 |
+
$invoice = $observer->getEvent()->getInvoice();
|
82 |
+
$order = $invoice->getOrder();
|
83 |
+
$order_id = $order->getIncrementId();
|
84 |
+
$data_model = Mage::getModel("referboard_retailer/data");
|
85 |
+
$data_model->load($order_id);
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Get saved order details from database
|
89 |
+
*/
|
90 |
+
$order_data = $data_model->getData();
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Delete saved data
|
94 |
+
*/
|
95 |
+
$data_model->delete();
|
96 |
+
if(!empty($order_data))
|
97 |
+
{
|
98 |
+
/**
|
99 |
+
* Only if we can find saved order details from database means this is the sales from referbaord
|
100 |
+
*/
|
101 |
+
|
102 |
+
$referboard = new Referboard_Plugin_Class($api_key);
|
103 |
+
|
104 |
+
|
105 |
+
$referboard_data_json = $order_data['json_data'];
|
106 |
+
$referboard_data = json_decode($referboard_data_json,true);
|
107 |
+
$total_amount = $order->getBaseGrandTotal()-$order->getShippingAmount();
|
108 |
+
$referboard_data['amount'] = $total_amount;
|
109 |
+
|
110 |
+
$result = $referboard->sendTransactionData($referboard_data);
|
111 |
+
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
|
116 |
+
|
117 |
+
|
118 |
+
|
119 |
+
//
|
120 |
+
}
|
121 |
+
|
122 |
+
|
123 |
+
// public function sendOrderToReferboard(Varien_Event_Observer $observer){
|
124 |
+
// $block = $observer->getBlock();
|
125 |
+
// $type = $block->getType();
|
126 |
+
// if($type=='catalog/product_price'){
|
127 |
+
//
|
128 |
+
// }
|
129 |
+
// }
|
130 |
+
|
131 |
+
public function test(){}
|
132 |
+
}
|
app/code/community/Referboard/Retailer/Model/Resource/Data.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by Smion Li.
|
4 |
+
* User: opentop_smionli
|
5 |
+
* Date: 2016/11/16
|
6 |
+
* Time: 16:55
|
7 |
+
*/
|
8 |
+
|
9 |
+
class Referboard_Retailer_Model_Resource_Data extends Mage_Core_Model_Resource_Db_Abstract {
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Init
|
13 |
+
*/
|
14 |
+
protected function _construct()
|
15 |
+
{
|
16 |
+
$this->_init('referboard_retailer/data','id');
|
17 |
+
$this->_isPkAutoIncrement = false;
|
18 |
+
}
|
19 |
+
}
|
app/code/community/Referboard/Retailer/Model/Resource/Data/Collection.php
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by Smion Li.
|
4 |
+
* User: opentop_smionli
|
5 |
+
* Date: 2016/11/16
|
6 |
+
* Time: 17:54
|
7 |
+
*/
|
8 |
+
|
9 |
+
class Referboard_Retailer_Model_Resource_Data_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract {
|
10 |
+
public function _construct()
|
11 |
+
{
|
12 |
+
$this->_init('referboard_retailer/data','id');
|
13 |
+
}
|
14 |
+
}
|
app/code/community/Referboard/Retailer/etc/config.xml
ADDED
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
|
3 |
+
<!-- The root node for Magento module configuration -->
|
4 |
+
<config>
|
5 |
+
|
6 |
+
<!--
|
7 |
+
The module's node contains basic
|
8 |
+
information about each Magento module
|
9 |
+
-->
|
10 |
+
<modules>
|
11 |
+
|
12 |
+
<!--
|
13 |
+
This must exactly match the namespace and module's folder
|
14 |
+
names, with directory separators replaced by underscores
|
15 |
+
-->
|
16 |
+
<Referboard_Retailer>
|
17 |
+
|
18 |
+
<!-- The version of our module, starting at 0.0.1 -->
|
19 |
+
<version>1.0.3</version>
|
20 |
+
|
21 |
+
</Referboard_Retailer>
|
22 |
+
|
23 |
+
</modules>
|
24 |
+
|
25 |
+
|
26 |
+
<frontend>
|
27 |
+
<layout>
|
28 |
+
<updates>
|
29 |
+
<referboard_retailer>
|
30 |
+
<file>referboard_retailer.xml</file>
|
31 |
+
</referboard_retailer>
|
32 |
+
</updates>
|
33 |
+
</layout>
|
34 |
+
</frontend>
|
35 |
+
|
36 |
+
<global>
|
37 |
+
<helpers>
|
38 |
+
<retailer>
|
39 |
+
<class>Referboard_Retailer_Helper</class>
|
40 |
+
</retailer>
|
41 |
+
</helpers>
|
42 |
+
<resources>
|
43 |
+
<referboard_retailer_setup>
|
44 |
+
<setup>
|
45 |
+
<module>Referboard_Retailer</module>
|
46 |
+
<class>Mage_Core_Model_Resource_Setup</class>
|
47 |
+
</setup>
|
48 |
+
</referboard_retailer_setup>
|
49 |
+
</resources>
|
50 |
+
<models>
|
51 |
+
<referboard_retailer>
|
52 |
+
<class>Referboard_Retailer_Model</class>
|
53 |
+
<resourceModel>referboard_retailer_resource</resourceModel>
|
54 |
+
</referboard_retailer>
|
55 |
+
|
56 |
+
<referboard_retailer_resource>
|
57 |
+
<class>Referboard_Retailer_Model_Resource</class>
|
58 |
+
<entities>
|
59 |
+
<data>
|
60 |
+
<table>referboard_retailer</table>
|
61 |
+
</data>
|
62 |
+
</entities>
|
63 |
+
</referboard_retailer_resource>
|
64 |
+
</models>
|
65 |
+
|
66 |
+
<!-- end data base setup -->
|
67 |
+
|
68 |
+
<blocks>
|
69 |
+
<referboard_retailer><class>Referboard_Retailer_Block</class></referboard_retailer>
|
70 |
+
</blocks>
|
71 |
+
|
72 |
+
<!-- Defining an event observer -->
|
73 |
+
<events>
|
74 |
+
|
75 |
+
<sales_order_place_after>
|
76 |
+
<!-- Defining an observer for this event -->
|
77 |
+
<observers>
|
78 |
+
|
79 |
+
<referboard_retailer>
|
80 |
+
|
81 |
+
<!-- The model to be instantiated -->
|
82 |
+
<class>referboard_retailer/observer</class>
|
83 |
+
|
84 |
+
<!-- The method of the class to be called -->
|
85 |
+
<method>saveOrder</method>
|
86 |
+
|
87 |
+
<!-- The type of class to instantiate -->
|
88 |
+
<type>singleton</type>
|
89 |
+
|
90 |
+
</referboard_retailer>
|
91 |
+
|
92 |
+
</observers>
|
93 |
+
|
94 |
+
</sales_order_place_after>
|
95 |
+
|
96 |
+
<sales_order_invoice_pay>
|
97 |
+
<observers>
|
98 |
+
|
99 |
+
<referboard_retailer>
|
100 |
+
|
101 |
+
<!-- The model to be instantiated -->
|
102 |
+
<class>referboard_retailer/observer</class>
|
103 |
+
|
104 |
+
<!-- The method of the class to be called -->
|
105 |
+
<method>sendOrderToReferboard</method>
|
106 |
+
|
107 |
+
<!-- The type of class to instantiate -->
|
108 |
+
<type>singleton</type>
|
109 |
+
|
110 |
+
</referboard_retailer>
|
111 |
+
|
112 |
+
</observers>
|
113 |
+
</sales_order_invoice_pay>
|
114 |
+
|
115 |
+
</events>
|
116 |
+
|
117 |
+
</global>
|
118 |
+
|
119 |
+
|
120 |
+
<adminhtml>
|
121 |
+
<acl>
|
122 |
+
<resources>
|
123 |
+
<admin>
|
124 |
+
<children>
|
125 |
+
<system>
|
126 |
+
<children>
|
127 |
+
<config>
|
128 |
+
<children>
|
129 |
+
<referboard_retailer_options>
|
130 |
+
<title>Referboard Retailer Setting</title>
|
131 |
+
</referboard_retailer_options>
|
132 |
+
</children>
|
133 |
+
</config>
|
134 |
+
</children>
|
135 |
+
</system>
|
136 |
+
</children>
|
137 |
+
</admin>
|
138 |
+
</resources>
|
139 |
+
</acl>
|
140 |
+
</adminhtml>
|
141 |
+
|
142 |
+
</config>
|
app/code/community/Referboard/Retailer/etc/system.xml
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
|
3 |
+
<!-- The root node for Magento module configuration -->
|
4 |
+
<config>
|
5 |
+
|
6 |
+
<tabs>
|
7 |
+
<retailer translate="label" module="retailer">
|
8 |
+
<label>Referboard Setting</label>
|
9 |
+
<sort_order>1</sort_order>
|
10 |
+
</retailer>
|
11 |
+
</tabs>
|
12 |
+
|
13 |
+
<sections>
|
14 |
+
<referboard_retailer_options translate="label" module="retailer">
|
15 |
+
<label>Referboard Retailer Settings</label>
|
16 |
+
<tab>retailer</tab>
|
17 |
+
<frontend_type>text</frontend_type>
|
18 |
+
<sort_order>1</sort_order>
|
19 |
+
<show_in_default>1</show_in_default>
|
20 |
+
<show_in_website>1</show_in_website>
|
21 |
+
<show_in_store>1</show_in_store>
|
22 |
+
<groups>
|
23 |
+
<section translate="label">
|
24 |
+
<label>Setting</label>
|
25 |
+
<frontend_type>text</frontend_type>
|
26 |
+
<sort_order>1</sort_order>
|
27 |
+
<show_in_default>1</show_in_default>
|
28 |
+
<show_in_website>1</show_in_website>
|
29 |
+
<show_in_store>1</show_in_store>
|
30 |
+
<fields>
|
31 |
+
<api_key>
|
32 |
+
<label>API Key</label>
|
33 |
+
<frontend_type>text</frontend_type>
|
34 |
+
<sort_order>1</sort_order>
|
35 |
+
<show_in_default>1</show_in_default>
|
36 |
+
<show_in_website>1</show_in_website>
|
37 |
+
<show_in_store>1</show_in_store>
|
38 |
+
<comment>You Referboard API Key</comment>
|
39 |
+
</api_key>
|
40 |
+
|
41 |
+
<price_currency>
|
42 |
+
<label>Currency</label>
|
43 |
+
<frontend_type>text</frontend_type>
|
44 |
+
<sort_order>2</sort_order>
|
45 |
+
<show_in_default>1</show_in_default>
|
46 |
+
<show_in_website>1</show_in_website>
|
47 |
+
<show_in_store>1</show_in_store>
|
48 |
+
<comment>Product Price Currency.</comment>
|
49 |
+
</price_currency>
|
50 |
+
</fields>
|
51 |
+
|
52 |
+
</section>
|
53 |
+
|
54 |
+
</groups>
|
55 |
+
</referboard_retailer_options>
|
56 |
+
</sections>
|
57 |
+
|
58 |
+
</config>
|
app/code/community/Referboard/Retailer/sql/referboard_retailer_setup/install-1.0.0.php
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by Smion Li.
|
4 |
+
* User: opentop_smionli
|
5 |
+
* Date: 2016/11/16
|
6 |
+
* Time: 16:09
|
7 |
+
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Referboard Retailer Data Installation Script
|
11 |
+
* @author smion@referboard.com
|
12 |
+
*/
|
13 |
+
|
14 |
+
|
15 |
+
/* @var $installer Mage_Core_Model_Resource_Setup */
|
16 |
+
$installer = $this;
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Creating
|
20 |
+
*/
|
21 |
+
|
22 |
+
$table = $installer->getConnection()->newTable($installer->getTable('referboard_retailer/data'))
|
23 |
+
->addColumn('id',Varien_Db_Ddl_Table::TYPE_INTEGER, 10,
|
24 |
+
array(
|
25 |
+
'unsigned' => true,
|
26 |
+
'identity' => true,
|
27 |
+
'nullable' => false,
|
28 |
+
'primary' => true,
|
29 |
+
), 'Entity Id')
|
30 |
+
|
31 |
+
->addColumn('type',Varien_Db_Ddl_Table::TYPE_VARCHAR, 20,
|
32 |
+
array(
|
33 |
+
'nullable' => false,
|
34 |
+
'default' => 'order'
|
35 |
+
), 'Type')
|
36 |
+
|
37 |
+
->addColumn('value',Varien_Db_Ddl_Table::TYPE_VARCHAR, 255,
|
38 |
+
array(
|
39 |
+
'nullable' => false,
|
40 |
+
'default' => ''
|
41 |
+
), 'Value')
|
42 |
+
|
43 |
+
->addColumn('json_data',Varien_Db_Ddl_Table::TYPE_TEXT, null,
|
44 |
+
array(
|
45 |
+
'nullable' => false,
|
46 |
+
), 'JSON Data')
|
47 |
+
|
48 |
+
->addColumn('created',Varien_Db_Ddl_Table::TYPE_DATETIME, null,
|
49 |
+
array(
|
50 |
+
'nullable' => true,
|
51 |
+
'default' => null
|
52 |
+
), 'Creation Time')
|
53 |
+
|
54 |
+
->addColumn('modified',Varien_Db_Ddl_Table::TYPE_DATETIME, null,
|
55 |
+
array(
|
56 |
+
'nullable' => true,
|
57 |
+
'default' => null
|
58 |
+
), 'Updated Time')
|
59 |
+
|
60 |
+
->addIndex(
|
61 |
+
$installer->getIdxName($installer->getTable('referboard_retailer/data'),array('type'),Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX),
|
62 |
+
array('type'),array('type'=>Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX))
|
63 |
+
|
64 |
+
->setComment('Referboard Retailer Item')
|
65 |
+
;
|
66 |
+
|
67 |
+
Mage::log("init this",null,'mylogfile.log',true);
|
68 |
+
|
69 |
+
if (!$installer->getConnection()->isTableExists($installer->getTable('referboard_retailer/data'))) {
|
70 |
+
$installer->getConnection()->createTable($table);
|
71 |
+
}
|
app/code/community/Referboard/Retailer/sql/referboard_retailer_setup/install-1.0.3.php
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by Smion Li.
|
4 |
+
* User: opentop_smionli
|
5 |
+
* Date: 2016/11/16
|
6 |
+
* Time: 16:09
|
7 |
+
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Referboard Retailer Data Installation Script
|
11 |
+
* @author smion@referboard.com
|
12 |
+
*/
|
13 |
+
|
14 |
+
|
15 |
+
/* @var $installer Mage_Core_Model_Resource_Setup */
|
16 |
+
$installer = $this;
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Creating
|
20 |
+
*/
|
21 |
+
|
22 |
+
$table = $installer->getConnection()->newTable($installer->getTable('referboard_retailer/data'))
|
23 |
+
->addColumn('id',Varien_Db_Ddl_Table::TYPE_INTEGER, 10,
|
24 |
+
array(
|
25 |
+
'unsigned' => true,
|
26 |
+
'identity' => true,
|
27 |
+
'nullable' => false,
|
28 |
+
'primary' => true,
|
29 |
+
), 'Entity Id')
|
30 |
+
|
31 |
+
->addColumn('type',Varien_Db_Ddl_Table::TYPE_VARCHAR, 20,
|
32 |
+
array(
|
33 |
+
'nullable' => false,
|
34 |
+
'default' => 'order'
|
35 |
+
), 'Type')
|
36 |
+
|
37 |
+
->addColumn('value',Varien_Db_Ddl_Table::TYPE_VARCHAR, 255,
|
38 |
+
array(
|
39 |
+
'nullable' => false,
|
40 |
+
'default' => ''
|
41 |
+
), 'Value')
|
42 |
+
|
43 |
+
->addColumn('json_data',Varien_Db_Ddl_Table::TYPE_TEXT, null,
|
44 |
+
array(
|
45 |
+
'nullable' => false,
|
46 |
+
), 'JSON Data')
|
47 |
+
|
48 |
+
->addColumn('created',Varien_Db_Ddl_Table::TYPE_DATETIME, null,
|
49 |
+
array(
|
50 |
+
'nullable' => true,
|
51 |
+
'default' => null
|
52 |
+
), 'Creation Time')
|
53 |
+
|
54 |
+
->addColumn('modified',Varien_Db_Ddl_Table::TYPE_DATETIME, null,
|
55 |
+
array(
|
56 |
+
'nullable' => true,
|
57 |
+
'default' => null
|
58 |
+
), 'Updated Time')
|
59 |
+
|
60 |
+
->addIndex(
|
61 |
+
$installer->getIdxName($installer->getTable('referboard_retailer/data'),array('type'),Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX),
|
62 |
+
array('type'),array('type'=>Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX))
|
63 |
+
|
64 |
+
->setComment('Referboard Retailer Item')
|
65 |
+
;
|
66 |
+
|
67 |
+
Mage::log("init this:".$installer->getTable('referboard_retailer/data'),null,'mylogfile.log',true);
|
68 |
+
|
69 |
+
|
70 |
+
if (!$installer->getConnection()->isTableExists($installer->getTable('referboard_retailer/data'))) {
|
71 |
+
Mage::log("init this start:".$installer->getTable('referboard_retailer/data'),null,'mylogfile.log',true);
|
72 |
+
|
73 |
+
$result = $installer->getConnection()->createTable($table);
|
74 |
+
Mage::log("init this end:".$result,null,'mylogfile.log',true);
|
75 |
+
|
76 |
+
}
|
app/design/frontend/base/default/layout/referboard_retailer.xml
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<layout version="0.1.0">
|
3 |
+
<default>
|
4 |
+
<reference name="head">
|
5 |
+
<!--<block type="core/text" name="referboard_js">-->
|
6 |
+
<!--<action method="setText"><text><![CDATA[<script src="//www.referboard.com/js/referButton/cookie_track.js"></script>]]></text></action>-->
|
7 |
+
<!--</block>-->
|
8 |
+
|
9 |
+
<block type="core/template" name="referboard_header_block" as="referboard_header_block" template="referboard_retailer/header.phtml" />
|
10 |
+
</reference>
|
11 |
+
</default>
|
12 |
+
|
13 |
+
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
<catalog_product_view>
|
18 |
+
<!--<reference name="head">-->
|
19 |
+
<!--<block type="core/template" name="referboard_block" as="referboard_block" template="referboard_retailer/button.phtml" />-->
|
20 |
+
<!--</reference>-->
|
21 |
+
<!-- Allow you to change the content of the product area -->
|
22 |
+
<reference name="product.info.extrahint">
|
23 |
+
<block type="core/template" name="referboard_block" as="referboard_block" template="referboard_retailer/button.phtml" />
|
24 |
+
</reference>
|
25 |
+
</catalog_product_view>
|
26 |
+
</layout>
|
app/design/frontend/base/default/template/referboard_retailer/button.phtml
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
<?php
|
3 |
+
|
4 |
+
|
5 |
+
|
6 |
+
$help = Mage::helper('retailer/common');
|
7 |
+
//
|
8 |
+
|
9 |
+
$_product = Mage::registry('current_product');
|
10 |
+
|
11 |
+
echo $help->generateReferbutton($_product);
|
app/design/frontend/base/default/template/referboard_retailer/header.phtml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
$help = Mage::helper('retailer/common');
|
5 |
+
|
6 |
+
echo $help->generateHomePageCode([],'all');
|
app/design/frontend/base/default/template/referboard_retailer/index.phtml
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
<?php
|
3 |
+
// $orderId = $this->getOrderId();
|
4 |
+
// if($orderId){
|
5 |
+
// $orders = Mage::getModel('sales/order')->loadByIncrementId($orderId);
|
6 |
+
// $orderItems = $orders->getAllVisibleItems();
|
7 |
+
// $storeName = Mage::app()->getStore()->getName();
|
8 |
+
// $grandTotal = $orders->getData('grand_total');
|
9 |
+
// $shipping = $orders->getData('shipping_amount');
|
10 |
+
// $taxAmount = $orders->getData('tax_amount');
|
11 |
+
// // Transaction Data
|
12 |
+
// $trans = array('id'=>$orderId, 'affiliation'=>$storeName,'revenue'=>$grandTotal, 'shipping'=>$shipping, 'tax'=>$taxAmount);
|
13 |
+
//
|
14 |
+
// // List of Items Purchased.
|
15 |
+
// $items = array();
|
16 |
+
// foreach($orderItems as $item)
|
17 |
+
// {
|
18 |
+
// $productId = $item->getData('product_id');
|
19 |
+
// $name = $item->getData('name');
|
20 |
+
// $price = $item->getData('price');
|
21 |
+
// $sku = $item->getSku();
|
22 |
+
// $qty = $item->getQtyOrdered();
|
23 |
+
// $product = Mage::getModel('catalog/product')->load($productId);
|
24 |
+
// $categories = $product->getCategoryIds();
|
25 |
+
// foreach ($categories as $categoryId) {
|
26 |
+
// $category = Mage::getModel('catalog/category')->load($categoryId) ;
|
27 |
+
// $catName = $category->getName();
|
28 |
+
// }
|
29 |
+
// $items[] = array('sku'=>$sku, 'name'=>$name, 'category'=>$catName, 'price'=>$price, 'quantity'=>$qty);
|
30 |
+
// }
|
31 |
+
// }
|
32 |
+
?>
|
33 |
+
<?php
|
34 |
+
// Function to return the JavaScript representation of a TransactionData object.
|
35 |
+
//function getTransactionJs(&$trans) {
|
36 |
+
// return <<<HTML
|
37 |
+
//ga('ecommerce:addTransaction', {
|
38 |
+
// 'id': '{$trans['id']}',
|
39 |
+
// 'affiliation': '{$trans['affiliation']}',
|
40 |
+
// 'revenue': '{$trans['revenue']}',
|
41 |
+
// 'shipping': '{$trans['shipping']}',
|
42 |
+
// 'tax': '{$trans['tax']}'
|
43 |
+
//});
|
44 |
+
//HTML;
|
45 |
+
//}
|
46 |
+
//
|
47 |
+
//// Function to return the JavaScript representation of an ItemData object.
|
48 |
+
//function getItemJs(&$transId, &$item) {
|
49 |
+
// return <<<HTML
|
50 |
+
//ga('ecommerce:addItem', {
|
51 |
+
// 'id': '$transId',
|
52 |
+
// 'name': '{$item['name']}',
|
53 |
+
// 'sku': '{$item['sku']}',
|
54 |
+
// 'category': '{$item['category']}',
|
55 |
+
// 'price': '{$item['price']}',
|
56 |
+
// 'quantity': '{$item['quantity']}'
|
57 |
+
//});
|
58 |
+
//HTML;
|
59 |
+
//}
|
60 |
+
?>
|
61 |
+
123123123123
|
62 |
+
<script type="text/javascript"> console.log('load index');</script>
|
63 |
+
|
app/etc/modules/Referboard_Retailer.xml
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Referboard_Retailer>
|
5 |
+
|
6 |
+
<!-- Whether our module is active: true or false -->
|
7 |
+
<active>true</active>
|
8 |
+
|
9 |
+
<!-- Which code pool to use: core, community or local -->
|
10 |
+
<codePool>community</codePool>
|
11 |
+
|
12 |
+
</Referboard_Retailer>
|
13 |
+
</modules>
|
14 |
+
|
15 |
+
<frontend>
|
16 |
+
<models>
|
17 |
+
<refeboard_retailer>
|
18 |
+
<class>Referboard_Retailer_Model</class>
|
19 |
+
</refeboard_retailer>
|
20 |
+
</models>
|
21 |
+
|
22 |
+
|
23 |
+
<!--<events>-->
|
24 |
+
<!--<core_block_abstract_to_html_before>-->
|
25 |
+
<!--<observers>-->
|
26 |
+
<!--<refeboard_retailer>-->
|
27 |
+
<!--<type>singletion</type>-->
|
28 |
+
<!--<class>Referboard_Retailer_Model_Observer</class>-->
|
29 |
+
<!--<method>addButton</method>-->
|
30 |
+
<!--</refeboard_retailer>-->
|
31 |
+
<!--</observers>-->
|
32 |
+
<!--</core_block_abstract_to_html_before>-->
|
33 |
+
<!--</events>-->
|
34 |
+
</frontend>
|
35 |
+
</config>
|
lib/Referboard/Referboard_Plugin_Class.php
ADDED
@@ -0,0 +1,507 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* User: referboard_smionli
|
5 |
+
* Date: 2016/8/17
|
6 |
+
* Time: 17:29
|
7 |
+
* @author: smion.li<smion@referboard.com>
|
8 |
+
* @description: base class for different platform plugin
|
9 |
+
*/
|
10 |
+
class Referboard_Plugin_Class
|
11 |
+
{
|
12 |
+
const CALLBACK_URL = 'https://www.referboard.com/referSales/purchase';
|
13 |
+
const tracker_table = 'referboard_tracker';
|
14 |
+
const CHECK_RETAILER_URL = "https://www.referboard.com/webservice/";
|
15 |
+
const SERVER_API = "refer123Nipo12j)12mn";
|
16 |
+
// const SERVER_DOMAIN = 'www.referboard.com';
|
17 |
+
const SERVER_DOMAIN = 'www.referboard.com';
|
18 |
+
|
19 |
+
public $api_key;
|
20 |
+
public $availableRetailer = false;
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Creates a new instance for the model
|
24 |
+
* @param $api retailer api code
|
25 |
+
*/
|
26 |
+
public function __construct($api)
|
27 |
+
{
|
28 |
+
$this->setApi_Key($api);
|
29 |
+
}
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Setup Api Key and automatically check api available
|
33 |
+
* @param $api
|
34 |
+
*/
|
35 |
+
public function setApi_Key($api){
|
36 |
+
$this->api_key = $api;
|
37 |
+
//$this->checkApiAvailable();
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* check retailer api key is available
|
42 |
+
*/
|
43 |
+
public function checkApiAvailable(){
|
44 |
+
$data = [
|
45 |
+
'command' => 'checkRetailerApi',
|
46 |
+
'api_key' => $this->api_key,
|
47 |
+
];
|
48 |
+
$result = $this->curlSend($data,$this::CHECK_RETAILER_URL);
|
49 |
+
|
50 |
+
/**
|
51 |
+
* check retailer
|
52 |
+
* @TODO: need to apply status checking
|
53 |
+
*/
|
54 |
+
if($result['accept']){
|
55 |
+
$result_data = json_decode($result['response'],true);
|
56 |
+
if($result_data && isset($result_data['result']) && $result_data['result']==true){
|
57 |
+
$this->availableRetailer = true;
|
58 |
+
return true;
|
59 |
+
}
|
60 |
+
}
|
61 |
+
$this->availableRetailer = false;
|
62 |
+
return false;
|
63 |
+
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Check Product Detail is correct or not
|
67 |
+
* @param array $data
|
68 |
+
* @return array|bool true | array of error
|
69 |
+
*/
|
70 |
+
protected function checkProductDetail(array &$data){
|
71 |
+
$error_result =[];
|
72 |
+
/**
|
73 |
+
* optional
|
74 |
+
*/
|
75 |
+
if(!isset($data['product_id'])){
|
76 |
+
$data['product_id'] = '';
|
77 |
+
}
|
78 |
+
|
79 |
+
if(!isset($data['product_desc'])){
|
80 |
+
$data['product_desc'] = '';
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* mandatory
|
85 |
+
*/
|
86 |
+
if(!isset($data['product_title'])){
|
87 |
+
$error_result['product_title'] = 'missed';
|
88 |
+
}
|
89 |
+
|
90 |
+
if(!isset($data['product_image'])){
|
91 |
+
$error_result['product_image'] = 'missed';
|
92 |
+
}
|
93 |
+
|
94 |
+
if(!isset($data['product_image_list'])){
|
95 |
+
$error_result['product_image_list'] = 'missed';
|
96 |
+
}else if(!is_array($data['product_image_list'])){
|
97 |
+
$error_result['product_image_list'] = 'not array';
|
98 |
+
}
|
99 |
+
|
100 |
+
if(!isset($data['product_price'])){
|
101 |
+
$error_result['product_price'] = 'missed';
|
102 |
+
}
|
103 |
+
|
104 |
+
if(!isset($data['product_price_type'])){
|
105 |
+
$error_result['product_price_type'] = 'missed';
|
106 |
+
}
|
107 |
+
|
108 |
+
if(!isset($data['product_url'])){
|
109 |
+
$error_result['product_url'] = 'missed';
|
110 |
+
}
|
111 |
+
|
112 |
+
|
113 |
+
/**
|
114 |
+
* api key
|
115 |
+
*/
|
116 |
+
if(!isset($data['product_retailer_id'])){
|
117 |
+
if(empty($this->api_key)){
|
118 |
+
$error_result['product_retailer_id'] = 'missed';
|
119 |
+
}else{
|
120 |
+
$data['product_retailer_id'] = $this->api_key;
|
121 |
+
}
|
122 |
+
}
|
123 |
+
|
124 |
+
if(!empty($error_result)){
|
125 |
+
return $error_result;
|
126 |
+
} else return true;
|
127 |
+
}
|
128 |
+
|
129 |
+
/**
|
130 |
+
* @param array $data
|
131 |
+
* @param string $output_type
|
132 |
+
* @return array|bool|string
|
133 |
+
*/
|
134 |
+
public function generateReferButtonCode(array $data,$output_type='full'){
|
135 |
+
|
136 |
+
$checkResult = $this->checkProductDetail($data);
|
137 |
+
|
138 |
+
if($checkResult === true){
|
139 |
+
|
140 |
+
$img_list = '';
|
141 |
+
foreach($data['product_image_list'] as $item){
|
142 |
+
$img_list .= "'".str_replace("'","\\'",$item)."' ,";
|
143 |
+
}
|
144 |
+
|
145 |
+
$top = "
|
146 |
+
|
147 |
+
<script type=\"text/javascript\">
|
148 |
+
//setup refer button settings
|
149 |
+
var refer_settings = {
|
150 |
+
//setup product id in referboard, recommend and it need to be unique [optional]
|
151 |
+
product_id: '".str_replace("'","\\'",$data['product_id'])."',
|
152 |
+
//product title [mandatory]
|
153 |
+
product_title: '".str_replace("'","\\'",$data['product_title'])."',
|
154 |
+
//product description [optional]
|
155 |
+
product_desc: '".str_replace("'","\\'",$data['product_desc'])."',
|
156 |
+
//product image url (full address) Use the largest product image [mandatory]
|
157 |
+
product_image: '".str_replace("'","\\'",$data['product_image'])."',
|
158 |
+
//array of image url links All other product images e.g. ['http://exmaple.com/123.jpg','http://example.com/123-2.jpg'], a [mandatory]
|
159 |
+
product_image_list: [".$img_list."],
|
160 |
+
//product price [mandatory]
|
161 |
+
product_price: '".$data['product_price']."',
|
162 |
+
//product price type, default is Australian dollar [mandatory]
|
163 |
+
product_price_type: '".$data['product_price_type']."',
|
164 |
+
//product url, full address include http or https [mandatory]
|
165 |
+
product_url: '".str_replace("'","\\'",$data['product_url'])."',
|
166 |
+
//setup retailer api key [mandatory]
|
167 |
+
product_retailer_id: '".str_replace("'","\\'",$data['product_retailer_id'])."'
|
168 |
+
};
|
169 |
+
var referPluginS = document.createElement('script');
|
170 |
+
referPluginS.async = true;
|
171 |
+
referPluginS.type = 'text/javascript';
|
172 |
+
var useSSL = 'https:' == document.location.protocol;
|
173 |
+
referPluginS.src = (useSSL ? 'https:' : 'http:') + '//".$this::SERVER_DOMAIN."/js/referButton/refer_popup.js';
|
174 |
+
var node = document.getElementsByTagName('script')[0];
|
175 |
+
node.parentNode.insertBefore(referPluginS, node);
|
176 |
+
var Refer_Opentop = Refer_Opentop || {};
|
177 |
+
Refer_Opentop.cmd = Refer_Opentop.cmd || [];
|
178 |
+
</script>
|
179 |
+
";
|
180 |
+
|
181 |
+
$button = "
|
182 |
+
|
183 |
+
<div id=\"referboard_button_div\">
|
184 |
+
<script type=\"text/javascript\">
|
185 |
+
Refer_Opentop.cmd.push(function(){
|
186 |
+
Refer_Opentop.load_popup(refer_settings,'referboard_button_div');
|
187 |
+
});
|
188 |
+
</script>
|
189 |
+
</div>
|
190 |
+
|
191 |
+
";
|
192 |
+
|
193 |
+
switch($output_type){
|
194 |
+
case 'top':
|
195 |
+
$result = $top;
|
196 |
+
break;
|
197 |
+
case 'button':
|
198 |
+
$result = $button;
|
199 |
+
break;
|
200 |
+
default:
|
201 |
+
$result = $top.$button;
|
202 |
+
break;
|
203 |
+
}
|
204 |
+
|
205 |
+
return $result;
|
206 |
+
}else return $checkResult;
|
207 |
+
}
|
208 |
+
|
209 |
+
/**
|
210 |
+
* Home Page Tracking Code
|
211 |
+
* @param array $data
|
212 |
+
* @return bool|string false | output string
|
213 |
+
*/
|
214 |
+
public function generateHomePageCode(array $data = [],$type='all'){
|
215 |
+
if(!empty($this->api_key)){
|
216 |
+
|
217 |
+
if($type=='all')
|
218 |
+
{
|
219 |
+
$output = "<script type=\"text/javascript\" src=\"//".$this::SERVER_DOMAIN."/js/referButton/cookie_track.js?api=".$this->api_key."\"></script>
";
|
220 |
+
}else{
|
221 |
+
$output = '//'.$this::SERVER_DOMAIN."/js/referButton/cookie_track.js?api=".$this->api_key;
|
222 |
+
}
|
223 |
+
|
224 |
+
}else $output = false;
|
225 |
+
return $output;
|
226 |
+
}
|
227 |
+
|
228 |
+
|
229 |
+
|
230 |
+
/**
|
231 |
+
* Check Transaction Data
|
232 |
+
* @param array $data
|
233 |
+
* @return array|bool
|
234 |
+
*/
|
235 |
+
protected function checkTransactionData(array &$data){
|
236 |
+
$error_result =[];
|
237 |
+
/**
|
238 |
+
* optional
|
239 |
+
*/
|
240 |
+
if(!isset($data['cid'])){
|
241 |
+
$data['cid'] = '';
|
242 |
+
}
|
243 |
+
|
244 |
+
if(!isset($data['extra'])){
|
245 |
+
$data['extra'] = '';
|
246 |
+
}
|
247 |
+
|
248 |
+
/**
|
249 |
+
* mandatory
|
250 |
+
*/
|
251 |
+
if(!isset($data['id'])){
|
252 |
+
$error_result['id'] = 'ref_product/id missed';
|
253 |
+
}
|
254 |
+
|
255 |
+
if(!isset($data['email'])){
|
256 |
+
$error_result['email'] = 'customer email missed';
|
257 |
+
}
|
258 |
+
|
259 |
+
if(!isset($data['amount'])){
|
260 |
+
$error_result['amount'] = 'missed';
|
261 |
+
}
|
262 |
+
|
263 |
+
if(!isset($data['buyer_ip'])){
|
264 |
+
$error_result['buyer_ip'] = 'missed';
|
265 |
+
}
|
266 |
+
|
267 |
+
if(!isset($data['buyer_history'])){
|
268 |
+
$error_result['buyer_history'] = 'missed';
|
269 |
+
}
|
270 |
+
|
271 |
+
if(!isset($data['currency'])){
|
272 |
+
$error_result['currency'] = 'missed';
|
273 |
+
}
|
274 |
+
|
275 |
+
if(!isset($data['tid'])){
|
276 |
+
$error_result['tid'] = 'transaction id missed';
|
277 |
+
}
|
278 |
+
|
279 |
+
|
280 |
+
/**
|
281 |
+
* api key
|
282 |
+
*/
|
283 |
+
if(!isset($data['rkey'])){
|
284 |
+
if(empty($this->api_key)){
|
285 |
+
$error_result['rkey'] = 'api key missed';
|
286 |
+
}else{
|
287 |
+
$data['rkey'] = $this->api_key;
|
288 |
+
}
|
289 |
+
}
|
290 |
+
|
291 |
+
if(!empty($error_result)){
|
292 |
+
return $error_result;
|
293 |
+
} else return true;
|
294 |
+
}
|
295 |
+
|
296 |
+
/**
|
297 |
+
* Confirmation Code for Confirmation Page with front end
|
298 |
+
* @param array $data
|
299 |
+
* @return array|bool|string
|
300 |
+
*/
|
301 |
+
public function generateConfirmationCode(array $data){
|
302 |
+
|
303 |
+
$checkResult = $this->checkTransactionData($data);
|
304 |
+
|
305 |
+
if($checkResult === true){
|
306 |
+
$output = "
|
307 |
+
|
308 |
+
<script type=\"text/javascript\">
|
309 |
+
var referPluginS = document.createElement('script');
|
310 |
+
referPluginS.async = true;
|
311 |
+
referPluginS.type = 'text/javascript';
|
312 |
+
var useSSL = 'https:' == document.location.protocol;
|
313 |
+
referPluginS.src = (useSSL ? 'https:' : 'http:') + '//".$this::SERVER_DOMAIN."/js/referButton/refer_popup.js';
|
314 |
+
var node = document.getElementsByTagName('script')[0];
|
315 |
+
node.parentNode.insertBefore(referPluginS, node);
|
316 |
+
var Refer_Opentop = Refer_Opentop || {};
|
317 |
+
Refer_Opentop.cmd = Refer_Opentop.cmd || [];
|
318 |
+
|
319 |
+
var tracking_params = {
|
320 |
+
// retailer API key
|
321 |
+
rkey: '".str_replace("'","\\'",$data['rkey'])."',
|
322 |
+
// refer product id
|
323 |
+
id: '".str_replace("'","\\'",$data['id'])."',
|
324 |
+
// referboard user's id
|
325 |
+
cid: '".str_replace("'","\\'",$data['cid'])."',
|
326 |
+
// customer's email
|
327 |
+
email: '".str_replace("'","\\'",$data['email'])."',
|
328 |
+
// order total
|
329 |
+
amount: '".str_replace("'","\\'",$data['amount'])."',
|
330 |
+
// verify the order
|
331 |
+
verify: 1,
|
332 |
+
//The ip address of buyer
|
333 |
+
buyer_ip: '".str_replace("'","\\'",$data['buyer_id'])."',
|
334 |
+
//Did user buy product in last one month
|
335 |
+
buyer_history:'".str_replace("'","\\'",$data['buyer_history'])."',
|
336 |
+
//currency, Three Characters for country by using ISO-4217 [optional, default will be AUD]
|
337 |
+
currency: '".str_replace("'","\\'",$data['currency'])."',
|
338 |
+
//retailer transaction id
|
339 |
+
tid:'".str_replace("'","\\'",$data['tid'])."',
|
340 |
+
//retailer reference, maximum 100 characters
|
341 |
+
extra:'".str_replace("'","\\'",$data['extra'])."',
|
342 |
+
//Request from js
|
343 |
+
frontend:1,
|
344 |
+
};
|
345 |
+
|
346 |
+
Refer_Opentop.cmd.push(function(){
|
347 |
+
//need to update cookies of buyer's buy history
|
348 |
+
Refer_Opentop.updateBuyHistoryCookies(tracking_params.buyer_history);
|
349 |
+
//Front end call back function
|
350 |
+
Refer_Opentop.successCallback(tracking_params);
|
351 |
+
}
|
352 |
+
</script>
|
353 |
+
|
354 |
+
";
|
355 |
+
return $output;
|
356 |
+
}else return $checkResult;
|
357 |
+
}
|
358 |
+
|
359 |
+
/**
|
360 |
+
* Send Transaction Data to referboard
|
361 |
+
* @param array $data
|
362 |
+
* @return array|bool|string true | error string | error array
|
363 |
+
*/
|
364 |
+
public function sendTransactionData(array $data){
|
365 |
+
$checkResult = $this->checkTransactionData($data);
|
366 |
+
|
367 |
+
if($checkResult === true){
|
368 |
+
$result = $this->curlSend($data,$this::CALLBACK_URL,'post');
|
369 |
+
|
370 |
+
/**
|
371 |
+
* check retailer
|
372 |
+
* @TODO: need to apply status checking
|
373 |
+
*/
|
374 |
+
if($result['accept']){
|
375 |
+
$result_data = json_decode($result['accept'],true);
|
376 |
+
if($result_data && isset($result_data['result']) && $result_data['result']===true){
|
377 |
+
return true;
|
378 |
+
}else return "invalid response from referboard:".$result['accept'];
|
379 |
+
}else return "send error:".$result['error'];
|
380 |
+
|
381 |
+
}else return $checkResult;
|
382 |
+
}
|
383 |
+
|
384 |
+
/**
|
385 |
+
* Capture Referboard Params
|
386 |
+
* @param $data ['rf_product'=>'','rf_buyer_ip'=> '','rf_rproduct'=>'','rf_user'=>'','buyer_history'=>'']
|
387 |
+
* @param string $type data|cookie
|
388 |
+
* @return array
|
389 |
+
*/
|
390 |
+
public function captureReferboardParams($data,$type='data')
|
391 |
+
{
|
392 |
+
$result = ['rf_product'=>'','rf_buyer_ip'=> '','rf_rproduct'=>'','rf_user'=>'','buyer_history'=>''];
|
393 |
+
switch($type){
|
394 |
+
case 'data':
|
395 |
+
$result['rf_product'] = empty($data['rf_product']) ? (empty($_REQUEST['rf_product']) ? '' : $_REQUEST['rf_product']) : $data['rf_product'];
|
396 |
+
$result['rf_buyer_ip'] = empty($data['rf_buyer_ip']) ? (empty($_REQUEST['rf_buyer_ip']) ? '' : $_REQUEST['rf_buyer_ip']) : $data['rf_buyer_ip'];
|
397 |
+
$result['rf_rproduct'] = empty($data['rf_rproduct']) ? (empty($_REQUEST['rf_rproduct']) ? '' : $_REQUEST['rf_rproduct']) : $data['rf_rproduct'];
|
398 |
+
$result['rf_user'] = empty($data['rf_user']) ? (empty($_REQUEST['rf_user']) ? '' : $_REQUEST['rf_user']) : $data['rf_user'];
|
399 |
+
$result['buyer_history'] = empty($data['buyer_history']) ? (empty($_REQUEST['buyer_history']) ? '' : $_REQUEST['buyer_history']) : $data['buyer_history'];
|
400 |
+
break;
|
401 |
+
case 'cookie':
|
402 |
+
//try cookie first by passing data
|
403 |
+
$result['rf_product'] = empty($data['rf_product']) ? (empty($_REQUEST['rf_product']) ? '' : $_REQUEST['rf_product']) : $data['rf_product'];
|
404 |
+
$result['rf_buyer_ip'] = empty($data['rf_buyer_ip']) ? (empty($_REQUEST['rf_buyer_ip']) ? '' : $_REQUEST['rf_buyer_ip']) : $data['rf_buyer_ip'];
|
405 |
+
$result['rf_rproduct'] = empty($data['rf_rproduct']) ? (empty($_REQUEST['rf_rproduct']) ? '' : $_REQUEST['rf_rproduct']) : $data['rf_rproduct'];
|
406 |
+
$result['rf_user'] = empty($data['rf_user']) ? (empty($_REQUEST['rf_user']) ? '' : $_REQUEST['rf_user']) : $data['rf_user'];
|
407 |
+
$result['buyer_history'] = empty($data['buyer_history']) ? (empty($_REQUEST['buyer_history']) ? '' : $_REQUEST['buyer_history']) : $data['buyer_history'];
|
408 |
+
|
409 |
+
//try cookie by browser if some record missed
|
410 |
+
if(!empty($_COOKIE['rb_order_info'])){
|
411 |
+
$cookie_data = $_COOKIE["rb_order_info"];
|
412 |
+
$cookie_data = json_decode($cookie_data,true);
|
413 |
+
if(is_array($cookie_data)){
|
414 |
+
$result['rf_product'] = empty($result['rf_product']) ? (empty($cookie_data['rf_product']) ? '' : $cookie_data['rf_product']) : $result['rf_product'];
|
415 |
+
$result['rf_buyer_ip'] = empty($result['rf_buyer_ip']) ? (empty($cookie_data['rf_buyer_ip']) ? '' : $cookie_data['rf_buyer_ip']) : $result['rf_buyer_ip'];
|
416 |
+
$result['rf_rproduct'] = empty($result['rf_rproduct']) ? (empty($cookie_data['rf_rproduct']) ? '' : $cookie_data['rf_rproduct']) : $result['rf_rproduct'];
|
417 |
+
}
|
418 |
+
}
|
419 |
+
break;
|
420 |
+
default:
|
421 |
+
break;
|
422 |
+
}
|
423 |
+
return $result;
|
424 |
+
}
|
425 |
+
|
426 |
+
|
427 |
+
|
428 |
+
/**
|
429 |
+
* Curl Tools
|
430 |
+
* @param array $data
|
431 |
+
* @param $url
|
432 |
+
* @param string $send_method
|
433 |
+
* @param string $accept_code
|
434 |
+
* @param string $reject_code
|
435 |
+
* @return array (accept=>true/false,response=>string,error=>string,send_value=>string)
|
436 |
+
*/
|
437 |
+
protected function curlSend(array $data, $url, $send_method = 'get', $accept_code = '', $reject_code = '')
|
438 |
+
{
|
439 |
+
/**
|
440 |
+
* format of result array
|
441 |
+
* 'accept' => true/false
|
442 |
+
* 'response' => text
|
443 |
+
* 'error' => text
|
444 |
+
* 'send_value' => text
|
445 |
+
*/
|
446 |
+
$result = array('accept' => '', 'response' => '', 'error' => '', 'send_value' => '');
|
447 |
+
if (!empty($url) && !empty($data)) {
|
448 |
+
$ch = curl_init();
|
449 |
+
try {
|
450 |
+
$data_string = http_build_query($data);
|
451 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
452 |
+
if ($send_method == 'post') {
|
453 |
+
curl_setopt($ch, CURLOPT_POST, count($data_string));
|
454 |
+
curl_setopt($ch, CURLOPT_POST, 1);
|
455 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
|
456 |
+
$result['send_value'] = $url . "?" . $data_string;
|
457 |
+
} else {
|
458 |
+
if (strpos($url, '?') !== false) {
|
459 |
+
$url = $url . "&" . $data_string;
|
460 |
+
} else {
|
461 |
+
$url = $url . "?" . $data_string;
|
462 |
+
}
|
463 |
+
$result['send_value'] = $url;
|
464 |
+
}
|
465 |
+
|
466 |
+
curl_setopt($ch, CURLOPT_URL, $url);
|
467 |
+
curl_setopt($ch, CURLOPT_HEADER, 0); // DO NOT RETURN HTTP HEADERS
|
468 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
469 |
+
//curl_setopt($ch, CURLOPT_SSLVERSION, 3);
|
470 |
+
|
471 |
+
$response = curl_exec($ch);
|
472 |
+
$result['response'] = $response;
|
473 |
+
|
474 |
+
//compare result with accept code or reject code
|
475 |
+
$result['accept'] = true;
|
476 |
+
if ($response !== false && $response !== null) {
|
477 |
+
if ($accept_code != null && $accept_code != '') {
|
478 |
+
if (stripos($response, $accept_code) !== false) {
|
479 |
+
$result['accept'] = true;
|
480 |
+
} else {
|
481 |
+
$result['accept'] = false;
|
482 |
+
}
|
483 |
+
}
|
484 |
+
|
485 |
+
if ($reject_code != null && $reject_code != '') {
|
486 |
+
if (stripos($response, $reject_code) !== false) {
|
487 |
+
$result['accept'] = false;
|
488 |
+
}
|
489 |
+
}
|
490 |
+
} else {
|
491 |
+
$result['error'] = curl_error($ch);
|
492 |
+
$result['send_method'] = $send_method;
|
493 |
+
$result['accept'] = false;
|
494 |
+
}
|
495 |
+
|
496 |
+
curl_close($ch);
|
497 |
+
} catch (Exception $e) {
|
498 |
+
curl_close($ch);
|
499 |
+
$result['accept'] = false;
|
500 |
+
$result['error'] = $e->getMessage();
|
501 |
+
$result['send_method'] = $send_method;
|
502 |
+
}
|
503 |
+
}
|
504 |
+
return $result;
|
505 |
+
}
|
506 |
+
|
507 |
+
}
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Referboard_Retailer</name>
|
4 |
+
<version>1.0.3</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://www.gnu.org/licenses/gpl-2.0.html">GPLv2</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Referboard easily enables your audience to refer your products to their friends and followers.</summary>
|
10 |
+
<description>Referboard is an exciting new platform which enables you to generate more website traffic and online sales, by enabling your audience to refer your products to their friends and followers. This Plug-in enables your website to easily integrate with the Referboard platform and get your products online quicker.</description>
|
11 |
+
<notes>Need to clear cache after installation</notes>
|
12 |
+
<authors><author><name>Smion Li</name><user>referboard</user><email>it@referboard.com</email></author></authors>
|
13 |
+
<date>2016-11-18</date>
|
14 |
+
<time>04:56:19</time>
|
15 |
+
<contents><target name="magecommunity"><dir name="Referboard"><dir name="Retailer"><dir name="Block"><file name="Retailer.php" hash="6775302550e225e73d33727fc23e27b4"/><file name="Test.php" hash="e0753df53b74e791cbc8798c48e0964d"/></dir><dir name="Helper"><file name="Common.php" hash="cd22e65096df4b0ead25ceda0de2c956"/><file name="Data.php" hash="9a7ef906b4bf201c3860762a9000c5b7"/></dir><dir name="Model"><file name="Data.php" hash="70606cf5dff6285ffa0c101daf2faff4"/><file name="Observer.php" hash="6d02cf3ac800e67ae52ca0e7aebefbf8"/><dir name="Resource"><dir name="Data"><file name="Collection.php" hash="a11acc493fc110879787f2aa11df7a66"/></dir><file name="Data.php" hash="94a73ffd763ae7dd65a535390b990e5e"/></dir></dir><dir name="etc"><file name="config.xml" hash="eee4c97aa0ac0e7d45450570b5610d40"/><file name="system.xml" hash="76bb8d34728cf59a01088a129383ff49"/></dir><dir name="sql"><dir name="referboard_retailer_setup"><file name="install-1.0.0.php" hash="083c1cef836e9f89e6ef51f8506f88d1"/><file name="install-1.0.3.php" hash="3bbac19d7753e8467a0d1b5bde9dfaa8"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="referboard_retailer.xml" hash="2702f879e86b973e3155240cb7160bc8"/></dir><dir name="template"><dir name="referboard_retailer"><file name="button.phtml" hash="bf7e4095319ba94bb6ecdad308e9901a"/><file name="header.phtml" hash="c5c305526a8f84a5cef2ec1d838b652e"/><file name="index.phtml" hash="9b28e3acf7257f9b1f5edc1da710dfd0"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Referboard_Retailer.xml" hash="ec78502636149704456fb52cbb987f00"/></dir></target><target name="magelib"><dir name="Referboard"><file name="Referboard_Plugin_Class.php" hash="ad2f595f72b354724032947fce6caf1e"/></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.4.0</min><max>7.0.0</max></php></required></dependencies>
|
18 |
+
</package>
|