Usind that we can get currently logged in admin details.


$d = Mage::getSingleton('admin/session')->getData();
$dm = $d['user']->getData();

For getting currently logged in admin email id.

$adminEmail = $dm['email'];

Thanks,
Bijal Bhavsar 🙂

Hello,

Below code will delete particular category in magento.


 require_once realpath(dirname(__FILE__).'/app/Mage.php';
 Mage::app('default'); // Default or your store view name.
 Mage::register('isSecureArea', 1);// This will set secure area as admin
 $category = Mage::getModel('catalog/category')->load(15);//Here 15 is category id & it create category object
 $category->delete(); // This code will delete category whose id is 15

I hope above content is useful to you. Thanks for reading my blog.

Thanks,
Bijal Bhavsar:)

Hello all,

Today i’ll show you how to add custom Form Element To an Adminhtml Form.

Create form app/code/local/CompanyName/ModuleName/Block/Form.php


class CompanyName_ModuleName_Block_Form extends Mage_Adminhtml_Block_Widget_Form
{
  protected function _prepareForm()
  {
   $form = new Varien_Data_Form(array(
     'id' => 'edit_form',
     'action' => $this->getUrl('*/*/save'),
     'method' => 'post'
   ));


   $fieldset = $form->addFieldset('fieldset', array('legend' => 'Your fieldset title')));

   //Here is what is interesting us
   //We add a new type, our type, to the fieldset
   //We call it extend_file
   $fieldset->addType('extend_file','CompanyName_ModuleName_Widget_Form_Element_ExtendFile');

   $fieldset->addField('file_element', 'extend_file', array(
     'label' => 'Label of Field',
     'name' => 'file_element',
     'required' => false,
   ));
  }
}

Code for custom element will be located here: app/code/local/CompanyName/ModuleName/Widget/Form/Element/ExtendFile.php


class CompanyName_ModuleName_Widget_Form_Element_ExtendFile extends Varien_Data_Form_Element_Abstract
{
    public function __construct($attributes=array())
    {
      parent::__construct($attributes);
      $this->setType('file');
    }

    public function getElementHtml()
    {
      if ($this->getValue()) {

        $url = Mage::getBaseUrl('media') . PATH_TO_YOUR_FILE. $this->getValue();
        $html = '<a href="'.$url.'">'.$this->getValue().'</a> ';
      }

      return $html;
    }

}

I hope above code will help to display file field value, same way we can create custom element for form.

Thanks,
Bijal Bhavsar 🙂

Hello,

I have created one extension to add custom link “Component sold Seperately” same as related, crossell & upsell products in magento Catalog product section.

You can install using key given in Url: http://www.magentocommerce.com/magento-connect/catalog/product/view/id/15766/s/magecracker-customlinks-6068/

You can check below video for the extension:

Thanks for regular reading my blog.

Thanks,
Bijal Bhavsar 🙂

Hello All,

Today i found how to set default filter in product grid by product type (e.g.  ‘simple’) in admin product grid. For that you need to rewrite grid.php class of product in path  yourproject/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php

You need to add below code in _construct() method of grid.php


  $this->setDefaultFilter( array(
                'type' => constant(get_class(Mage::getSingleton('catalog/product_type')) . '::TYPE_SIMPLE'),
            )); 

In above code ‘type’ is field and “constant(get_class(Mage::getSingleton(‘catalog/product_type’)) . ‘::TYPE_SIMPLE’)” is value, you can change its value as per your requirement.

I hope this code will help you, Thanks for reading my blog.

Thanks,

Bijal Bhavsar 🙂

Some question and answer of magento

How do I get the Magento Home URL?
Mage::getBaseUrl();
How do I get the Magento Home Directory?
Mage::getBaseDir();
How do I get the URL of a file in the skin directory?
$this->getSkinUrl(‘images/myfile.png’); // in a template or Block
Mage::getDesign()->getSkinUrl(‘images/myfile.png’); // from anywhere
How do I format a price value?
Mage::helper(‘core’)->formatPrice($amount);
How do I get the display value of a (multi-)select product attribute?
echo $product->getAttributeText(‘manufacturer’);
How do I create an object instance in magento?
Mage::getModel(‘module/class’); // for models
Mage::helper(‘module/class’); // for helpers
Mage::app()->getLayout()->createBlock(‘module/class’, ‘name_in_layout’); // for blocks
How do I get at GET/POST parameters?
Mage::app()->getRequest()->getParam(‘param_name’); // single parameter
Mage::app()->getRequest()->getParams(); // all parameters
How do I get the Id of the curent store view?
Mage::app()->getStore()->getId();
How do I get all Store Views?
Mage::app()->getStores(); // pass true to include the admin store view, too
How do I get the configurable/grouped/bundled product a simple product belongs to?
$simpleProduct->loadParentProductIds();
$parentProductIds = $simpleProduct->getParentProductIds();
How do I get the simple products assigned to a configurable product?
$configProduct->getTypeInstance()->getUsedProductCollection($configProduct);
How do I get an instance of an attribute?
Mage::getSingleton(‘eav/config’)->getAttribute($entityType, $attributeCode)

