Wednesday, June 22, 2011

How to get sold quantity of product in magento


If you want to have it so that it only shows quantity sold on the product page on items that are currently on sale.. use the following., There will also be an alert for customers when there is only 1 remaining in stock.Then use the following code.
<?php 
$_finalPrice 
$this->helper('tax')->getPrice($_product$_product->getFinalPrice());$_regularPrice $this->helper('tax')->getPrice($_product$_product->getPrice());
if (
$_regularPrice != $_finalPrice):$sku nl2br($_product->getSku());
$to $_product->getResource()->formatDate(time());$from $_product->getResource()->formatDate(time() - 60 60 24 1);$_productCollection Mage::getResourceModel('reports/product_collection')
->
addOrderedQty($from$totrue)
->
addAttributeToFilter('sku'$sku)
->
setOrder('ordered_qty''desc')
->
getFirstItem();$product $_productCollection;

echo 
'Already Bought Today '.(int)$product->ordered_qty
endif;
?>
<?php 
if ((int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()==1): ?><p style="color:#990000; padding:5px 0; text-align:right;"><strong>ONLY 1 LEFT IN STOCK!</strong></p><?php endif; ?>

Or if you want to show stock sold on the product page for the entire duration the product has been active, use the following
<?php 

$sku 
nl2br($_product->getSku());$_productCollection Mage::getResourceModel('reports/product_collection')
->
addOrderedQty()
->
addAttributeToFilter('sku'$sku)
->
setOrder('ordered_qty''desc')
->
getFirstItem();$product $_productCollection;

echo 
'Already Bought '.(int)$product->ordered_qty?>

and finally if you want to just just on the page how many have been sold of the product for today, use the following

<?php 
$sku 
nl2br($_product->getSku());
$to $_product->getResource()->formatDate(time());$from $_product->getResource()->formatDate(time() - 60 60 24 1);$_productCollection Mage::getResourceModel('reports/product_collection')
->
addOrderedQty($from$totrue)
->
addAttributeToFilter('sku'$sku)
->
setOrder('ordered_qty''desc')
->
getFirstItem();$product $_productCollection;

echo 
'Quantity Ordered Today '.(int)$product->ordered_qty
endif;
?>

Just copy and paste into your view.phtml file, into a suitable place :)

How to show static block only on home page in magento



<?php    $ref = new Mage_Page_Block_Html_Header();   if($ref->getIsHomePage()){ ?>   <div class="homepage"><?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('Your_StaticBlock_Id')->toHtml();?></div>   <?php   }   ?>
enjoy...........

Wednesday, June 15, 2011

How to get currency symbol in .phtml file in magento


You can use this:
<?php echo Mage::helper('core')->currency('123.23') ?>
which will output something like:
<span class="price">123,23 €</span>

Enjoy......

To Show currency switcher in magento in header, left,right


You can easily setup a multiple currency shop in Magento. By multiple currency shop, I mean giving the user to browse products in different currencies. Magento will provide a currency dropdown in category and product listing page. When you select your desired currency, the entire products price will be changed to your selected currency.
Here is a step-by-step procedure to setup multiple currency shop in Magento:-
- Go to System –> Configuration –> Currency Setup
- Under ‘Currency Options‘, select Allowed currencies.
The selected currencies will be displayed in currency dropdown in category and product listing page. Remember that your Base currency and Default display currency selection should also be selected in Allowed currencies.
- Click ‘Save Config‘ button.
- Go to System –> Manage Currency Rates
- Select Import Service. By default it is ‘Webservicex’.
- Click ‘Import‘ button. This will update the currency rates values.
- Click ‘Save Currency Rates‘ button.
- Go to category listing page. You will see currency selection dropdown list in left sidebar at top.
Now, user of your shop can browse product with price in their desired currency.
Additional Scenario:-
Suppose, you have two currencies (British pound and U.S. dollar) in your Magento shop. You also have two stores (Store A and Store B). You want to show British pound in Store A and U.S. dollar in Store B.
Here is the solution:-
- Follow the steps above to setup multiple currency Magento shop.
- You will have multiple currency shop.
- Follow these steps to show store specific currency:-
- Go to System -> Configuration -> GENERAL -> Currency Setup
- In left sidebar at top, you will see “Current Configuration Scope
- Select your desired store from the selection list
- Now, under “Currency Options“, you will see “Default Display Currency
- Select your desired currency from the selection list
You are done. In frontend, select the store for which you did the above changes. You will see the price in your desired currency.
and put this line of code where u you want to display currency converter
<?php echo $this->getLayout()->createBlock('directory/currency')->setTemplate('directory/currency.phtml')->toHtml(); ?>


Hope this helps. Thanks.