how to insert data in sales_flat_quote_item_option table of magento? - database

I am working on magento 1.7 . I need to insert data in sales_flat_quote_item_option table.I tried with following code:-
$customerId= Mage::helper('customer')->getCustomer()->getId();
$product_id = $_REQUEST['id1'];
$model = Mage::getModel('catalog/product');
$_product = $model->load($product_id);
$quoteObj=Mage::getModel('sales/quote')->assignCustomer($customerId);
$option = array('options'=>array(
"option_id1" => 'option_value1',
"option_id2" => 'option_value2'
));
$request = new Varien_Object();
$request->setData($option);
$quoteObj->addProduct($productObj,$request);
but not able to insert data in this table. Actually this table contains custom options value.I I don't have custom options so just insert another values in this table which is coming from another form.Can anybody help me?

I'm not 100% sure what you are trying to do, but I think it would be better if
Use an observer
Add your options to 'additional_options' instead of 'options'
See Magento - Quote/order product item attribute based on user input

Related

How to insert into database Drupal Custom Fields

I retrieve content types with the following code
$form['ct'] = array(
'#type' => 'checkboxes',
'#options' => node_type_get_names(),
'#title' => t('Hangi tür içerikler hakkında bilgi almak istersiniz?'),
);
And It gives the following output
http://i.stack.imgur.com/TOfS6.png
And when I press Create new Account button, the POST Array is so :
http://i.stack.imgur.com/BtxhC.png
My Question is How can I insert into database these values and read?
There are two ways of saving this data and associates with user ID ($user->uid).
Adding a new field for users from 'admin/config/people/accounts/fields'. Say the new field name is 'ct' and it is a list type field. In hook form_alter you can assign this options to 'ct'. Drupal will take care of saving the data.
You can create separate table to keep this information and use db_insert function in hook hook_user_update. To retrieve this information you need to use db_query in hook_user_load.

how to post values in cakephp 2.x and show the filtered records in another page

I have designed page in cakephp contains form which input filed name 'id' and submit button. I want to display the data filtered by the 'id' in view page. Please give me an example with code for this.
So you wanna search into a database for this ID and return back all stored data to the view?
First of all,you have to retrieve your data. See here: http://book.cakephp.org/2.0/en/models/retrieving-your-data.html
Secondly, you have to use
$this->set('var_name', $var_name_containing_found_data);
and finally you can handle your data into the view by manipulating as you wish the $var_name variable.
Put this action in your controller:
public function your_action($id = null) {//your action
if ($this->request->is('post')) {
$search = $this->YourModel->find('all', array('conditions' => array('id' => $this->request->data['id'])));//assuming id is submitted like you said $_POST['id']
$this->set('search', $search);
}
}
You can access the search variable in your view (your_view.ctp) like this $this->search
assuming your cakephp version is 2.x

How to create a dynamic form helper based on database tables?

Using cakephp 2.3.0
The conditions for the helper are:
1) I need to use many drop down boxes in multiple forms and I don't want to do loadModel in each and every controllers(12)
2) Need to fetch the datas from database tables
3) I am thinking of not baking files for the tables.
4) Want to use custom mysql queries.
E.g I've a table named countries and the dropdown should be key=>abbreviated name and name=>full name.
Any suggestions will be appreciated..
I created a function in helper
`
public function getDropDownList($table,$key,$value)
{
//$db =& ConnectionManager::getDataSource('default');
$fields = $key.','.$value;
$CommercialHeaders =& ClassRegistry::init('tablename');
$sql = $CommercialHeaders->query('select '.$fields.' from '.$table.' as DropDown');
foreach($sql as $val)
{
$countryList[$val['DropDown'][$key]] = $val['DropDown'][$value];
}
//debug($countryList);
return $countryList;
}
`
and just called it from the view by passing table name and field, which will generate an array so it solves my problem without setting it in appcontroller or using requestAction

Can't populate a Select options with related model info - CakePHP

Puling my hair out with this, I know its something very simple but I've been struggling to resolve it. For the record I'm using cakePHP 2.2.
I'm trying to populate a select input with related model data.
Basically I have users and user_statuses. The user model belongsTo the UserStatus model. Within the user/add() function I want to have a drop down select box populated with the data from the UserStatus model.
Heres the code:
UsersController/Add()
$groups = $this->User->Group->find('list');
$UserStatus = $this->User->UserStatus->find('list');
$this->set(compact('groups', 'UserStatus'));
View/Users/add.ctp
echo $this->Form->input('user_status_id', array('class' => 'span9'));
The field in the users table making the relationship is user_status_id which links to the id in the user_statuses table.
Based on the above the select box will NOT populate with the statuses from the user_statuses table. Interestingly enough, it will if I change the view code to just :
echo $this->Form->input('user_status_id', array('class' => 'span9'));
However, when I do this is will NOT write to the database.
Any help will be gratefully received.
Thanks in advance.
The options param should solve the problems for display and as long as there is a user_status_id in your User table, the below code should save the value in your User model on save.
echo $this->Form->input('User.user_status_id', array('options'=>$UserStatus,'class' => 'span9'));
Should be:
$userStatus = $this->User->UserStatus->find('list');
(note the lowercase 'u')

how to display the data returned by get_by_user_id() in DataMapper Code Igniter?

I am new to code igniter data mapper. I have a table called user, and I am trying to retrieve data from the database table and show them to the user.
Here is what I have in the model:
$u=new User();
$results=$u->get_by_user_id($id);
//$results here will be set to huge bunch of none sense data( which also includes the row that I am looking for as well)
if ($u->exists())
{
foreach ($results->all as $row){
$data['user']['first_name']=($row->user_first); //this where I am stuck ..
$data['user']['last_name']=($row->user_last);//this is also where I am stuck..
}
I don't know how to treat results to get a required fields I am looking for and store them in the $data I am passing to the user to view.
Thanks!
When you call get_by_x() on the model, the fields will be populated with data and you can access them like this:
$u = new User();
$u->get_by_user_id($id);
if($u->exists())
{
// you can access the table columns as object fields
$data['user']['first'] = $u->first;
$data['user']['last'] = $u->last;
}
else
{
$data['error'] = 'No such user!';
}
Have a look at the documentation which is really helpful: see Get and Get By.
Also, DataMapper expects all tables to have an id column: see Table Naming Rules. If your column is named id you should then call $u->get_by_id($id) instead of $u->get_by_user_id($id).

Resources