Magento : Tier price custom field - magento

I have modified magento extension for tier pricing and added three text fields in app->design->adminhtml->default->default->catalog->product->edit->price->tier.phtml file.
Data from three new field successfully inserted into table catalog_product_entity_tier_price.
Data is also visible on frontend. But problem is that in tier box price inserted data and field mismatched
<table>
<thead>
<tr class="headings">
<th>Website</th>
<th>Customer Group</th>
<th>Qty</th>
<th>Custom_field_1</th>
<th>Custom_field_2</th>
<th>Price</th>
<th>Custom_field_3</th>
<th>Action</th>
</thead>
</tr>
<tr>
<td>Showing Correct</td>
<td>Showing Correct</td>
<td>Showing Correct</td>
<td>Showing Custom_field_2</td>
<td>Showing Custom_field_3</td>
<td>Showing Correct</td>
<td>undefined</td>
<td> </td>
</tr>
</table>
<p> </p>
<p> </p>
<b>And javascript code is</b>
<script type="text/javascript">
var tierPriceRowTemplate = '<tr>'
+ ' <small class="nobr"><?php echo Mage::helper("catalog")->__("and above")?></small></td>'
+ '<td><input class="<?php echo $_htmlClass ?> Custom_field_1" type="text" name="<?php echo $_htmlName ?>[{{index}}][Custom_field_1]" value="{{Custom_field_1}}"
id="tier_price_row_{{index}}_Custom_field_1" /></td>'
+ '<td><input class="<?php echo $_htmlClass ?> Custom_field_2" type="text" name="<?php echo $_htmlName ?>[{{index}}][Custom_field_2]" value="{{Custom_field_2}}" id="tier_price_row_{{index}}_Custom_field_2" /></td>'
+ '<td><input class="<?php echo $_htmlClass ?> required-entry <?php echo $_priceValueValidation ?>" type="text" name="<?php echo $_htmlName ?>[{{index}}][price]" value="{{price}}" id="tier_price_row_{{index}}_price" /></td>'
+ '<td><input class="<?php echo $_htmlClass ?> Custom_field_3" type="text" name="<?php echo $_htmlName ?>[{{index}}][Custom_field_3]" value="{{Custom_field_3}}" id="tier_price_row_{{index}}_Custom_field_3"/></td>';
var data = {
website_id: '<?php echo $this->getDefaultWebsite() ?>',
group: '<?php echo $this->getDefaultCustomerGroup() ?>',
qty: '',
Custom_field_1:'',
price: '',
Custom_field_2:'',
Custom_field_3:'',
readOnly: false,
index: this.itemsCount++
};
//alert(Custom_field_1);
if(arguments.length >= 4) {
data.Custom_field_1 = arguments[4]
data.readOnly = arguments[5];
data.Custom_field_2 = arguments[7];
data.Custom_field_3 = arguments[8];
}
if (arguments.length == 5) {
data.readOnly = arguments[4];
}
$('tier_price_row_' + data.index + '_Custom_field_1').value = data.Custom_field_1;
$('tier_price_row_' + data.index + '_Custom_field_2').value = data.Custom_field_2;
$('tier_price_row_' + data.index + '_Custom_field_3').value = data.Custom_field_3;
</script>

Problem Solved: Problem was in jquery code.
Please check my edited code
if(arguments.length >=8) {
data.website_id = arguments[0];
data.group = arguments[1];
data.qty = arguments[2];
data.product_type = arguments[3]
data.ourprice = arguments[4];
data.price = arguments[5];
data.links = arguments[6];
data.readOnly = arguments[7];
}
if (arguments.length == 9) {
data.readOnly = arguments[8];
}
Element.insert($('<?php echo $_htmlId ?>_container'), {
bottom : this.template.evaluate(data)
});
$('tier_price_row_' + data.index + '_cust_group').value = data.group;
$('tier_price_row_' + data.index + '_website').value = data.website_id;

Related

Fetch corresponding value of a drop downlist

