How to Display a custom value like customer number in order Email - magento-1.9

I am working on a solution for the task to display a customer number in the order confirmation email.
There is already a custom attribute customer_number which is displayed in the register form and the customers back-end.
It seems to get displayed by calling a helper.
This is how it is displayed in the register form:
<input type="number"
name="<?php echo Company_Helper_Data :: CUSTOMER_NUMBER_FIELD ?>"
id="<?php echo Company_Helper_Data :: CUSTOMER_NUMBER_FIELD . "id" ?>"
value="<?php echo $this->escapeHtml($this->getFormData()->getData( Company_Helper_Data :: CUSTOMER_NUMBER_FIELD ) ) ?>"
title="<?php echo $this->__('Customer Number') ?>" class="input-text" />
This is how it gets called in the customer back-end
<input type="text"
name="customer_number"
id="customer_number"
value="<?php echo $this->getCustomer()->getCustomerNumber() ?>"
title="<?php echo $this->__(' Customer Number') ?>"
class="input-text" />
So I simply tried to put this code into the order/default.phmtl:
<?php echo $this->getCustomer()->getCustomerNumber()?>
Which does not work. The Order cannot be set.
I am rookie to programming. Does anyone has an idea how to call the customer-data in the order email-template and display it in the order confirmation?

For this in Magento, you'll have to go in magento backend admin panel,
next go to
system=>Transactional Emails
Here you'll find your email template.
After this open the email template and then place this where you would like
{{ var customer_number }}

Related

Wordpress custom widget that allows html codes

