foreach loop repeating same value - codeigniter

I am getting result from two table in my database. Table one has Project name and table two has sub project names under project name this two table is connected by a id.
Now when I output result using foreach by joining two table it is showing showing project name repeatedly as there are more than one subproject under that repeated project.
I want that the project name will be single and subproject result will loop under the main project name. How to do that?
I amusing codeigniter for development.
my view page:
<?php foreach ($reportlist as $project_item): { ?>
<tr>
<td>
<form method='post' action='update_project'>
<input type='hidden' value='<?php echo ($project_item['pid']); ?>' name='pid'>
<input type='hidden' value='<?php echo $project_item['pp_id']; ?>' name='pp_id'>
<input type="submit" class="linkButton" value="<?php echo $project_item['p_name'] ?>">
</form>
</td>
<td>
<form method='post' action='update_subproject'>
<input type='hidden' value='<?php echo $project_item['pid']; ?>' name='pid'>
<input type='hidden' value='<?php echo $project_item['pp_id']; ?>' name='pp_id'>
<input type="submit" class="linkButton" value="<?php echo $project_item['component_name'] ?>" >
</form>
</td>
<td><?php echo $project_item['coordinating_authority'] ?></td>
<td><?php echo $project_item['start_month'] ?></td>
<td><?php echo $project_item['target_month'] ?></td>
<td><?php echo $project_item['stat_pro'] ?></td>
<td><?php echo $project_item['stat_pro'] ?></td>
<td><?php echo $project_item['remark_pro'] ?></td>
</tr>
<?php } endforeach ?>
</tbody>
My cotroller page:
$this->load->model('projsubproj_add_model');
$data['reportlist'] = $this->projsubproj_add_model->existing_project();
$this->load->view('PAGE-DESIGN/adminheader');
$this->load->view('existing_project_view', $data);
$this->load->view('PAGE-DESIGN/footer');
and my model:
public function existing_project()
{
{
$this->db->select('project_tab.p_name,
pp_project_tab.pp_id AS pp_id,
pp_project_tab.pid AS pid,
pp_project_tab.ppname AS component_name,
pp_project_tab.pp_smonth AS start_month,
pp_project_tab.pp_emonth AS target_month,
pp_project_tab.pp_cordn_reqrd AS coordinating_authority,
pp_project_tab.pps_status AS stat_pro,
pp_project_tab.remarks AS remark_pro');
$this->db->from('project_tab');
$this->db->join('pp_project_tab', 'pp_project_tab.pid =project_tab.pid');
//$this->db->join('pp_status_tab', 'pp_status_tab.pp_id = pp_project_tab.pp_id');
$this->db->order_by('ppname', 'desc');
$query = $this->db->get();
return $query->result_array();
}
$query = $this->db->get_where('project_tab');
return $query->row_array();
}

I got the solution: I just edited my view file for through foreach loop. I made two function to to extract results from two tables and joined them with condition that if the pid of subproject table matches with the pid of subject table, then echo subproject name and its components inside foreach loop of Project loop.
Here is my code:
$projects is for extracting data from project_tab,
$components is for extracting data from pp_project_tab
<?php
foreach ($projects as $project) {
echo $project['p_name'];
foreach ($components as $component) {
if ($project['pid']==$component['pid']) {
echo $component['ppname'] ;
}
}
}
?>

Related

Invalid argument supplied for foreach() codeigniter

i am getting error message: Invalid argument for foreach() in my View. I wanted to display all entries in my mysql table but i kept on getting error message. I am a newbie in Codeigniter and couldn't really figure out how to solve this. The codes are the following... help me please
user_model.php
<?php
foreach ($daftar as $data) :
?>
<tr>
<td><?php echo $data->id_petugas; ?></td>
<td></td>
<td></td>
<td></td>
<td>
<button class="btn edit"><i class="icon-edit"></i></button>
<button class="btn btn-danger remove" data-toggle="confirmation">
<i class="icon-remove"></i></button>
</td>
</tr>
<?php
endforeach;
?>
user_controller
<?php
class User_controller extends CI_Controller{
function __Construct()
{
parent ::__construct();
}
function user(){
$this->load->model('user_model');
$data['daftar'] = $this->user_model->get_user_all();
$this->load->view('daftar_user',$data);
}
daftar_user.php
<?php
foreach ($daftar as $data) :
?>
<tr>
<td><?php echo $data->id_petugas; ?></td>
<td></td>
<td></td>
<td></td>
<td>
<button class="btn edit"><i class="icon-edit"></i></button>
<button class="btn btn-danger remove" data-toggle="confirmation">
<i class="icon-remove"></i></button>
</td>
</tr>
<?php
endforeach;
?>
i've a bug from this file
This is not a proper coding technique you were using. So please correct your model query code first like:
$query = $this->db->from('petugas')->order_by('id_petugas','ASC')->get()->result();
return $query;
No need to change anything else. You will get your all data in view.
I hope this will help you.
function get_user_all()
{
$query=$this->db->query("select * from petugas order by asc");
return $query->result();
$this->db->select('*');
$this->db->from('petugas');
$this->db->order_by('id_petugas','ASC');
$query=$this->db->get();
if($query->num_rows() > 0){
foreach($query->result() as $data){
$daftar[]= $data;
}
return $daftar;
}
}
ok, it worked .. thanks a lot
my login system is ok. It's working.. I have three user type 1.admin 2.customer service 3. waiter.
I need , if login into admin and cs or waiter. its redirect three different view...
I've tried divert the two different views, how should assign more than two views?
<?php if($level == "1"){ ?>
<?php echo $this->view('admin/template'); ?>
<?php } else { ?>
<?php echo $this->view('cs/template'); ?>
<?php } ?>

magento output custom options

Is it possible to output the available list of custom options onto the view.phtml page within Magento? Obviously the drop down lists allow you to filter down but I need to list them in a html table and allow the customer to add to cart on each item.
I will show you how to convert dropdown and multi-select options into table format. This is the code that do the trick.
<?php
$product = Mage::Registry('current_product');
$options = $product->getOptions();
//check for option exists
if($options):
foreach ($options as $option) :
//table format allows only for select options
if($option->getType()== Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN ||
$option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE):
$require = ($option->getIsRequire()) ? ' required-entry' : '';
if($option->getType()== Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN):
$value_name = 'options['.$option->getid().']';
else:
$value_name = 'options['.$option->getid().'][]';
endif;
?>
<table border="1" style="width:500px;margin-bottom:30px">
<thead>
<tr<?php if ($option->getIsRequire()) echo ' class="required"' ?>>
<th><?php echo $option->getTitle() ?></th>
<th><?php if ($option->getIsRequire()) echo '<em>*</em>' ?></th>
</tr>
</thead>
<tbody id="<?php echo 'select_'.$option->getId() ?>" class="<?php echo $require.' product-custom-option' ?>">
<?php
foreach ($option->getValues() as $values) :
$value = $values->getOptionTypeId();
$value_title = $values->getTitle();
?>
<tr>
<td>
<?php
if($option->getType()== Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN):
?>
<input type="radio" name="<?php echo $value_name; ?>" class="radio_option" id="<?php echo 'radio_option_'.$value ?>" value="<?php echo $value; ?>" />
<?php
else:
?>
<input type="checkbox" name="<?php echo $value_name; ?>" class="checkbox_option" id="<?php echo 'checkbox_option_'.$value ?>" value="<?php echo $value; ?>" />
<?php
endif;
?>
</td>
<td><?php echo $value_title; ?></td>
</tr>
<?php
endforeach;
?>
</tbody>
</table>
<?php
endif;
endforeach;
endif;
?>
Here for dropdown options, we are using radio button to show their values. For multiselect options, checkbox inputs are used. So if checkbox appears in the table, that means it a multi select option and hence more than one checkboxes can have tick at a time. Since radio buttons are used for dropdown options, it is important to make sure that, only one radio button is checked at a time. (We need to use javascript for ensure this).
So if we are set some custom options for a product through admin like this..
The output correspond to our code will be look like this
Note: Please note that, the code is in very basic format. You may require additional css and javascripts make it more user frontly. This is for giving you a basic idea and additional css, js are hence out of box topic.
For more information about code, check out my blog
Hope it helps

Opencart can't load Region / State dropdown

I'm using opencart 1.5.5.1 with a theme (sancart) and I'm getting a very annoying bug.
In the modules checkout/cart and account/register the dropdown menu for Region/State field won't load the relative values (i guess are called zone or zone_id) and remains empty, blank.
The same function instead works well in the module checkout/checkout proceeding both as Guest or user registration.
Googleing around I've notice that is a pretty common bug with many themes, above all for those using SSH (that's not my case), but I couldn't find any real solution.
You can see my website at the URL http://i-tec.pro (ID: guest , PW: itec2013)
register.tpl
<?php echo $header; ?>
<?php if ($error_warning) { ?>
<div class="warning"><?php echo $error_warning; ?></div>
<?php } ?>
<?php echo $column_left; ?><?php echo $column_right; ?>
<div id="content"><?php echo $content_top; ?>
<div class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<?php echo $breadcrumb['separator']; ?><?php echo $breadcrumb['text']; ?>
<?php } ?>
</div>
<h1><?php echo $heading_title; ?></h1><div class="padding20">
<p><?php echo $text_account_already; ?></p>
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">
<h2><?php echo $text_your_details; ?></h2>
<div class="content">
<table class="form">
<tr>
<td><span class="required">*</span> <?php echo $entry_firstname; ?></td>
<td><input type="text" name="firstname" value="<?php echo $firstname; ?>" />
<?php if ($error_firstname) { ?>
<span class="error"><?php echo $error_firstname; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_lastname; ?></td>
<td><input type="text" name="lastname" value="<?php echo $lastname; ?>" />
<?php if ($error_lastname) { ?>
<span class="error"><?php echo $error_lastname; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_email; ?></td>
<td><input type="text" name="email" value="<?php echo $email; ?>" />
<?php if ($error_email) { ?>
<span class="error"><?php echo $error_email; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_telephone; ?></td>
<td><input type="text" name="telephone" value="<?php echo $telephone; ?>" />
<?php if ($error_telephone) { ?>
<span class="error"><?php echo $error_telephone; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><?php echo $entry_fax; ?></td>
<td><input type="text" name="fax" value="<?php echo $fax; ?>" /></td>
</tr>
</table>
</div>
<h2><?php echo $text_your_address; ?> </h2>
<div class="content">
<table class="form">
<tr>
<td><?php echo $entry_company; ?></td>
<td><input type="text" name="company" value="<?php echo $company; ?>" /></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_address_1; ?></td>
<td><input type="text" name="address_1" value="<?php echo $address_1; ?>" />
<?php if ($error_address_1) { ?>
<span class="error"><?php echo $error_address_1; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><?php echo $entry_address_2; ?></td>
<td><input type="text" name="address_2" value="<?php echo $address_2; ?>" /></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_city; ?></td>
<td><input type="text" name="city" value="<?php echo $city; ?>" />
<?php if ($error_city) { ?>
<span class="error"><?php echo $error_city; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_postcode; ?></td>
<td><input type="text" name="postcode" value="<?php echo $postcode; ?>" />
<?php if ($error_postcode) { ?>
<span class="error"><?php echo $error_postcode; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_country; ?></td>
<td><select name="country_id" onchange="$('select[name=\'zone_id\']').load('index.php?route=account/register/zone&country_id=' + this.value + '&zone_id=<?php echo $zone_id; ?>');">
<option value=""><?php echo $text_select; ?></option>
<?php foreach ($countries as $country) { ?>
<?php if ($country['country_id'] == $country_id) { ?>
<option value="<?php echo $country['country_id']; ?>" selected="selected"><?php echo $country['name']; ?></option>
<?php } else { ?>
<option value="<?php echo $country['country_id']; ?>"><?php echo $country['name']; ?></option>
<?php } ?>
<?php } ?>
</select>
<?php if ($error_country) { ?>
<span class="error"><?php echo $error_country; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_zone; ?></td>
<td><select name="zone_id">
</select>
<?php if ($error_zone) { ?>
<span class="error"><?php echo $error_zone; ?></span>
<?php } ?></td>
</tr>
</table>
</div>
<h2><?php echo $text_your_password; ?></h2>
<div class="content">
<table class="form">
<tr>
<td><span class="required">*</span> <?php echo $entry_password; ?></td>
<td><input type="password" name="password" value="<?php echo $password; ?>" />
<?php if ($error_password) { ?>
<span class="error"><?php echo $error_password; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_confirm; ?></td>
<td><input type="password" name="confirm" value="<?php echo $confirm; ?>" />
<?php if ($error_confirm) { ?>
<span class="error"><?php echo $error_confirm; ?></span>
<?php } ?></td>
</tr>
</table>
</div>
<h2><?php echo $text_newsletter; ?></h2>
<div class="content">
<table class="form">
<tr>
<td><?php echo $entry_newsletter; ?></td>
<td><?php if ($newsletter == 1) { ?>
<input type="radio" name="newsletter" value="1" checked="checked" />
<?php echo $text_yes; ?>
<input type="radio" name="newsletter" value="0" />
<?php echo $text_no; ?>
<?php } else { ?>
<input type="radio" name="newsletter" value="1" />
<?php echo $text_yes; ?>
<input type="radio" name="newsletter" value="0" checked="checked" />
<?php echo $text_no; ?>
<?php } ?></td>
</tr>
</table>
</div>
<?php if ($text_agree) { ?>
<div class="buttons">
<div class="right"><?php echo $text_agree; ?>
<?php if ($agree) { ?>
<input type="checkbox" name="agree" value="1" checked="checked" />
<?php } else { ?>
<input type="checkbox" name="agree" value="1" />
<?php } ?>
<input type="submit" value="<?php echo $button_continue; ?>" class="button" />
</div>
</div>
<?php } else { ?>
<div class="buttons">
<div class="right">
<input type="submit" value="<?php echo $button_continue; ?>" class="button" />
</div>
</div>
<?php } ?>
</form></div>
<?php echo $content_bottom; ?></div>
<script type="text/javascript"><!--
$('select[name=\'zone_id\']').load('index.php?route=account/register/zone&country_id=<?php echo $country_id; ?>&zone_id=<?php echo $zone_id; ?>');
//--></script>
<script type="text/javascript"><!--
$('.colorbox').colorbox({
width: 560,
height: 560
});
//--></script>
<?php echo $footer; ?>
cart.tpl
<?php echo $header; ?>
<?php if ($attention) { ?>
<div class="attention"><?php echo $attention; ?><img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>
<?php } ?>
<?php if ($success) { ?>
<div class="success"><?php echo $success; ?><img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>
<?php } ?>
<?php if ($error_warning) { ?>
<div class="warning"><?php echo $error_warning; ?><img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>
<?php } ?>
<?php echo $column_left; ?><?php echo $column_right; ?>
<div id="content"><?php echo $content_top; ?>
<div class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<?php echo $breadcrumb['separator']; ?><?php echo $breadcrumb['text']; ?>
<?php } ?>
</div>
<h1><?php echo $heading_title; ?><div class="padding20">
<?php if ($weight) { ?>
(<?php echo $weight; ?>)
<?php } ?>
</h1>
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">
<div class="cart-info">
<table>
<thead>
<tr>
<td class="image"><?php echo $column_image; ?></td>
<td class="name"><?php echo $column_name; ?></td>
<td class="model"><?php echo $column_model; ?></td>
<td class="quantity"><?php echo $column_quantity; ?></td>
<td class="price"><?php echo $column_price; ?></td>
<td class="total"><?php echo $column_total; ?></td>
</tr>
</thead>
<tbody>
<?php foreach ($products as $product) { ?>
<tr>
<td class="image"><?php if ($product['thumb']) { ?>
<img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" />
<?php } ?></td>
<td class="name"><?php echo $product['name']; ?>
<?php if (!$product['stock']) { ?>
<span class="stock">***</span>
<?php } ?>
<div>
<?php foreach ($product['option'] as $option) { ?>
- <small><?php echo $option['name']; ?>: <?php echo $option['value']; ?></small><br />
<?php } ?>
</div>
<?php if ($product['reward']) { ?>
<small><?php echo $product['reward']; ?></small>
<?php } ?></td>
<td class="model"><?php echo $product['model']; ?></td>
<td class="quantity"><input type="text" name="quantity[<?php echo $product['key']; ?>]" value="<?php echo $product['quantity']; ?>" size="1" />
<input type="image" src="catalog/view/theme/default/image/update.png" alt="<?php echo $button_update; ?>" title="<?php echo $button_update; ?>" />
<img src="catalog/view/theme/default/image/remove.png" alt="<?php echo $button_remove; ?>" title="<?php echo $button_remove; ?>" /></td>
<td class="price"><?php echo $product['price']; ?></td>
<td class="total"><?php echo $product['total']; ?></td>
</tr>
<?php } ?>
<?php foreach ($vouchers as $vouchers) { ?>
<tr>
<td class="image"></td>
<td class="name"><?php echo $vouchers['description']; ?></td>
<td class="model"></td>
<td class="quantity"><input type="text" name="" value="1" size="1" disabled="disabled" />
<img src="catalog/view/theme/default/image/remove.png" alt="<?php echo $text_remove; ?>" title="<?php echo $button_remove; ?>" /></td>
<td class="price"><?php echo $vouchers['amount']; ?></td>
<td class="total"><?php echo $vouchers['amount']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</form>
<?php if ($coupon_status || $voucher_status || $reward_status || $shipping_status) { ?>
<h2><?php echo $text_next; ?></h2>
<div class="content">
<p><?php echo $text_next_choice; ?></p>
<table class="radio">
<?php if ($coupon_status) { ?>
<tr class="highlight">
<td><input type="radio" name="next" value="coupon" id="use_coupon" /></td>
<td><label for="use_coupon"><?php echo $text_use_coupon; ?></label></td>
</tr>
<?php } ?>
<?php if ($voucher_status) { ?>
<tr class="highlight">
<td><input type="radio" name="next" value="voucher" id="use_voucher" /></td>
<td><label for="use_voucher"><?php echo $text_use_voucher; ?></label></td>
</tr>
<?php } ?>
<?php if ($reward_status) { ?>
<tr class="highlight">
<td><input type="radio" name="next" value="reward" id="use_reward" /></td>
<td><label for="use_reward"><?php echo $text_use_reward; ?></label></td>
</tr>
<?php } ?>
<?php if ($shipping_status) { ?>
<tr class="highlight">
<td><input type="radio" name="next" value="shipping" id="shipping_estimate" /></td>
<td><label for="shipping_estimate"><?php echo $text_shipping_estimate; ?></label></td>
</tr>
<?php } ?>
</table>
</div>
<div class="cart-module">
<div id="coupon" class="content">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">
<?php echo $entry_coupon; ?>
<input type="text" name="coupon" value="<?php echo $coupon; ?>" />
<input type="hidden" name="next" value="coupon" />
<input type="submit" value="<?php echo $button_coupon; ?>" class="button" />
</form>
</div>
<div id="voucher" class="content">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">
<?php echo $entry_voucher; ?>
<input type="text" name="voucher" value="<?php echo $voucher; ?>" />
<input type="hidden" name="next" value="voucher" />
<input type="submit" value="<?php echo $button_voucher; ?>" class="button" />
</form>
</div>
<div id="reward" class="content">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">
<?php echo $entry_reward; ?>
<input type="text" name="reward" value="<?php echo $reward; ?>" />
<input type="hidden" name="next" value="reward" />
<input type="submit" value="<?php echo $button_reward; ?>" class="button" />
</form>
</div>
<div id="shipping" class="content">
<p><?php echo $text_shipping_detail; ?></p>
<table>
<tr>
<td><span class="required">*</span> <?php echo $entry_country; ?></td>
<td><select name="country_id" onchange="$('select[name=\'zone_id\']').load('index.php?route=checkout/cart/zone&country_id=' + this.value + '&zone_id=<?php echo $zone_id; ?>');">
<option value=""><?php echo $text_select; ?></option>
<?php foreach ($countries as $country) { ?>
<?php if ($country['country_id'] == $country_id) { ?>
<option value="<?php echo $country['country_id']; ?>" selected="selected"><?php echo $country['name']; ?></option>
<?php } else { ?>
<option value="<?php echo $country['country_id']; ?>"><?php echo $country['name']; ?></option>
<?php } ?>
<?php } ?>
</select></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_zone; ?></td>
<td><select name="zone_id">
</select></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_postcode; ?></td>
<td><input type="text" name="postcode" value="<?php echo $postcode; ?>" /></td>
</tr>
</table>
<input type="button" value="<?php echo $button_quote; ?>" id="button-quote" class="button" />
</div>
<?php } ?>
</div>
<div class="cart-total">
<table id="total">
<?php foreach ($totals as $total) { ?>
<tr>
<td colspan="5" class="right"><b><?php echo $total['title']; ?>:</b></td>
<td class="right"><?php echo $total['text']; ?></td>
</tr>
<?php } ?>
</table>
</div>
<div class="buttons">
<div class="right"><?php echo $button_checkout; ?></div>
<div class="center"><?php echo $button_shopping; ?></div>
</div></div>
<?php echo $content_bottom; ?></div>
<script type="text/javascript"><!--
$('input[name=\'next\']').bind('change', function() {
$('.cart-module > div').hide();
$('#' + this.value).show();
});
<?php if ($next == 'coupon') { ?>
$('#use_coupon').trigger('click');
<?php } ?>
<?php if ($next == 'voucher') { ?>
$('#use_voucher').trigger('click');
<?php } ?>
<?php if ($next == 'reward') { ?>
$('#use_reward').trigger('click');
<?php } ?>
<?php if ($next == 'shipping') { ?>
$('#shipping_estimate').trigger('click');
<?php } ?>
//--></script>
<?php if ($shipping_status) { ?>
<script type="text/javascript"><!--
$('#button-quote').live('click', function() {
$.ajax({
url: 'index.php?route=checkout/cart/quote',
type: 'post',
data: 'country_id=' + $('select[name=\'country_id\']').val() + '&zone_id=' + $('select[name=\'zone_id\']').val() + '&postcode=' + encodeURIComponent($('input[name=\'postcode\']').val()),
dataType: 'json',
beforeSend: function() {
$('#button-quote').attr('disabled', true);
$('#button-quote').after('<span class="wait"> <img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('#button-quote').attr('disabled', false);
$('.wait').remove();
},
success: function(json) {
$('.success, .warning, .attention, .error').remove();
if (json['error']) {
if (json['error']['warning']) {
$('#notification').html('<div class="warning" style="display: none;">' + json['error']['warning'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
$('.warning').fadeIn('slow');
$('html, body').animate({ scrollTop: 0 }, 'slow');
}
if (json['error']['country']) {
$('select[name=\'country_id\']').after('<span class="error">' + json['error']['country'] + '</span>');
}
if (json['error']['zone']) {
$('select[name=\'zone_id\']').after('<span class="error">' + json['error']['zone'] + '</span>');
}
if (json['error']['postcode']) {
$('input[name=\'postcode\']').after('<span class="error">' + json['error']['postcode'] + '</span>');
}
}
if (json['shipping_method']) {
html = '<h2><?php echo $text_shipping_method; ?></h2>';
html += '<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">';
html += ' <table class="radio">';
for (i in json['shipping_method']) {
html += '<tr>';
html += ' <td colspan="3"><b>' + json['shipping_method'][i]['title'] + '</b></td>';
html += '</tr>';
if (!json['shipping_method'][i]['error']) {
for (j in json['shipping_method'][i]['quote']) {
html += '<tr class="highlight">';
if (json['shipping_method'][i]['quote'][j]['code'] == '<?php echo $shipping_method; ?>') {
html += '<td><input type="radio" name="shipping_method" value="' + json['shipping_method'][i]['quote'][j]['code'] + '" id="' + json['shipping_method'][i]['quote'][j]['code'] + '" checked="checked" /></td>';
} else {
html += '<td><input type="radio" name="shipping_method" value="' + json['shipping_method'][i]['quote'][j]['code'] + '" id="' + json['shipping_method'][i]['quote'][j]['code'] + '" /></td>';
}
html += ' <td><label for="' + json['shipping_method'][i]['quote'][j]['code'] + '">' + json['shipping_method'][i]['quote'][j]['title'] + '</label></td>';
html += ' <td style="text-align: right;"><label for="' + json['shipping_method'][i]['quote'][j]['code'] + '">' + json['shipping_method'][i]['quote'][j]['text'] + '</label></td>';
html += '</tr>';
}
} else {
html += '<tr>';
html += ' <td colspan="3"><div class="error">' + json['shipping_method'][i]['error'] + '</div></td>';
html += '</tr>';
}
}
html += ' </table>';
html += ' <br />';
html += ' <input type="hidden" name="next" value="shipping" />';
html += ' <input type="submit" value="<?php echo $button_shipping; ?>" class="button" />';
html += '</form>';
$.colorbox({
overlayClose: true,
opacity: 0.5,
width: '600px',
height: '400px',
href: false,
html: html
});
}
}
});
});
//--></script>
<script type="text/javascript"><!--
$('select[name=\'zone_id\']').load('index.php?route=checkout/cart/zone&country_id=<?php echo $country_id; ?>&zone_id=<?php echo $zone_id; ?>');
//--></script>
<?php } ?>
<?php echo $footer; ?>
Thank you in advance!
The problem is in the URL it is trying to load:
http://www.i-tec.pro/index.php?route=account/register/zone&country_id=30
In the controller catalog/controller/account/register.php there is no such an action called zone - therefore the server returns a 404 response and no zones are loaded.
This action is not present in that controller at least from version 1.5.3 (have no access to older versions right now, will check that later) - but You are using the latest OC version.
Probably the theme is not compatible with newer versions of OC - check that with the theme creators...
EDIT: Should You wish to repair the template for Yourself, add this JavaScript code at the end of the register.tpl
$('select[name=\'country_id\']').bind('change', function() {
$.ajax({
url: 'index.php?route=account/register/country&country_id=' + this.value,
dataType: 'json',
beforeSend: function() {
$('select[name=\'country_id\']').after('<span class="wait"> <img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('.wait').remove();
},
success: function(json) {
if (json['postcode_required'] == '1') {
$('#postcode-required').show();
} else {
$('#postcode-required').hide();
}
html = '<option value=""><?php echo $text_select; ?></option>';
if (json['zone'] != '') {
for (i = 0; i < json['zone'].length; i++) {
html += '<option value="' + json['zone'][i]['zone_id'] + '"';
if (json['zone'][i]['zone_id'] == '<?php echo $zone_id; ?>') {
html += ' selected="selected"';
}
html += '>' + json['zone'][i]['name'] + '</option>';
}
} else {
html += '<option value="0" selected="selected"><?php echo $text_none; ?></option>';
}
$('select[name=\'zone_id\']').html(html);
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});
$('select[name=\'country_id\']').trigger('change');
and remove any previous $('select[\'name=country_id\']').change(...); calls.
change the javascript code from catalog/view/theme/YOUR THEME/template/account/register.tpl to this code here
<script type="text/javascript"><!--
$('select[name=\'country_id\']').bind('change', function() {
$.ajax({
url: 'index.php?route=account/register/country&country_id=' + this.value,
dataType: 'json',
beforeSend: function() {
$('select[name=\'country_id\']').after('<span class="wait"> <img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('.wait').remove();
},
success: function(json) {
if (json['postcode_required'] == '1') {
$('#postcode-required').show();
} else {
$('#postcode-required').hide();
}
html = '<option value=""><?php echo $text_select; ?></option>';
if (json['zone'] != '') {
for (i = 0; i < json['zone'].length; i++) {
html += '<option value="' + json['zone'][i]['zone_id'] + '"';
if (json['zone'][i]['zone_id'] == '<?php echo $zone_id; ?>') {
html += ' selected="selected"';
}
html += '>' + json['zone'][i]['name'] + '</option>';
}
} else {
html += '<option value="0" selected="selected"><?php echo $text_none; ?></option>';
}
$('select[name=\'zone_id\']').html(html);
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});
$('select[name=\'country_id\']').trigger('change');
//--></script>

Fetch the entered quantity box values from multiple quantity box to cart page in magento

I am new to Magento.
I am displaying the attributes in table format using foreach in product detail page.
Problem i am facing is when i enter the value in any quantity box, it takes the last quantity value to the cart page since i am using foreach loop to display the quantity box.I need to display the exact value which i have entered in the quantity box.
Code:
<table border="1" style="width:100%;">
<thead>
<tr>
<th>Fabric</th>
<th>Color</th>
<th>Required Qty</th>
<th>Total Cost</th>
<th>Cart</th>
</tr>
</thead>
<?php
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'fabric');
$buttonTitle = $this->__('Add to Cart');
$i=0;foreach ( $attribute->getSource()->getAllOptions(true, true) as $option){
$i++;
if($i==1) continue;
?>
<tbody>
<tr>
<td>
<?php echo $attributeArray[$option['value']] = $option['label'];
?>
</td>
<td>
<select name="color" id="color">
<option>Select Color</option>
<?php
$color = Mage::getModel('eav/config')->getAttribute('catalog_product', 'fabric_color');
$j=0;foreach ( $color->getSource()->getAllOptions(true, true) as $option_color){
$j++;
if($j==1) continue;?>
<option value="<?php echo $option_color['value'];?>" price="<?php echo $option_color['price'];?>"><?php echo $option_color['label'];?></option>
<? }
?>
</select>
</td>
<td>
<?php if($_product->isSaleable()): ?>
<div class="add-to-cart">
<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<div class="qty_pan">
<input type="text" name="qty" id="qty<?=$i;?>" maxlength="12" value="1" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
</div>
<?php endif; ?>
</div>
<?php endif; ?>
</td>
<td ><span class="qty<?=$i;?>" id=""><?php echo $_product->getPrice();?></span></td>
<td>
<button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
<!-- <span id='ajax_loader' style='display:none'><img src='<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif')?>'/></span>-->
<?php //echo $this->getChildHtml('', true, true) ?>
</td>
</tr>
</tbody>
<?php }?>
</table>
Screenshot:
https://imageshack.us/scaled/large/12/detailpage.png
Any help is appreciated!.
I Got The solution.
We can use Query String to fetch the quantity values to cart.
Yourdomain.com/checkout/cart/add?product=getId();?>&qty=1
You can use the above querystring in href.
Hope this Helps.

JToolbar frontend submit value on click

I'm building a joomla component and I can't find a solution to the following. In my front end I'm using the joomlas build in class JToolbar to handle events on click like edit, delete so one.
<form action="<?php echo JRoute::_('index.php');?>" method="post"
name="termForm" id="adminForm">
<table class="stripeMe">
<tbody>
<thead>
<tr>
<th>Begriff</th>
<th>Definition</th>
<?php if ($user->authorize('com_glossary', 'edit', 'glossary', 'all')): ?><th>Published</th> <?php endif; ?>
</tr>
</thead>
<?php foreach($this->items as $i => $item): ?>
<tr>
<td>
<span class="title"><?php echo $item->tterm; ?></span>
<?php if ($user->authorize('com_glossary', 'edit', 'bearbeiten', 'all')):?>
<?php echo $this->getEdit(); ?><?php endif; ?>
</td>
<td><?php echo $item->tdefinition; ?></td>
<?php if ($user->authorize('com_glossary', 'edit', 'bearbeiten', 'all')): ?>
<td><?php echo $this->getPublished(); ?></td> <?php endif; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div>
<input type="hidden" name="task" value="" /> <input type="hidden"
name="id" value="" onclick="submitbutton(<?php echo count( $item->id ); ?>);" /> <input type="hidden"
name="option" value="com_glossary" /> <input type="hidden"
name="controller" value="bearbeiten" />
<?php echo JHtml::_('form.token'); ?>
</div>
</form>
I would like to pass to id of the selected row to the sub-controller on button event and I don't really know how to do it
Here you have some useful tips about using JToolbar on the frontend http://docs.joomla.org/How_to_use_the_JToolBar_class_in_the_frontend
I have done it once in the past, and from what I remember I did some tricks in order to make it work.
1.) Firstly remove the "id" input and add the following one at the end of your form:
<input type="hidden" name="boxchecked" value="0" />
2.) Secondly make sure Mootools is attached to the source
3.) Finally: There, where you started your foreach loop, after "tr" tag add another table column:
<td><?php echo JHTML::_('grid.id', $i, $item->id ); ?></td>
Don't forget to create a column heading in thead for this column.
These steps will create a checkbox in the first cell of every row and make the form able to send selected field's id with request.
edit:
tbody tag is in wrong place, it's supposed to be after thead tag. Also there is no use of attaching events to hidden input as they won't be triggered
Cheers
Peter

Resources