I want to fetch the corresponding value of my dropdown the image below shows the form and the database. the table was inside the javascript and Iam having a dificult time in figuring out this problem. please help me how to solve this problem... Thank you very much in advance...
Database
forms entry
My Controller
function getFeetypeEndDate() {
$feetype_id = $this->input->get('feety_id[]');
$data = $this->feegroup_model->getFeetypeByEndDate($feetype_id);
echo json_encode($data);
}
My Model
public function get($id = null) {
$this->db->select()->from('feetype');
$this->db->where('is_system', 0);
if ($id != null) {
$this->db->where('id', $id);
} else {
$this->db->order_by('id');
}
$query = $this->db->get();
if ($id != null) {
return $query->row_array();
} else {
return $query->result_array();
}
}
My Javascript in the View Section
<script>
$(document).ready(function (){
$("body").on('click', '.btn-add-more', function (e) {
e.preventDefault();
var amount = $("#amount").val();
var penalty = $("#penalty").val();
var $sr = ($(".jdr1").length + 1);
var rowid = Math.random();
var $html = '<tr class="jdr1" id="' + rowid + '">' +
'<td><span class="btn btn-sm btn-default">' + $sr + '</span><input type="hidden" name="count[]" value="'+Math.floor((Math.random() * 10000) + 1)+'"></td>' +
'<td><select id="feetype_id[]" name="feetype_id[]" class="form-control" >' +
'<?php foreach ($feetypeList as $feetype) { ?>' +
' <option value="<?php echo $feetype['id'] ?>" ' +
'<?php if (set_value('feetype_id[]') == $feetype['id']) { echo "selected =selected"; } ?>><?php echo $feetype['type'] ?></option> <?php $count++; } ?> </select></td>' +
'<td><input type="text" id="startDate" name="startDate" value="<?php echo date($this->customlib->getSchoolDateFormat($feetype->start_date), $this->customlib->dateyyyymmddTodateformat($feetype->start_date)); ?>" placeholder="Start Date" class="form-control input-sm"/></td>' +
'<td><input type="text" id="endDate" name="endDate" value="<?php echo date($this->customlib->getSchoolDateFormat($feetype->end_date), $this->customlib->dateyyyymmddTodateformat($feetype->end_date)); ?>" placeholder="End Date" class="form-control input-sm"/></td>' +
'<td><input type="text" name="amount_td[]" placeholder="Amount" class="form-control input-sm" value="'+amount+'"></td>' +
'<td><input type="text" name="penalty_td" placeholder="Penalty" class="form-control input-sm" value="'+penalty+'"></td>' +
'</tr>';
$("#table-details").append($html);
});
$("body").on('click', '.btn-remove-detail-row', function (e) {
e.preventDefault();
if($("#table-details tr:last-child").attr('id') != 'row1'){
$("#table-details tr:last-child").remove();
}
});
});

Mulitple row insert into db in codeigniter

ajax change function execute listByBatch() and show the table with data by batch which is post by ajax. And then I trying to insert table rows by insertAttendance, code below:
Jquery post:
$("#batch-list").change(function(){
/*dropdown post */
$.ajax({
url:"<?php echo base_url(); ?>index.php/attendance/list_ByBatch",
data: {batchid: $(this).val()},
type: "POST",
dataType:'json',
success: function(data){
$("#traineeList").html(data);
$("#subTotal").html("Total: " + $('#traineeList tr').length.toString());
document.getElementById("classHour").defaultValue = "4";
}
});
});
Controller:
public function list_ByBatch() {
$batch = $this->input->post('batchid', TRUE);
$data['trainee']= $this->AttendanceModel->get_traineeList($batch);
if (!empty($data['trainee'])) {
echo form_open('attendance/insertAttendance');
echo"<table class='table table-hover type-list2'id='traineeList'>
<tr class='success'>
<th>Trainee ID</th>
<th>Trainee Name</th>
<th>Present</th>
</tr>";
foreach ($data['trainee'] as $row) {
echo "
<tr><td>" . str_pad($row->TraineeID, 7, "0", STR_PAD_LEFT) . "</td>
<td>" . $row->Name . "</td>
<td><input type='checkbox' name='.$row->TraineeID[]' value='" . $row->TraineeID . "' checked></td>
</tr>";
}
echo"</table>";
echo"
<div class='row'>
<div class='form-group col-sm-2'>
<h5 id='subTotal'></h5>
</div>
<div class='form-group col-sm-6'>
<input type='date' class='form-control' name='attnDate' id='attnDate' placeholder='Attendance Date' required>
</div>
<div class='form-group col-sm-2'>
<input type='number ' class='form-control' name='classHour' id='classHour' placeholder='Class Hour' required>
</div>
<div class='form-group col-sm-2'>
<input type='submit' class='btn btn-default btn-success' name='record' value='Record'>
</div>
</div>";
echo "</form>";
}
}
public function insertAttendance() {
$TID ['TID']= $this->input->post('trainee');
$attnDate = $this->input->post('attnDate');
$classHour = $this->input->post('classHour');
echo '<pre>';
print_r($TID);
if(is_array($TID)){
foreach ($TID as $TID=>$key) {
$query = "INSERT INTO `tbl_attn_temp` (TraineeID, Date, classHour) VALUES ('" . $key . "','" . $attnDate . "','" . $classHour . "')";
$this->db->query($query);
}
}else{
echo "Trainee ID is not array";
}
}
I just trying to insert all rows (TraineeID) shows in table with "attnDate" and 'classHour" by clicking submit button.

