Displaying a cms page from within a template file - magento

I'm trying to display a home page for logged in users and a different home page for non logged in users. Up until now i've been using the standard homepage with the url key 'home' as my homepage. I've created a new cms page with the url key 'home1' which will be for non logged in users.
I'm able to output some content from the non logged in users page but if I add a table and insert images using the wysisyg then the image src is stripped when i go to view the page. It's only displaying text at the moment, if I hard code the images its fine but i need to be able to use the wysiwyg.
Both pages are using the empty.phtml template file.
Inside this template file i have the following code
# Check if user is logged in and output the standard home page
if($this->helper('customer')->isLoggedIn()) {
echo $this->getChildHtml('content');
}
else
{
# Load cms page for non logged in users then output the content
$model = Mage::getModel('cms/page')->load('home1','identifier');
echo $model->getContent();
}
there's probably a much better way of doing this so if anybody knows it then I'd appreciate your input.
Thank you

Try to show the both content from Magento Static Blocks instead using two cms pages.
if($this->helper('customer')->isLoggedIn())
{
// Static Block Content for Logged in Customers
echo $this->getLayout()->createBlock('cms/block')->setBlockId('logged_in_customers')->toHtml();
}
else
{
// Static Block Content for Non-Logged in Customers
echo $this->getLayout()->createBlock('cms/block')->setBlockId('non_logged_in_customers')->toHtml();
}

Related

Prestashop 1.7 Breadcrumb titles

I am trying to edit the breadcrumbs in a custom Prestashop theme that I am making based on the Classic theme in version 1.7.6.8. The website I am working on has Prestashop located in a folder at mydomain.com/shop, so I would like the breadcrumbs to read:
Home / Shop / Products
Where Home links to mydomain.com and Shop goes to mydomain.com/shop.
I have added the link for Home to mydomain.com ok. Now I want to change the default Prestashop breadcrumbs because it currently reads:
Home / Home / Products
The second home goes to the right link (mydomain.com/shop) but I don't know how to change it to read Shop instead of Home. I have found a way to edit the controllers so as to remove the second home link, this would allow me to just add a new link with Shop next to the new Home link that I already added, however this doesn't seem like a very elegant solution and will require altering the script on lots of pages. Surely there must be a better way?
Thanks for any feedback.
Edit: Here is the code from controllers/productController.php
public function getBreadcrumbLinks()
{
/*$breadcrumb = parent::getBreadcrumbLinks();*/
$categoryDefault = new Category($this->product->id_category_default, $this->context->language->id);
foreach ($categoryDefault->getAllParents() as $category) {
if ($category->id_parent != 0 && !$category->is_root_category) {
$breadcrumb['links'][] = $this->getCategoryPath($category);
}
}
if (!$categoryDefault->is_root_category) {
$breadcrumb['links'][] = $this->getCategoryPath($categoryDefault);
}
/*$breadcrumb['links'][] = array(
'title' => $this->product->name,
'url' => $this->context->link->getProductLink($this->product, null, null, null, null, null, (int) $this->getIdProductAttributeByRequest()),
);*/
return $breadcrumb;
}
You can see the two sections I have removed, the first removes the default "Home" link, the second removes the link with the product name that I do not need. Obviously the code goes somewhere to look up the link and matches it to a name, I just don't know where.
I found the answer, you can change the tag from "Home" to "Shop" by altering the files in shoproot/var/cache/prod/translations/catalogue.[your language].php
There are a number of places where "Home" appears in the file, to change the breadcrumb it is around line 6370 in the en-gb version.
EDIT: Here is a better option, from your Prestashop control panel you can go to international, translations, modify translations. From the drop downs select theme translation, the theme you are working on, the language, click modify, search for "home" and then put the translation as "shop". This saves you having to make the change to the cached file if you have to clear the cache from the control panel.

Magento LiteMage Cache - Excluding a block from caching

