Sunday, 9 October 2011

Magento Code to get General Store Information


Most of the time we want to access Store Contact info at different places of our magento site to do this we have a very simple and useful code i.e
echo Mage::getStoreConfig('general/store_information');
This code will fetch you an array containing complete store which is provided at backend From System->Configuration->General->Store Information. use address
echo Mage::getStoreConfig('general/store_information/address'); 
use phone no
echo Mage::getStoreConfig('general/store_information/phone'); 
or you can get using
$info = Mage::getStoreConfig('general/store_information');
store name : $info['name']
store address : $info['address']
store Phone : $info['phone']

Monday, 26 September 2011

Magento: Adding New attributes in Category General Information

Add Below code to any file and change with my_attribute to your attribute than run that file. so for example if you past it in category/view.phtml file than open any category page from frontside and Attribute was created. see in backend category page. it will be done dont forgot to remove this code from that file after attribute was created.
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('catalog_category', 'my_attribute', array(
    'group'         => 'General',
    'input'         => 'text',
    'type'          => 'varchar',
    'label'         => 'My Attribute',
    'backend'       => '',
    'visible'       => 1,
    'required'      => 0,
    'user_defined' => 1,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
you can use it If it is a text field (textbox or textarea), this is all you have to do:
echo $_product->getMyAttribute()
If you are using a dropdown or a multiple select, you have to call it a little differently:
echo $_product->getAttributeText('my_attribute')

Saturday, 24 September 2011

Magento Jextn Faq SQLSTATE[42S22]: Column not found: 1054 Unknown column 'store' in 'where clause'

When I installed  Jextn Faq  Extension I got the following error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'store' in 'where clause'

I have just comment on three lines and works for me.
app\code\community\Jextn\Faq\Model\Mysql4\Faq\collection.php
after 
public function setFirstStoreFlag($flag = false)
{
    $this->$previewFlag = $flag;
    return $this;
}
 before
public function setFirstStoreFlag($flag = false)
{
//  $this->$previewFlag = $flag;
    return $flag;
}
In same file remove If condition from  function _afterLoad() and its look like this
protected function _afterLoad()
{
//        if ($this->$previewFlag) {
        $items = $this->getColumnValues('faq_id');
        if (count($items)) {
            $select = $this->getConnection()->select()
                    ->from($this->getTable('faq_store'))
                    ->where($this->getTable('faq_store').'.faq_id IN (?)', $items);
            if ($result = $this->getConnection()->fetchPairs($select)) {
                foreach ($this as $item) {
                    if (!isset($result[$item->getData('faq_id')])) {
                        continue;
                    }
                    if ($result[$item->getData('faq_id')] == 0) {
                        $stores = Mage::app()->getStores(false, true);
                        $storeId = current($stores)->getId();
                        $storeCode = key($stores);
                    } else {
                        $storeId = $result[$item->getData('faq_id')];
                        $storeCode = Mage::app()->getStore($storeId)->getCode();
                    }
                    $item->setData('_first_store_id', $storeId);
                    $item->setData('store_code', $storeCode);
                }
            }
        }
//        }
    parent::_afterLoad();
}
change in this file also app\code\community\Jextn\Faq\Model\Mysql4\faq.php change
after
$collection = Mage::getModel('faq/faq')->getCollection()
                ->addStoreFilter($storeId)
                ->addIsActiveFilter();
before
$collection = Mage::getModel('faq/faq')->getCollection()
                //->addStoreFilter($storeId)
                ->addIsActiveFilter();

Thursday, 22 September 2011

Remove Category option from Layered Navigation options list

Try this:
1) open app\code\core\Mage\Catalog\Block\Layer\View.php
2) find
$categryBlock = $this->getLayout()->createBlock('catalog/layer_filter_category')
            ->setLayer($this->getLayer())
            ->init();

$this->setChild('layer_state', $stateBlock);
$this->setChild('category_filter', $categryBlock);
3) change with
$this->setChild('layer_state', $stateBlock);

Monday, 19 September 2011

Magento: Login required for Add Review

If you want to restriction for adding review than add below condition to form which is located at.
app\design\frontend\base\default\template\review\form.phtml
add below code to before form start
if ((boolean) $this->helper('customer')->isLoggedIn() )
{ ?>
add below code to after form end and before script start
else //customer is NOT logged in
{
        echo $this->__('To prevent SPAM we ask our customers to login before posting a review. Thank you for your understanding!'); 
        echo 'Please Sign In to post review ';
} 
?>

Magento: Remove auto Breaks("br/") from product description

By Default Magento automatically adds

html tags to product descriptions for display on the customer interface.  If you have created a nice description with the WYSIWYG Editor or imported HTML descriptions you most likely want to remove this behavior.   Luckily this is not hard to do.
  1. Find the file "description.phtml" here:  app/design/frontend/default/ 
  2. Remove the "nl2br" tag
Before:
helper('catalog/output')->productAttribute($this->getProduct(), 
nl2br($this->getProduct()->getDescription()), 'description') ?>
After:
helper('catalog/output')->productAttribute($this->getProduct(),   
$this->getProduct()->getDescription()), 'description' ?>

Monday, 12 September 2011

Magento how to add Date field with DatePicker

I have creating a form i'm using in the admin page on a custome module I have been writing, Im using addField to add text fields however now need to add a date field. I changed the type from text to date and add format. heres what I have done put below code to your admin block file.

$outputFormat = Mage::app()->getLocale()->
    getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
$fieldset->addField('created_time', 'date', 
            array('label' = > Mage::helper('schedulelist')->__('Created Date'),
            'required' => true,
            'name' => 'created_time',
            'image' => $this->getSkinUrl('images/grid-cal.gif'),
            'format' => $outputFormat,
));