Magento shop static block with different content in shops - magento

so as you read title, i need help with magento static block, my task is to make static block content different in 2 shops, if it's even possible? ty for answers.
P.S. Sorry for bad english.

FYI the correct Magento way to do this in multi-store is to create 2 static block with the same ID and assign each one to the store view you want it to show on. Magento will load the correct version based on the current store being viewed.

Try this one it works for me. I made it with html/javascript. You can get store name by
var shopName= '{{config path="general/store_information/name"}}';
and then compare by your needs. Paste code into static block editor.
<!DOCTYPE html>
<html>
<body onload="websiteMessage()">
<p>Happy new years !!!</p>
<p id="static_block"></p>
<script>
function websiteMessage() {
var shopName= '{{config path="general/store_information/name"}}';
var string = "";
if(shopName.localeCompare("Leather_shoes_shop") == 0)
{
string = "leather shoes";
}
else if(shopName.localeCompare("Rubber_shoes_shop") == 0)
{
string = "rubber shoes";
}
else
{
string = "other";
}
document.getElementById('static_block').innerHTML = string;
}
</script>
</body>
</html>

Related

Why does my header end up way outside the page with TuesPechkin?

I do a convert
document.Objects.Clear();
document.GlobalSettings.PaperSize = PaperKind.A4;
document.Objects.Add(new ObjectSettings
{
HtmlText = xml,
HeaderSettings = new HeaderSettings { HtmlUrl = headerPath, RightText = "[page]/[sitepages]", ContentSpacing = 10 },
FooterSettings = new FooterSettings { HtmlUrl = headerPath, RightText = "[page]/[sitepages]" },
});
and the HTML is visible in the footer, but in the header it's way outside the page. It looks like it tries to put the header on the previous page, that's how far outside it it.
OK, the answer was as simple and not obvious. The header HTML is a bit more sensitise so it needed a <!doctype html> first in the file.

Is it possible to open embedded HTML file using Xamarin.Essetianls.Browser

Need to present fairly large T&Cs embedded document in Xamarin Native (NOT Xamarin.Forms). Xamarin.Essetianls.Broswser.OpenAsync("url") works brilliantly for the website page, but getting error:
The specified URL has an unsupported scheme. Only HTTP and HTTPS URLs are supported.
if trying
await Browser.OpenAsync("file://Data/TsAndCs.html")
In android, you can put the your local html page to the Assets folder, please notice the Build Action to the AndroidAsset.
Then you can create a interface to get the html file path.
public interface IBaseUrl
{
string Get();
}
Achieve it in the Android folder.
[assembly: Dependency(typeof(BaseUrl_Android))]
namespace MyWebView.Droid
{
public class BaseUrl_Android : IBaseUrl
{
public BaseUrl_Android()
{
}
public string Get()
{
return "file:///android_asset/";
}
}
}
For IOS achievement, you can refer to this thread:
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/webview?tabs=windows#local-html-content
Notice: If you want to Interaction between JS code and control of xamarin forms before html page displayed, please put this part code to Navigated="MywebView_Navigated"
Here is my local html.
<!DOCTYPE html>
<html>
<body>
<span id="myfont">This is Local Html</span>
<script type="text/javascript">
function factorial(num) {
if (num === 0 || num === 1)
return 1;
for (var i = num - 1; i >= 1; i--) {
num *= i;
}
return num;
}
</script>
</body>
</html>
Here is running screenshot.

Display cms page in a module page

