Just another WordPress.com weblog

Wrapping it up in a class:

class Nick_Module_Model_Log {
  protected $_adapter;

  public __construct() {
    $this->_adapter = Mage::getModel('core/log_adapter', 'my_module.log');
  }

  // It's public incase we want to use ->debug(), ->info(), and friends
  public function getAdapter() {
    return $this->_adapter;
  }

  public function log($message) {
    $this->getAdapter()->log($message);
  }

}
Set up your own log adapter with:
$my_log = Mage::getModel('core/log_adapter', 'my_module.log');

and log away!

$my_log = Mage::getSingleton('nick/log');
$my_log->log("Logging away!");

Thanks,

Vatsal Patadia

Add custom Field/attribute to category using script in magento
$setup = new Mage_Eav_Model_Entity_Setup(‘core_setup’);
// below code will add text attribute
$setup->addAttribute(‘catalog_category’, ‘attribute_code’, array(
‘group’         => ‘General’,
‘input’         => ‘text’,
‘type’          => ‘varchar’,
‘label’         => ‘Attribute label’,
‘backend’       => ”,
‘visible’       => 1,
‘required’      => 0,
‘user_defined’ => 1,
‘global’        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));

// below code will add yes/no attribute

$setup->addAttribute(‘catalog_category’, ‘attribute_code’,  array(
‘type’     => ‘int’,
‘label’    => ‘Attribute label’,
‘input’    => ‘select’,
‘source’   => ‘eav/entity_attribute_source_boolean’,
‘global’   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
‘required’ => false,
‘default’  => 1,
‘user_defined’  => 1,
‘default’  => 0
));

// below code will use to add image attribute

$setup->addAttribute(‘catalog_category’, ‘attribute_code’,  array(
‘group’         => ‘General’,
‘type’     => ‘varchar’,
‘label’    => ‘Attribute Label’,
‘input’    => ‘image’,
‘source’   => ‘eav/entity_attribute_source_boolean’,
‘global’        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
‘required’ => false,
‘backend’ => ‘catalog/category_attribute_backend_image’,
‘frontend_input’ =>”,
‘default’  => 1,
‘visible’       => 1,
‘user_defined’  => 1,
));

 

‘attribute_code’ will be replace with your own attribute code and same way ‘Attribute Label’ will be replace with attribute label.

Once you execute above script, it will automatically creates attribute.

Thanks,

Bijal Bhavsar :)

 

client denied by server configuration: PROJECT_DIR/app/etc/local.xml

It seems that magento is testing to see if the file can be accessed each time a page is loaded and alerts 
you to the fact that this file contains your MySQL database password is readable. 

So it is correct but seems odd that every page should check this filling the log with error messages 
instead of just doing it once at the login page.

To resolve the above error not shown in error_log at cpanel

To get rid of this security check, do not attempt to hack the Magento core (as some forum threads have
 suggested in the past). Instead, you can just modify the admin-theme to remove this check. 
Open up the following file or create it if it does not exist:
"app/design/adminhtml/default/default/layout/local.xml"

Add below code in local.xml of adminhtml/layout

<layout>
 <default>
 <remove name="notification_security" />
 <remove name="notification_survey" />
 </default>
</layout> 

This removes the blocks notification_security and notification_survey from the backend-pages entirely, 
skipping therefor the security check. No core hacks involved. 

Thanks,
Bijal Bhavsar :) 

Hello,

 

We can get order object by increment id using following code:

$orders = Mage::getModel('sales/order')
  ->getCollection() 
  ->addAttributeToFilter('increment_id', 100000001)
  ->getFirstItem();

 

Thanks,

Bijal Bhavsar :)

Hello

For Mass deletion of Coupon and change the “from” and “to” date in mass
For that we have to copy the app/code/core/Mage/Adminhtml/Block/Promo/Quote/Grid.php into

app/code/local/Mage/Adminhtml/Block/Promo/Quote/grid.php and following functions

protected function _prepareMassaction()
{
$dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
$this->setMassactionIdField(‘rule_id’);
$this->getMassactionBlock()->setFormFieldName(‘rule’);

$this->getMassactionBlock()->addItem(‘delete’, array(
‘label’ => Mage::helper(‘rule’)->__(‘Delete’),
‘url’ => $this->getUrl(‘*/*/massDelete’),
‘confirm’ => Mage::helper(‘rule’)->__(‘Are you sure?’)
));

array_unshift($da, array(‘label’=>”, ‘value’=>”));
$this->getMassactionBlock()->addItem(‘date’, array(
‘label’=> Mage::helper(‘salesrule’)->__(‘Change Date’),
‘url’ => $this->getUrl(‘*/*/massDate’, array(‘_current’=>true)),
‘additional’ => array(
‘visibility’ => array(
‘name’ => ‘from_date’,
‘type’ => ‘date’,
‘class’ => ‘required-entry date’,
‘image’ => $this->getSkinUrl(‘images/grid-cal.gif’),
‘format’ => $dateFormatIso,
‘index’ => ‘from_date’,
‘label’ => Mage::helper(‘rule’)->__(‘From Date’)
),
array(
‘name’ => ‘to_date’,
‘type’ => ‘date’,
‘class’ => ‘required-entry date’,
‘format’ => $dateFormatIso,
‘index’ => ‘to_date’,
‘image’ => $this->getSkinUrl(‘images/grid-cal.gif’),
‘label’ => Mage::helper(‘rule’)->__(‘To Date’),
//’values’ => $date
)
)

));

return $this;
}

Clear the Cache from admin Hope this will help

Regards
Sandeep

Hello

If you want to show the exact search reuslt for your products
Two things need to be changed

1) In admin system->configuration->catalog->catlogsearch->Search Type
Make it as Like

2)Just copy the fulltext.php file in local folder as given
app/code/local/Mage/CatalogSearch/Model/Resource/Fulltext.php

and just replace the above code

foreach ($words as $word) {
$like[] = $helper->getCILike(‘s.data_index’, $word, array(‘position’ => ‘any’));
}
if ($like) {
$likeCond = ‘(‘ . join(‘ OR ‘, $like) . ‘)';
}

BY

foreach ($words as $word) {
$like[] = ‘`s`.`data_index` LIKE :likew’ . $likeI;
$bind[‘:likew’] = ‘%’ . $queryText . ‘%';
}
if ($like) {
$likeCond = ‘(‘ . join(‘ AND ‘, $like) . ‘)';
}

and clear the cache and reindex the data from admin

Regards
Sandeep

js error Mage.Cookies.path var Mage not defined

To resolve this issues you need to be sure that in head.phtml (app/design/frontend/default/default/template/page/html/head.phtml ) you have
getChildHtml() ?> after getCssJsHtml() ?>.
So it should look like:
getCssJsHtml() ?>
getChildHtml() ?>

Follow

Get every new post delivered to your Inbox.