I just need a widget with a textarea where I can paste an embed code. Right now, whenever I save the widget, it auto removes the html codes.
<label for="<?php echo $this->get_field_id( 'embed' ); ?>"><?php _e( 'Embed:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'embed' ); ?>" name="<?php echo $this->get_field_name( 'embed' ); ?>" type="text" value="<?php echo esc_attr( $embed ); ?>" />
It should work like the default text-widget where it runs HTML. Any way I can put a certain code to retain and run the HTML in my custom widget?
Please use the default textwidget, it will serve your purposes.

Undefined variable (opencart)

on the line where the error apparently is the code looks like this:
<?php if ($filter_name) { ?>
I know this is probably a vague questions but if anyone can help that would be great!
This is very Vague question. most probably you would be getting this error in header.tpl because you are using theme made for 1.5.4.x ( or earlier) with 1.5.5.x
in your catalog/view/theme/your_theme/template/common/header.tpl
Find
<?php if ($filter_name) { ?>
<input type="text" name="filter_name" value="<?php echo $filter_name; ?>" />
<?php } else { ?>
<input type="text" name="filter_name" value="<?php echo $text_search; ?>" onclick="this.value = '';" onkeydown="this.style.color = '#000000';" />
<?php } ?>
replace with
<input type="text" name="search" placeholder="<?php echo $text_search; ?>" value="<?php echo $search; ?>" />
If you would have searched before asking you would have found this http://forum.opencart.com/viewtopic.php?f=20&t=97790
go to path : catalog/view/theme/your_theme/template/common/header.tpl
open the file header.tpl
search <?php if($filter_name) { ?>
replace above by <?php if(isset($filter_name)) { ?>
yes , it is a version defect , its common when u use a 1.5.4 theme for 1.5.5 version , but u can solve it easily (if one or two errors) using the above stated method. only this file needs to be changed : catalog/view/theme/your-theme/template/common/header.tpl , and dont crack up the core files for safety .
https://github.com/justinmarsan/opencart-blank-theme/issues/7
This link really helped me,
Just replace
This:
<?php if ($filter_name) { ?>
With This:
<?php if (isset($filter_name)) { ?>

Wordpress Custom Registration Form

I have a client that needs a custom registration form.
I need to make a custom design on this page
I need to add custom fields like First Name, Company, Phone, etc.
Someone can help me with this?
A better place to ask WordPress questions is probably on WordPress Answers. Anyhoo, if you want to solve this without plugins, you need three things:
A custom WordPress theme
A Page Template
A WordPress Page that uses the Page Template
When you have these three parts in place, you can do the following in your Page Template:
<?php
/*
Template Name: Registration
*/
global $current_user;
wp_get_current_user();
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$company = $_POST['company'];
if (($firstname != '') && ($lastname != '') && ($company != '')) {
// TODO: Do more rigorous validation on the submitted data
// TODO: Generate a better login (or ask the user for it)
$login = $firstname . $lastname;
// TODO: Generate a better password (or ask the user for it)
$password = '123';
// TODO: Ask the user for an e-mail address
$email = 'test#example.com';
// Create the WordPress User object with the basic required information
$user_id = wp_create_user($login, $password, $email);
if (!$user_id || is_wp_error($user_id)) {
// TODO: Display an error message and don't proceed.
}
$userinfo = array(
'ID' => $user_id,
'first_name' => $firstname,
'last_name' => $lastname,
);
// Update the WordPress User object with first and last name.
wp_update_user($userinfo);
// Add the company as user metadata
update_usermeta($user_id, 'company', $company);
}
if (is_user_logged_in()) : ?>
<p>You're already logged in and have no need to create a user profile.</p>
<?php else : while (have_posts()) : the_post(); ?>
<div id="page-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="content">
<?php the_content() ?>
</div>
<form action="<?php echo $_SERVER['REQUEST_URI'] ?>" method="post">
<div class="firstname">
<label for="firstname">First name:</label>
<input name="firstname"
id="firstname"
value="<?php echo esc_attr($firstname) ?>">
</div>
<div class="lastname">
<label for="lastname">Last name:</label>
<input name="lastname"
id="lastname"
value="<?php echo esc_attr($lastname) ?>">
</div>
<div class="company">
<label for="company">Company:</label>
<input name="company"
id="company"
value="<?php echo esc_attr($company) ?>">
</div>
</form>
</div>
<?php endwhile; endif; ?>
Now, when you want to retrieve the stuff you've stored, you need to know whether the information is within the User object itself or in metadata. To retrieve the first and last name (of a logged-in user):
global $current_user;
$firstname = $current_user->first_name;
$lastname = $current_user->last_name;
To retrieve the company name (of a logged-in user):
global $current_user;
$company = get_usermeta($current_user->id, 'company');
That's the basic gist of it. There's still a lot of stuff missing here, like validation, error message output, the handling of errors occurring within the WordPress API, etc. There's also some important TODO's that you have to take care of before the code will even work. The code should probably also be split into several files, but I hope this is enough to get you started.
An advantage of using a custom registration form is that modifying the code according to the user's needs becomes easy. For a custom submit form you can make use of existing hooks in Wordpress like template_redirect and then map that hook to some function which will do the post-processing of the form, like validation and submitting data to the site's database. You can refer to an in-depth article here.
<div class="employee">
<input type="hidden" name="show_msg">
<form name="customer_details" method="POST" required="required" class="input-hidden">
Your Name: <input type="text" id="name" name="customer_name">
Your Email: <input type="text" id="email" name="customer_email">
Company: <input type="text" id="company" name="company">
Sex: <input type="radio" name="customer_sex" value="male">Male <input type="radio" name="customer_sex" value="female">Female
<textarea id="post" name="experience" placeholder="Write something.." style="height:400px;width:100%"></textarea>
<input type="submit" value="Submit">
<!--?php wp_nonce_field( 'wpshout-frontend-post','form-submit' ); ?-->
</form></div>
PHP function
function wpshout_frontend_post() {
wpshout_save_post_if_submitted();
}
add_action('template_redirect','wpshout_frontend_post', 2);
A custom WordPress registration form has two major advantages over the standard form.
The first is the integration with the overall look and feel of the website theme. Standard forms often don’t work well with custom themes and there is always a chance that the custom CSS files do not render well with the form. A custom form, on the other hand, can be easily set up to work with custom CSS.
The second and more popular reason of using a custom registration form is the option of custom fields that are not included on the standard form. A small custom registration form speeds up the process and collects all the necessary data from a neat interface.
function wordpress_custom_registration_form( $first_name, $last_name, $username, $password, $email) {
global $username, $password, $email, $first_name, $last_name;
echo '
<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">
First Name :
<input type="text" name="fname" value="' . ( isset( $_POST['fname']) ? $first_name : null ) . '">
Last Name:
<input type="text" name="lname" value="' . ( isset( $_POST['lname']) ? $last_name : null ) . '">
Username <strong>*</strong>
<input type="text" name="username" value="' . ( isset( $_POST['username'] ) ? $username : null ) . '">
Password <strong>*</strong>
<input type="password" name="password" value="' . ( isset( $_POST['password'] ) ? $password : null ) . '">
Email: <strong>*</strong>
<input type="text" name="email" value="' . ( isset( $_POST['email']) ? $email : null ) . '">
<input type="submit" name="submit" value="Register"/>
</form>
';
}
This form can be inserted anywhere by using the shortcode [wp_registration_form]. Here is the code snippet for setting up the shortcode:
function wp_custom_shortcode_registration() {
ob_start();
wordpress_custom_registration_form_function();
return ob_get_clean();
}
I hope that by now you have a fair idea of creating a WordPress custom Registration form.Still any confusion kindly check Build Custom WordPress Registration Forms

Passing data from DB to update form using CI CRUD

I'm trying to write a compact update controller for CRUD activity. Here is the basic code:
Controller:
function update($id)
{
$this->form_validation->set_rules('name','Name','required');
$this->form_validation->set_rules('age','Age','required|is_numeric');
$this->form_validation->set_rules('country','Country','');
$this->form_validation->set_error_delimiters('<br /><span class="error">', '</span>');
if ($this->form_validation->run() == FALSE) {
//Failed validation or first run
$data = $this->my_model->get_record($id);
$this->load->view('myform_view', $data);
} else {
//Validation success, update DB
}
}
View:
<?php
$attributes = array('class' => '', 'id' => '');
echo form_open('my_form', $attributes); ?>
<p>
<label for="name">Name</label>
<?php echo form_error('name'); ?>
<br /><input id="name" type="text" name="name" value="<?php echo set_value('name'); ?>" />
</p>
<p>
<label for="age">Age</label>
<?php echo form_error('age'); ?>
<br /><input id="age" type="text" name="age" value="<?php echo set_value('age'); ?>" />
</p>
<p>
<label for="country">Country</label>
<?php echo form_error('country'); ?>
<br /><input id="country" type="text" name="country" value="<?php echo set_value('country'); ?>" />
</p>
<p>
<?php echo form_submit( 'submit', 'Submit'); ?>
</p>
<?php echo form_close(); ?>
This is the basic structure, however the first time the form is run there is no validated data. Therefore I have to grab this from the DB. Whats the best way to pass this to the view on the first run? And then once the form has been submitted, if validation fails then I want the failed data to show not to reload from the DB again. Whats the best way to do this?
You should have another method for the viewing aspect. Then submit your form against the "update" method. In there, you define the the form_validation as you have now.
I asked a similar question. See this link
grab the data in update controller first for edit such as
$query = $this->db->where('id',$id)->get('table_name');
$data['edit'] = $query->result_array();
and then check it in view file
value="<?php if(isset($edit[0]['age'])){echo $edit[0]['age'];}else{echo set_value('age');}?>"

form text-input unwanted redirection on click

Please help, I can't understand why the code below keeps bringing me to viewcart.php when I click on the textbox that is used to input qty to buy, I made sure to close all the anchor tags in the page. I even removed all the links to viewcart.php but no luck:
<form name="cx" method="get" action="viewcart.php?action=add&id=<?php $pid; ?>">
<?php
while($row=mysql_fetch_assoc($result)){
$pid=$row['PID'];
?>
<tr>
<td><?php echo $row['PID']; ?></td>
<td> <?php echo $row['PRODUCT']; ?></td>
<td><?php echo $row['CATEGORY']; ?></td>
<td><?php echo $row['P_DESC']; ?></td>
<td><?php echo $row['QTYHAND']; ?></td>
<td><?php echo $row['S_PRICE']; ?></td>
<input type="hidden" value="<?php echo $row['QTYHAND']; ?>" name="qoh[]"/>
<input type="hidden" value="<?php echo $row['S_PRICE']; ?>" name="sprice[]"/>
<?php echo "<td><img src=\"../img/system/add-icon.png\"></td>"; ?>
<td><input type="checkbox" name="sc[]" id="<?php echo $row['PID'];?>" value="<?php echo $row['PID']; ?>"></input></td>
<td><input type="text" name="qbuys[]" value="" id="qb"></input></td> <!--when I click on this, it seems like I'm clicking on a link to viewcart.php -->
</table>
<input type="submit" value="submit"></input>
</form>
I removed some of the code which I don't think is useful in solving this problem. Please help. Thanks.
Your code has two issues. YOu're not echoing the $pid and you have a scoping error.
<form name="cx" method="get" action="viewcart.php?action=add&id=<?php $pid; ?>">
You need to add an echo:
<form name="cx" method="get" action="viewcart.php?action=add&id=<?php echo $pid; ?>">
Also, $pid doesn't exists until you're inside the while loop so you'll always be echoing '':
// $pid == null;
<form name="cx" method="get" action="viewcart.php?action=add&id=<?php $pid; ?>">
<?php
while($row=mysql_fetch_assoc($result)){
$pid=$row['PID']; // NOW $pid has a value
?>
If you view the source of this page you should see:
<form name="cx" method="get" action="viewcart.php?action=add&id=">
Notice the empty id. This would keep sending you back to viewcart.php
You are not echoing your $pid into the form action.
This means that when you submit your form it is not going where you expect.
action="viewcart.php?action=add&id=<?php echo $pid; ?>"
or
action="viewcart.php?action=add&id=<?=$pid?>"
This second examle will only work if your server has short tags enabled.
Rather than looking at the PHP code that generates the page, i would suggest loading the page in your browser, and then clicking "view source". That way you can see exactly what code is being generated, then work back from there to identify which statement is going wrong.
However, I would suggest looking at the following line:
<td> <?php echo $row['PRODUCT']; ?></td>
There is no echo on the 'Product' property.