I use a 3rd party module for the Customer Service of my website.
In this module, there is a dedicate page to create a ticket.
I try to add a cms page (already create in Pages of Prestashop) in the left of the form of this page.
For that, I create a function in modules/{THEmodule}/controllers/front/function.php
public function getFAQ($id_cms, $id_lang = null, $id_shop = null){
if (is_null($id_lang)) {
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
}
if (is_null($id_shop)) {
$id_shop = (int)Configuration::get('PS_SHOP_DEFAULT');
}
$sql = new DbFAQ();
$sql->select('content');
$sql->from('cms_lang');
$sql->where('id_cms = .(int)$id_cms.' AND 'id_lang = .(int)$id_lang.' AND 'id_shop = .(int)$id_shop');
return Db::getInstance()->executeS($sql);
}
Then I call the function in .tpl
<div id="support-getFAQ">
{$getFAQ=12} {* 12 is the id of the cms page that I want display *}
</div>
But when I check the page, nothing is display, so I guess is not the good way.
Could someone help me?
Thanks to #marcin-jaworski to give me the way.
The solution is simple.
No need to add function, just write in tpl:
{assign var=new_smarty_var value=CMS::getCMSContent(12)}
{$new_smarty_var.content nofilter}
Don't forget "nofilter" to print html.
Because of good practise you should assign smarty variable in your module controller or display function for hook.
PrestaShop DevDocs
Displaying content on the front office
You can get CMS content by use function already made in CMS class (/classes/CMS.php):
public static function getCMSContent($id_cms, $id_lang = null, $id_shop = null)
public static function getCMSPages($id_lang = null, $id_cms_category = null, $active = true, $id_shop = null)
Also i have little trick witch you can use in .tpl
{assign var=new_smarty_var value=(CMS::getOneCMS(11, $language.id)}
{$new_smarty_var.content}

Google App Scripts Function to Open URL [duplicate]

Is there a way to write a google apps script so when ran, a second browser window opens to www.google.com (or another site of my choice)?
I am trying to come up with a work-around to my previous question here:
Can I add a hyperlink inside a message box of a Google Apps spreadsheet
This function opens a URL without requiring additional user interaction.
/**
* Open a URL in a new tab.
*/
function openUrl( url ){
var html = HtmlService.createHtmlOutput('<html><script>'
+'window.close = function(){window.setTimeout(function(){google.script.host.close()},9)};'
+'var a = document.createElement("a"); a.href="'+url+'"; a.target="_blank";'
+'if(document.createEvent){'
+' var event=document.createEvent("MouseEvents");'
+' if(navigator.userAgent.toLowerCase().indexOf("firefox")>-1){window.document.body.append(a)}'
+' event.initEvent("click",true,true); a.dispatchEvent(event);'
+'}else{ a.click() }'
+'close();'
+'</script>'
// Offer URL as clickable link in case above code fails.
+'<body style="word-break:break-word;font-family:sans-serif;">Failed to open automatically. Click here to proceed.</body>'
+'<script>google.script.host.setHeight(40);google.script.host.setWidth(410)</script>'
+'</html>')
.setWidth( 90 ).setHeight( 1 );
SpreadsheetApp.getUi().showModalDialog( html, "Opening ..." );
}
This method works by creating a temporary dialog box, so it will not work in contexts where the UI service is not accessible, such as the script editor or a custom G Sheets formula.
You can build a small UI that does the job like this :
function test(){
showURL("http://www.google.com")
}
//
function showURL(href){
var app = UiApp.createApplication().setHeight(50).setWidth(200);
app.setTitle("Show URL");
var link = app.createAnchor('open ', href).setId("link");
app.add(link);
var doc = SpreadsheetApp.getActive();
doc.show(app);
}
If you want to 'show' the URL, just change this line like this :
var link = app.createAnchor(href, href).setId("link");
EDIT : link to a demo spreadsheet in read only because too many people keep writing unwanted things on it (just make a copy to use instead).
EDIT : UiApp was deprecated by Google on 11th Dec 2014, this method could break at any time and needs updating to use HTML service instead!
EDIT :
below is an implementation using html service.
function testNew(){
showAnchor('Stackoverflow','http://stackoverflow.com/questions/tagged/google-apps-script');
}
function showAnchor(name,url) {
var html = '<html><body>'+name+'</body></html>';
var ui = HtmlService.createHtmlOutput(html)
SpreadsheetApp.getUi().showModelessDialog(ui,"demo");
}
There really isn't a need to create a custom click event as suggested in the bountied answer or to show the url as suggested in the accepted answer.
window.open(url)1 does open web pages automatically without user interaction, provided pop- up blockers are disabled(as is the case with Stephen's answer)
openUrl.html
<!DOCTYPE html>
<html>
<head>
<base target="_blank">
<script>
const url1 ='https://stackoverflow.com/a/54675103';
const winRef = window.open(url1);
winRef ? google.script.host.close() : window.alert('Allow popup to redirect you to '+url1) ;
window.onload=function(){document.getElementById('url').href = url1;}
</script>
</head>
<body>
Kindly allow pop ups</br>
Or <a id='url'>Click here </a>to continue!!!
</body>
</html>
code.gs:
function modalUrl(){
SpreadsheetApp.getUi()
.showModalDialog(
HtmlService.createHtmlOutputFromFile('openUrl').setHeight(50),
'Opening StackOverflow'
)
}
Google Apps Script will not open automatically web pages, but it could be used to display a message with links, buttons that the user could click on them to open the desired web pages or even to use the Window object and methods like addEventListener() to open URLs.
It's worth to note that UiApp is now deprecated. From Class UiApp - Google Apps Script - Google Developers
Deprecated. The UI service was deprecated on December 11, 2014. To
create user interfaces, use the HTML service instead.
The example in the HTML Service linked page is pretty simple,
Code.gs
// Use this code for Google Docs, Forms, or new Sheets.
function onOpen() {
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.createMenu('Dialog')
.addItem('Open', 'openDialog')
.addToUi();
}
function openDialog() {
var html = HtmlService.createHtmlOutputFromFile('index')
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.showModalDialog(html, 'Dialog title');
}
A customized version of index.html to show two hyperlinks
<a href='http://stackoverflow.com' target='_blank'>Stack Overflow</a>
<br/>
<a href='http://meta.stackoverflow.com/' target='_blank'>Meta Stack Overflow</a>
Building of off an earlier example, I think there is a cleaner way of doing this. Create an index.html file in your project and using Stephen's code from above, just convert it into an HTML doc.
<!DOCTYPE html>
<html>
<base target="_top">
<script>
function onSuccess(url) {
var a = document.createElement("a");
a.href = url;
a.target = "_blank";
window.close = function () {
window.setTimeout(function() {
google.script.host.close();
}, 9);
};
if (document.createEvent) {
var event = document.createEvent("MouseEvents");
if (navigator.userAgent.toLowerCase().indexOf("firefox") > -1) {
window.document.body.append(a);
}
event.initEvent("click", true, true);
a.dispatchEvent(event);
} else {
a.click();
}
close();
}
function onFailure(url) {
var div = document.getElementById('failureContent');
var link = 'Process';
div.innerHtml = "Failure to open automatically: " + link;
}
google.script.run.withSuccessHandler(onSuccess).withFailureHandler(onFailure).getUrl();
</script>
<body>
<div id="failureContent"></div>
</body>
<script>
google.script.host.setHeight(40);
google.script.host.setWidth(410);
</script>
</html>
Then, in your Code.gs script, you can have something like the following,
function getUrl() {
return 'http://whatever.com';
}
function openUrl() {
var html = HtmlService.createHtmlOutputFromFile("index");
html.setWidth(90).setHeight(1);
var ui = SpreadsheetApp.getUi().showModalDialog(html, "Opening ..." );
}
I liked #Stephen M. Harris's answer, and it worked for me until recently. I'm not sure why it stopped working.
What works for me now on 2021-09-01:
function openUrl( url ){
Logger.log('openUrl. url: ' + url);
const html = `<html>
<a id='url' href="${url}">Click here</a>
<script>
var winRef = window.open("${url}");
winRef ? google.script.host.close() : window.alert('Configure browser to allow popup to redirect you to ${url}') ;
</script>
</html>`;
Logger.log('openUrl. html: ' + html);
var htmlOutput = HtmlService.createHtmlOutput(html).setWidth( 250 ).setHeight( 300 );
Logger.log('openUrl. htmlOutput: ' + htmlOutput);
SpreadsheetApp.getUi().showModalDialog( htmlOutput, `openUrl function in generic.gs is now opening a URL...` ); // https://developers.google.com/apps-script/reference/base/ui#showModalDialog(Object,String) Requires authorization with this scope: https://www.googleapis.com/auth/script.container.ui See https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes
}
https://developers.google.com/apps-script/reference/base/ui#showModalDialog(Object,String) Requires authorization with this scope: https://www.googleapis.com/auth/script.container.ui See https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes

IText "IntelliSense"

I need some guidance on achieving the below mentioned objective.
Develop something that can run as a scheduled job on Windows Server 2012 that can convert HTML file to PDF. We used to use Omniformat, but after migrating to Windows Server 2012, this is no longer an option as it will just stuck there.
I did some POC using iText, look promising except for the following points:
i. if the styling did not specify the font-family, IE will render it correctly, however IText will just print an empty block. This happened to my test case with Arabic and Russian characters.
<html>
<head></head>
<body>
Random Text, which I have no idea what are there.<br/>
<span style="font-family: Arabic Typesetting">This works!
Arabic : سعيد
</span>
<span> This isn't working
Arabic : سعيد
</span>
<br/>
<span>
Russian: Счастливый
</span>
<span style="font-family: MingLiu">
Simplfied Chinese: 快乐
</span>
<br/>
<span style="font-family: MingLiu">
Traditional Chinese: 快樂
</span>
</body>
</html>
What I have done so far.
I presume I have to have a customized TagProcessor.
public class MyParaGraph extends ParaGraph
{
#Override
public List<Element> content(WorkerContext arg0, Tag arg1, String arg2)
{
List<Element> elements = super.content(arg0, arg1,arg2);
Iterator<Element> eleIter = elements.iterator();
while( eleIter.hasNext())
{
Element element = eleIter.next();
List<Chunk> chunks = element.getChunks();
Iterator<Chunk> chunkIter = chunks.Iterator();
while (chunkIter.hasNext())
{
Chunk chunk = chunkIter.next();
for ( char charStr : arg2.toCharArray() )
{
//Intention is for future, if there is multiple Unicode characteres of different langauge, to create different chunk with differnt Font assigned.
//For now, quite useless loop,
//isarabic
if ( (code > 0x600 && code < code < 0x6FF) || (code > 0x750 && code < code < 0x77F))
{
//Pardon me, my dev is not linked to internet, i cant copy and paste so i just define a sub set.
if (chunk.getFont.getBaseFont()==null)
{
//It appear the processor failed to find the font-family style being define, as other tag with font-family define will not be null.
FontFactory.register("C:/Windows/Font/Arabaric Typesetting.ttf");
Font font = FontFactory.getFont("Arabaric TypeSetting");
chunk.setFont(font); //Its doesnt seems to update it to ask IText ot use Arabaric Typesetting..
}
}
}
}
}
}
}
HTMLPDFConverter.java
Main:
public static void main(String[] args){
TagProcessorFactory factory = Tags.getHtmlTagProcessorFactory();
factory.addProcessor(new MyParaGraph(), "p","span", "div");
Document doc = new Document();
PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("D:/sample.pdf"));
writer.setPageSize(PageSize.A4);
document.open();
HtmlPipelineContext htmlContext = new HtmlPipelineContext (null);
htmlContext.setTagFactory(factory);
CssResolver cssResolver = XMLWorkerHelper.getInstance().getDefaultCssResolver(true);
Pipeline<?> pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlContext, new PdfWriterPipleline(doc. writer)));
XMLWorker worker= new XMLWorker(pipeline, true);
XMLParser p = new XMLParser(worker);
p.parse( new InputStreamReader(new FileInputStream("D:/sample.html"), "UTF-8");
doc.close();
}
The Arabaric and Russian are not showing in the PDF.
Appreciate any advise.
Sorry for the mess, I can't copy and paste my POC code from development as they are on different network.
Thanks

Resources