Magento change backgrounds per session - session

I'm looking for a simple extension that allows via admin console to load some background pics and display them on the frontend per user session (not on refresh). I don't think anything is out there so some pointers on how to start building one would be great too. Thanks!

Here is a solution for you.
You can upload images through Magento admin into media storage. Lets say you created a subdir "backgrounds" in there and uploaded various images there. Then all you need to do is add the following code into app/design/frontend/[your-interface]/[your-theme]/template/page/html/header.php
<?php
if(!$background = Mage::getSingleton('core/session')->getBackground()){
$img_arr = array();
if($handle = opendir(Mage::getBaseDir('base').'/media/backgrounds/')){
while(false !== ($entry = readdir($handle))){
if(!preg_match('/^\.+$/', $entry)){
$img_arr[] = $entry;
}
}
closedir($handle);
}
if($img_cnt = count($img_arr)){
$background = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK).$img_arr[rand(0, $img_cnt-1)]
Mage::getSingleton('core/session')->setBackground($background);
}
}
?>
<?php if(isset($background) && $background) : ?>
<style> background:url(<?php echo $background; ?>); </style>
<?php endif; ?>
Did not tested it live. Let me know.

Related

Embed Twitter pics as a collage for a website

I'm trying to create a collage of images that are sourced from a twitter feed to be displayed in a website banner.
So far I have set up the Twitter authentication
I'm not sure how to go about extracting just the images from her feed, or embed them in the desired manner.
Any help or information would be greatly appreciated.
Click here to view a possible outcome I'm looking for.
Thanks!
To simply dump a couple of images, try this:
<?php
require_once("/twitteroauth/twitteroauth.php");
$consumerKey = "0LQwV6gQi1hi8TPOMvfqy7qpM";
$consumerSecret = "AuShkWcg7lj8VYyKYOH6WPW8tY6B2QuB8kgRpmALVrg0VK0mM0";
$accessToken = "624631261-DjWeq4RB0eGAB2lr68skZE1zbfDcg2x6BEyJzFZO";
$accessTokenSecret = "8XnWnkiFQ803r9sHVkDrZNhD50EuJlnw8sZI2EPsA9p7X";
$connection = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);
$tweets = $connection->get("https://api.twitter.com/1.1/search/tweets.json?q=%rhyareegaming%20filter%3Aimages&include_entities=true");
foreach ($tweets->statuses as $status) {
?>
<img src="<?php echo $status->entities->media[0]->media_url; ?>">
<?php
}

Only one product on homepage using CMS Page in Magento 1.9.0.1

After one product is displayed, the catalog/product/list.pthml seems not to be executed anymore.
I followed these steps
but it doesn't work. I also have tried to change the indicated lines in list.pthml directly.
I have also ReIndexed to check if product is available, enabled etc.
Any ideas to fix this ?
I made first effords. I replace the indicated lines with following code:
<?php
if ($this->getChild('name.after')) {
$_nameAfterChildren = $this->getChild('name.after')->getSortedChildren();
foreach ($_nameAfterChildren as $_nameAfterChildName) {
$_nameAfterChild = $this->getChild('name.after')->getChild($_nameAfterChildName);
$_nameAfterChild->setProduct($_product);
echo $_nameAfterChild->toHtml();
}
}
?>
And at the bottom
<?php
if ($this->getChild('after')) {
$_afterChildren = $this->getChild('after')->getSortedChildren();
foreach ($_afterChildren as $_afterChildName) {
$_afterChild = $this->getChild('after')->getChild($_afterChildName);
//set product collection on after blocks
$_afterChild->setProductCollection($_productCollection);
echo $_afterChild->toHtml();
}
}
?>
Now it's working, I get everything displayed. PHP log only have 2 "File does not exist" errors.
But now the Design is not responsive. It's not formated anymore. ???

I want change page heading position

In Joomla Page heading showing inside of an article I want to change the position of page heading, is it possible to customize page heading position?
I had included following code in template/protostar/index.php
<?php if ($this->params->get('show_page_heading', 1)) : ?>
<div class="page-header">
<h1> <?php echo $this->escape($this->params->get('page_heading')); ?> </h1>
</div>
<?php endif;
if (!empty($this->item->pagination) && $this->item->pagination && !$this->item->paginationposition && $this->item->paginationrelative)
{
echo $this->item->pagination;
}
?>
What you can do:
Just update one of the css files in the correct template to display the header correctly. If the header should only be reformatted on some pages and not all then you should be using different templates.
What you should do:
Otherwise (if you want to change the php instead) you can override the components/com_content/views/article/default.php using the standard joomla override method.
You can do both the above if necessary.
You should not need to override the index.php of your template in order to do this. However if you really want to i would use the code
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
if ($option=="com_content" && $view=="article") {
$ids = explode(':',JRequest::getString('id'));
$article_id = $ids[0];
$article =& JTable::getInstance("content");
$article->load($article_id);
echo $article->get("title");
}
Sorry if you want more you need to give more :)
PS. I am on joomla 2.5 but i know that for joomla 3 it is more or less the same thing.
Sources: http://forum.joomla.org/viewtopic.php?t=525350
http://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core

