Oct 22 2012

Adding thumbnail image for custom column in magento admin grid

Sometimes we  need to show thumbnail image for custom attribute in magento admin grid. As we might know it is little tricky to add thumbnail image in a grid in magento admin. Here we’ve discussed the way how we can add thumbnail image.

1.  Firstly we have to add the following code snippet in _prepareColumns() function, in Grid.php(path: code/local/Packagename/Modulename/Block/Adminhtml/Modulename/Grid.php). Here we use the local path you can use community.

<?php
$this->addColumn('modulenameimage', array(
'header' => Mage::helper('modulename')->__('Image'),
'align' => 'left',
'index' => 'modulenameimage',
'renderer' => 'modulename/adminhtml_modulename_renderer_image',
'width' => '107'
));
?>

Note: Here modulenameimage is the custom attribute.

2. Here we can see that a renderer block(adminhtml_modulename_renderer_image), so now our task is to create that block in Packagename_Modulename_Block_Adminhtml_Modulename_Renderer_Image file as below:

 

<?php
class Packagename_Modulename_Block_Adminhtml_Modulename_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {

public function render(Varien_Object $row) {
$html = '<img ';
$html .= 'id="' . $this->getColumn()->getId() . '" ';
$html .= 'width="' . $this->getColumn()->getWidth() . '" ';
$html .= 'src="' . Mage::getBaseUrl("media") . 'images/' . $row->getData($this->getColumn()->getIndex()) . '"';
$html .= 'class="grid-image ' . $this->getColumn()->getInlineCss() . '"/>';
return $html;
}
}
?>

These are all you need to do to show thumbnail image in grid view. Now you can the grid for that particular module and see the image there. You can change the custom column, image path, width, height as you desire.

Oct 17 2012

Test Credit Card Account Numbers

Test Credit Card Account Numbers

While testing, use only the credit card numbers listed here. Other numbers produce an error.

Expiration Date must be a valid date in the future (use the mmyy format).

Test Credit Card Account Numbers

Credit Card Type Credit Card Number
American Express 378282246310005
American Express 371449635398431
American Express Corporate 378734493671000
Australian BankCard 5610591081018250
Diners Club 30569309025904
Diners Club 38520000023237
Discover 6011111111111117
Discover 6011000990139424
JCB 3530111333300000
JCB 3566002020360505
MasterCard 5555555555554444
MasterCard 5105105105105100
Visa 4111111111111111
Visa 4012888888881881
Visa 4222222222222

Note : Even though this number has a different character count than the other test numbers, it is the correct and functional number.

Processor-specific Cards
Dankort (PBS) 76009244561
Dankort (PBS) 5019717010103742
Switch/Solo (Paymentech) 6331101999990016
Oct 8 2011

Troubleshooting in UBUNTU

Today I faced a problem in UBUNTU 11.04. When I try to open a browser as a root from terminal, in terminal these error show

 

Initializing nautilus-gdu extension
** (nautilus:2158): WARNING **: Failed to get the current CK session: GDBus.Error:org.freedesktop.ConsoleKit.Manager.GeneralError: Unable to lookup session information for process ’2158′
(nautilus:2158): GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)’ failedNautilus-Share-Message: Called “net usershare info” but it failed: ‘net usershare’ returned error 255: net usershare: cannot open usershare directory /var/lib/samba/usershares. Error No such file or directoryPlease ask your system administrator to enable user sharing.

 

I did not get any clue, whatever I got I delete a user, which I delete from ubuntu user/account option.

 

After searching few times I got the recovery, since within a account there are group, group id, and files, these error happened.

 

The recovery is:

sudo groupadd sambashare
sudo adduser `whoami` sambashare

 

 

Oct 8 2011

Update or Upgrade Ubuntu from Terminal

Run this command from your terminal to upgrade your UBUNTU OS.

sudo apt-get update && sudo apt-get upgrade

Sep 21 2011

Quick help in UBUNTU

1. To open file browser as a root user, type “gksudo nautilus” in terminal.

