Just another WordPress.com weblog

Archive for June, 2009

Import data in newsletter subscriber from csv

-Make new module
-add this action

public function saveAction() {
if ($data = $this->getRequest()->getPost()) {
if(isset($_FILES[‘filename’][‘name’]) && $_FILES[‘filename’][‘name’] != ”) {
try {
$uploader = new Varien_File_Uploader(‘filename’);
$path = Mage::getBaseDir(‘var’) . DS .”import” . DS;
$uploader->save($path, date(‘Y-m-d’).$_FILES[‘filename’][‘name’] );
} catch (Exception $e) {
$data[‘filename’] = $_FILES[‘filename’][‘name’];
$rows = array();
$handle = fopen($path.date(‘Y-m-d’).$data[‘filename’],’r’);
$row_count = 0;
while (($data = fgetcsv($handle, 1000, “,”)) !== FALSE) {
$email = trim($data[1]);
if (Zend_Validate::is($email, ‘EmailAddress’))
$status = Mage::getModel(‘newsletter/subscriber’)->subscribe($email);
Mage::getSingleton(‘adminhtml/session’)->addSuccess(Mage::helper(‘adminhtml’)->__($row_count.’ Records Imported Sucessfully’));

give csv to this code , it will put all d records in newsletter_subscriber table

-Bijal Bhavsar


User can delete own account

if u want to give functionality to user to delete their own account ::

in  app\code\core\Mage\Customer\controllers\AccountController.php

add below action

public function deleteAction()
$customerId = $this->getRequest()->getParam(‘id’, false);
$customerUrl = Mage::getSingleton(‘customer/session’)->getCustomer();
$temp = explode(“,”,$customerUrl);
$cust_id = $temp[1];   // user id from session

/* remove this condition if you use userid from session directly */
if($customerId != $cust_id)
else {
$customer = Mage::getModel(‘customer/customer’)->load($customerId);
$customer->delete(); // delete customer
->setBeforeAuthUrl(Mage::getUrl()); // for loging out user


pass current user id in query string or u can also take it fron session

also change in app\code\core\Mage\Customer\Model\Customer.php

in this function

protected function _beforeDelete()
// $this->_protectFromNonAdmin();  // comment this line
return parent::_beforeDelete();

comment $this->_protectFromNonAdmin();

– Meghna Vora

Error : pdo_mysql extension is not installed

If this error occur

change in your php.ini file


Make these three line enable ,

if php.ini  not in your site root ther then put php.ini with these three lines

if u have 2 sites in your magento then put 2 php.ini in your site root path

–Vishal Surani

To open product image in popup

<a onclick=”popWin(‘&lt;?php echo $this-&gt;helper(‘catalog/image’)-&gt;init($_product, ‘image’) ?&gt;’, ‘gallery’, ‘width=339,height=550,left=50,top=50,location=no,status=yes,scrollbars=yes,resizable=yes,background-color=222222’); return false;” href=”#”> POPUP  </a>

–Vishal Surani

View Random Products from a store

Create new PHTML file random_product.phtml at


$_parent_category =  Mage::app()->getStore()->getRootCategoryId();
$storeId = Mage::app()->getStore()->getStoreId();

$_productCollection = Mage::getResourceModel(‘catalog/product_collection’)->addStoreFilter($storeId)->load();
$_items = $_productCollection->getItems();
$_collectionSize = $_productCollection->count();
shuffle($_items); ?>

<?php foreach ($_items as $_Product):

$_product = Mage::getModel(‘catalog/product’)->load($_Product->getId());

// put your listing coding here

<?php endforeach;?>

Now you can put block to call thatfile

{{block type=”catalog/product” template=”catalog/product/random_product.phtml”}}

–Vishal Surani

Authentication before product view

To Authenticate user before product view

open : \app\code\core\Mage\Catalog\controllers\ProductController.php

in viewAction write this code ::

if (!Mage::getSingleton(‘customer/session’)->isLoggedIn())
$session = Mage::getSingleton(‘customer/session’);
$session->setBeforeAuthUrl(Mage::helper(‘core/url’)->getCurrentUrl()); /* set redirecting session  */

$this->_redirect(‘customer/account/login/’);  /* Here your login page url */

at line $session->setBeforeAuthUrl(Mage::helper(‘core/url’)->getCurrentUrl()); u can use your own redirect session

in $this->_redirect(‘customer/account/login/’); use your login page url

-Vishal Surani

Remove key from Admin URL

Go to Admin Side

System >> configuration

then Click ‘ Admin

After that u can see Security TAB  at right side

Click on it & set NO at Add Secret Key to URLs

Vishal Surani