This site is the bee's knees


December 2014

Custom attribute fetching in Magento

How to Obtain Custom Attribute Values in Magento
Posted byDevin R. Olsen on in Magento Tutorials, PHP Tutorials | 29 comments

Today let’s talk about Magento and custom attributes. With Magento you can create as many custom attributes for your products as you like, and there are different attribute types such as:

Text Field
Text Area
Multiple Select
Media Image
Fixed Product Tax

Because there are different types of attributes there are also different ways of obtaining an attributes value. If we were to create a new custom attribute called “theme_color” and the attribute was of a “Text Field” type, we could do something like the following at a product level (meaning a product is loaded) to obtain its value.


$_product is the product of question we have loaded up and ready to work with, and we use “getThemeColor();” because our attribute was named “theme_color”. It’s important to realize that when calling out the value of an attribute with this method, we start with “get” and then capitalize the first letter of each word that is divided by a “_”.

Now this method would give us the value of a simple “Text Field” attribute but what if the attribute was a “Dropdown or a Multiple Select” type? Well if you try to use this “getYourAttributesName()” method on a none “Text Field” or “Textarea” attribute type you will most likely get nothing.

So how do we obtain the value of a “Dropdown or a Multiple Select” attribute type you ask? Well some would argue that you would do so via this method:


However, what this would do is return an array of the “Dropdown or Multiple Select” options instead of the value of the selected option you would have set. There is another way to obtain these types of attributes selected value and it looks like this:

$themeColor = $attributes[‘theme_color’]->getFrontend()->getValue($_product);
echo $themeColor;

With this method we are simply creating a new variable called “$attributes” and pointing to our “$_product” to then using the “getAttributes()” function to gather all the attributes of this product.

Once we have all the product’s attributes inside of the “$attributes” variable, we make another new variable called “$themeColor”. “$themeColor” then assigns its self to our “$attributes” array that we in turn call out our custom attribute [‘theme_color’].

Once we have pointed to the custom attribute in the “$attributes” array, we simply run through the front end via the function “getFrontend()” and then pull the value down via “getValue($_product)”.

If we then echo our “$themeColor” you should get the value of your custom Drop Down or Multiple Select attribute to do what you will with it.

So to recap:

getThemeColor() ?>

Would get the value of an attribute wholes type is of Text Field or Text Area’s

getAttributeText(‘theme_color’) ?>

That will not give a value of a Text Field or Text Area attribute type but rather gather an array of all options in a Drop Down or Multiple Select attribute type.

$themeColor = $attributes[‘theme_color’]->getFrontend()->getValue($_product);

That will give you the value of any type of attribute, even the value from “Drop Down or Multiple Select” attribute types.

I hope this clears some things up and helps some developers out there .


Devin R. Olsen


Magento discussion

Below link is useful for magento developers discussion

Magento bulk product import with images (data flow profile will allow only one image)

Magento bulk product import with images

by Robin Hislop · 19 February 2014

I recently had to transfer the inventory of an old Shop Factory site into Magento 1.7. Magento offers a powerful facility to do this via CSV using its DataFlow profiles but this is not without its quirks and pitfalls so I thought I’d share my experiences.
Importing product data

First, you will need to know the data format required by Magento for import. The simplest way to do this is to create a sample product in Magento and export all products. To do this:

Go to System > Import/Export > DataFlow – Profiles
Edit the Export All Products profile and Run Profile

The exported CSV file will be placed in the /var/export folder. You will need to FTP into your Magento hosting to retrieve the file.

Open this file in a spreadsheet application. I used OpenOffice Calc as it allows the CSV to be saved as UTF-8 which is required by Magento. The first row shows the product field names required by Magento – for your first import, you will need all these fields to be present, even if the values are blank. Copy and paste the columns of data from the CSV exported from your old inventory into the Magento CSV. You don’t need all the columns, if in doubt just leave them with the same values as your sample product. The values you must have are:

sku – this is the unique product ID and is used by Magento to allocate the data to the correct product in its database. Any subsequent imports with the same sku will update the data. I didn’t have unique skus from my previous inventory so I created them using the product names converted to lowercase and with spaces replaced by hyphens.
type – this must be set. I used “simple”.
category_ids – these will need to be mapped from your old categories to the new categories in Magento. You can look up the Magento category IDs in Catalog > Manage Categories by clicking on the category – the ID will be shown at the top. If you have a lot of categories like I did, you can export them from phpMyAdmin using the following SQL query:

SELECT ccev.entity_id AS categoryID, cce.path, ccev.value FROM catalog_category_entity cce JOIN catalog_category_entity_varchar ccev ON ( cce.entity_id = ccev.entity_id ) GROUP BY ccev.entity_id ORDER BY path

I then placed these values in a separate spreadsheet, and manually entered the corresponding old category ID in the next column. Now I could use Calc’s LOOKUP function to map each old category ID to the new one in the Magento CSV. This saved a lot of time when making changes to category allocations, and also prevented me having to manually enter the new category IDs for each product.
image, small_image, thumbnail – leave these blank. It’s better to import the images separately (see below) because Magento will not import the product if it can’t find the referenced image (for instance if the image filename is wrong).

Once you have all your product data in the correct columns, save the spreadsheet as a CSV, making sure to use quotes around text fields and to save in UTF-8.

Now you can import the product data by running the Import All Products DataFlow profile. Upload your edited CSV and run the profile. It’s pretty slow, taking about a second a product, so now may be a good time for a cup of tea.
Importing product images

Now that your products exist in the Magento database, you can perform a separate import to attach your images to the products.

First, FTP your product images to the /media/import folder of your Magento installation. Magento will resize your images to the correct dimensions on import, so just upload the best quality image you have for each product.
Create a new spreadsheet with the following columns: sku, image.
Copy the sku column from your product data CSV.
Copy the image filenames from your old inventory export to the image column. The filenames should have the format:


(note the leading slash).
Save the CSV as import-product-images.csv in UTF-8.
Create a new DataFlow profile called Import Product Images with the following settings:
Entity Type: Products
Direction: Import
Data Transfer: Interactive
Type: CSV/Tab Separated
Field Mapping: sku > sku, image > image
Upload your import-product-images.csv and Run Profile.

Voila! Your products should now have images.

Magento DataFlow does not have very helpful error messages, for example it will tell you “Image not found” but not tell you which image. The mysterious “Product type not set” message is probably because a text field is not enclosed in quotes.
Removing duplicate images

Every time you run a product image import, Magento copies the image from /media/import into a subdirectory of the /media/catalog/product folder. Annoyingly, it does not replace the image but rather adds it to the product and creates a copy _2.jpg etc. So after several imports, you will have several copies of each image in your media folder and duplicate images on each product. You can remove the duplicate images from the product data with this script, and delete unused duplicate images with this extension. However, when importing the complete catalog several times, I found it simpler to:

Delete the /media/catalog/product folder.
Delete the product image references in the Magento database using the following SQL:

DELETE FROM catalog_product_entity_media_gallery
DELETE FROM catalog_product_entity_media_gallery_value

Be warned! Only do this to clear all product images and start again.

Once you have successfully imported all images, you can safely delete any images in /media/import to free up server space.

Magento Search is searching Description

Here i found out a problem that in search if we enter anything it will look in to our short description and description and if any matches found it will display frontend.


Goto admin ->catalog->attribute->manage attribute->

and you can see all attributes then search for description or shot
and quick search is enabled as no

Date field in magento checkout

I have used below plugin to add date field .

later i got requirement like add two more fields so that i have created two fields in sales_fat_order table and

go to module index controller and save method i have found setShipmentDate (in this shipment_date is my table field )

so it will insert the value


Mini Tutorial: Adding a Shipping Date Selector
June 2, 2014 by Keegan


While working on a B2B site, a recent client requested that the customer have the ability to choose their own ship date for certain products. On a normal B2C site, this maybe audacious and an all around bad idea, but on a site that is selling to businesses, this is a common request. This mini tutorial will show how to add a shipping date selector feature in Magento.
The Situation

