disabling magento round up - mysql

I need to know how to disable magento from removing decimals in a form field of text type in my admin html backend. If I put a number in this field:
$fieldset->addField('radiorate', 'text', array(
'label' => Mage::helper('radiosupplier')->__('Single Radio Rate'),
'name' => 'radiorate',
));
like 523.42 after saving I get 523.00. I tried to modify my db settings for this field and set the type from integer to decimal 10,2 but then I get 523.00
How can I prevent this?
Magento version 1.7.0.2

try this in saveAction()
before save statement
$value = number_format($value, 2);
or
$value = number_format(523.42, 2);
for example you want to change price field which contain decimal value
$post['price']= number_format($post['price'], 2);
$model->setData($post);
hope this will help you

Related

CakePHP 4 do not get new added fields from DB

I have some trouble getting content of a new created field from Database.
At the beginning i created my "Menue" table in phpmyadmin and then in cake with "bin/cake bake all Menue". So far so good. But i forgot a field "price" which i added right now in the database and filled it with content.
In cake i added this field "price" in src/Model/Entitiy/Menue and src/Table/MenuesTable.php. In the Controller src/Controller/MenuesController i wanted to get the price with $menue->price but there is no field key or content. Also print_r($menue); return all other fields and content but not the price field.
is there another file where i have to add this field?
In phpmyadmin i can do a simple sql statement and i get this field with content in the results... so i am thinking cake is missing something.
Thanks in advance!
The following query was created by the bake command.
$menue = $this->Menues->get($id, [
'contain' => ['Restaurants'],
]);
also a self written query do do deliver the field "price"
$menue = $this->Menues
->find()
->where(['id ='=>$id]);
foreach($menue as $m){
print_r($m);
}
I just figured out, that this field and a again newly created "test" field are loaded in another Controller written by hand with
$this->loadModel('Menues');
...
$contents = $this->Menues
->find()
->select(['id',
'title',
'short_description',
'additives',
'price',
'currency',
'image_path'
'test'
])
->where(['restaurant_id =' => $restaurant_id,'menuegroup' => $cat['menuegroup']])
->order(['sort_order' => 'ASC']);
But why my other controller do not want to give me the price is still a question i can not answer. maybe someone knows.
THX

Magento 1.9 add custom column to associated products grid

We have an existing customization that appears to have broken when we upgraded from 1.7 to 1.9 community.
The customization adds a column to the associated products grid.
The customization is a local override of
app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Group.php
This was done before I started on the project
$this->addColumn('breakdown_part_no', array(
'header' => Mage::helper('catalog')->__('Part No'),
'name' => 'breakdown_part_no',
'type' => 'varchar',
'index' => 'breakdown_part_no',
'width' => '120px',
'editable' => true,
));
This was added to _prepareColumns()
Another customization was added to method getSelectedGroupedProducts()
public function getSelectedGroupedProducts()
{
$associatedProducts = Mage::registry('current_product')->getTypeInstance(true)
->getAssociatedProducts(Mage::registry('current_product'));
$products = array();
foreach ($associatedProducts as $product) {
$products[$product->getId()] = array(
'qty' => $product->getQty(),
'position' => $product->getPosition(),
'breakdown_part_no' => $product->getBreakdownPartNo(),
);
}
return $products;
}
The behavior is that the column appears in the admin and can be edited, however when saved, it does not save any value.
If I modify the getSelectedGroupedProducts part and set a hard coded value, it displays still no value (blank field), but interestingly if I click save with no value, it saves the value that was hard coded. If I enter any value in the field, it saves as a blank. This is really strange behavior that makes no sense to me.
If I change one of the other fields, such as position to be a hard coded value, it appears instantly and works as expected. Please let me know the proper way for this to work.
There are several posts on various forums about how to do the above and the modification mentioned is true, but what all of the other posts left out was the adminhtml layout input. When a user edits product data in Magento Admin (Associated Products), the data is serialized and sent to the controller save action. I noticed that the fields were not present when a value was entered. This is because the value wasn't in the layout so it was being stripped off of the request before it was posted to the controller.
Add input field in adminhtml/default/default/layout/catalog.xml
adminhtml_catalog_product_supergroup
addColumnInputName