I have a Magento site with LiteMage cache on.
My website share a common header at every pages. In the header, I have the following code, which checks to see if a customer is logged in to show either "Account" if logged in or "Log in" otherwise.
My problem is that, when a customer is logged in, it still shows "Log in" in some pages but "Account" at some other pages.
I believe this problem is related to my cache, how do I fix this?
How do I set to exclude this particular block from caching in LiteMage, if this is how it should be fixed.
The following code is the relevant part of the codes I have at my header.phtml
<?php
//check the user is logged on or not
if (! Mage::getSingleton('customer/session')->isLoggedIn()){
//if user logged on show the logout link - add this code within anchor tag
echo ''.$this->__('Log In').'';
}
else{
//if user is not logged on yet show the login link - add this code within anchor tag
echo ''.$this->__('Account').'';
}
?>
You need to identify which block contains this code. Like in default magento sample data, the login link is inside "top.links", and that block is hold punched. Try not to use the full header for it, the smaller the scope, the faster it is. Once you know the block name, you can add that in the "customized block name for top links".

Joomla 3.0 administration protection remove iframe

I have more joomla pages, and i must work at the same time on more admin. panels, so i have created a page where i load pages in iframe, but joomla admin. area is protected from iframe, know someone how can i deactivate this protection?
If i try to open in iframe:www.mypage.com/administrator then i will be redirected to normal page.
I have tried to create new admin template, without any scripts but protection is yet here, i can't found anything with keyword "iframe" or something...
you are looking for the noframes behavior, the com_login view loads
JHtml::_('behavior.noframes');
which ends up calling the noFrames function in the JHtmlBehavior class (libraries/joomla/html/behavior.php)
which loads
$js = "window.addEvent('domready', function () {
if (top == self) {
document.documentElement.style.display = 'block';
}" .
" else {top.location = self.location; }
});";
basically telling the window to change location, so either change how noFrames works or remvoe the JHtml::_('behavior.noframes') call
But note that you shouldnt mod core files as they will get overwritten on updates that need to update that file.

Displaying a static block as a popup window in Magento

I'm trying to display a static block in Magento as a popup window, but can't seem to get the code to work.
I've found code in various places on the internet that seems to be fairly close to what I want but I can't get any results. I've used the basic code to return the "top links" to my site so I know that the basics work.
I've created a delpopup.php script in my Magento root folder and put in this code:
<?php
require_once('app/Mage.php');
umask(0);
$layout = Mage::app()
->getLayout();
$layout
->getUpdate()
->addHandle('default')
->load();
$layout
->generateXml()
->generateBlocks();
echo '<p>before</p>';
echo $layout
->createBlock('cms/block')
->setBlockId('delivery-info')
->toHtml();
echo '<p>after</p>';
?>
Unfortunately the code doesn't display the static block. That part of the output is blank.
The idea is that I can place a link in a regular page in Magento and have my delivery into pop up. Like this:
<a title="" onclick="popWin('http://www.mysite.com.au/delpopup.php', 'deliveryinfo', 'width=300,height=300,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;" href="#">Delivery Info</a>
Basically I want to be able to display a static block in a popup window that uses my Magento site's theme. Any ideas would be greatly appreciated.
As I thought, the problems lies on incorrect Block Id.
Now that the cms is able to be shown.
So now the question is: how to get the theme work?
Not really sure what do you mean by theme, if what you mean is css that was included in <default> tag, you can use:
Mage::getDesign()->setTheme('your theme');
echo $layout->getBlock('head')->toHtml();
After the xml has been finished generated, it means put that code after:
$layout
->generateXml()
->generateBlocks();
I'd first setup a controller and block(s) to render the type of layout that you want to throw within the popup. So, instead of doing this within a standalone php file, do it within the regular mage framework within a specific controller action.
Then, once you have that working - the question is how to pull it into a popup. I'd go with maybe a nice jquery popup widget that allows you to specify a URL to hit - and then just pass in the one that you prepped for step 1 above.
You may want to look at adminhtml/default/default/template/popup.phtml for inspiration. That's actually a popup template for the admin, not the frontend, but you can see what they've done.
They're pulling in some standard magento blocks including the head block, which should pull in all your CSS and JS, in order to give you the general color scheme / look&feel of your frontend, but without all of the navigation, etc.

