Some Useful Url function in Magento

Posted on

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK); or you can write $this->getUrl();
e.g:- http://yoursite.com/index.php/

Get Magento Media Url
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
e.g:- http://yoursite.com/media/
Get Magento Skin Url

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN); or you can write $this->getSkinUrl();
e.g:- http://yoursite.com/skin/

Get Magento Store Url
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
e.g:- http://yoursite.com/

Get Magento Js Url
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);
http://www.yoursite.com/js

Advertisements

Magento orders made by paypal not shown in My orders

Posted on Updated on

If u have setup paypal on magento and made transactions using paypal. You might have noticed that the paypal orders are not shown on the “My Orders” section on the customers “My Account” section.

Wasted my whole day on this issue. Finaly found the solution to this.
It seems that setting up the api information in magento isn’t enough. This will just process the transaction and the orders will be shown in magento admin and Paypal but it won’t show the order in magento frontend and moreover there is no transaction id on the backend of magento.
So, in order to fix this issue, what we need to do is, set up paypal ipn on the paypal site.
paypal standard payments setup with ipn
This site shows how to setup paypal ipn.
Follow the steps as mentioned under the section “Turning On IPN in PayPal”

After turning on the IPN feature, perform a checkout
Aloha!!! Theย order appears in the “My Orders” section.

Hope, this was useful to you.
Cheers!!!

JS to prevent user from navigation away from current html page

Posted on Updated on

Here is a simple js script to prevent a user from navigating away from the current html page. What this script does is that the user will be shown a dialog box when they try to navigate away from the current page(page refresh or close browser). This could be very useful while performing critical processes through ajax and you don’t want user to navigate away from the current page in the middle of the process. Anyways you can’t stop user from closing the browser though :P, if they press the “leave page” button on confirmation, then the browser would eventually close. Afterall Users are users ๐Ÿ™‚

This script will show confirmation dialog when navigating away from page. So put this script on the page or at the start of the ajax call.
/***********************************************************************/

window.onbeforeunload = function() { return "Are you sure you want to leave this page?"; };

/***********************************************************************/

leave page confirmation
Leave page confirmation Dialog

This script will remove the confirmation dialog. Put this script when you are done processing and you don’t mind user leaving the page.
/***********************************************************************/

window.onbeforeunload = null;

/***********************************************************************/
Thank you for reading this tuto.
Hope this was useful to you ๐Ÿ™‚

Grab images in Bulk from url using php and CURL

Posted on Updated on

Here is a simple php script to grab and store images from image URL using CURL.
In this example I have a list of images in an excel formatted xml file which has a field of the images link. we are using the image links to grab it.

function GetImageFromUrl($link){
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch,CURLOPT_URL,$link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
return $result;
}
if (file_exists('images.xml')) {
$xml = simplexml_load_file('images.xml');
foreach($xml->Worksheet->Table->Row as $ab){
$file = $ab->Cell->Data;
$ch = curl_init($file);
if($file==" "){
continue;
}
$sourcecode=GetImageFromUrl($file);
$file = str_replace(" ","_",$file);//replace spaces from file with an underscore
$pos = strrpos($file,'/');
$filename = str_split($file,$pos+1);
$savefile = fopen('test/'.$filename[1], 'w');
fwrite($savefile, $sourcecode);
fclose($savefile);
echo($filename." has been uploaded");
}
} else {
exit('Failed to open xml file.');
}

Magento Product Importing – basic fields

Posted on Updated on

Want to import products from your csv file to magento, its pretty simple.
Magento has very effective import/export feature for u.

Here is what you need to do:
1. Goto System->Import/Export->Profiles
2. Click on the “Import All Products” from the list
3. Click on the “upload Files” tab from the left sidebar.
4. Select Your CSV file and click “save and continue edit” button
5. Click “Run Profile” and select your CSV file from the drop down and click “Run Profile”
6. Importing process starts.

Some tips.
Basic field required for successful importing:
attribute_set(category) ,type(product type-simple,configurable.etc), sku, category_ids, status, visibility, tax_class_id, weight, price, name, description, short_description

Eg. of basic CSV data :
attribute_set,type,sku,category_ids,status,visibility,tax_class_id,weight,price,name,description,short_description
Shoes,simple,qurak101,8,Enabled,Catalog,Taxable Goods,1,100, Quark,this is description,this is short description

Simple Jquery script to toggle the child of a list

Posted on Updated on

This is a simple jquery script to toggle the child of a list. This might to useful to browse hierarchial categories.
This script shows the top level list items at the start and hides all the child lists. Click a list item, and the child items show up in a nice easy scroll animation ๐Ÿ™‚

Here is the js

function hideAll(){
jQuery('.hunting-places-list ul').hide();

}
jQuery(document).ready(function(){
hideAll();
jQuery('.hunting-places-list li a').click(function(){
jQuery(this).siblings().toggle('slow');
});
});

And here is a sample list

Hope this was useful to you. Thankx for reading ๐Ÿ™‚
Cheers!!!

Sending Email in Magento in simple and easy steps

Posted on Updated on

Sending Email in Magento in simple and easy steps
Put this in your controller function from where u want to send an email.

<?php
public function sendMailAction(){
$html=put your html content here";
$mail = Mage::getModel('core/email');
$mail->setToName('Your Name');
$mail->setToEmail('Youe Email');
$mail->setBody($html);
$mail->setSubject('Mail Subject');
$mail->setFromEmail('Sender Mail Id');
$mail->setFromName("Msg to Show on Subject");
$mail->setType('html');// YOu can use Html or text as Mail format
try {
$mail->send();
Mage::getSingleton('core/session')->addSuccess('Your request has been sent');
$this->_redirect('');
}
catch (Exception $e) {
Mage::getSingleton('core/session')->addError('Unable to send.');
$this->_redirect('');
}
}
?>

Cheers!!