Remove category path from product URL in magento

The file to edit is /app/code/core/Mage/Catalog/Model/Url.php though i advise rather than editing this directly you create a copy in /app/code/local/Mage/Catalog/Model/Url.php.

Then within function getProductRequestPath (around line 685) amend the following code

1
2
3
4
5
6
7
8
9
10
11
12
/**
     * Prepare product base request path
     */
    if ($category->getLevel() > 1) {
        // To ensure, that category has path either from attribute or generated now
        $this->_addCategoryUrlPath($category);
        $categoryUrl = Mage::helper('catalog/category')->getCategoryUrlPath($category->getUrlPath(),
            false, $storeId);
        $requestPath = $categoryUrl . '/' . $urlKey;
    } else {
        $requestPath = $urlKey;
    }

to this

1
2
3
4
5
6
7
8
9
10
11
12
/**
     * Prepare product base request path
     */
    /*if ($category->getLevel() > 1) {
        // To ensure, that category has path either from attribute or generated now
        $this->_addCategoryUrlPath($category);
        $categoryUrl = Mage::helper('catalog/category')->getCategoryUrlPath($category->getUrlPath(),
            false, $storeId);
        $requestPath = $categoryUrl . '/' . $urlKey;
    } else {*/
        $requestPath = $urlKey;
    //}

And for good measure also amend the function generatePath to edit around line 831 and comment out this section.

1
2
3
4
5
6
7
8
9
10
/*if ($category->getLevel() > 1) {
                // To ensure, that category has url path either from attribute or generated now
                $this->_addCategoryUrlPath($category);
                $categoryUrl = Mage::helper('catalog/category')->getCategoryUrlPath($category->getUrlPath(),
                    false, $category->getStoreId());
                return $this->getUnusedPath($category->getStoreId(), $categoryUrl . '/' . $urlKey . $productUrlSuffix,
                    $this->generatePath('id', $product, $category)
                );
            }*/

and around 851

1
2
3
4
/*if ($category && $category->getLevel() > 1) {
    return 'catalog/product/view/id/' . $product->getId() . '/category/' . $category->getId();
}*/

and around 348

1
2
3
4
5
/*if ($category->getLevel() > 1) {
            $categoryId = $category->getId();
            $updateKeys = false;
        }*/

The next file to edit is /app/code/core/Mage/Catalog/Model/Product/Url.php (again I advise rather than editing this directly you create a copy in /app/code/local) in which we need to ensure the categoryid used for generating the links is always set to null. Edit the function getUrl around line 172 and make the follow amend

1
2
3
4
5
6
7
8
9
10
11
/* commenting this out and setting the categoryId to null everytime
if (isset($params['_ignore_category'])) {
    unset($params['_ignore_category']);
    $categoryId = null;
} else {
    $categoryId = $product->getCategoryId() && !$product->getDoNotUseCategoryId()
        ? $product->getCategoryId() : null;
}*/
$categoryId = null;

http://blueclawecommerce.co.uk/blog/remove-category-path-from-product-url-in-magento/

Set NumberSuffix in PHP

function addOrdinalNumberSuffix($num) {
if (!in_array(($num % 100),array(11,12,13))){
switch ($num % 10) {
// Handle 1st, 2nd, 3rd
case 1:  return $num.’st’;
case 2:  return $num.’nd’;
case 3:  return $num.’rd’;
}
}
return $num.’th’;
}

Magento: How to get Currency Rates?

You can see the currency Rates from Magento Admin
System -> Manage Currency Rates

You can change base currency and allowed currencies from
System -> Configuration -> GENERAL -> Currency Setup -> Currency Options

Now, here I will show you how you can get currency rates values for any given currency code.

 

Here, I will be fetching currency rates for base currency. You can keep any currency code instead of basecurrency.

/**
 * Get the base currency
 */
$baseCurrencyCode = Mage::app()->getBaseCurrencyCode();     
/**
 * Get all allowed currencies
 * returns array of allowed currency codes
 */
$allowedCurrencies = Mage::getModel('directory/currency')
                            ->getConfigAllowCurrencies();   
/**
 * Get the currency rates
 * returns array with key as currency code and value as currency rate
 */
$currencyRates = Mage::getModel('directory/currency')
                        ->getCurrencyRates($baseCurrencyCode, array_values($allowedCurrencies));

Similarly, you can get currency rates for any currency code. But remember that the currency should be set as allowed currency in
System -> Configuration -> GENERAL -> Currency Setup -> Currency Options -> Allowed Currencies

$allowedCurrencies = Mage::getModel('directory/currency')
                            ->getConfigAllowCurrencies();   
/**
 * Get currency rates for Nepalese Currency
 */
$currencyRates = Mage::getModel('directory/currency')
                        ->getCurrencyRates('NPR', array_values($allowedCurrencies));

Hope this helps.