Updating one data on datagrid using checkbox codeigniter

i have some issue when i updating every single or one data using checkbox. i want to do is to update only the selected checkbox updated. How do I stop the foreach from running if a checkbox has not been checked.
this is my model
function save_cargo_details() {
$data = array();
$waybillno = $this->input->post('waybillno');
$quantity = $this->input->post('quantity');
$waybilldate = $this->input->post('waybilldate');
$declared_value = $this->input->post('declared_value');
$consignee = $this->input->post('consignee');
$count = count($waybillno);
if(empty($waybillno)){
}else{
for ($i = 0; $i < $count; $i++) {
$data = array(
'waybillno' => $waybillno[$i],
'quantity' => $quantity[$i],
'waybilldate' => $waybilldate[$i],
'declared_value' => $declared_value[$i],
'consignee' => $consignee[$i],
);
// SUBRACT REMAINING_QUANTITY //
$this->db->select('wd.remaining_qty');
$this->db->where('wd.waybillno',$waybillno[$i]);
$this->db->from(self::WAYBILL_DETAILS_TABLE. " as wd");
$query = $this->db->get()->row();
$qty = $query->remaining_qty;
$remaining = abs($data['quantity'] - $qty);
$this->db->where('waybillno',$waybillno[$i]);
$this->db->set('remaining_qty',$remaining);
$this->db->update(self::WAYBILL_DETAILS_TABLE);
// INSERT DATA //
$this->db->insert('sys_cargodetails', $data);
$this->session->set_flashdata('success', '<p id="success_message">Record has been successfully saved.</p>');
}
}
}
this is my controller
public function create_cargo_manifest(){
$core_model = new Core_m;
$core_model->save_cargo_details();
redirect('core/cargo_lookup/');
}
this is my view
<?php foreach($waybill_header as $waybill_header) { ?>
<?php echo form_open('core/create_cargo_manifest'); ?>
<tr style="text-align: center;">
<td><input type="checkbox" name="waybillno[]" value="<?php echo $waybill_header->waybillno; ?>"></td>
<td><?php echo $waybill_header->waybillno; ?></td>
<td><?php echo $waybill_header->waybilldate; ?><input type="hidden" value="<?php echo $waybill_header->waybilldate; ?>" name="waybilldate[]"></td>
<td><input type="text" size="5" value="<?php echo $waybill_header->remaining_qty; ?>" name="quantity[]">
<input type="hidden" value="<?php echo $waybill_header->declared_value; ?>" name="declared_value[]">
<input type="hidden" value="<?php echo $waybill_header->consignee; ?>" name="consignee[]">
</td>
</tr>
<?php } ?>
You can give an extra field in the database for the checkbox.If the check box is checked it takes 1 as the value and if unchecked 0 as the value.Give the default value as per your requirement.If you want every checkbox to be checked give 1 as default else otherwise.Then you will just need to put a condition before foreach loop,i.e. if value of checkbox is 1 run the foreach loop else not.

model to fetch single result from db with jquery