Magento: How to use admin configforms in frontend?

I have an extension which should give the users (logged in as an Admin in the magento backend) the ability to change some configs in the frontend area. I want to have a link in the frontend which loads the config area via ajax and gives the user the possibility to edit&save this config in the loaded div. I want to use the magento backend forms for this so i don't have to code the forms myself.
My current approach has the link on the pages and loads via ajax the correct backend page (e.g. System > Configuration > Design). For this approach I created a Controller which extends the Mage_Adminhtml_Controller_Action. This Controller get the params from the ajax request and uses an action (like the editAction of the class Mage_Adminhtml_System_ConfigController) to get the right config page in the backend.
My Problems are:
- showing only the correct Area (I just want the user to edit only the section "themes" under System > Configuration > Design) everything else should be not available... so how to remove all the information around this config section?
The form needs the JS-variable Form_Key. How to get the current Form_Key (in the frontend)?
After the ajax has loaded the content the form doesnt get initialized correctly. So if I'm trying to submit the form my firebug says "JS-Error: configForm is not defined". How to solve this form initialising ? Any ideas?
I really hope anybody here can give me a hint how to solve this problems to get the backend config work in the frontend.
This is untested, but it should be enough to get you on the right track:
Output only a specific block
In the frontend most blocks are instantiated via layout XML. In the adminhtml area this is different, so you need to work with PHP instantiation much more.
In your AJAX action I assume you are currently calling loadLayout() and renderLayout().
To only output a specific section use this instead:
public function yourAjaxAction()
{
// assuming the required config section is set in the AJAX request
$sectionCode = $this->getRequest()->getParam('section');
$sections = Mage::getSingleton('adminhtml/config')->getSections();
$blockName = (string)$sections->frontend_model;
if (empty($blockName)) {
$blockName = Mage_Adminhtml_Block_System_Config_Edit::DEFAULT_SECTION_BLOCK;
}
$block = $this->getLayout()->createBlock($blockName)->initForm();
// Set the AJAX response content
$this->getResponse()->setBody($block->toHtml());
}
The form key
The form key can be fetched via
Mage::getSingleton('core/session')->getFormKey()
It must be present in the form posted back to the server. You can use the following code to create a HTML hidden field with the formkey:
// If loadLayout() was called:
$formkeyHtml = Mage::app()->getLayout()->getBlock('formkey')->toHtml();
// If working without layout XML:
$formkeyHtml = Mage::app()->getLayout()->createBlock('core/template', 'formkey')
->setTemplate('formkey.phtml') // adminhtml theme formkey
//->setTemplate('core/formkey.phtml') // frontend theme formkey
->toHtml();
Add configForm JavaScript
The configForm variable is an JS varienForm object of the DOM element containing the config fields.
It is instantiated using:
// config_edit_form is the CSS id
configForm = new varienForm('config_edit_form');
The varienForm declaration is in the file js/varien/form.js.
There also is some additional javascript used by the system configuration. Magento always adds in these blocks to set up the system config JS environment:
Mage::app()->getLayout()->getBlock('js')->append(
$this->getLayout()->createBlock('adminhtml/template')
->setTemplate('system/shipping/ups.phtml')
);
Mage::app()->getLayout()->getBlock('js')->append(
$this->getLayout()->createBlock('adminhtml/template')
->setTemplate('system/config/js.phtml')
);
Mage::app()->getLayout()->getBlock('js')->append(
$this->getLayout()->createBlock('adminhtml/template')
->setTemplate('system/config/applicable_country.phtml')
);
I hope that gets you started.

Resources