Magento – Get Product View Price By JavaScript

1,use prototype overwriting Product.Options.prototype.reloadPrice

Product.Options.prototype.oldReloadPrice = Product.Options.prototype.reloadPrice;
Product.Options.prototype.reloadPrice = function(){
    this.oldReloadPrice();
    var currentPrice = howToGetThePrice();
    doSomethingWithTheCurrentPrice(currentPrice);
};

2,use jQuery get the current price by cleaning the html inside an span

function getCurrentPrice(){
    var ds = optionsPrice.priceFormat.decimalSymbol,
    gs =optionsPrice.priceFormat.groupSymbol,
    pf=optionsPrice.priceFormat.pattern;

    var price = 0;
    jQuery('#product-price-<?php echo $_product->getId() ?>_clone span')
        .html()
        .replace(new RegExp("\\"+gs,'g'),'')
        .replace(new RegExp("\\"+ds,'g'),'.')
        .sub(/([0-9\.\,]+)/,function(matches){
            price = parseFloat(matches[1]);
    });
    return price;
}

3,Update element value with this code,you can update total price with qty.

$('totalPrice').innerHTML = currentPrice * $('qty').value

Magento – Get the Total Price of items currently in the Cart

If you want to get the total price of items in your Magento cart, you can use code like this:

<?php
echo $this->helper('checkout')->formatPrice(Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal());
?>

Magento Use jQuery with Prototype

General

The jQuery library, and virtually all of its plugins are constrained within the jQuery namespace. As a general rule, “global” objects are stored inside the jQuery namespace as well, so you shouldn’t get a clash between jQuery and any other library (like Prototype, MooTools, or YUI).

That said, there is one caveat: By default, jQuery uses “$” as a shortcut for “jQuery”

Overriding the $-function

However, you can override that default by calling jQuery.noConflict() at any point after jQuery and the other library have both loaded. For example:

 <html>
 <head>
   <script src="prototype.js"></script>
   <script src="jquery.js"></script>
   <script>
     jQuery.noConflict();

     // Use jQuery via jQuery(...)
     jQuery(document).ready(function(){
       jQuery("div").hide();
     });

     // Use Prototype with $(...), etc.
     $('someid').hide();
   </script>
 </head>
 <body></body>
 </html>

This will revert $ back to its original library. You’ll still be able to use “jQuery” in the rest of your application.

Additionally, there’s another option. If you want to make sure that jQuery won’t conflict with another library – but you want the benefit of a short name, you could do something like this: [Read more...]

The Way To Sort Regions Address In Magento

In Magento, we need to sort regions address,we can do this:

First,modify magento front code

Open ./app/code/core/Mage/Directory/Helper/Data.php

public function getRegionJson()
{
...
$collection = Mage::getModel('directory/region')->getResourceCollection()
->addCountryFilter($countryIds)
->load();
...
}

TO

public function getRegionJson(){
...
$collection = Mage::getModel('directory/region')->getResourceCollection()
->addCountryFilter($countryIds)
->addOrder('default_name', 'ASC')
->load();
...
}

Second,modify magento adminhtml code

Open ./app/code/core/Mage/Adminhtml/controllers/JsonController.php

public function countryRegionAction(){
...
$arrRegions = Mage::getResourceModel('directory/region_collection')
->addCountryFilter($countryId)
->load()
->toOptionArray();
...
}

To

public function countryRegionAction(){
...
$arrRegions = Mage::getResourceModel('directory/region_collection')
->addCountryFilter($countryId)
->addOrder('default_name', 'ASC')
->load()
->toOptionArray();
...
}

Magento Get a Product’s Name instead Product ID

You can get product name

$_product = Mage::getModel('catalog/product')->load(__PRODUCT_ID__);
$manufacturer = $_product->getManufacturer();

You’ll know that you get the product’s id instead of it’s name. Which may or may not be what you would have expected. But the magento product model provides a nice helper method for getting an attributes value, in case it was not what you were expecting. Below is the code to get a product’s name instead of it’s ID.

$_product = Mage::getModel('catalog/product')->load(__PRODUCT_ID__);
$manufacturer = $_product->getAttributeText('manufacturer');

Magento Converting Currency From One to Another

Sometimes, we need to convert currency from one to another in magento, we can use the tips.

By using Magento’s Directory Helper class, you can easily convert between available currencies.

You have to make sure that you have loaded the exchange rates for the currencies you are converting.

// Currency conversion rates have to be available in the target currency
$fromCur = 'USD'; // currency code to convert from - usually your base currency
$toCur = 'EUR'; // currency to convert to
$price = Mage::helper('directory')->
    currencyConvert($tax-&gt;getPrice($product, $product->getFinalPrice(), false), $fromCur, $toCur);
// if you want it rounded:
$converted_final_price = Mage::app()->getStore()->roundPrice($price);

Magento Feature: Merge JavaScript Files

Magneto, all the Javascript files came with Magento and are placed in “page.xml”, were merged in one link automatically and it was only capable of merging up to 10 JS files. Since version 1.4, a new feature, “Merge JavaScript Files” has added and is not set to Yes by default. We noticed quite a number of people who upgraded their sites are not aware of this change including our existing and new customers, and we have had to answered the same question over and over as some customers thought our Magento themes don’t have the feature.

however I have noticed that there are many shops that are not using Magento’s default feature to merge JavaScript files. At the time prior to Magento 1.4, JavaScript merging was included, however it was limited to 10 files. Now that’s not a case anymore.

All you need to do is: [Read more...]

Using jQuery in Magento

Add jQuery in Magento:

  1. The latest version of Magento comes with a somewhat outdated version of the script.aculo.us effects file, which is part of the problem. Go get the latest version . You may want to rename it with the version number at the end, like effects-1.8.1.js
  2. Upload the file to [Magento]/js/scriptaculous
  3. Open the file page.xml at [Magento]/app/design/frontend/default/default/layout/page.xml
  4. On about line 41, there will be a line like this:
    <action method=”addJs”><script>scriptaculous/effects.js</script></action>
    Change the file name to your new file
  5. The layout files are normally cached, so you’ll need to clear that cache to see the effect take place. Log into the backend and go to System > Cache Management
  6. Select “refresh” from the All Cache menu and save (which should clear your cache) [Read more...]

Great Features of the New Magento Enterprise Release 1.10

Many new and great features has been introduced by the recent release of Magento Enterprise 1.10, Magento Professional 1.10 and Community edition 1.5 . Lets have a closer look about some of the major new features below:
- Major enhancements to the call center functionality
- Support for newly hosted and secure payment methods with PayPal and Authorize.Net
- Enhancements to Authorize.Net payment functionality
- Gift Options [Read more...]

How to create an international shipping table in magento

whatever you call it you will have to create a table of values to use to calculate shipping.  In this post I will talk about how to create that table using country codes so that you can assign shipping rates for international shipping.  You will need to do this because you don’t really want to charge the same shipping for the country where you live, and somewhere much farther away.

For me, I will have domestic rates for USA, a set of rates for Canada, and then I just threw out a bigger rate for all other international shipping.  I don’t really have a market there, but if someone wants to pay it, then I will want to sell to them but not have shipping eat up all of my margin.

And I want to use a table rate as I have a variety of vendors that don’t all charge the same for shipping.  I am averaging their costs to me, and providing a simple, single shipping cost to my customers.

Country Codes:

First we need to get the country codes to use for our table.  These codes will be the first column of data. [Read more...]