Wednesday, August 13, 2014

How to change core configuration data in magento programmatically

$coreConfig = Mage::getModel('core/config');
$coreConfig ->saveConfig($path, $value, $scope = ‘default’, $scopeId = 0);

For it magento use core_config_data table and
core_config_data table contain two important fields scope and scope_id.
There are three scope types
default
websites
stores
If scope is set to default then scope_id is always 0.
If scope is set to websites then scope_id is website_id.
If scope is set to stores then scope_id is store_id(store view).
Imagine that we need to get some config value.
How Magento will get the it for current store view?
Search value by priority:
scope == stores and scope_id == store_id(store view)
scope == websites and scope_id == website_id (to which belongs current store view)
scope == default
default section of config.xml

Wednesday, July 30, 2014

Magento : Difference between “Flush Magento Cache” and “Flush Cache Storage” in magento cache management

Flush Magento Cache

Removes all items in the default Magento cache (var/cache) and the var/full_page cache that have a Magento tag

Flush Cache Storage

Removes all items in the cache. This is the equivalent of deleting the entire contents of the cache folder on the server.If your system uses an alternate cache location, any cached files used by other applications will be removed.

Sunday, June 15, 2014

Add wysiwyg editor in Magento Custom Module

Considering custom module Bd_Demo

Add following function in Bd_Demo_Block_Adminhtml_Demo_Edit

protected function _prepareLayout() {
parent::_prepareLayout();
if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
}
}

Then use as in grid from Bd_Demo_Block_Adminhtml_Demo_Edit_Tab_Form
$fieldset->addField("wood_description", "editor", array(
"label" => Mage::helper("woodflooring")->__("Description"),
"class" => "required-entry",
"required" => true,
"name" => "wood_description",
'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
'wysiwyg' => true,
));

Wednesday, May 14, 2014

Accordion using jQuery

<div id="accordion">
<h3 class="title">First header</h3>
<div class="content">First content panel</div>
<h3 class="title">Second header</h3>
<div class="content">Second content panel</div>
</div>

<style>
.content{display:none;}
</style>

//Type One
<script>
jQuery('#accordion .title').each(function(){
jQuery(this).addClass('active');
jQuery(this).toggle(function(){
jQuery(this).addClass('active').next().slideDown(200);
},function(){
jQuery(this).removeClass('active').next().slideUp(200);
})
});
</script>

//Type Two
<script>
a = jQuery('.footer-menu').find('#accordion .title');
console.log(a.hasClass('active'));
jQuery('#accordion .title').click(function(e){
e.preventDefault();
speed = 300;
if(jQuery(this).hasClass('active') === true) {
} else if(a.hasClass('active') === false) {
jQuery(this).addClass('active').next('.content').slideDown(speed);
} else {
a.removeClass('active').next('.content').slideUp(speed);
jQuery(this).addClass('active').next('.content').delay(speed).slideDown(speed);
}
});
</script>

Tuesday, May 6, 2014

Magento : SQL Injection in Magento

SQL injection is a technique where malicious users can inject SQL commands into an SQL statement, via web page input.

Binding is the way to go for direct queries in Magento.
As
$write = Mage::getSingleton("core/resource")->getConnection("core_write");
$query = "insert into table_name(name, email, company, description) values (:name, :email, :company, :desc)";
$binds = array(
'name' => "name' or 1=1",
'email' => "email",
'company' => "company",
'desc' => "desc",
);
$write->query($query, $binds);

Monday, April 21, 2014

Add a link to show Desktop View for responsive site

<span class="destop-versite">View Desktop Version</span>
var targetWidth = 1280;

jQuery('.destop-versite').bind('click', function(){
jQuery('meta[name="viewport"]').attr('content', 'width=' + targetWidth);
});

Tuesday, April 1, 2014

How to add sharing functionality to website

<?php
$message='';
$url=urlencode($url);
?>
<div class="share-this">
<span><?php echo $this->__('Share this article on');?></span>
<ul>
<li class="fb-share">
<a href="javascript:poptastic('https://www.facebook.com/sharer/sharer.php?u=<?php echo $url; ?>')" title="<?php echo $this->__('Share on Facebook'); ?>">Facebook</a>
</li>

<li class="twitter-share">
<a href="javascript:poptastic('http://twitter.com/intent/tweet?text=<?php echo $message; ?>&url=<?php echo $url; ?>');" title="<?php echo $this->__('Share With Twitter'); ?>">Tweet</a>
</li>

<li class="zing-share">
<a href="javascript:poptastic('http://link.apps.zing.vn/share?u=<?php echo $url; ?>&t=&desc=&images=&media=&width=0&height=0')">Zing</a>
</li>

<script>
function poptastic(url) {
var newWindow = window.open(url, 'name', 'height=600,width=450,top=100,left=500');
if (window.focus) {
newWindow.focus();
}

}
</script>

</ul>
</div>
Subscribe to: Comments (Atom)

AltStyle によって変換されたページ (->オリジナル) /