Powered by Blogger.

Thêm đơn vị tiền tệ VND cho Prestashop


B
ài viết dưới đây sẽ trình bày cách thêm đơn vị tiền tệ Việt Nam Đồng cho Prestashop và hiển thị giá sản phẩm Prestashop dưới dạng có ký tự phân cách 0.000.000 Đ hoặc 0 000 000 VND.



Xem thêm Hướng dẫn cách thêm sản phẩm cho PrestaShop
Áp dụng cho phiên bản Prestashop 1.0.
Thực hiện cách bước làm như sau :
Chú ý: Trước khi sửa code bạn phải sao lưu file cần sửa.
1. Mở file /classes/Tools.php và sửa file Tools.php trong thư mục classes. Tìm đến dòng code sau:
Code:
switch ($c_format) // dòng 210
{
/* X 0,000.00 */
case 1:
$ret = $c_sign.' '.number_format($price, 2, '.', ',');
break;
/* 0 000,00 X*/
case 2:
$ret = number_format($price, 2, ',', ' ').' '.$c_sign;
break;
/* X 0.000,00 */
case 3:
$ret = $c_sign.' '.number_format($price, 2, ',', '.');
break;
/* 0,000.00 X */
case 4:
$ret = number_format($price, 2, '.', ',').' '.$c_sign;
break;
// Thêm vào đoạn mã sau /* 0.000 X as with VND*/
case 5:     

$ret = number_format($price, 0, ',', '.').' '.$c_sign;
break;
/* 0 000 X as with VND*/
case 6:     

$ret = number_format($price, 0, ',', ' ').' '.$c_sign;
break;

}
2. Sửa file AdminCurrencies.php trong Admin/Tabs. Tìm đến đoạn code sau:
Code:
<select name="format">';
$currency_formats = array(
1 => '
X0,000.00 ('.$this->l('as with dollars').')',
2 => '
0 000,00X ('.$this->l('as with euros').')',
3 => '
X0.000,00',
4 => '
0,000.00X',// Thêm vào đoạn mã sau

5 => '0.000X ('.$this->l('as with VNĐ').'),
6 => '0 000X ('.$this->l('as with VNĐ').')
);
Với bản Prestashop 1.1 làm tương tự như sau
// file Tools.php dòng 210 switch ($c_format)
{
/* X 0,000.00 */
case 1:
$ret = $c_char.$blank.number_format($price, $c_decimals, '.', ',');
break;
/* 0 000,00 X*/
case 2:
$ret = number_format($price, $c_decimals, ',', ' ').$blank.$c_char;
break;
/* X 0.000,00 */
case 3:
$ret = $c_char.$blank.number_format($price, $c_decimals, ',', '.');
break;
/* 0,000.00 X */
case 4:
$ret = number_format($price, $c_decimals, '.', ',').$blank.$c_char;
break;
// Thêm đoạn mã sau
/* 0.000,00 X */   
case 5:
$ret = number_format($price, $c_decimals, ',', '.').$blank.$c_char;
break;
default:
$ret = number_format($price, $c_decimals, ',', '.').$blank.$c_char;
break;   
}
File AdminCurrencies.php dòng 143
$currency_formats = array(
 1 => 'X0,000.00 ('.$this->l('as with dollars').')',
 2 => '0 000,00X ('.$this->l('as with euros').')',
 3 => 'X0.000,00',
 4 => '0,000.00X',
// Thêm đoạn mã sau
5 => '0.000,00X ('.$this->l('as with Vietnam Dong').')'
 );
3. Tiếp theo, Đăng nhập trang quản trị PrestaShop
Back Office >> Payment >> Currencies
Tạo một đơn vị tiền tệ (currency) mới bằng cách:
Click vào Add new
Nhập các giá trị sau:
Currency: VNĐ
ISO Code: VND
Conversion rate:tỉ giá VNĐ so với giá của đồng Euro (mặc định)
Mình chỉ dùng đồng $ và VNĐ nên set Conversion rate của $ là 1.
Formatting: 0.000,00 X (as with VNĐ)
Chọn VND làm loại tiền chính từ drop-down list.
4. Sau đó cập nhật tỉ giá tiền tệ bằng cách click vào nút Update Conversion rate:
Cần sửa code để set VND làm loại tiền chính khi cập nhật tỉ giá.
Còn nữa...
Chúc thành công!
Xem demo tại đây http://toanquyen.com
hoặc www.didong.org
    Blogger Comment
    Facebook Comment