Just another WordPress.com weblog

Archive for September, 2009

To add custom date field in custom module of admin panel

You can see the below code to add start date and end date field in admin custom module(Which is created using module creator).

Create two fields “start_date” and “end_date” in database table of your custom module.
$dateFormatIso = Mage::app()->getLocale() ->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
$fieldset->addField(‘start_date’, ‘date’, array(
‘label’ => Mage::helper(‘banner’)->__(‘Start Date’),
‘title’ => Mage::helper(‘banner’)->__(‘Start Date’),
‘name’ => ‘start_date’,
‘image’ => $this->getSkinUrl(‘images/grid-cal.gif’),
‘format’ => $dateFormatIso,
‘value’ => ‘start_date’,
//’required’ => true,
$fieldset->addField(‘end_date’, ‘date’, array(
‘label’ => Mage::helper(‘banner’)->__(‘End Date’),
‘title’ => Mage::helper(‘banner’)->__(‘End Date’),
‘name’ => ‘end_date’,
‘image’ => $this->getSkinUrl(‘images/grid-cal.gif’),
‘format’ => $dateFormatIso,
‘value’ => ‘end_date’,
//’required’ => true,

Copy and paste the above code to your custom_module/block/adminhtml/custom_module/Edit/Tab/Form.php file
and than open controller of the same module
Path :: custom_module/controllers/adminhtml/custommoduleController.php

Add below lines before $model->save() to save dates in
function saveAction().

if($data[‘start_date’] != NULL )
$date = Mage::app()->getLocale()->date($data[‘start_date’], Zend_Date::DATE_SHORT);
$model->setStartDate($date->toString(‘YYYY-MM-dd HH:mm:ss’));
if($data[‘end_date’] != NULL)
$date1 = Mage::app()->getLocale()->date($data[‘end_date’], Zend_Date::DATE_SHORT);
$model->setEndDate($date1->toString(‘YYYY-MM-dd HH:mm:ss’));

Please give feedback if this post is useful to you. 🙂

-Bijal Bhavsar 🙂

To call Static block in phtml

<?php echo $this->getLayout()->createBlock(‘cms/block’)

->setBlockId(‘contact_form_text’)->toHtml() ?>

-Meghna Vora

How to set session and get session in magento

You can create new session using below syntax:

$Data = Mage::getSingleton('core/session')->getYourVariable();
-Bijal Bhavsar 🙂

How to add wholesale price in shopping cart


If you want to add wholesale price and you want to do some calculations on total price to change subtotal, than follow below steps:

Step1: Create one attribute `wholesale_price` .

Step2: Add getWholesalePrice() function defined bellow in


public function getWholesalePrice($pID)
$_product = Mage::getModel(‘catalog/product’);
return   $_product->getResource()->getAttribute(‘wholesale_price’)

Step3:  Open file yourproject/app/code/local/Mage/Sales/Model/Quote/item.php

Add below line in   function setProduct  ->setWholesalePrice(Mage::getModel(‘checkout/cart’)


after ->setCost($product->getCost()) statement in function

Step4: To change subtotal open below path file


public function collect(Mage_Sales_Model_Quote_Address $address)
* Reset subtotal information

* Process address items
$items = $address->getAllItems();
/*******Start:: Changes  for wholesale price calculation********/
$isWholesalePrice = false;
$finaltotal = ”;
/*******END:: Changes  for wholesale price calculation********/
foreach ($items as $item) {
if (!$this->_initItem($address, $item) || $item->getQty()<=0) {
$this->_removeItem($address, $item);
/******START:: Changes  for wholesale price calculation*******/
$_totWholesalePrice = $item->getWholesalePrice() * $item->getQty();
$_totPrice = $item->getPrice() * $item->getQty();
if($_totWholesalePrice >= 500 || $_totPrice >= 1000)
$isWholesalePrice = true;
$finaltotal += $_totWholesalePrice;
/*******END::Changes  for wholesale price calculation*******/
/******START::Changes  for wholesale price calculation******/
/******END:: Changes  for wholesale price calculation********/

/*** Initialize grand totals***/



return $this;

Explaination of above function:: In above function we changed calculation of subtotal, here condition is if total wholesale price(wholesale price *  Qty) of any product is more than 500 or total price(Sale price * Qty)  is more than 1000 than subtotal is calculated on wholesale price.

Above four step will help u to change subtotal and grand total according to subtotal for only one page checkout. To reflect the above calculation to multishipping than follow step5also.

Step5: Open file /yourproject/app/code/local/Mage/Sales/Model/Quote/Address/Item.php

Add below line in   function importQuoteItem


after ->setPrice($quoteItem->getPrice()) statement.

If this post is helpful to you than please do write feedback.


-Bijal Bhavsar

Notice : Undefined index: website_price in /app/code/core/Mage/Catalog/Model/Product/Type/Price.php

if u find any notice related to website_price in tier price functionality when user is logged in :

set the Catalog Price Scope (system->config->catalog->price) “Global”  to “Website”

– Meghna Vora

How to import categories ?

contact  : meghna.vora@indianic.com

– Meghna Vora

How to get different URLs?

* Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);
* Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
* Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
* Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
* Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

–  Vishal Surani