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...]

Hide The Magento Region Field In Checkout Progress

For some country,it’s not necessary to let your customers enter a region or province in the checkout. Today, I will tell you some knowledge about Magento and Javascript.

You must have noticed that for countries where it’s required, the text input field changes into a dropdown with the available regions. Also, this dropdown is required. That’s not functionality we will change. What we will do is hide the field when it changes to a text field. Without touching one single template.

First of all, it’s useful to know how Magento determines whether the field is required or not. It simply looks up whether there are known regions for the selected country. If there are no known regions, Magento assumes the region not required. If there are, it shows a dropdown of available regions and makes the field required. So if you don’t want to show the region field for a particular country, simply remove all regions from the table directory_country_region. [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...]

How To Edit Footer In Magento stock

The items in the footer area are in two different locations. One part is a static block created within the magento admin area (CMS > Static Block). The other part is held in the related .phtml / .php / .xml files within the design files.

First off, the XML files

app/design/frontend/*/*/layout/page.xml
Here you will find some footer reference:




app/design/frontend/*/*/layout/cms.xml




footer_links


You can see that the footer area of each page (page.xml) adds footer links via:
app/design/frontend/*/*/template/page/html/footer.phtml
This file (footer.phtml) contains a method to get it’s children HTML as referenced in the page.xml file – ($this->getChildHtml();)
-app/design/frontend/*/*/template/page/switch.phtml
-app/design/frontend/*/*/template/page/template/links.phtml
[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...]