Skip to content

Commit c40997a

Browse files
committed
Merge pull request #45 from zendesk/mmolina/upgrade_to_web_widget
[CE-707] Data upgrade script from 1.4.0 to 2.0.0
2 parents c5db4ca + 512c5de commit c40997a

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright 2015 Zendesk
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/**
19+
* In version 2.0 we are replacing the deprecated Feedback Tab with the new
20+
* Embeddables Web Widget.
21+
* More info: https://www.zendesk.com/embeddables
22+
*
23+
* In this data upgrade we are going to drop the Feedback Tab related settings
24+
* from the database, and inserting the required fields for the Web Widget.
25+
*/
26+
27+
$config = new Mage_Core_Model_Config();
28+
29+
// We won't need the Feedback Tab code snippet anymore
30+
$config->deleteConfig('zendesk/frontend_features/feedback_tab_code');
31+
32+
// We won't check in our code whether to show or not the Feedback Tab
33+
$config->deleteConfig('zendesk/frontend_features/feedback_tab_code_active');
34+
35+
// Retrieve the domain from the config settings
36+
$domain = Mage::getStoreConfig('zendesk/general/domain');
37+
38+
if($domain) {
39+
// We are activating the Web Widget by default
40+
$config->saveConfig('zendesk/frontend_features/web_widget_code_active', 1);
41+
42+
// The Web Widget code snippet, using the account zendesk domain from settings
43+
$webWidgetSnippet=<<<EOJS
44+
<!-- Start of Zendesk Widget script -->
45+
<script>/*<![CDATA[*/window.zEmbed||function(e,t){var n,o,d,i,s,a=[],r=document.createElement("iframe");window.zEmbed=function(){a.push(arguments)},window.zE=window.zE||window.zEmbed,r.src="javascript:false",r.title="",r.role="presentation",(r.frameElement||r).style.cssText="display: none",d=document.getElementsByTagName("script"),d=d[d.length-1],d.parentNode.insertBefore(r,d),i=r.contentWindow,s=i.document;try{o=s}catch(c){n=document.domain,r.src='javascript:var d=document.open();d.domain="'+n+'";void(0);',o=s}o.open()._l=function(){var o=this.createElement("script");n&&(this.domain=n),o.id="js-iframe-async",o.src=e,this.t=+new Date,this.zendeskHost=t,this.zEQueue=a,this.body.appendChild(o)},o.write('<body onload="document._l();">'),o.close()}("//assets.zendesk.com/embeddable_framework/main.js","{$domain}");/*]]>*/</script>
46+
<!-- End of Zendesk Widget script -->
47+
EOJS;
48+
49+
$config->saveConfig('zendesk/frontend_features/web_widget_code_snippet', $webWidgetSnippet);
50+
} else {
51+
// There is no domain on the settings, we can't activate the Web Widget
52+
// The user should probably re-run the Setup from the Zendesk extension settings page
53+
$config->saveConfig('zendesk/frontend_features/web_widget_code_active', 0);
54+
$config->saveConfig('zendesk/frontend_features/web_widget_code_snippet', '');
55+
}

src/app/code/community/Zendesk/Zendesk/etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@
250250
<customer_sync>0</customer_sync>
251251
</general>
252252
<frontend_features>
253-
<feedback_tab_code_active>0</feedback_tab_code_active>
253+
<web_widget_code_active>0</web_widget_code_active>
254254
<contact_us>0</contact_us>
255255
</frontend_features>
256256
<backend_features>

0 commit comments

Comments
 (0)