Add a non database attribute to order email - email

we have a single attribute which is shown on single product page. Attribut Name is lieferkW. For any order of a product i want to send the content of this attribute to our customers in the order email.
i dont want to save the content of this attribute in database. Do you have any solution for my problem?

You can use other resources, like the session, the local storage, or a temporary file.
However, I would suggest that you should store this in the database and remove it when you send the email. You could have a table like this
temporary_attributes(id, userId, attribute, orderId)
insert it when you need it and remove it once you have sent the email.

To include your custom attribute lieferkW in your sales order email, make these changes
1) Open \app\code\core\Mage\Sales\Model\Order.php
$customAttr = 'custom_value'; // the attribute "lieferkW" value
$mailer->setTemplateParams(array(
'order' => $this,
'billing' => $this->getBillingAddress(),
'payment_html' => $paymentBlockHtml,
'custom' => $customAttr //your custom value here
)
);
2) Now change the email template located at \app\locale\en_US\template\email\sales\order_new.html
You can access you variable here like
{{var custom}}
P.S. I advice not to make changes in the core files.

Related

Defining sort-order of associated model select box from CakePHP's FormHelper?

In this instance I'm working with two models: Departments, and Users.
Departments belongsTo Users
(In this instance, a user is a department manager [null allowed].)
Using FormHelper, I simply defined the selection of the User id as:
echo $this->Form->input('user_id', array('label'=>'Department/Group Manager (leave blank if none)', 'empty' => true));
By default, FormHelper seems to order the selection items by User.id ASC (the HTML select element's "value" property). To make things nicer in the add.ctp form, I created a virtual field as "Lastname, Firstname" to be used as the User model's display field:
public $virtualFields = array(
'name' => "CONCAT(User.lastName, ', ', User.firstName)"
);
public $displayField = 'name';
This worked great. Unfortunately, I'd love to be able to order the items in the rendered select box by the virtual field's value, ascending (or User.lastName in this case) instead of by User.id. I was unable to figure out a way to do this using FormHelper. Is there another way to do this (if FormHelper can't do it)?
MVC:
The MODEL retrieves the data (business logic).
The CONTROLLER sets the data for the view [$this->set()].
The VIEW simply handles your output, and any logic that is not capable of being handled elsewhere.
Using Cake convention based on how the cake bake output is created, you'd want to set the ORDER BY clause in the call to the model's find() method in your controller, related to the particular view. In this case, your Department's add() method.
public function add(){
// ... other code ...
$users = $this->Department->User->find('list', array('order' => array('lastName' => 'asc'));
$this->set(compact('users'));
}
Be aware that if you are using the Containable Behavior you may need to adjust its settings to achieve the default (most likely working) code example above.

MVC4 edit method changes values to null if correspndong fields don't exist in the form

My table has two columns CreatedBy and CreateTime. In my view form, I don't have these fields. Now when I update a record using ASP.NET MVC4 Edit (post) method, these columns are set to null. But I want to retain the values. I know in my Edit (post) method, I can retrieve the record from the database and set these manually. But I am wondering whether I can ask Entity Framework not to change the values of these fields.
No you can't, if you want to keep the old values then you have to get the record first and then manually assign the values that you want to update. The only other way is to go through your entity property by property and tag which ones you want to modify, like so:
db.MyEntity.Attach(myEntity);
db.Entry(myEntity).Property(e => e.MyProperty).IsModified = true;
db.SaveChanges();
either way you end up having to do the manual work yourself.
You have to choices here:
1) As #KennyZ mentioned, add to #Html.HiddenFor() somewhere in your view, into your form:
#Html.HiddenFor(m => m.CreatedBy)
#Html.HiddenFor(m => m.createTime)
2) You can manually update that entity and leave those two properties alone:
var ent = dbctx.Entities.Find(model.ID);
ent.Prop1 = model.Prop1;
// ... also for other properties except those two property
dbctx.SaveChanges();
Sure you can. I assume they are already in your model, just add them to the form with Html.HiddenFor(m => m.createdBy). Now they are in the form but not displayed, and still have values on Post methods.

Autofill Field in SugarCRM

In Quotes module (SugarCRM Pro) i made one field region (drop down). When we select billing account name in quote name then address automatically fill up . I want that region field will automatically fill up as i have made same region in account module . I want it will automatically fetch the region from the account module as it fetch all the address.
in your editviewdefs for that module, on the field array element, you need to add something like:
'displayParams' => array( 'field_to_name_array' => array( 'FIELDFROMACCOUNTS' => 'FIELDTOPOPULATE', 'FIELDFROMACCOUNTS2' => 'FIELDTOPOPULATE2'),),
Replace the all caps words with your fields and you should be ready to go. Keep in mind that relate fields have a hidden field that is used for the ids and make sure that you are populating it properly.
Cheers.

Unique field in user registration form in Drupal 7

I am working in drupal 7. I need a field in the user registration form which needs to be unique. It is an integer field which stores the ID of the user. I have been searching around for a few hours now without any development. Can someone guide me through this?
Thank You.
You can add a custom "staff id" field to the user entity type from admin/config/people/account/fields (configuration->people->account settings). You can add a new integer field, and mark it to display in the registration form, and/or required.
To check that the field value is unqiue you will need to use a custom module. In your custom module use the form_id_form_alter hook to add a custom validation to the registration form. Then during validation you can check that the value does not already exist in the database and return a form error.
Example of the custom module:
<?php
function mymodule_form_user_register_form_alter(&$form, &$form_state, $form_id){
$form['#validate'][] = 'mymodule_user_registration_validate';
}
function mymodule_user_registration_validate(&$form,&$form_state){
$staff_id = $form_state['values']['staff_id_field'];
$check_unique_query = 'SELECT field_staff_id_value FROM {field_data_staff_id} WHERE field_staff_id_value = :staff_id LIMIT 1';
//if a result is returned, that means the $staff_id exists
if (db_query($check_unique_query,array(':staff_id'=>$staff_id))->fetchField()){
form_set_error('staff_id_field','This Staff ID is already in use');
}
}
Have you tried the Unique field module? Pretty sure it does what you need here.
Field validation does the trick https://drupal.org/project/field_validation. You can set any rules per field even on the registration form

How to override default user profile fields in drupal 7 ising form API?

I'd like to know how to override/change the default fields in user profile such as: button Save, name, timezone etc.
I'd like to alter, delete('cause i don't need them) some of them.
To alter the user profile i use the hook: hook_form_alter using which i managed to add my own fieldds to user profile. But now i want to alter the default fields. How can i do it?
It is possible with the hook_form_alter, though it is better to use hook_form_FORM_ID_alter!
To be able to alter the form you need to know the structure of the arrays, the easiest way to get to know this is by installing the Devel module. Then you can view the structure by placing dpm($form); inside your alter function.
You can use this function on your custom module or in your theme (in template.php file).
Usually user profile form_id is user_profile_form. A simple example would be:
function mymodule_form_user_profile_form_alter(&$form,$form_state,$form_id){
$form['timezone']['#access'] = FALSE; //remove the "timezone" field from the form (default value is still saved)
$form['field_somefield']['#weight'] = -50; //move the field up
$form['actions']['submit']['#value'] = t('Add this content now'); //change the submit button text
}
For a good tutorial see the Lullabot tutorial here (is for drupal 6 but works the same way for d7!).
API: hook_form_FORM_ID_alter