How to check query of collection?
echo $colleciton->getSelect();// note: this will not work when you use load() to get object of any product/category etc id

How to see which class is used?
echo get_class(Mage::getModel('catalog/product')); // Default it will return Mage_Catalog_Model_Product
echo get_class(Mage::helper('product')); // Default it will return Mage_Catalog_Helper_Product

Here: get_class is php function

I hope this code will help you, Thanks for reading my blog.

Thanks,
Bijal Bhavsar :)

Hello Guys,

I want to share you how to change product attribute input type from dropdown to multiselect in magento.

Below code will change input type of attribute ‘grade’ & remove value of attribute already exist in products. You can create file and add below code, Don’t forget to replace ‘grade’ with your attribute code.


<?php
define('MAGENTO_ROOT', getcwd());

$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
umask(0);
Mage::app('default');

$installer = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();

$entityTypeId = $installer->getEntityTypeId('catalog_product');

$idAttributeOldSelect = $installer->getAttribute($entityTypeId, 'grade', 'attribute_id');
$installer->updateAttribute($entityTypeId,$idAttributeOldSelect, 'frontend_input','multiselect');
$installer->updateAttribute($entityTypeId,$idAttributeOldSelect, 'backend_type','varchar');
$installer->updateAttribute($entityTypeId,$idAttributeOldSelect, 'backend_model','eav/entity_attribute_backend_array');
$installer->updateAttribute($entityTypeId,$idAttributeOldSelect, 'source_model','');
$installer->run("DELETE FROM `catalog_product_entity_int` where `attribute_id` = {$idAttributeOldSelect}");
$installer->endSetup();
?>

 

I hope above code will help you.

Thank You,
Bijal Bhavsar 🙂

Hello guys,

We can add new action in grid row like ‘Edit’ link at admin grid.

Open your module Grid.php file, below is path to file:
(i.e. yourproject/app/code/local/yourcompany/yourmodulename/block/adminhtml/modulename/grid.php)

In That file, search ‘action’ column, it will be like below code:


$this->addColumn('action',
array(
          'header' => Mage::helper('modulename')->__('Action'),
          'width' => '100',
          'type' => 'action',
          'getter' => 'getId',
          'actions' => array(
                 array(
                      'caption' => Mage::helper('modulename')->__('View'),
                      'url' => array('base'=> '*/*/view'),
                      'field' => 'id'
                    )),
          'filter' => false,
          'sortable' => false,
          'index' => 'stores',
          'is_system' => true,
));

To add new action, you need to add another array in parameter ‘actions’ like below


array(
    'caption' => Mage::helper('modulename')->__('Edit'),
    'url' => array('base'=> '*/*/edit'),
    'field' => 'id'
)

So now code will be like below:



$this->addColumn('action', array(
                      'header' => Mage::helper('modulename')->__('Action'),
                      'width' => '100',
                      'type' => 'action',
                      'getter' => 'getId',
                      'actions' => array(
                              array(
                                 'caption' => Mage::helper('modulename')->__('View'),
                                 'url' => array('base'=> '*/*/view'),
                                 'field' => 'id'
                              ),
                              array(
                                  'caption' => Mage::helper('modulename')->__('Edit'),
                                  'url' => array('base'=> '*/*/edit'),
                                  'field' => 'id'
                              )
                      ),
                      'filter' => false,
                      'sortable' => false,
                      'index' => 'stores',
                      'is_system' => true,
                )
);

I hope the above information will help you.

Thanks,
Bijal Bhavsar 🙂

Using Below code we can get post data in observer file.


Mage::app()->getFrontController()->getRequest()->getParams();

I hope this code will help you, Thanks for reading my blog.

Thanks,
Bijal Bhavsar 🙂

To upgrade magento project with latest version, you have to follow below steps:

1) Take backup of whole project + Database.
2) List out the extensions which are already exists in project(xyz) and take it out from project.
3) Download and install latest version of magento.
4) create new db (i.e xyz_to_upgrade) and Upload backup database of your project(xyz).
5) Than add all extensions which are there in ur project(xyz) to latest magento and yes, if extensions which are used, available for latest version than install that one.
6) Test latest version of magento well.. is everything working proper or not.
7) Now remove app/etc/local.xml from that latest magento, and re install it with db details(which is created in point 4).
8) Resolve errors which you face while installation, you can find most of solution in Google.

Note: Above xyz is project name.

I hope the above information will help you.

Thanks,
Bijal Bhavsar 🙂