The exact request was for date selector in the checkout, in which the first available date to choose was a week from the current day. Once the order is placed, the date would then be viewable on the admin order screen.
Choose a suitable calendar API

My first step was to find a suitable calendar API that would allow me to set the earliest possible date. Although there are many good date selector APIs out there, I went with Zebra Datepicker. Once the datepicker has been downloaded, the appropriate files will need to be loaded on the checkout page.




Add the Datepicker and date field

Next, I added the datepicker and date field onto the shipping method section of the onepage checkout.


__(‘Select date for products to be shipped by:’) ?>

At the bottom of the file, I included the js code that inserts the datepicker. For this example, I’m going to use 5 days as the minimum amount of time from today that the customer can choose to have their order shipped.


The part that says “direction:5″ is what tells the datepicker that everything up until 5 days from today should be disabled and unable to choose.

Once this was done, I had to create modules that would create the ship date field in the database and save that value to the database. To do so, I created the following files:


In the above module, I am overriding an action method in the Onepage controller, creating an observer that will fire on order save, and adding the shipment_date field to the database.

In the first file; the controller, I overrode the saveShippingMethodAction() in order to include the shipdate attribute in the quote.

_expireAjax()) {
if ($this->getRequest()->isPost()) {
$data = $this->getRequest()->getPost(‘shipping_method’, ”);
$shipdate = $this->getRequest()->getPost(‘shipdate’, ”);
$quote = $this->getOnepage()->getQuote();
$result = $this->getOnepage()->saveShippingMethod($data);
// $result will contain error data if shipping method is empty
if (!$result) {
‘request’ => $this->getRequest(),
‘quote’ => $this->getOnepage()->getQuote()));

$result[‘goto_section’] = ‘payment’;
$result[‘update_section’] = array(
‘name’ => ‘payment-method’,
‘html’ => $this->_getPaymentMethodsHtml()

After that, I used an observer to save the updated quote to the order.

$quote = $order->getQuote();


In order for any of that to work, we need to add the shipment_date field to the order and quote tables in the database. This could easily be done through phpmyadmin, or shell access to the DB, but this is poor practice. Its always a much better idea to use Magento’s built in functionality to edit tables, as you will not always have direct access to the DB for security reasons, and there are less chances of error occurring.


$orderItemTable = $installer->getTable(‘sales_flat_quote’);

‘type’ => Varien_Db_Ddl_Table::TYPE_DATE,
‘nullable’ => true,
‘comment’ => ‘Shipment Date’

$orderItemTable2 = $installer->getTable(‘sales_flat_order’);

‘type’ => Varien_Db_Ddl_Table::TYPE_DATE,
‘nullable’ => true,
‘comment’ => ‘Shipment Date’


Then the config.xml and Demac_Checkout.xml which contain the standard module override and activation properties.





Its important to note the inclusion of 0.1.0 in these files. This tells magento the version number of the module, and tells it whether it needs to run the mysql install or update file.
Display the Shipdate on the Order Edit Screen

The last step I needed to do was to show the shipdate on the Order edit screen on the backend. Since I was editing a template in the adminhtml section, Magento doesn’t allow us to overwrite adminhtml template files with the regular frontend files, I had to include the following module:



Just remember to change [your_theme] with your actual theme name.

The file I had to override is located at:



helper(‘sales’)->__(‘No shipping information available’); ?>

I added

__(‘Ship Items By ‘) ?>
getShipmentDate() ?>

Once this was all done, I had a full functioning frontend datepicker that saved a date to the order, and was viewable on the backend per order by the admin.

HTACCESS for putting www in url

step 1 we need to add cname in a rocrd has www
step 2 after that we can use below code and add www

# Use PHP5.4 as default
AddHandler application/x-httpd-php54 .php
RewriteEngine On

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

force to add http into https

# Use PHP5.4 as default
AddHandler application/x-httpd-php54 .php
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Create a free website or blog at

Up ↑