CakePHP 3 - Get Form Input Field Name in Array - Use Hash?

OK, I've got a simple form submitted to my controller.
In my controller:
$thedata = $this->request->data;
debug($thedata);
Results in:
[
'number' => '102',
'color' => 'blue',
'size' => 'large'
]
I want to extract from this result an array that is the input field names. The result should be
$thearray = ['number','color','size'];
What is the best way to do this in CakePHP? I'm using using 3.5.2.
Will Hash::extract do this? If so, how would that work?
Thanks in advance for any advice.
D.
This solved my issue:
$thearray = array_keys($thedata);

Symfony 2 / Doctrine Not Saving Any Zeros in varchar field

UPDATE
As asked for,
$NewUser = new Users();
$Form = $this->createForm(new UserType(), $NewUser, [])
->add('save', 'submit', ['label' => 'Save',
'attr' => ['class' => 'SaveButton ftLeft'],
]);
$Form->handleRequest($request);
if ($Form->isValid()) {
/*
Sometimes add more data to the entity.....
*/
$em = $this->getDoctrine()->getManager();
$em->persist( $NewUser );
$em->flush();
}
$FormRender = $Form->createView();
return $this->render('xxxxBundle:Users/add.html.twig',
['AddUser' => $FormRender]);
Sometimes I will add extra to the entity, on fields being set within the php code, e.g. account sign up date, but in most cases just save the entity with the form data.
Very simple issue, I have a new (ish) system and have notice that when trying to save zeros, for anything, phone number inputs, it does not save any zeros?
I am using YMAL files to control my doctrine ORM, here is how I have set it up within my User table,
mobileNumber:
type: string
nullable: false
length: 50
options:
fixed: false
column: mobile_number
This does save/make the field has a varchar, and thought nothing about it until I did a random test and saw it was not saving any leading zeros?
I know you can not save leading zeros in a int field type, but this is a varchar. Also when I go into the database, and manually add a zero to that input, its fine, so I take its not the database. Something to do with how I get doctrine to save the data?
If so how do I change that? I have just been saving the data with a standard persist() and flush() commands? Not sure why it would not save the zeros? I was thinking that I had to change the YMAL type to something like phone? I have been over the docs, can not see it.
All help most welcome..
Thanks.
The reason is in your comment:
User form type has the mobile number set to 'number' input.
This value is being casted to int by the Form component. Change the field type to regular string.
If you want to validate value to be only digits, use Validation component

Cakephp 3.0 I would like to include a Year input field with a drop down, but it is inputing as an array

I have a Year field in a form and I am using FormHelper.
echo $this->Form->input('year', [
'type' => 'year',
'minYear' => date('Y')-10,
'maxYear' => date('Y')
]);
The table file validator looks like:
->add('year', 'valid', ['rule' => 'numeric'])
->allowEmpty('year')
I have a very similar input in another app that seems to work fine. I set the MySql column to int(5) to match what I had working elsewhere.
Checking debugkit it shows the "year" input as an array while the other inputs are strings. If I remove the validation rule it throws an illegal array to string conversion, so I assume this is where the error is.
Any help is greatly appreciated.
I have just tested with your above code and it is working fine for me. Try to delete the cache and check it once more.
Creates a select element populated with the years from minYear to maxYear. Additionally, HTML attributes may be supplied in $options. If $options['empty'] is false, the select will not include an empty option:
empty - If true, the empty select option is shown. If a string, that
string is displayed as the empty element.
orderYear - Ordering of
year values in select options. Possible values ‘asc’, ‘desc’. Default
‘desc’ value The selected value of the input.
maxYear The max year to
appear in the select element.
minYear The min year to appear in the
select element.
Try this one:
<?php
echo $this->Form->year('exp_date', [
'minYear' => date('Y')-10,
'maxYear' => date('Y'),
'id' => 'cc-year',
'class' => 'form-control',
'empty' => false,
'orderYear' => 'asc'
]);
?>
Official Documentation: CookBook - Creating Year Inputs