Itembase - Version 2.0.0

Version Notes

Stable release

Download this release

Release Info

Developer Itembase
Extension Itembase
Version 2.0.0
Comparing to
See all releases


Version 2.0.0

app/code/community/Itembase/Plugin/Block/Plugin.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+ class Itembase_Plugin_Block_Plugin extends Mage_Core_Block_Template
3
+ {
4
+ }
app/code/community/Itembase/Plugin/Block/Registrationlabel.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Itembase_Plugin_Block_Registrationlabel extends Mage_Adminhtml_Block_Abstract implements Varien_Data_Form_Element_Renderer_Interface
3
+ {
4
+ /**
5
+ * Render element html
6
+ *
7
+ * @param Varien_Data_Form_Element_Abstract $element
8
+ * @return string
9
+ */
10
+ public function render(Varien_Data_Form_Element_Abstract $element)
11
+ {
12
+ foreach(Mage::app()->getStores() as $shop) {
13
+ if(Mage::getStoreConfig('itembase_section/itembase_group/api_key', $shop->getStoreId()) === NULL) {
14
+ return sprintf(
15
+ '<tr class="system-fieldset-sub-head" id="row_%s"><td colspan="5"><h4 id="%s"><a href="%s">%s</a></h4></td></tr>',
16
+ $element->getHtmlId(),
17
+ $element->getHtmlId(),
18
+ Mage::helper('adminhtml')->getUrl('adminhtml/itembase', array('key' => Mage::getSingleton('adminhtml/url')->getSecretKey('itembase', 'index'))),
19
+ $this->__('If you have no Itembase keys click here!')
20
+ );
21
+ }
22
+ }
23
+ return '';
24
+ }
25
+ }
app/code/community/Itembase/Plugin/Plugin.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Itembase_Plugin_Plugin
4
+ {
5
+ public function displayPlugin(Varien_Event_Observer $observer)
6
+ {
7
+ $observerData = $observer->getData();
8
+ $order = Mage::getModel('sales/order');
9
+ $order->load(is_array($observerData['order_ids']) ? $observerData['order_ids'][0] : $observerData['order_ids']);
10
+
11
+ eval('function itembaseErrorHandler($errno, $errstr, $errfile, $errline) {
12
+ '.((bool)Mage::getStoreConfig('itembase_section/itembase_group/debug') ? 'echo "
13
+ <!--ITEMBASE
14
+ ".print_r(array($errno, $errstr, $errfile, $errline), true)."ITEMBASE-->
15
+ ";' : '').'
16
+ return true;
17
+ }');
18
+ set_error_handler('itembaseErrorHandler', E_ALL);
19
+
20
+ try {
21
+ include('Itembase/Plugin/plugindata.php');
22
+ include('Itembase/Plugin/oauth.php');
23
+
24
+ $responseArray = json_decode(authenticateClient(Mage::getStoreConfig('itembase_section/itembase_group/api_key'), Mage::getStoreConfig('itembase_section/itembase_group/secret')), true);
25
+ if(!isset($responseArray['access_token'])) itembaseErrorHandler(0, 'no access_token for '.Mage::getStoreConfig('itembase_section/itembase_group/api_key').' '.substr(Mage::getStoreConfig('itembase_section/itembase_group/secret'), 0, 4).'... '.ITEMBASE_SERVER_OAUTH.' '.print_r($responseArray, true), __FILE__, __LINE__ - 1);
26
+
27
+ $allProducts = array();
28
+ foreach ($order->getAllItems() as $item) {
29
+ $product = $item->getProduct();
30
+ $category = null;
31
+ if (is_array($categoryIds = $product->getCategoryIds())) {
32
+ $category = Mage::getModel('catalog/category');
33
+ $category->load($categoryIds[0]);
34
+ }
35
+
36
+ $allProducts [] = array(
37
+ 'id' => $product->getId(),
38
+ 'category' => $category ? $category->getName() : '',
39
+ 'name' => $product->getName(),
40
+ 'quantity' => $item->getQtyOrdered(),
41
+ 'price' => $item->getPriceInclTax(),
42
+ 'ean' => '',
43
+ 'isbn' => '',
44
+ 'asin' => '',
45
+ 'description' => $product->getDescription(),
46
+ 'pic_thumb' => Mage::app()->getLayout()->helper('catalog/image')->init($product, 'thumbnail')->__toString(),
47
+ 'pic_medium' => Mage::app()->getLayout()->helper('catalog/image')->init($product, 'small_image')->__toString(),
48
+ 'pic_large' => Mage::app()->getLayout()->helper('catalog/image')->init($product, 'image')->__toString(),
49
+ 'url' => $product->getProductUrl(),
50
+ );
51
+ }
52
+
53
+ $dataForItembase = array(
54
+ 'access_token' => $responseArray['access_token'],
55
+ 'email' => $order->getCustomerEmail(),
56
+ 'firstname' => $order->getCustomerFirstname(),
57
+ 'lastname' => $order->getCustomerLastname(),
58
+ 'street' => implode(' ', $order->getBillingAddress()->getStreet()),
59
+ 'zip' => $order->getBillingAddress()->getPostcode(),
60
+ 'city' => $order->getBillingAddress()->getCity(),
61
+ 'country' => Mage::getModel('directory/country')->load($order->getBillingAddress()->getCountryId())->getIso2Code(),
62
+ 'phone' => $order->getBillingAddress()->getTelephone(),
63
+ 'lang' => substr(Mage::app()->getLocale()->getDefaultLocale(), 0 , 2),
64
+ 'purchase_date' => $order->getCreatedAt(),
65
+ 'currency' => $order->getOrderCurrencyCode(),
66
+ 'total' => $order->getGrandTotal(),
67
+ 'order_number' => $order->getId(),
68
+ 'customer_id' => $order->getCustomerId(),
69
+ 'shipping_cost' => $order->getShippingAmount(),
70
+ 'shipping_method' => $order->getShippingDescription(),
71
+ 'shop_name' => Mage::app()->getStore()->getName(),
72
+ 'products' => $allProducts,
73
+ );
74
+
75
+ utf8EncodeRecursive($dataForItembase);
76
+ if(is_callable('json_last_error')) {
77
+ json_encode($dataForItembase);
78
+ if(json_last_error() != JSON_ERROR_NONE) itembaseErrorHandler(0, 'json_encode error '.json_last_error(), __FILE__, __LINE__ - 1);
79
+ }
80
+
81
+ $block = Mage::app()->getLayout()->createBlock('itembase/plugin')
82
+ ->setTemplate('itembase/checkout_success.phtml')
83
+ ->assign('ibdata', $dataForItembase)
84
+ ->assign('ibembedserver', ITEMBASE_SERVER_EMBED)
85
+ ->assign('ibhostserver', ITEMBASE_SERVER_HOST)
86
+ ->assign('ibpluginversion', ITEMBASE_PLUGIN_VERSION);
87
+ Mage::app()->getLayout()->getBlock('content')->append($block);
88
+ } catch(Exception $e) {
89
+ itembaseErrorHandler($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine());
90
+ }
91
+
92
+ restore_error_handler();
93
+ }
94
+ }
app/code/community/Itembase/Plugin/controllers/Adminhtml/ItembaseController.php ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Itembase_Plugin_Adminhtml_ItembaseController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ public function indexAction()
6
+ {
7
+ $session = Mage::getSingleton('adminhtml/session');
8
+ include('Itembase/Plugin/plugindata.php');
9
+ $language = substr(Mage::app()->getLocale()->getDefaultLocale(), 0 , 2);
10
+
11
+ $html = '';
12
+
13
+ // registration data gathering
14
+ $employee = Mage::getSingleton('admin/session')->getUser();
15
+ $user = array(
16
+ 'email' => $employee->getEmail(),
17
+ 'firstname' => $employee->getFirstname(),
18
+ 'lastname' => $employee->getLastname(),
19
+ 'street' => Mage::getStoreConfig('shipping/origin/street_line1').(Mage::getStoreConfig('shipping/origin/street_line2') ? ' '.Mage::getStoreConfig('shipping/origin/street_line2') : ''),
20
+ 'zip' => Mage::getStoreConfig('shipping/origin/postcode'),
21
+ 'town' => Mage::getStoreConfig('shipping/origin/city'),
22
+ 'state' => '',
23
+ 'country' => Mage::getStoreConfig('general/store_information/merchant_country'),
24
+ 'telephone' => Mage::getStoreConfig('general/store_information/phone'),
25
+ 'fax' => '',
26
+ );
27
+ $shops = array();
28
+ foreach(Mage::app()->getStores() as $shop) {
29
+ if(Mage::getStoreConfig('itembase_section/itembase_group/api_key', $shop->getStoreId()) === NULL) {
30
+ $shops[] = array(
31
+ 'shop_id' => $shop->getStoreId(),
32
+ 'shop_name' => Mage::getStoreConfig('general/store_information/name', $shop->getStoreId()) !== NULL ? Mage::getStoreConfig('general/store_information/name', $shop->getStoreId()) : Mage::getStoreConfig('general/store_information/name'),
33
+ 'shop_url' => Mage::getStoreConfig('web/unsecure/base_url', $shop->getStoreId()) !== NULL ? Mage::getStoreConfig('web/unsecure/base_url', $shop->getStoreId()) : Mage::getStoreConfig('web/unsecure/base_url'),
34
+ 'register' => 1,
35
+ 'street' => (Mage::getStoreConfig('shipping/origin/street_line1', $shop->getStoreId()) !== NULL ? Mage::getStoreConfig('shipping/origin/street_line1', $shop->getStoreId()) : Mage::getStoreConfig('shipping/origin/street_line1')).(Mage::getStoreConfig('shipping/origin/street_line2', $shop->getStoreId()) !== NULL ? ' '.Mage::getStoreConfig('shipping/origin/street_line2', $shop->getStoreId()): (Mage::getStoreConfig('shipping/origin/street_line2') !== NULL ? ' '.Mage::getStoreConfig('shipping/origin/street_line2') : '')),
36
+ 'zip' => Mage::getStoreConfig('shipping/origin/postcode', $shop->getStoreId()) !== NULL ? Mage::getStoreConfig('shipping/origin/postcode', $shop->getStoreId()) : Mage::getStoreConfig('shipping/origin/postcode'),
37
+ 'town' => Mage::getStoreConfig('shipping/origin/city', $shop->getStoreId()) !== NULL ? Mage::getStoreConfig('shipping/origin/city', $shop->getStoreId()) : Mage::getStoreConfig('shipping/origin/city'),
38
+ 'state' => '',
39
+ 'country' => Mage::getStoreConfig('general/store_information/merchant_country', $shop->getStoreId()) !== NULL ? Mage::getStoreConfig('general/store_information/merchant_country', $shop->getStoreId()) : Mage::getStoreConfig('general/store_information/merchant_country'),
40
+ 'telephone' => Mage::getStoreConfig('general/store_information/phone', $shop->getStoreId()) !== NULL ? Mage::getStoreConfig('general/store_information/phone', $shop->getStoreId()) : Mage::getStoreConfig('general/store_information/phone'),
41
+ 'fax' => '',
42
+ 'email' => Mage::getStoreConfig('trans_email/ident_general/email', $shop->getStoreId()) !== NULL ? Mage::getStoreConfig('trans_email/ident_general/email', $shop->getStoreId()) : Mage::getStoreConfig('trans_email/ident_general/email'),
43
+ );
44
+ }
45
+ }
46
+
47
+ // registration data saving
48
+ if($this->getRequest()->getParam('itembaseRegistration')) {
49
+ $responseData = json_decode(base64_decode($this->getRequest()->getParam('itembaseRegistration')), true);
50
+ if(isset($responseData['errors'])) {
51
+ $session->addError($this->__('Registration error.').'<br />'.implode('<br />', $responseData['errors']));
52
+ $user['email'] = $responseData['user']['email'];
53
+ $user['firstname'] = $responseData['user']['firstname'];
54
+ $user['lastname'] = $responseData['user']['lastname'];
55
+ } else {
56
+ $this->saveConfiguration($responseData);
57
+ $session->addSuccess($this->__('Registration completed.').'<br />'.$responseData['success'].' <a href="'.Mage::helper("adminhtml")->getUrl("adminhtml/system_config/edit", array('section' => 'itembase_section', 'key' => Mage::getSingleton('adminhtml/url')->getSecretKey('system_config','edit'))).'">'.$this->__('Click here to continue.').'</a>');
58
+ $this->loadLayout()->renderLayout();
59
+ return;
60
+ }
61
+ }
62
+
63
+ if($shops) {
64
+ // registration data sending
65
+ if($this->getRequest()->getParam('submitItembaseRegistration')) {
66
+ $data = array(
67
+ 'user' => $user = $this->getRequest()->getParam('user'),
68
+ 'shops' => $shops = $this->getRequest()->getParam('shops'),
69
+ 'shop_software' => $this->getRequest()->getParam('shop_software'),
70
+ 'return' => 'json',
71
+ 'lang' => $language,
72
+ );
73
+ $header[] = 'Authorization: OAuth Content-Type: application/x-www-form-urlencoded';
74
+ $ibCurl = curl_init();
75
+ curl_setopt($ibCurl, CURLOPT_HEADER, false);
76
+ curl_setopt($ibCurl, CURLOPT_HTTPHEADER, $header);
77
+ curl_setopt($ibCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
78
+ curl_setopt($ibCurl, CURLOPT_SSL_VERIFYHOST, 2);
79
+ curl_setopt($ibCurl, CURLOPT_URL, ITEMBASE_SERVER_HOST.'/api/register_retailer');
80
+ curl_setopt($ibCurl, CURLOPT_POST, true);
81
+ curl_setopt($ibCurl, CURLOPT_RETURNTRANSFER, true);
82
+ curl_setopt($ibCurl, CURLOPT_POSTFIELDS, http_build_query($data));
83
+ $jsonResponse = curl_exec($ibCurl);
84
+ if($jsonResponse === FALSE) {
85
+ $session->addError($this->__('Curl error.').'<br />'.curl_error($ibCurl));
86
+ } else {
87
+ $responseData = json_decode($jsonResponse, true);
88
+ if(isset($responseData['errors'])) {
89
+ $session->addError($this->__('Registration error.').'<br />'.implode('<br />', $responseData['errors']));
90
+ } else {
91
+ $this->saveConfiguration($responseData);
92
+ $session->addSuccess($this->__('Registration completed.').'<br />'.$responseData['success'].' <a href="'.Mage::helper("adminhtml")->getUrl("adminhtml/system_config/edit", array('section' => 'itembase_section', 'key' => Mage::getSingleton('adminhtml/url')->getSecretKey('system_config','edit'))).'">'.$this->__('Click here to continue.').'</a>');
93
+ $this->loadLayout()->renderLayout();
94
+ return;
95
+ }
96
+ }
97
+ curl_close($ibCurl);
98
+ }
99
+
100
+ // registration data output
101
+ $registrationHtml .= '
102
+ <form action="'.(extension_loaded('curl') ? preg_replace('/(\&|\?)itembaseRegistration=[a-z0-9]*/i', '', $_SERVER['REQUEST_URI']) : ITEMBASE_SERVER_HOST.'/api/register_retailer').'" method="post">';
103
+ if(Mage::getStoreConfig('itembase_section/itembase_group/email') === NULL) {
104
+ $registrationHtml .= '
105
+ <div class="itembase-reg-left">
106
+ <label>'.$this->__('Email').'</label>
107
+ <input type="text" name="user[email]" value="'.$user['email'].'" />
108
+ <label>'.$this->__('Firstname').'</label>
109
+ <input type="text" name="user[firstname]" value="'.$user['firstname'].'" />
110
+ <label>'.$this->__('Lastname').'</label>
111
+ <input type="text" name="user[lastname]" value="'.$user['lastname'].'" />
112
+ <input type="hidden" name="user[street]" value="'.$user['street'].'" />
113
+ <input type="hidden" name="user[zip]" value="'.$user['zip'].'" />
114
+ <input type="hidden" name="user[town]" value="'.$user['town'].'" />
115
+ <input type="hidden" name="user[state]" value="'.$user['state'].'" />
116
+ <input type="hidden" name="user[country]" value="'.$user['country'].'" />
117
+ <input type="hidden" name="user[telephone]" value="'.$user['telephone'].'" />
118
+ <input type="hidden" name="user[fax]" value="'.$user['fax'].'" />
119
+ </div>';
120
+ } else {
121
+ $registrationHtml .= '
122
+ <div class="itembase-reg-left">
123
+ <label>'.$this->__('Email').'</label>
124
+ <input type="text" value="'.Mage::getStoreConfig('itembase_section/itembase_group/email').'" disabled="disabled" />
125
+ <input type="hidden" name="user[email]" value="'.Mage::getStoreConfig('itembase_section/itembase_group/email').'" />
126
+ </div>';
127
+ }
128
+ $registrationHtml .= '
129
+ <div class="itembase-reg-right">
130
+ <label class="itembase-form-label-reg">'.$this->__('Register shop').'</label>';
131
+ foreach($shops as $shop) {
132
+ $registrationHtml .= '
133
+ <div class="itembase-shop">
134
+ <input class="input-check" type="checkbox" name="shops['.$shop['shop_id'].'][register]" '.($shop['register'] ? ' checked="checked"' : '').' /><span class="itembase-shopname">'.$shop['shop_name'].'</span>
135
+ <input type="hidden" name="shops['.$shop['shop_id'].'][shop_id]" value="'.$shop['shop_id'].'" />
136
+ <input type="hidden" name="shops['.$shop['shop_id'].'][shop_name]" value="'.$shop['shop_name'].'" />
137
+ <input type="hidden" name="shops['.$shop['shop_id'].'][shop_url]" value="'.$shop['shop_url'].'" />
138
+ <input type="hidden" name="shops['.$shop['shop_id'].'][street]" value="'.$shop['street'].'" />
139
+ <input type="hidden" name="shops['.$shop['shop_id'].'][zip]" value="'.$shop['zip'].'" />
140
+ <input type="hidden" name="shops['.$shop['shop_id'].'][town]" value="'.$shop['town'].'" />
141
+ <input type="hidden" name="shops['.$shop['shop_id'].'][state]" value="'.$shop['state'].'" />
142
+ <input type="hidden" name="shops['.$shop['shop_id'].'][country]" value="'.$shop['country'].'" />
143
+ <input type="hidden" name="shops['.$shop['shop_id'].'][telephone]" value="'.$shop['telephone'].'" />
144
+ <input type="hidden" name="shops['.$shop['shop_id'].'][fax]" value="'.$shop['fax'].'" />
145
+ </div>';
146
+ }
147
+ $registrationHtml .= '
148
+ <input type="hidden" name="shop_software" value="TWFnZW50bzFfN18w" />
149
+ <input type="hidden" name="lang" value="'.$language.'" />
150
+ </div>
151
+ <div class="itembase-reg-final">
152
+ <input type="checkbox" id="confirmItembaseTAC" /><span class="itembase-shopname">'.$this->__("I accept itembase <a href='http://partners.itembase.com/docs/tac.pdf' target='_blank' style='text-decoration:underline;'>Terms</a>").'</span>
153
+ <input class="itembase-button-green" type="submit" name="submitItembaseRegistration" value="'.$this->__('Register').'" onclick="if(!document.getElementById(\'confirmItembaseTAC\').checked){ alert(\''.$this->__('Accept itembase Terms first').'\'); return false; }" />
154
+ </div>
155
+ <input name="form_key" type="hidden" value="'.Mage::getSingleton('core/session')->getFormKey().'" />
156
+ </form>';
157
+ $html .= str_replace('[form]', $registrationHtml, file_get_contents(ITEMBASE_SERVER_EMBED.'/embed/registration?shop_software=TWFnZW50bzFfN18w&lang='.$language, false, stream_context_create(array('http' => array('ignore_errors' => true)))));
158
+ }
159
+
160
+ $this->loadLayout()->_addContent($this->getLayout()->createBlock('core/text', 'registration')->setText($html))->renderLayout();
161
+ }
162
+
163
+ private function saveConfiguration($responseData) {
164
+ $config = Mage::getConfig();
165
+ if(Mage::getStoreConfig('itembase_section/itembase_group/email') === NULL) {
166
+ $config->saveConfig('itembase_section/itembase_group/email', $responseData['user']['email']);
167
+ }
168
+ foreach($responseData['shops'] as $shop) {
169
+ $config->saveConfig('itembase_section/itembase_group/api_key', $shop['api_key'], 'stores', $shop['shop_id']);
170
+ $config->saveConfig('itembase_section/itembase_group/secret', $shop['secret'], 'stores', $shop['shop_id']);
171
+ }
172
+ $config->reinit();
173
+ }
174
+ }
app/code/community/Itembase/Plugin/controllers/IndexController.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Itembase_Plugin_IndexController extends Mage_Core_Controller_Front_Action
3
+ {
4
+ public function indexAction()
5
+ {
6
+ include('Itembase/Plugin/plugindata.php');
7
+
8
+ $language = substr(Mage::app()->getLocale()->getDefaultLocale(), 0 , 2);
9
+ $opts = array('http' =>
10
+ array(
11
+ 'ignore_errors' => true,
12
+ 'method' => 'POST',
13
+ 'header' => 'Content-type: application/x-www-form-urlencoded',
14
+ 'content' => http_build_query(array_merge($_GET, array(
15
+ 'lang' => $language,
16
+ 'api_key' => Mage::getStoreConfig('itembase_section/itembase_group/api_key'),
17
+ )))
18
+ )
19
+ );
20
+ $context = stream_context_create($opts);
21
+ $html = file_get_contents(ITEMBASE_SERVER_EMBED.'/embed/publicpage', false, $context);
22
+
23
+ $this->loadLayout();
24
+ $this->getLayout()->getBlock('content')->append($this->getLayout()->createBlock('core/text', 'itembase/page')->setText($html));
25
+ $this->renderLayout();
26
+ }
27
+ }
app/code/community/Itembase/Plugin/etc/config.xml ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Itembase_Plugin>
5
+ <version>1.0.0</version>
6
+ </Itembase_Plugin>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <itembase>
11
+ <class>Itembase_Plugin_Block</class>
12
+ </itembase>
13
+ </blocks>
14
+ <events>
15
+ <checkout_onepage_controller_success_action>
16
+ <observers>
17
+ <itembase_plugin_observer>
18
+ <type>singleton</type>
19
+ <class>Itembase_Plugin_Plugin</class>
20
+ <method>displayPlugin</method>
21
+ </itembase_plugin_observer>
22
+ </observers>
23
+ </checkout_onepage_controller_success_action>
24
+ </events>
25
+ <helpers>
26
+ <itembase_plugin>
27
+ <class>Mage_Core_Helper</class>
28
+ </itembase_plugin>
29
+ </helpers>
30
+ </global>
31
+ <frontend>
32
+ <routers>
33
+ <itembase>
34
+ <use>standard</use>
35
+ <args>
36
+ <module>Itembase_Plugin</module>
37
+ <frontName>itembase</frontName>
38
+ </args>
39
+ </itembase>
40
+ </routers>
41
+ </frontend>
42
+ <admin>
43
+ <routers>
44
+ <adminhtml>
45
+ <args>
46
+ <modules>
47
+ <itembase_plugin before="Mage_Adminhtml">Itembase_Plugin_Adminhtml</itembase_plugin>
48
+ </modules>
49
+ </args>
50
+ </adminhtml>
51
+ </routers>
52
+ </admin>
53
+ <adminhtml>
54
+ <translate>
55
+ <modules>
56
+ <Itembase_Plugin>
57
+ <files>
58
+ <default>Itembase_Plugin.csv</default>
59
+ </files>
60
+ </Itembase_Plugin>
61
+ </modules>
62
+ </translate>
63
+ <acl>
64
+ <resources>
65
+ <admin>
66
+ <children>
67
+ <system>
68
+ <children>
69
+ <config>
70
+ <children>
71
+ <itembase_section translate="title">
72
+ <title>Itembase</title>
73
+ <sort_order>999</sort_order>
74
+ </itembase_section>
75
+ </children>
76
+ </config>
77
+ </children>
78
+ </system>
79
+ </children>
80
+ </admin>
81
+ </resources>
82
+ </acl>
83
+ </adminhtml>
84
+ </config>
app/code/community/Itembase/Plugin/etc/system.xml ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <itembase_section>
5
+ <label>Itembase</label>
6
+ <sort_order>999</sort_order>
7
+ <show_in_default>1</show_in_default>
8
+ <show_in_website>1</show_in_website>
9
+ <show_in_store>1</show_in_store>
10
+ <tab>sales</tab>
11
+ <groups>
12
+ <itembase_group>
13
+ <label>itembase</label>
14
+ <sort_order>1</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <fields>
19
+ <register>
20
+ <label>Registration label</label>
21
+ <frontend_model>itembase/registrationlabel</frontend_model>
22
+ <sort_order>1</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>1</show_in_store>
26
+ </register>
27
+ <api_key translate="label">
28
+ <label>API key</label>
29
+ <sort_order>1</sort_order>
30
+ <show_in_default>0</show_in_default>
31
+ <show_in_website>0</show_in_website>
32
+ <show_in_store>1</show_in_store>
33
+ <frontend_input>text</frontend_input>
34
+ </api_key>
35
+ <secret translate="label">
36
+ <label>Secret key</label>
37
+ <sort_order>2</sort_order>
38
+ <show_in_default>0</show_in_default>
39
+ <show_in_website>0</show_in_website>
40
+ <show_in_store>1</show_in_store>
41
+ <frontend_input>text</frontend_input>
42
+ </secret>
43
+ <debug translate="label">
44
+ <label>Enable Debug mode (optional)</label>
45
+ <sort_order>3</sort_order>
46
+ <show_in_default>0</show_in_default>
47
+ <show_in_website>0</show_in_website>
48
+ <show_in_store>1</show_in_store>
49
+ <frontend_input>text</frontend_input>
50
+ </debug>
51
+ <no_shop translate="label">
52
+ <label>Please select your shop from Configuration Scope before changing configuration.</label>
53
+ <sort_order>1</sort_order>
54
+ <show_in_default>1</show_in_default>
55
+ <show_in_website>1</show_in_website>
56
+ <show_in_store>0</show_in_store>
57
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
58
+ </no_shop>
59
+ </fields>
60
+ </itembase_group>
61
+ </groups>
62
+ </itembase_section>
63
+ </sections>
64
+ </config>
app/code/community/Itembase/Plugin/oauth.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // Method for oAuth process
4
+ function authenticateClient($clientId, $clientSecret) {
5
+ // Receive access token via oAuth
6
+ if(extension_loaded('curl')) {
7
+ $header[] = 'Authorization: OAuth Content-Type: application/x-www-form-urlencoded';
8
+ $ibCurl = curl_init();
9
+ curl_setopt($ibCurl, CURLOPT_HEADER, false);
10
+ curl_setopt($ibCurl, CURLOPT_HTTPHEADER, $header);
11
+ curl_setopt($ibCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
12
+ curl_setopt($ibCurl, CURLOPT_SSL_VERIFYHOST, 2);
13
+ curl_setopt($ibCurl, CURLOPT_URL, ITEMBASE_SERVER_OAUTH);
14
+ curl_setopt($ibCurl, CURLOPT_POST, true);
15
+ curl_setopt($ibCurl, CURLOPT_RETURNTRANSFER, true);
16
+ curl_setopt($ibCurl, CURLOPT_POSTFIELDS, array(
17
+ 'client_id' => $clientId,
18
+ 'client_secret' => $clientSecret,
19
+ 'response_type' => 'token',
20
+ 'grant_type' => 'client_credentials'
21
+ ));
22
+ $jsonResponse = curl_exec($ibCurl);
23
+ if($jsonResponse === FALSE) itembaseErrorHandler(0, curl_error($ibCurl), __FILE__, __LINE__ - 1);
24
+ curl_close($ibCurl);
25
+ } else {
26
+ $opts = array('http' => array('ignore_errors' => true));
27
+ $context = stream_context_create($opts);
28
+ $jsonResponse = file_get_contents(ITEMBASE_SERVER_OAUTH.'?client_id='.$clientId.'&client_secret='.$clientSecret.'&response_type=token&grant_type=client_credentials', false, $context);
29
+ if($jsonResponse === FALSE) itembaseErrorHandler(0, 'file_get_contents', __FILE__, __LINE__ - 1);
30
+ }
31
+ return $jsonResponse;
32
+ }
33
+
34
+ // Method for preparing UTF-8 data for Itembase
35
+ $encodings;
36
+ function utf8EncodeRecursive(&$data) {
37
+ if(is_array($data) || is_object($data)) {
38
+ settype($data, 'array');
39
+ foreach($data as &$_val)
40
+ utf8EncodeRecursive($_val);
41
+ } else {
42
+ $data = strip_tags(html_entity_decode($data));
43
+ if(extension_loaded('mbstring')) {
44
+ global $encodings;
45
+ if(!$encodings) {
46
+ $encodings = array();
47
+ foreach(explode(',', 'UTF-8,ISO-8859-1,ISO-8859-2,ISO-8859-3,ISO-8859-4,ISO-8859-5,ISO-8859-6,ISO-8859-7,ISO-8859-8,ISO-8859-9,ISO-8859-10,ISO-8859-13,ISO-8859-14,ISO-8859-15,ISO-8859-16,Windows-1252,Windows-1250,Windows-1251,Windows-1254') as $encoding) {
48
+ if(in_array($encoding, mb_list_encodings())) {
49
+ $encodings[] = $encoding;
50
+ }
51
+ }
52
+ mb_detect_order(array_merge($encodings, mb_list_encodings()));
53
+ }
54
+ if(($encoding = mb_detect_encoding($data, null, true)) != 'UTF-8') {
55
+ mb_convert_variables('UTF-8', $encoding, $data);
56
+ }
57
+ } elseif(!preg_match('%^(?:
58
+ [\x09\x0A\x0D\x20-\x7E] # ASCII
59
+ | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
60
+ | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
61
+ | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
62
+ | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
63
+ | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
64
+ | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
65
+ | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
66
+ )*$%xs', $data)
67
+ ) {
68
+ if(extension_loaded('iconv')) {
69
+ $data = iconv(iconv_get_encoding('internal_encoding'), 'UTF-8//IGNORE', $data);
70
+ } else {
71
+ $data = utf8_encode($data);
72
+ }
73
+ }
74
+ }
75
+ }
app/code/community/Itembase/Plugin/plugindata.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Itembase config values for plugin
5
+ * Please do not change any of these values unless you know what you do!
6
+ **/
7
+
8
+ define('ITEMBASE_PLUGIN_VERSION', '2.0');
9
+ define('ITEMBASE_SERVER_OAUTH', 'https://auth-m2.itembase.com/oauth/v2/token');
10
+ define('ITEMBASE_SERVER_EMBED', 'https://deliver-static-d1.itembase.com');
11
+ define('ITEMBASE_SERVER_HOST', 'https://www.itembase.com');
app/design/frontend/base/default/template/itembase/checkout_success.phtml ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/javascript" src="https://d3jaattgax33fv.cloudfront.net/js/jqplugin.js"></script>
2
+ <script type="text/javascript" charset="utf-8">
3
+ var $itembase_jq = jQuery;
4
+
5
+ $itembase_jq(document).ready(function($itembase_jq) {
6
+
7
+ var ibEmbedHost = "<?php echo $ibembedserver ?>";
8
+ var ibHost = "<?php echo $ibhostserver ?>";
9
+ var ibData = <?php echo json_encode($ibdata) ?>;
10
+
11
+ // Method to add click funcitonality
12
+ function addClickListener() {
13
+ $itembase_jq('#itembasecontainer .js-trackButton').click(function(event) {
14
+ if (!$itembase_jq(this).hasClass('disabled')) {
15
+ if ($itembase_jq('#itembase_data').length==0) {
16
+ $itembase_jq('#itembasecontainer').append('<form id="itembaseform" method="post" action="'+ibHost+'/api/add_to_my_collection" target="_blank"><textarea id="itembase_data" name="data"><?php echo addslashes(json_encode($ibdata)) ?></textarea><input type="submit" value="" cols="1" rows="1" style="width=1px;height:1px;visibility:hidden;" /></form>');
17
+ };
18
+ document.getElementById('itembaseform').submit();
19
+ $itembase_jq('#itembase_data').hide();
20
+ } else {
21
+ $itembase_jq('label.red').removeClass('hidden');
22
+ }
23
+ return false;
24
+ });
25
+ }
26
+
27
+ // Method to add a single product entry
28
+ function addProductEntry(currentTr, currentIndex, currentProduct) {
29
+ var productName = currentProduct.name;
30
+ if (productName.length > 25) {
31
+ productName = productName.substr(0, 25) + '&hellip;';
32
+ }
33
+ var productPrice = parseFloat(currentProduct.price);
34
+ productPrice = productPrice.toFixed(2);
35
+ currentTr.attr('id', 'product'+currentIndex);
36
+ $itembase_jq('#itembasecontainer .js-productTable').append(currentTr);
37
+ $itembase_jq('#itembasecontainer #product'+currentIndex+' .js-ibShopName').html(ibData.shop_name.length > 13 ? ibData.shop_name.substr(0, 13)+'&hellip;' : ibData.shop_name);
38
+
39
+ // Some product specific information is optional
40
+ if (ibPluginOptions.display_product_names)
41
+ $itembase_jq('#itembasecontainer #product'+currentIndex+' .js-ibProductName').html(productName);
42
+ if (ibPluginOptions.display_product_images) {
43
+ if (!(currentProduct.pic_large == '' || currentProduct.pic_large == null)) {
44
+ $itembase_jq('#itembasecontainer #product'+currentIndex+' .js-ibProductImage img').attr('src', currentProduct.pic_large);
45
+ }
46
+ }
47
+ if (ibPluginOptions.display_purchase_date)
48
+ $itembase_jq('#itembasecontainer #product'+currentIndex+' .js-ibPurchaseDate').html(ibData.purchase_date);
49
+ if (ibPluginOptions.display_product_prices)
50
+ $itembase_jq('#itembasecontainer #product'+currentIndex+' .js-ibProductPrice').html(productPrice+' '+ibData.currency);
51
+ if (ibPluginOptions.display_product_categories)
52
+ $itembase_jq('#itembasecontainer #product'+currentIndex+' .js-ibProductCategory').html();
53
+ if (ibPluginOptions.display_product_quantities)
54
+ $itembase_jq('#itembasecontainer #product'+currentIndex+' .js-ibProductQuantity').html(currentProduct.quantity);
55
+ if (ibPluginOptions.display_product_descriptions)
56
+ $itembase_jq('#itembasecontainer #product'+currentIndex+' .js-ibProductDescription').html(currentProduct.description);
57
+
58
+ }
59
+
60
+ // Method to add plugin data
61
+ function renderPlugin(data) {
62
+ $itembase_jq('#itembasecontainer').html('');
63
+ $itembase_jq('#itembasecontainer').append(data);
64
+
65
+ // Set order data locally
66
+ var trData = $itembase_jq('#itembasecontainer .js-productTable tr.js-productEntry');
67
+ $itembase_jq('#itembasecontainer .js-productTable tr.js-productEntry').remove();
68
+
69
+ if (ibPluginOptions.type == 'single') {
70
+ addProductEntry($itembase_jq(trData), 0, ibData.products[0]);
71
+ if (ibData.products.length > 1) {
72
+ $itembase_jq('.js-ibMoreItemsNumber').html(ibData.products.length - 1);
73
+ $itembase_jq('.js-ibMoreItems').attr('style', '');
74
+ }
75
+ } else {
76
+ $itembase_jq.each(ibData.products, function(currentIndex, currentProduct) {
77
+ addProductEntry($itembase_jq(trData), currentIndex, currentProduct);
78
+ });
79
+ }
80
+ addClickListener();
81
+ }
82
+
83
+ // Method to load plugin data with JSONP
84
+ function refreshPluginData() {
85
+ $itembase_jq.ajax({
86
+ data: {pluginVersion: '<?php echo $ibpluginversion ?>'},
87
+ dataType: 'jsonp',
88
+ jsonp: 'ib_callback',
89
+ url: ibEmbedHost + '/embed/confirm/<?php echo $ibdata["access_token"] ?>/<?php echo $ibdata["lang"] ?>',
90
+ success: function (data) {
91
+ renderPlugin(data.response);
92
+ sendOrderData();
93
+ }
94
+ });
95
+ }
96
+
97
+ // Method to save order data
98
+ function sendOrderData() {
99
+ var orderData = new Object();
100
+ for(i in ibData) {
101
+ if(i != 'email' && i != 'firstname' && i != 'lastname' && i != 'street' && i != 'zip' && i != 'city' && i != 'state' && i != 'country' && i != 'phone' && i != 'fax' && i != 'customer_id') {
102
+ orderData[i] = ibData[i];
103
+ }
104
+ }
105
+ if(ibPluginOptions.send_email) {
106
+ orderData['email'] = ibData['email'];
107
+ }
108
+ orderData['anonymouse_order'] = 1;
109
+ $itembase_jq.ajax({
110
+ type: 'POST',
111
+ data: {data: orderData},
112
+ url: ibHost + '/api/add_to_my_collection'
113
+ });
114
+ }
115
+
116
+
117
+ refreshPluginData();
118
+ });
119
+
120
+ jQuery.noConflict(true);
121
+ </script>
122
+ <div id="itembasecontainer"></div>
app/etc/modules/Itembase_Plugin.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Itembase_Plugin>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Itembase_Plugin>
8
+ </modules>
9
+ </config>
app/locale/de_DE/Itembase_Plugin.csv ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "itembase","itembase"
2
+ "API key","API Schlüssel"
3
+ "Secret key","Sicherheitsschlüssel"
4
+ "Enable Debug mode (optional)","Debug-Modus aktivieren (optional)"
5
+ "Please select your shop from Configuration Scope before changing configuration.","Bitte wählen Sie Ihren Shop im Konfig.-Bereich aus, bevor Sie Ihre Konfiguration ändern."
6
+ "If you have no Itembase keys click here!","Falls Sie noch keinen itembase-Schlüssel haben, klicken Sie hier!"
7
+ "Registration error.","Fehler bei der Registrierung."
8
+ "Registration completed.","Registrierung erfolgreich."
9
+ "Click here to continue.","Hier klicken um fortzusetzen"
10
+ "Curl error. ","Curl Fehler."
11
+ "Email","E-Mail"
12
+ "Firstname","Vorname"
13
+ "Lastname","Nachname"
14
+ "Register shop","Shop"
15
+ "I accept itembase <a href='http://partners.itembase.com/docs/tac.pdf' target='_blank' style='text-decoration:underline;'>Terms</a>","Ich akzeptiere die itembase <a href='http://partners.itembase.com/docs/tac.pdf' target='_blank' style='text-decoration:underline;'>AGB</a>"
16
+ "Register","Registrieren"
17
+ "Accept itembase Terms first","Bitte zuerst die AGB´s akzeptieren"
app/locale/en_US/Itembase_Plugin.csv ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "itembase","itembase"
2
+ "API key","API key"
3
+ "Secret key","Secret key"
4
+ "Enable Debug mode (optional)","Enable Debug mode (optional)"
5
+ "Please select your shop from Configuration Scope before changing configuration.","Please select your shop from Configuration Scope before changing configuration."
6
+ "If you have no Itembase keys click here!","If you have no Itembase keys click here!"
7
+ "Registration error.","Registration error."
8
+ "Registration completed.","Registration completed."
9
+ "Click here to continue.","Click here to continue."
10
+ "Curl error.","Curl error."
11
+ "Email","Email"
12
+ "Firstname","Firstname"
13
+ "Lastname","Lastname"
14
+ "Register shop","Register shop"
15
+ "I accept itembase <a href='http://partners.itembase.com/docs/tac.pdf' target='_blank' style='text-decoration:underline;'>Terms</a>","I accept itembase <a href='http://partners.itembase.com/docs/tac.pdf' target='_blank' style='text-decoration:underline;'>Terms</a>"
16
+ "Register","Register"
17
+ "Accept itembase Terms first","Accept itembase Terms first"
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Itembase</name>
4
+ <version>2.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Itembase plugin</summary>
10
+ <description>Itembase plugin</description>
11
+ <notes>Stable release</notes>
12
+ <authors><author><name>Itembase</name><user>itembase</user><email>kg@itembase.biz</email></author></authors>
13
+ <date>2013-01-21</date>
14
+ <time>11:57:13</time>
15
+ <contents><target name="magecommunity"><dir name="Itembase"><dir name="Plugin"><dir name="Block"><file name="Plugin.php" hash="08bd54b8795873cc84f1c81b54e5bb1e"/><file name="Registrationlabel.php" hash="da1c9830449a1af6602b813ef2e8745b"/></dir><file name="Plugin.php" hash="d5028b5bff167bfdf31e483069553268"/><dir name="controllers"><dir name="Adminhtml"><file name="ItembaseController.php" hash="fd8f48a86e3bc068681d190ff95ed662"/></dir><file name="IndexController.php" hash="ab00d97f209a41b9dc4b95a20e539089"/></dir><dir name="etc"><file name="config.xml" hash="6f3844a88e13ee0f80ba0908a822548e"/><file name="system.xml" hash="b6c0852bc0d958b0e9c2aa1113476940"/></dir><file name="oauth.php" hash="e3a6b961c2ca1e2bc6a70a6a6ecb56b3"/><file name="plugindata.php" hash="4256b4c98b083ecac353c575cdcf8c7c"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Itembase_Plugin.xml" hash="31903842e872b0c72d24f6ee6b7fd390"/></dir></target><target name="magelocale"><dir><dir name="de_DE"><file name="Itembase_Plugin.csv" hash="fbcbb04e8ffb2b64e5d438628466f065"/></dir><dir name="en_US"><file name="Itembase_Plugin.csv" hash="0fead96374795d4b8e13b793b8186337"/></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="itembase"><file name="checkout_success.phtml" hash="8677044de3490ca3b8630e927c3ab4ba"/></dir></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>