Just another WordPress.com weblog

Archive for September, 2010

Get Country from Country Code

Hi All
If you have to find Country from CountryCode
Here is the code for you…

$countryModel = Mage::getModel(‘directory/country’)->loadByCode(‘country_code’);

$countryName = $countryModel->getName();

I hope this will help you
Thanks ..
-Vishal Surani

Advertisements

Get Region name from RegionId

Hi all
if you wish to find region from region_id
Here is the code

$regionModel = Mage::getModel(‘directory/region’)->load(‘region_id’);
$region = $regionModel->getName();

$region is region name …..

Thanks …..
-Vishal Surani

format price decimal

Hello ,
If you wand to display price with/without decimal points
here is the solution

$currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
$currency= Mage::getModel(‘directory/currency’)->load($currency_code);
echo $currency->formatPrecision(PRICE,DECIMAL NUMBERS);

if we have to diplay $480.00 as $480 simply use
echo $currency->formatPrecision(480,0);

if we have to display $480.00 as $480.0000 simply use
echo $currency->formatPrecision(480,4);

I hope this will help you….

Thanks ..
Vishal Surani

DateTime Attribute for Admin->Products

Hello Friends …
If you want attribute type as Datetime instead of date Change in following files…
1.lib/Varien/Data/Form/Element/Date.php

Put this line at top of Function

$outputFormat = Mage::app()->getLocale()->getDateTimeFormat( Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);

replace

$displayFormat = Varien_Date::convertZendToStrFtime($outputFormat, true, (bool)$this->getTime());

with this

$displayFormat = Varien_Date::convertZendToStrFtime($outputFormat = Mage::app()->getLocale()->getDateTimeFormat( Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));

And Replace

$this->getTime() ? ‘true’ : ‘false’

With

$this->getTime() ? ‘true’ : ‘true’

Also change in
2.app/code/core/Mage/Core/Model/Locale.php
Find

public function date($date=null, $part=null, $locale=null, $useTimezone=true)

in this function Change this

$date = new Zend_Date($date, $part, $locale);

With this

$date = new Zend_Date($date, “”, $locale);

Thanks
Vishal Surani

Error :: canReturnItemToStock() or canParentReturnToStock()..

I got this error while credit memo ..
So i have placed this two function in
Mage/Adminhtml/Block/Sales/Items/Abstract.php

Here is the functions..
public function canReturnItemToStock($item=null) {
$canReturnToStock = Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_CAN_SUBTRACT);
if (!is_null($item)) {
if (!$item->hasCanReturnToStock()) {
$product = Mage::getModel(‘catalog/product’)->load($item->getOrderItem()->getProductId());
if ( $product->getId() && $product->getStockItem()->getManageStock() ) {
$item->setCanReturnToStock(true);
}
else {
$item->setCanReturnToStock(false);
}
}
$canReturnToStock = $item->getCanReturnToStock();
}
return $canReturnToStock;
}

public function canParentReturnToStock($item = null)
{
$canReturnToStock = Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_CAN_SUBTRACT);
if (!is_null($item)) {
if ( $item->getCreditmemo()->getOrder()->hasCanReturnToStock() ) {
$canReturnToStock = $item->getCreditmemo()->getOrder()->getCanReturnToStock();
}
} elseif ( $this->getOrder()->hasCanReturnToStock() ) {
$canReturnToStock = $this->getOrder()->getCanReturnToStock();
}
return $canReturnToStock;
}

I hope this will helpful….
Vishal Surani

Delete particular Order from database

Hello everyone,

Below code will help to delete particular order using increment_id of that order.

select @order_id:=entity_id from sales_order_entity where increment_id='100000001';
delete from sales_order_entity where entity_id=@order_id or parent_id=@order_id;

I hope this will help u to particular delete order.
Ref: http://www.magentocommerce.com/boards/viewthread/1680/#t29687

Thanks,
Bijal Bhavsar 🙂