|
| 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 | +} |
0 commit comments