Magento admin form not saving the decimal values with decimal - magento

For one of my custom module I have following sql setup script
$installer = $this;
$installer->startSetup();
$installer->run("
CREATE TABLE {$this->getTable('wholesale')} (
`wholesale_id` int(11) unsigned NOT NULL auto_increment,
`title` varchar(255) NOT NULL default '',
`percentage` float(5,3) NOT NULL,
`status` smallint(6) NOT NULL default '0',
`created_time` datetime NULL,
`update_time` datetime NULL,
PRIMARY KEY (`wholesale_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
");
$installer->endSetup();
The value passed to this percentage` float(5,3) NOT NULL, column is saving with decimal but always with 00 for example. If I save a value 10.23 it save in database as 10.00.
Please help

I ran into the same issue. After clearing the cache with "Flush Magento cache", it started to save properly. In my case, I had altered the column and it was being cached.

I truncated the table and inserted one record manually and it worked for me.
I am not sure why this happened but this worked for me.

Related

Automatic Casting of Default Values on Insert

This may be a feature instead of a bug, so I thought to include it on SO instead of MariaDB's Jira.
Yesterday I updated my MariaDB install on Homebrew from 10.1.23 to 10.2.6. All my selects are still working correctly, but now in my legacy app, I get a bunch of errors on inserts where the code is "assuming" MariaDB will set a default value. For example...
INSERT INTO table SET
email = 'some#email.com', -- varchar
phone_number = '', -- bigint
ts = '2017-05-30 23:51:23', -- datetime
some_val = '689728' -- varchar
This code was working fine before, but since I've upgraded I now get the following couple of errors...
Error 1 (is_some_toggle is a tinyint and is not defined in the query above, it is assumed that MariaDB would just insert a 0)
Field 'is_some_toggle' doesn't have a default value
Error 2 (after I set the default value to is_some_toggle)
Incorrect integer value: '' for column 'phone_number' at row 1
I'm guessing this is a feature, not a bug. I've looked through their changelogs for 10.2 series and I'm not seeing anything jump out, but there's a lot so I could have missed it. I saw a server config for OLD_SQL but that didn't seem to be what I was looking for. Any thoughts?
macOS Sierra 10.12.5 btw
CREATE TABLE `table` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(200) NOT NULL,
`phone_number` bigint(20) NOT NULL,
`some_val` varchar(6) NOT NULL,
`ts` datetime DEFAULT NULL,
`is_some_toggle` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
KEY `email_code` (`email`(15),`some_val`),
KEY `phone_number_code` (`phone_number`,`some_val`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
Looks like going through the changelog VERY slowly worked for me.
sql_mode was updated as was outlined in this article.
Option | Old default value | New default value
sql_mode | NO_AUTO_CREATE_USER, NO_ENGINE_SUBSTITUTION | STRICT_TRANS_TABLES, ERROR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER, NO_ENGINE_SUBSTITUTION
I changed it back to the default and I'm good as gold.

Make ajax script insert in dbase

I want to make these code insert in DBase in table chat; let's say, but I dont know how. I am bad at AJAX and I want to learn. Can you help me do it?Thank you very much.
Here is my table from DBase:
CREATE TABLE IF NOT EXISTS `legacy_chat` (
`id` int(99) NOT NULL AUTO_INCREMENT,
`chatter` int(100) NOT NULL DEFAULT '0',
`who` int(100) NOT NULL DEFAULT '0',
`timesent` int(50) NOT NULL DEFAULT '0',
`msgtext` varchar(255) NOT NULL DEFAULT '',
`rid` int(99) NOT NULL DEFAULT '0',
`exposed` char(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
codes
Indeed, you need to create a php file that takes the information you wish to add/change/delete to/from the database. You will load that file using AJAX (or jQuery) via POST or GET with the info you wish to manipulate. You may also update the requesting page using the callback to notify the user that the action was or not successfully executed.
Have a look over the following tutorials which guide you step-by-step:
Infotuts.com
Programming-free
CodeofNinja.com

Joomla migration issue

I have transferred my website to a new server after updating the files and database I am getting this issue
Table 'jimcorbe_jimcorbe.xpivg_session' doesn't exist SQL=INSERT INTO xpivg_session (session_id, client_id, time) VALUES ('18f0b96cfc5e1cb723b8405137ff36a6', 0, '1427709725')
I am very new to joomla so could not understand what it means. Can anyone provide me with the solution to get back my website live.
During the migration, it's possible that database table prefixes have changed.
Open PhpMyAdmin and look for the session table. If it doesn't exist, run the following SQL command:
CREATE TABLE IF NOT EXISTS `xpivg_session` (
`session_id` varchar(200) NOT NULL DEFAULT '',
`client_id` tinyint(3) unsigned NOT NULL DEFAULT '0',
`guest` tinyint(4) unsigned DEFAULT '1',
`time` varchar(14) DEFAULT '',
`data` mediumtext,
`userid` int(11) DEFAULT '0',
`username` varchar(150) DEFAULT '',
`usertype` varchar(50) DEFAULT '',
PRIMARY KEY (`session_id`),
KEY `whosonline` (`guest`,`usertype`),
KEY `userid` (`userid`),
KEY `time` (`time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

yii2 : can't get data from two table with active record

I want get data from two table comments,users.
comments have hasOne relation with users
public function getUser()
{
return $this->hasOne(Users::className(), ['user_id' => 'user_id']);
}
i want get comments.comment_id,comments.comment_content,comments.user_id from comments table and uses.user_name , users.user_display_name from users table to use in gridview widget.
i use
$res = Comments::find()
->select([
'comments.comment_id',
'comments.comment_content',
'comments.user_id',
'users.user_id',
'users.user_display_name',
'users.user_name',
])
->innerJoinWith('user')
->all();
this code get comments field but i can't get users.user_name,users.user_display_name from database.
How should I do it?
note: user table in database is users but when i create model with Gii,relation method declare as getUser(), i don't know why.
update 1:
comments table:
DROP TABLE IF EXISTS `comments`;
CREATE TABLE `comments` (
`comment_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`comment_content` text NOT NULL,
`comment_approved` enum('no','yes') NOT NULL DEFAULT 'no',
`comment_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`comment_parent` bigint(20) unsigned NOT NULL DEFAULT '0',
`sms_id` bigint(20) unsigned NOT NULL DEFAULT '0',
`user_id` bigint(20) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`comment_id`),
KEY `fk_comment_sms_id` (`sms_id`),
KEY `fk_commetn_user_id` (`user_id`),
CONSTRAINT `fk_comment_sms_id` FOREIGN KEY (`sms_id`) REFERENCES `sms` (`sms_id`),
CONSTRAINT `fk_commetn_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8;
users table:
CREATE TABLE `users` (
`user_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`user_name` varchar(60) NOT NULL DEFAULT '',
`user_pass` varchar(64) NOT NULL DEFAULT '',
`user_level` int(11) NOT NULL DEFAULT '1',
`user_email` varchar(100) NOT NULL DEFAULT '',
`user_display_name` varchar(250) NOT NULL DEFAULT '',
`user_phone_number` varchar(11) NOT NULL,
`user_registered` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`user_activation_key` varchar(60) NOT NULL,
`user_status` enum('active','deactive','delete') NOT NULL DEFAULT 'deactive',
PRIMARY KEY (`user_id`),
UNIQUE KEY `u_user_sign` (`user_name`) USING BTREE,
UNIQUE KEY `u_user_email` (`user_email`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8;
Not sure how you're displaying or testing if the query returned any data but you should read up on relations in Yii.
Working with Relational Data
Lazy and Eager Loading
With lazy loading the data doesn't exist until you try to access it so may not appear in things like print_r or var_dump
I recommend renaming your tables to comment and user. Read here: Table Naming Dilemma: Singular vs. Plural Names why you should use singular names.
The reason Gii generates getUser and not getUsers is because of the hasOne relationship. It's getting one -user- and not multiple -users-
Are you sure the relationship definition is correct? Is user_id the PK in the users table and the FK in the comments table? And are you sure there is correct data in the DB?

How To Recreate A Table In Magento

I dropped a table manually in magento. Now I want my code to recreate the same table.. I Have written the create statement in app/code/local/namespace/my_module/sql folder like this
DROP TABLE IF EXISTS {$this->getTable('cod')};
CREATE TABLE {$this->getTable('cod')} (
`cod_id` int(11) unsigned NOT NULL auto_increment,
`status` smallint(6) NOT NULL default '0',
'amount' int(11) unsigned NOT NULL,
`created_time` datetime NULL,
`update_time` datetime NULL,
PRIMARY KEY (`cod_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
How will this query execute so that it can recreate the table...
This query is executed when you run magento with your module first time. After this magento adds row to core_resource table my_module_setup | 0.01 | 0.01
which means, your module was set up successfully.
So, to recreate table you should drop row my_module_setup from core_resource table and run any magento page again.
Please note, version & data_version columns let you hold module's version up to date. If you change module's version in config.xml to higher than it is in core_resource, magento will look for mysql4-upgrade-0.1.0-0.1.1.php.

Resources