Or “sudo nautilus”

Jul 4 2011

How to send email from localhost in xampp

The process is as below:

1.Edit your php.ini (xampp\php\php.ini). Search for [mail function] and change these parameters accordingly.
SMTP = smtp.gmail.com
smtp_port = 587
sendmail_from = [your_gmail_username]@gmail.com
Note: this gmail account will be used to send the email
sendmail_path = “\”D:\xampp\sendmail\sendmail.exe\” -t”
Note: I did install my xampp at D:\xampp
Edit your sendmail.ini (xampp\sendmail\sendmail.ini)
Comment the “Mercury” and “A free mail service example” contents as shown below:
# Mercury
#account Mercury
#host localhost
#from postmaster@localhost
#auth off

# A freemail service example
#account Hotmail
#tls on
#tls_certcheck off
#host smtp.live.com
#from [exampleuser]@hotmail.com
#auth on
#user [exampleuser]@hotmail.com
#password [examplepassword]

2. Add the account through which you want to send your mails. In my example I have configured the Gmail account as shown below:

account Gmail
tls on
tls_certcheck off
host smtp.gmail.com
from [your_gmail_username]@gmail.com
auth on
user [your_gmail_username]@gmail.com
password [your_gmail_password]

port 587

3. Set the default account to Gmail as shown below:

account default : Gmail

Special Thanks to Selim vai for sharing this, original post : http://egrasp.wordpress.com/2010/02/03/sending-email-in-php-using-xampp-lite-1-7-3-on-windows/

Jun 14 2011

Background image for magento email template

Hi, I read a thread ‘http://www.magentocommerce.com/boards/view/viewthread/218412/#’, for email template in magento, Someone post this for help, but unfortunately I can’t reply there [captcha was not working].
So I share the solution here,
<div style=”background-image:url({{skin url=’images/template_bg.gif’}})  no-repeat;”>
Here the url is http://127.0.0.1/magento/skin/adminhtml/default/default/images/template_bg.gif, for my localhost.

Jun 7 2011

Get home page url or store url in magento

We can use one of the following to access home page in magento.

[php]
echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
[/php]
or

[php]
echo Mage::app()->getStore()->getHomeUrl();
[/php]

We can also use the [html] {{store url=”}}[/html] in static block or CMS page to access home page.

Jun 2 2011

Configurable product options in Category list page in magento

Often we may need to show product’s option in category list page, for example a product may contain a option ‘size’ where the values are small, medium and large and price may different for different options. We can display these options in category list page like product view page. This can be done as below:

[php]
$_productCollection=$this->getLoadedProductCollection();
foreach ($_productCollection as $_product):
$product = Mage::getModel(‘catalog/product’)->setStoreId(Mage::app()->getStore()->getId());
$xml = "";
$hasAtts = 0;
$pass = 0;
$productType = $product->getTypeId();
if($productType == "configurable")
{
$attValConfig = $product->getTypeInstance(true)->setStoreFilter(Mage::app()->getStore(), $product)->getConfigurableAttributesAsArray($product);
if(sizeof($attValConfig)) {
$hasAtts++;
foreach($attValConfig as $attValConfigSingle)
{
echo "<select class=’cust_select’ name=’super_attribute[".$attValConfigSingle['attribute_id']."]’>";
foreach($attValConfigSingle['values'] as $attValConfigSingleVal) {
echo "<option value=’".$attValConfigSingleVal['value_index']."’>".$attValConfigSingleVal['label'].’ +’.Mage::helper(‘core’)->currency($attValConfigSingleVal['pricing_value'])."</option>";
}
echo "</select>";
}
}
}
endforeach;
[/php]

These code snippet shows the product’s options with prices.

May 29 2011

Magento “Current Url” in any page

Magento “Current Url” in any page

[php]
<?php $current_url = $this->helper(‘core/url’)->getCurrentUrl(); ?>
[/php]

Just use this ‘helper’ method, this will return the current page url in magento