Thứ Hai, 2 tháng 5, 2011

CSS Hack for Google Chrome and Safari

If you are developing any site or designing any website, having design problem in chrome and safari you can write the below css, It only works on Google chrome and Safari Browser



@media screen and (-webkit-min-device-pixel-ratio:0)
{

.classname{ background:#ccc; } /*It will works on Google chrome and safari */

}

Thứ Năm, 28 tháng 4, 2011

How to upload file in magento

If you are making your custom module in magento and if you unable to use default magento file upload then you can use magento custom file uploading code to upload file.



// If you want to upload files under media folder

$absolute_path = Mage::getBaseDir('media') . DS ;

$relative_path = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);

// File Upload

$files = $_FILES['file_upload']['name'];

if(isset($files) && $files != '')

{

try

{

if(file_exists($absolute_path.DS.$files))

{

$var = rand(0,99);

$files = $var.'_'.$files;

}

// Starting upload

$uploader = new Varien_File_Uploader('file_upload');

// Any extention would work

$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));

$uploader->setAllowRenameFiles(false);

//false -> get the file directly in the specified folder

//true -> get the file in the product like folders /media/catalog/product/file.gif

$uploader->setFilesDispersion(false);

//We set media as the upload dir

$uploader->save($absolute_path, $files);

}

catch(Exception $e)

{

Mage::getSingleton('adminhtml/session')->addError($e->getMessage());

}

// Your uploaded file Url will be

echo $file_url = $relative_path.$files;

}

How to fetch all associative product of a configurable product in magento

Configurable product is the product which is created by some Associated product, If you have an configurable product and you want to get list of all associated product and it's attribute then just write the below


You must have your configurable product Id, My configurable product Id is 11

$id=11; //Use your Configurable product Id

$_product = new Mage_Catalog_Model_Product();

$childIds = Mage::getModel('catalog/product_type_configurable')->getChildrenIds($id);

foreach($childIds[0] as $key=>$val)

{

   $associatedProduct = Mage::getModel('catalog/product') ->load($val);

   echo $associatedProduct ->getName();

//Let you have a color attribute in each associated product then you can fetch by

   $colorids[] = $associatedProduct ->getColor();

   $colorname[] = $associatedProduct ->getAttributeText('color');

}

Thứ Tư, 27 tháng 4, 2011

How to and where to change default product image in Magento

If you forgot to upload any product image then Magento always show a default image,If you think to change default image then login to admin panel then goto System -> Configuration then click on Catalog tab. From Product Image Placeholders change your Base Image , Small Image and Thumbnail . Now click on Save Config button to make changes.




Thứ Ba, 19 tháng 4, 2011

How to Add option to select box by jquery


I have write the below code to add option to select drop down by jquery. Add value to the below input box then click on add button.You can see the effect.That option will be added to the below selectbox





The code you need to write is



$('#selectbox').append($("<option></option>").attr("value",option_value).text(text_to_display));

Thứ Sáu, 1 tháng 4, 2011

How to add new order status in magento admin panel

To add New Status in magento admin panel, you need to write your own custom module , then in your config.xml file write the below code to add new Status



<config>
<global>
<sales>
<order>
<statuses>
<custom_status translate="label"><label><![CDATA[Custom Status]]></label></custom_status>
</statuses>
<states>
<new><!-- order state where you want to assign your custom status e.g:- New, Onhold, Canceld etc-->
<statuses>
<custom_status/>
</statuses>
</new>
</states>
</order>
</sales>
</global>
</config>


It will work upto 1.4.2 , But in Magento 1.5.0 or above there is Special Option to do this. To make own Custom status above magento 1.5 version go to System->Order Statuses. Then Click on Create New Status. After creating new status click on Assign Status to State to assign that status

Thứ Hai, 28 tháng 3, 2011

How To Create a custom url redirect in Magento using URL Rewrite Management

To make magento more SEO friendly, It needs to redirect to a custom url, By default magento have this feature but if you have created any module whose url like modulename/id/3, then you needs to redirect it to a SEO friendly url. To redirect the url to a "301 Permanent redirect" you just login to your admin panel, then go to -> Catalog -> URL Rewrite Management, from the drop down select Custom ,follow the below screenshot to make it more easy.



1) In the Id path give your current url (e.g: review/product/list/id/14/category/3)

2) In Request Path write same as Id path (e.g: review/product/list/id/14/category/3)

3) In Target Path give oyu custom Url with domain name (e.g:- http://www.mysite.com/mobile.html)