I have a controller function which is called by jquery:
function get_sku_prices(){
$this->load->model('Sales_model');
if (isset($_GET['term'])){
$q = strtolower($_GET['term']);
$this->Sales_model->get_sku_price($q);
}
}
The model, get_sku_price is:
function get_sku_price($q){
$this->db->select('price');
$this->db->where('sku', $q);
$query = $this->db->get('products');
if($query->num_rows > 0){
foreach ($query->result_array() as $row){
$row_set[] = htmlentities(stripslashes($row['price'])); //build an array
}
$this->output->set_content_type('application/json')->set_output(json_encode($row_set));
}
}
what I want, is to return the result of the above query(which is essentially select price from products where sku=36113) to the input variable 'price' on my view form.
My view syntax is:
<html>
<head>
<title>
Capture blank Order
</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<link rel="stylesheet" href="<?php echo base_url() ?>css/sales.css" />
<script type="text/javascript">
function callAutocomplete(element)
{
$(element).autocomplete(
{
source: "sales/get_sku_codes",
messages:
{
noResults: '',
results: function() {}
},
select: function( event, ui )
{
var selectedObj = ui.item;
$.post('sales/get_sku_prices', {data:selectedObj.value},function(result) {
$(ui).parent('tr').find('input[id^="pricepercube"]').val(result);
});
}
});
}
$(function()
{
var counter = 1;
jQuery("table.authors-list").on('change','input[name^="qty"]',function(event)
{
event.preventDefault();
counter++;
var newRow = jQuery('<tr>'+
' <td><a class="deleteRow"> x </a></td>' +
' <td><input type="text" id="product' + counter + '" name="product' + counter + '" /></td>' +
' <td><input type="text" id="qty' + counter + '" name="qty' + counter + '" /></td>'+
' <td><input type="text" id="price' + counter + '" name="price' + counter + '" /></td>'+
' <td><input type="text" id="discount' + counter + '" name="discount' + counter + '" /></td>'+
' <td valign=top><input type="checkbox" id="treated' + counter + '" name="treated' + counter + '" /></td>'+
' </tr>');
jQuery('table.authors-list').append(newRow);
callAutocomplete("#product"+ counter);
});
$("#product").autocomplete(
{
source: "sales/get_sku_codes",
messages:
{
noResults: '',
results: function() {}
},
select: function( event, ui )
{
var selectedObj = ui.item;
$.post('<?=site_url("sales/get_sku_prices")?>', {data:selectedObj.value},function(result)
{
$("#price").val(result);
});
}
});
});
</script>
</head>
<body>
<table class="authors-list" border=0>
<tr><td></td><td>Product</td><td>Qty</td><td>Price/Cube</td><td>Discount</td><td>treated</td></tr>
<tr>
<td><a class="deleteRow"> x </a></td>
<td><input type="text" id="product" name="product" /></td>
<td><input type="text" id="qty" name="qty" /></td>
<td><input type="text" id="price" name="price" /></td>
<td><input type="text" id="discount" name="discount" /></td>
<td valign="top" ><input type="checkbox" id="treated" name="treated" /></td>
</tr>
</table>
</body>
</html>
Firefox returns a 200 OK message. you can see the post information contains the contents of the product input, but the returned HTML is blank?
UPDATE
mysql
post
blank html
is my model query correct? is the post being correctly passed tot he model? how can I verify this?
Thanks again.
You are passing data inside $.post and getting it as term.
Change
if (isset($_GET['term'])){
to
if (isset($_POST['data'])){
You should be outputing your data from the controller, not the model.
Controller:
function get_sku_prices(){
$this->load->model('Sales_model');
if (isset($_GET['term'])){
$q = strtolower($_GET['term']);
$data = $this->Sales_model->get_sku_price($q);
$this->output->set_content_type('application/json')->set_output(json_encode(data));
}
}
Model:
function get_sku_price($q){
$this->db->select('price');
$this->db->where('sku', $q);
$query = $this->db->get('products');
if($query->num_rows > 0){
foreach ($query->result_array() as $row){
$row_set[] = htmlentities(stripslashes($row['price'])); //build an array
}
return $row_set;
}
}
Further to the above, you are passing your data via AJAX as POST data, yet in your controller you are trying to receive data from the GET array.

Joomla plugin database mistakes? What is wrong here?

i've just started learning Jplugin development, so here i made a little voting script. Everything here works fine, but i want conf.php file to be made in joomla framework style. As you see here, 1 and 2 files works perfectly together. I want to use third example instead of second, in which i use simple php code. The last example i tried to do is using joomla framework, but it doesnt work. I have no idea what's wrong with that code. Anyone see could tell where I made a mistake or maybe far away from doing it right ?
<?php
defined( '_JEXEC' ) or die;
?>
<?php
class plgSystemRatingx extends JPlugin
{
public function onContentBeforeDisplay()
{
?>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$(".like").click(function()
{
var id=$(this).attr("id");
var name=$(this).attr("name");
var dataString = 'id='+ id + '&name='+ name;
$("#votebox").slideDown("slow");
$("#flash").fadeIn("slow");
$.ajax
({
type: "POST",
url: "conf.php",
data: dataString,
cache: false,
success: function(html)
{
$("#flash").fadeOut("slow");
$("#content").html(html);
}
});
});
$(".close").click(function()
{
$("#votebox").slideUp("slow");
});
});
</script>
<body>
<div style="margin:50px">
Like -- Dislike
<div id="votebox">
<span id='close'>X</span>
<div style="height:13px">
<div id="flash">Loading........</div>
</div>
<div id="content">
</div>
</div>
</div>
<?php
return true;
}
}
this piece of code works perfectly
<?php
$mysql_hostname = "localhost";
$mysql_user = "px";
$mysql_password = "px";
$mysql_database = "jum";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password)
or die("Opps some thing went wrong");
mysql_select_db($mysql_database, $bd) or die("Opps some thing went wrong");
if($_POST['id'])
{
$id=mysql_real_escape_string($_POST['id']);
$name=mysql_real_escape_string($_POST['name']);
mysql_query("update messages set $name=$name+1 where id='$id'");
$result=mysql_query("select up,down from messages where id='$id'");
$row=mysql_fetch_array($result);
$up_value=$row['up'];
$down_value=$row['down'];
$total=$up_value+$down_value;
$up_per=($up_value*100)/$total;
$down_per=($down_value*100)/$total;
?>
<div style="margin-bottom:10px">
<b>Ratings for this blog</b> ( <?php echo $total; ?> total)
</div>
<table width="700px">
<tr>
<td width="30px"></td>
<td width="60px"><?php echo $up_value; ?></td>
<td width="600px"><div id="greebar" style="width:<?php echo $up_per; ?>%"></div></td>
</tr>
<tr>
<td width="30px"></td>
<td width="60px"><?php echo $down_value; ?></td>
<td width="600px"><div id="redbar" style="width:<?php echo $down_per; ?>%"></div></td>
</tr>
</table>
<?php
}
?>
and this made in joomla style doesnt work at all
<?php
defined( '_JEXEC' ) or die;
?>
<?php
if(JRequest::getVar('id'))
{
$id = JRequest::getInt('id');
$name = JRequest::getInt('name');
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query2 = $db->getQuery(true);
$queryup = $db->getQuery(true);
$querydown = $db->getQuery(true);
$query->update('messages');
$query->set("message = 1");
$query->where("id = $id");
$query2->select('up,down');
$query2->from('messages');
$query2->where("id = $id");
$queryup->select('up');
$queryup->from('messages');
$queryup->where("id = $id");
$querydown->select('down');
$querydown->from('messages');
$querydown->where("id = $id");
$db->setQuery( $query );
$db->query();
$db->setQuery( $query2 );
$db->query();
$db->setQuery( $queryup );
$data0 = $db->query();
$db->setQuery( $querydown );
$data1 = $db->query();
$up_value= $db->insertid($data0);;
$down_value = $db->insertid($data1);
$total=$up_value+$down_value;
$up_per=($up_value*100)/$total;
$down_per=($down_value*100)/$total;
?>
<table width="700px">
<tr>
<td width="30px"></td>
<td width="60px"><?php echo $up_value; ?></td>
<td width="600px"><div id="greebar" style="width:<?php echo $up_per; ?>%"></div></td>
</tr>
<tr>
<td width="30px"></td>
<td width="60px"><?php echo $down_value; ?></td>
<td width="600px"><div id="redbar" style="width:<?php echo $down_per; ?>%"></div></td>
</tr>
</table>
<?php
}
Try this
$query->where('id = ' . $db->qn($id));
etc

Resources