How to display error or success message in a template file?

I want to show message on some condition in a template file(custom module template file).I am having following code.
<?php
if(count($collection)): ?>
<?php foreach($collection as $coll): ?>
some calculations
<?php endforeach; ?>
<?php else: ?>
<?php $message = $this->__('There is no data available'); ?>
<?php echo Mage::getSingleton('core/session')->addNotice($message);?>
<?php endif;?>
But this is not working properly. The message is displayed on other pages not on the same page.
If you really need to implement that right in the template, you may use the code below:
<?php echo $this->getLayout()->createBlock('core/messages')->addNotice('My Message')->toHtml(); ?>
But the solution described by Amit Bera sounds like a better way to resolve it.
Muk,According to your code
Mage::getSingleton('core/session')->addNotice($message);
add an notice to magento.This is code set notice to session and which is reflecting on page refresh according php session ,a session variable set value is reflecting after page refresh.
If you already added this notice on other page before came to your file then ,you need to add core/session to custom module template file controllers file.
Code is $this->_initLayoutMessages('core/session');
In controller you need below code in controller.
/* load the layout from xml */
$this->loadLayout();
$this->_initLayoutMessages('core/session');
/* rendering layout */
$this->renderLayout();
Read more at inchoo blog
I found that $this->loadLayout() is what reads and clears messages from the session, therefore if you add messages before calling $this->loadLayout() then those messages should be displayed on the current page.
Example:
public function chooseFileAction() {
// a quick and dirty way to find the larger out of post_max_size and upload_max_filesize
$post_max_size = ini_get('post_max_size'); $post_max_size_int = str_replace('K', '000', str_replace('M', '000000', str_replace('G', '000000000', $post_max_size)));
$upload_max_filesize = ini_get('upload_max_filesize'); $upload_max_filesize_int = str_replace('K', '000', str_replace('M', '000000', str_replace('G', '000000000', $upload_max_filesize)));
$maxsize = $post_max_size_int < $upload_max_filesize_int ? $post_max_size : $upload_max_filesize;
// display max file size to user in a message box
$msg = 'Max file size: ' . $maxsize;
Mage::getSingleton('core/session')->addNotice($msg);
$this->loadLayout();
$this->_title($this->__('Catalog'))->_title($this->__('File Upload'));
$this->_setActiveMenu('catalog/customfileupload');
$block = $this->getLayout()->createBlock('customfileupload/adminhtml_customfileupload_choosefile');
$this->_addContent($block);
$this->renderLayout();
}
Caveat: this is tested in Magento 1.9, not 1.7.

Magento Active Filters on Search Page

I want to implement active filters on my magento ecommerce site.
I have been successful in implementing it, but the issue is, the code works on only category pages and not search page
Here's the code that I'm using
<?php /*Create filter dependencies*/
$_activeFilters[] = array();
$_filters = Mage::getSingleton(‘Mage_Catalog_Block_Layer_State’)->getActiveFilters();
foreach ($_filters as $_filter):?>
<?php echo $this->stripTags($_filter->getLabel()) ?><a href=”<?php echo $_filter- >getRemoveUrl() ?>” title=”<?php echo $this->__(‘Remove This Item’) ?>”><?php echo $this->__(‘Remove This Item’) ?></a>
<?php endforeach; ?>
I'm using this code in toolbar.phtml. Any clue as in why its not working on search page. Any Solutions would be of great help.
Thanks,
Sushil
You can use this code for fetching filters on either category list page or search results page
<?php
if(Mage::registry('current_category')) {
$_filters = Mage::getSingleton('catalog/layer')->getState()->getFilters();
} else {
$_filters = Mage::getSingleton('catalogsearch/layer')->getState()->getFilters();
}
?>
I have used this code in toolbar.phtml, to show removable filters below the toolbar, like flipkart does.
The problem is with this line:
$_filters = Mage::getSingleton(‘Mage_Catalog_Block_Layer_State’)->getActiveFilters();
This gets a singleton which only contains the necessary data when on a category page.
See this question for more details: Magento - How to add Layered Navigation to Advanced Search?

Resources