Skip to content

Commit

Permalink
fix: wWhen a product is purchased with a price of more than 8 degit t…
Browse files Browse the repository at this point in the history
…he calculation is wrong is fixed #819 (#825)
  • Loading branch information
saimonh3 authored May 11, 2020
1 parent b3bf1fd commit 1c7663f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
12 changes: 6 additions & 6 deletions includes/Install/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ function create_withdraw_table() {
$sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}dokan_withdraw` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) unsigned NOT NULL,
`amount` float(11) NOT NULL,
`amount` decimal(19,4) NOT NULL,
`date` timestamp NOT NULL,
`status` int(1) NOT NULL,
`method` varchar(30) NOT NULL,
Expand All @@ -283,8 +283,8 @@ function create_sync_table() {
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`order_id` bigint(20) DEFAULT NULL,
`seller_id` bigint(20) DEFAULT NULL,
`order_total` float(11,4) DEFAULT NULL,
`net_amount` float(11,4) DEFAULT NULL,
`order_total` decimal(19,4) DEFAULT NULL,
`net_amount` decimal(19,4) DEFAULT NULL,
`order_status` varchar(30) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `order_id` (`order_id`),
Expand Down Expand Up @@ -332,7 +332,7 @@ function create_refund_table() {
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`order_id` bigint(20) unsigned NOT NULL,
`seller_id` bigint(20) NOT NULL,
`refund_amount` float(11) NOT NULL,
`refund_amount` decimal(19,4) NOT NULL,
`refund_reason` text NULL,
`item_qtys` varchar(200) NULL,
`item_totals` varchar(200) NULL,
Expand Down Expand Up @@ -361,8 +361,8 @@ function create_vendor_balance_table() {
`trn_id` bigint(20) unsigned NOT NULL,
`trn_type` varchar(30) NOT NULL,
`perticulars` text NOT NULL,
`debit` float(11) NOT NULL,
`credit` float(11) NOT NULL,
`debit` decimal(19,4) NOT NULL,
`credit` decimal(19,4) NOT NULL,
`status` varchar(30) DEFAULT NULL,
`trn_date` timestamp NOT NULL,
`balance_date` timestamp NOT NULL,
Expand Down
1 change: 1 addition & 0 deletions includes/Upgrade/Upgrades.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Upgrades {
'2.9.16' => Upgrades\V_2_9_16::class,
'2.9.19' => Upgrades\V_2_9_19::class,
'2.9.23' => Upgrades\V_2_9_23::class,
'3.0.4' => Upgrades\V_3_0_4::class,
];

/**
Expand Down
47 changes: 47 additions & 0 deletions includes/Upgrade/Upgrades/V_3_0_4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace WeDevs\Dokan\Upgrade\Upgrades;

use WeDevs\Dokan\Abstracts\DokanUpgrader;

class V_3_0_4 extends DokanUpgrader {

/**
* Get table_name and columns in key value pair
*
* @since DOKAN_LITE_SINCE
*
* @return array
*/
public static function get_tables() {
return [
'dokan_withdraw' => [ 'amount' ],
'dokan_refund' => [ 'refund_amount' ],
'dokan_vendor_balance' => [ 'debit', 'credit' ],
'dokan_orders' => [ 'order_total', 'net_amount' ],
];
}

/**
* Update various dokan tables
*
* @since DOKAN_LITE_SINCE
*
* @return void
*/
public static function update_dokan_tables() {
global $wpdb;

foreach ( self::get_tables() as $table => $columns ) {
$table_name = $wpdb->prefix . $table;

if ( $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $table_name ) ) !== $table_name ) {
continue;
}

foreach ( $columns as $column ) {
$wpdb->query( "ALTER TABLE `{$table_name}` MODIFY COLUMN `{$column}` DECIMAL(19,4)" );
}
}
}
}

0 comments on commit 1c7663f

Please sign in to comment.