Opencart registration page State/region dropdown doesn't load - themes
I'm using opencart 1.5.1 with the theme crista_blue which according to their website is compatible with opencart 1.5.1.
A very similar question was asked here: -SOLVED- Opencart can't load Region / State dropdown but the answer there says "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."
My enroll.php file does have a zone action in it. Which makes me think the problem is of a different nature.
Two other people built this site and are no longer around to maintain it. It seems at first they used the default register.tpl/register.php for the account creation but then decided to change the welcome page where the "register" link takes you to enroll.php/enroll.tpl.
This is the website https://www.mybaysix.com/. If you click the Register link at the bottom you are brought to a form where the Region / State dropdown appears but is empty. If you hit continue the page displays the error messages for the required fields, and the Region / State dropdown box is now loaded with options.
Here is the enroll.tpl file:
<?php echo $header; ?><?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>
<?php if ($error_warning) { ?>
<div class="warning"><?php echo $error_warning; ?></div>
<?php } ?>
<p><?php echo $text_buyer_information; ?></p>
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="register">
<!-- Company info -->
<h2><?php echo $text_your_address; ?> </h2>
<div class="content">
<table class="form">
<tr>
<td><span class="required">*</span> <?php echo $entry_company; ?></td>
<td><input type="text" name="company" value="<?php echo $company; ?>" />
<?php if ($error_company) { ?>
<span class="error"><?php echo $error_company; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_federal_tax; ?></td>
<td><input type="text" name="federal_tax" value="<?php echo $federal_tax; ?>" />
<?php if ($error_federal_tax) { ?>
<span class="error"><?php echo $error_federal_tax; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_dba; ?></td>
<td><input type="text" name="dba" value="<?php echo $dba; ?>" />
<?php if ($error_dba) { ?>
<span class="error"><?php echo $error_dba; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_state_resale; ?></td>
<td><input type="text" name="state_resale" value="<?php echo $state_resale; ?>" />
<?php if ($error_state_resale) { ?>
<span class="error"><?php echo $error_state_resale; ?></span>
<?php } ?></td>
</tr>
<tr>
<td> <?php echo $entry_store_website; ?></td>
<td><input type="text" name="store_website" value="<?php echo $store_website; ?>" /></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_buyer_information; ?></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_owner_information; ?></h2>
<div class="content">
<table class="form">
<tr>
<td><?php echo $entry_owner_fname; ?></td>
<td><input type="text" name="owner_fname" value="<?php echo $owner_fname; ?>" /></td>
</tr>
<tr>
<td><?php echo $entry_owner_lname; ?></td>
<td><input type="text" name="owner_lname" value="<?php echo $owner_lname; ?>" /></td>
</tr>
<tr>
<td><?php echo $entry_owner_phone; ?></td>
<td><input type="text" name="owner_phone" value="<?php echo $owner_phone; ?>" /></td>
</tr>
<tr>
<td><?php echo $entry_owner_fax; ?></td>
<td><input type="text" name="owner_fax" value="<?php echo $owner_fax; ?>" /></td>
</tr>
<tr>
<td><?php echo $entry_owner_email; ?></td>
<td><input type="text" name="owner_email" value="<?php echo $owner_email; ?>" /></td>
</tr>
</table>
</div>
<h2><?php echo $text_manager_information; ?></h2>
<div class="content">
<table class="form">
<tr>
<td><?php echo $entry_manager_fname; ?></td>
<td><input type="text" name="manager_fname" value="<?php echo $manager_fname; ?>" /></td>
</tr>
<tr>
<td><?php echo $entry_manager_lname; ?></td>
<td><input type="text" name="manager_lname" value="<?php echo $manager_lname; ?>" /></td>
</tr>
<tr>
<td><?php echo $entry_manager_phone; ?></td>
<td><input type="text" name="manager_phone" value="<?php echo $manager_phone; ?>" /></td>
</tr>
<tr>
<td><?php echo $entry_manager_fax; ?></td>
<td><input type="text" name="manager_fax" value="<?php echo $manager_fax; ?>" /></td>
</tr>
<tr>
<td><?php echo $entry_manager_email; ?></td>
<td><input type="text" name="manager_email" value="<?php echo $manager_email; ?>" /></td>
</tr>
</table>
</div>
<h2><?php echo $text_other_information; ?></h2>
<div class="content">
<table class="form">
<tr>
<td><?php echo $entry_other_fname; ?></td>
<td><input type="text" name="other_fname" value="<?php echo $other_fname; ?>" /></td>
</tr>
<tr>
<td><?php echo $entry_other_lname; ?></td>
<td><input type="text" name="other_lname" value="<?php echo $other_lname; ?>" /></td>
</tr>
<tr>
<td><?php echo $entry_other_phone; ?></td>
<td><input type="text" name="other_phone" value="<?php echo $other_phone; ?>" /></td>
</tr>
<tr>
<td><?php echo $entry_other_fax; ?></td>
<td><input type="text" name="other_fax" value="<?php echo $other_fax; ?>" /></td>
</tr>
<tr>
<td><?php echo $entry_other_email; ?></td>
<td><input type="text" name="other_email" value="<?php echo $other_email; ?>" /></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 } ?>
<a onclick="$('#register').submit();" class="button"><span><?php echo $button_continue; ?></span></a></div>
</div>
<?php } else { ?>
<div class="buttons">
<div class="right"><a onclick="$('#register').submit();" class="button"><span><?php echo $button_continue; ?></span></a></div>
</div>
<?php } ?>
</form>
<?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"><!--
$('.fancybox').fancybox({
width: 560,
height: 560,
autoDimensions: false
});
//--></script>
<?php echo $footer; ?>
This is the zone function at the bottom of enroll.php:
public function zone() {
$output = '<option value="">' . $this->language->get('text_select') . '</option>';
$this->load->model('localisation/zone');
$results = $this->model_localisation_zone->getZonesByCountryId($this->request->get['country_id']);
foreach ($results as $result) {
$output .= '<option value="' . $result['zone_id'] . '"';
if (isset($this->request->get['zone_id']) && ($this->request->get['zone_id'] == $result['zone_id'])) {
$output .= ' selected="selected"';
}
$output .= '>' . $result['name'] . '</option>';
}
if (!$results) {
$output .= '<option value="0">' . $this->language->get('text_none') . '</option>';
}
$this->response->setOutput($output);
}
I've never used opencart before so if there is any more information that would help figure out the problem just ask.
EDIT: I attempted shadyyx's first answer below and this was the result.
I changed the .load to ('index.php?route=account/enroll/zone&country_id=<?php echo $country_id; ?>&zone_id=<?php echo $zone_id; ?>');
I also tried with the full path /catalog/controller/account/enroll/. The dropdown still didn't populate. When I hit continue with nothing filled out an error appears at the top Notice: Undefined index: zone_id in /home/mybaysix/public_html/catalog/controller/account/enroll.php on line 551
Line 551 of enroll.php is if ($this->request->post['zone_id'] == '') { $this->error['zone'] = $this->language->get('error_zone'); }
First, welcome to Stack OverFlow!
Your enroll.php maybe does have the zone() function, but in Your HTML's JavaScript, You are calling:
<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>
Thus You are trying to load /catalog/controller/account/register.php::zone()...
Instead You should be calling:
<script type="text/javascript"><!--
$('select[name=\'zone_id\']').load('index.php?route=<DIRECTORY>/enroll/zone&country_id=<?php echo $country_id; ?>&zone_id=<?php echo $zone_id; ?>');
//--></script>
Switch the <DIRECTORY> value with the correct one...
EDIT:
use only account/enroll/zone, not the full path
change the condition on that line 551 from
if ($this->request->post['zone_id'] == '')
to
if ($this->request->get['zone_id'] == '') (mind switching from post -> get).
EDIT 2:
I guess the dev team messed many things up when reimplementing the registration form... The $('#register').submit(); is OK as Your <form ...> has id="register". Try again this change: from
if ($this->request->get['zone_id'] == '')
to
if (isset($this->request->get['zone_id'] == ''))
Now the Notice: Undefined index: zone_id error shouldn't occur.
Related
how to parse field value without parsing record id with codeigniter
In my database one project has many tasks. I was able to give the edit option for each record by parsing the record id when the update button is clicked. But as one project has many task now I need to parse the projectname when the button clicked and show all the tasks related to that project. Can Somebody help me? This is the button with record This is the code <table class="table table-lg"> <thead > <tr class="filters"> <th class="col-lg-1"><input type="text" class="form-control" placeholder="Project" disabled></th> <th class="col-lg-1"><input type="text" class="form-control" placeholder="Client" disabled></th> <th class="col-lg-1"><input type="text" class="form-control" placeholder="Task " disabled></th> <th class="col-lg-1"><input type="text" class="form-control" placeholder="Description" disabled></th> <th class="col-lg-2"><input type="text" class="form-control" placeholder="Create Date and Time" disabled></th> <th class="col-lg-2"><input type="text" class="form-control" placeholder="Start Date and Time" disabled></th> <th class="col-lg-2"><input type="text" class="form-control" placeholder="Due Date and Time" disabled></th> <th class="col-lg-1"> Edit</th> <th class="col-lg-1"> Delete</th> </tr> </thead> <tbody> <?php if(isset($view_data) && is_array($view_data) && count($view_data)): $i=1; foreach ($view_data as $key => $data) { ?> <tr <?php if($i%2==0){echo 'class="even"';}else{echo'class="odd"';}?>> <td><?php echo $data['projectname']; ?></td> <td><?php echo $data['cname']; ?></td> <td><?php echo $data['mytext']; ?></td> <td><?php echo $data['mytext1']; ?></td> <td><?php echo $data['mytext2']; ?></td> <td><?php echo $data['mytext3']; ?></td> <td><?php echo $data['mytext4']; ?></td> <td><?php echo $data['mytext5']; ?></td> <td><a class="btn btn-warning" role="button" href="<?php echo site_url('Task/edit_data/'. $data['id'].''); ?>"><i class="glyphicon glyphicon-pencil"></i> Edit</a></td> <td><a type="button" class="btn btn-danger" href="<?php echo site_url();?>/Task/delete_data/<?php print($data['id']);?>"> <img src='' title="Delete" onClick="return doconfirm();" /> </a></td> </tr> <?php $i++; } else: ?> <tr> <td colspan="7" align="center" >No Records Found..</td> </tr> <?php endif; ?> </tbody> </table>
Display 5 stars for adding ratings instead of radio buttons
default magento will display the ratings as below image but i want to change like this : i am using default magento code form.phtml [app/design/frontend/rwd/theme/template/review/form.phtml] <?php if( $this->getRatings() && $this->getRatings()->getSize()): ?> <h4><?php echo $this->__('Your Rating') ?> <em class="required"></em></h4> <span id="input-message-box"></span> <table class="data-table review-summary-table ratings" id="product-review-table"> <col width="1" /> <col /> <col /> <col /> <col /> <col /> <thead> <tr> <th> </th> <th> <div class="rating-box"> <span class="rating-number">1</span> <span class="rating nobr" style="width:20%;"><?php echo $this->__('1 star') ?></span> </div> </th> <th> <div class="rating-box"> <span class="rating-number">2</span> <span class="rating nobr" style="width:40%;"><?php echo $this->__('2 star') ?></span> </div> </th> <th> <div class="rating-box"> <span class="rating-number">3</span> <span class="rating nobr" style="width:60%;"><?php echo $this->__('3 star') ?></span> </div> </th> <th> <div class="rating-box"> <span class="rating-number">4</span> <span class="rating nobr" style="width:80%;"><?php echo $this->__('4 star') ?></span> </div> </th> <th> <div class="rating-box"> <span class="rating-number">5</span> <span class="rating nobr" style="width:100%;"><?php echo $this->__('5 star') ?></span> </div> </th> </tr> </thead> <tbody> <?php foreach ($this->getRatings() as $_rating): ?> <tr> <th><?php echo $this->escapeHtml($_rating->getRatingCode()) ?></th> <?php foreach ($_rating->getOptions() as $_option): ?> <td class="value"><label for="<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>_<?php echo $_option->getValue() ?>"><input type="radio" name="ratings[<?php echo $_rating->getId() ?>]" id="<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>_<?php echo $_option->getValue() ?>" value="<?php echo $_option->getId() ?>" class="radio" /></label></td> <?php endforeach; ?> </tr> <?php endforeach; ?> </tbody> </table> <input type="hidden" name="validate_rating" class="validate-rating" value="" /> <script type="text/javascript">decorateTable('product-review-table')</script> <?php endif; ?> please help me to find solution Thanks in advance
I recently dealt with it and my code looks something like this: form.phtml <?php foreach ($this->getRatings() as $_rating): ?> <tr> <th><?php echo $this->escapeHtml($_rating->getRatingCode()) ?>: </th> <?php foreach ($_rating->getOptions() as $_option): ?> <td class="value"> <label for="<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>_<?php echo $_option->getValue() ?>"> <input type="radio" name="ratings[<?php echo $_rating->getId() ?>]" id="<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>_<?php echo $_option->getValue() ?>" value="<?php echo $_option->getId() ?>" class="radio" /> <i class="fa fa-star"></i> </label> </td> <?php endforeach; ?> </tr> <?php endforeach; ?> *.css .review-summary-table tbody td label input { display: none; } // default .review-summary-table tbody td label input + .fa { color: #E6E6E6; } // hover, clicked, ... .review-summary-table tbody td label:hover input + .fa, .review-summary-table tbody td label input:checked + .fa, .review-summary-table tbody td.active label input + .fa, .review-summary-table tbody tr:hover td.tmp-active label input + .fa { color: #50A4CF; } *.js var reviewTable = $('#product-review-table'); if (reviewTable.length > 0) { reviewTable.each(function() { $(this).find('tbody tr').each(function() { var row = $(this), tdValues = row.find('td.value'); tdValues.each(function(index) { $(this).find('label').hover(function() { tdValues.removeClass('tmp-active'); tdValues.slice(0, index + 1).addClass('tmp-active'); }).click(function() { tdValues.removeClass('active'); tdValues.slice(0, index + 1).addClass('active'); }); }); }); }); }
DataTables warning: table id=datatable - Requested unknown parameter '1' for row 0
can someone tell me what's wrong with my code? been stuck here for hours... it always says that "DataTables warning: table id=datatable - Requested unknown parameter '1' for row 0." here's my code: <table id="datatable" class="table table-bordered table-striped dataTable"> <thead> <tr> <th>Name</th> <th></th> </tr> </thead> <tbody> <?php echo $this->session->flashdata('message'); ?> <?php $offset = $this->uri->segment(3, 0) + 1; ?> <?php foreach ($query->result() as $row): ?> <tr> <td><?php echo $row->manufacturer_name; ?></td> <?php echo "<form method='post' action='asset_management/updateForm'>";?> <input type="hidden" name="manufacturer_id" value="<?php echo $row->manufacturer_id;?>"/> <?php echo form_open('asset_management/updateForm'); echo form_submit('p_submit', 'Update', "class='btn btn-warning btn-xs'"); ?> <?php echo form_close(); ?> </form> <a class="btn btn-danger btn-xs" onclick="javascript:deleteConfirm('<?php echo site_url('asset_management/deletemanu/' . $row->manufacturer_id); ?>');" deleteConfirm href="#"> <span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a></th> </tr> <?php endforeach; ?> </tbody> </table> Thank you so much!
no. of table heading may not matches with no. of td in the table. It shows the mentioned error. visit https://www.datatables.net/
Remove array from multidimensional array yii ajaxlink
I have a page to add items to a table that is rendered with renderpartial via ajax. Every time the user adds an item, I render the table with all the items. I also have an ajaxlink to delete the item the user chooses. The problem is that I can only delete the last record of the table, if I click on other ajaxlink, nothing happens. here is the view file to search and add items <div class="row"> <?php $this->widget('zii.widgets.jui.CJuiAutoComplete', array( 'name' => 'test_autocomplete', 'source'=>$this->createUrl('insumos/ver'), 'value' => "", 'options' => array( 'minChars'=>1, 'autoFill'=>false, 'focus'=> 'js:function( event, ui ) { $( "#test_autocomplete" ).val( ui.item.label ); return false; }', 'select'=>'js:function( event, ui ) { $( "#Pedidos_codigoinsumo").val(ui.item.id); $( "#Pedidos_codigo").val(ui.item.codigo); $( "#Pedidos_nombre").val(ui.item.label); $( "#Pedidos_cantidad").focus(); $( "#cantidades").show(); return false; }', ), 'htmlOptions'=>array( 'autocomplete'=>'off'), )); ?> </div> <div id="cantidades"> <div class="row"> <?php echo $form->labelEx($model,'codigo'); ?> <?php echo $form->textField($model,'codigo',array('size'=>60,'maxlength'=>300)); ?> <?php echo $form->hiddenField($model,'codigoinsumo'); ?> </div> <div class="row"> <?php echo $form->labelEx($model,'nombre'); ?> <?php echo $form->textField($model,'nombre',array('size'=>60,'maxlength'=>300)); ?> </div> <div class="row"> <?php echo $form->labelEx($model,'cantidad'); ?> <?php echo $form->textField($model,'cantidad',array('size'=>60,'maxlength'=>300)); ?> <?php echo $form->error($model,'codigoinsumo'); ?> </div> <div class="row"> <?php echo $form->labelEx($model,'observaciones'); ?> <?php echo $form->textArea($model,'observaciones',array('rows'=>6, 'cols'=>50)); ?> </div> <?php echo CHtml::ajaxButton('Agregar', array('pedidos/adicion'), array('type'=>'POST','data'=>'js:$("#pedidoalmacen-form").serialize()','update'=>'#req_res02')); echo CHtml::ajaxButton('Cancelar Pedido', array('pedidos/cancelar'), array('update'=>'#req_res02')); ?> <?php $this->endWidget(); ?> <div id="req_res02"></div> the view that has the table is: if($ver==1) { ?> <table> <tr> <td align="center">Borrar</td> <td align="center">Código</td> <td align="center">Insumo</td> <td align="center">Cantidad</td> <td align="center">Observaciones</td> </tr> <?php $codigo= Yii::app()->session['pedido-codigo']; $contado=count($codigo); $i=0; while($i<$contado) { ?> <tr> <td align="left"><?php echo CHtml::ajaxLink('Quitar', Yii::app()->createUrl('pedidos/quitar'),array('update'=>'#req_res02','type'=>'POST','data'=>array('dato'=>$codigo[$i]['contador'])),array('id'=>'quitar-'. uniqid())); ?></td> <td align="left"><?php echo $codigo[$i]['contador']; ?></td> <td align="left"><?php echo $codigo[$i]['insumo']; ?></td> <td align="left"><?php echo $codigo[$i]['cantidad']; ?></td> <td align="left"><?php echo $codigo[$i]['observaciones']; ?></td> </tr> <?php $i++; } ?> </table> <div class="row buttons"> <?php echo CHtml::submitButton('Agregar'); ?> </div> <?php } ?> and the controller is public function actionAdicion() { $model=new Pedidos; if(isset($_POST['Pedidos'])) { $model->attributes=$_POST['Pedidos']; if(isset(Yii::app()->session['pedido-codigo'])) { $codigo= Yii::app()->session['pedido-codigo']; $contador=count($codigo)+1; $auxiliar=array('contador'=>$contador,'id'=>$model->codigoinsumo,'codigo'=>$model->codigo,'insumo'=>$model->nombre,'cantidad'=>$model->cantidad,'observaciones'=>$model->observaciones); } else { $auxiliar=array('contador'=>1,'id'=>$model->codigoinsumo,'codigo'=>$model->codigo,'insumo'=>$model->nombre,'cantidad'=>$model->cantidad,'observaciones'=>$model->observaciones); } $codigo[]=$auxiliar; Yii::app()->session['pedido-codigo']=$codigo; $this->renderPartial('insumosporpedir',array('ver'=>'1'),FALSE,TRUE); //Yii::app()->end(); //echo $_POST['data1'];//CHtml::encode(print_r("hola", true)); } } public function actionCancelar() { unset(Yii::app()->session['pedido-codigo']); $this->renderPartial('insumosporpedir',array('ver'=>'0'),FALSE,TRUE); } public function actionQuitar() { if(isset($_POST['dato'])) { $codigo= Yii::app()->session['pedido-codigo']; $compara=$_POST['dato']; foreach ($codigo as $subkey => $subarray) { if($subarray['contador']==$compara) { unset($codigo[$subkey]); //echo $codigo[$subkey]; } } $ver=1; if(count($codigo)>0) { Yii::app()->session['pedido-codigo']=$codigo; } else { unset(Yii::app()->session['pedido-codigo']); $ver=0; } //$this->layout=''; $this->renderPartial('insumosporpedir',array('ver'=>$ver),false,true); //Yii::app()->end(); } thank you!
I found the problem. the problem wasnt the unset method, it was in the view where I showed the values in the array. insted of using while($i<$contado) { ?> <tr> <td align="left"><?php echo CHtml::ajaxLink('Quitar', Yii::app()->createUrl('pedidos/quitar'),array('update'=>'#req_res02','type'=>'POST','data'=>array('dato'=>$codigo[$i]['contador'])),array('id'=>'quitar-'. uniqid())); ?></td> <td align="left"><?php echo $codigo[$i]['contador']; ?></td> <td align="left"><?php echo $codigo[$i]['insumo']; ?></td> <td align="left"><?php echo $codigo[$i]['cantidad']; ?></td> <td align="left"><?php echo $codigo[$i]['observaciones']; ?></td> </tr> <?php $i++; } I replaced it with foreach ($codigo as $key => $value) { ?> <tr> <td align="left"><?php echo CHtml::ajaxLink('Quitar', Yii::app()->createUrl('pedidos/quitar'),array('update'=>'#req_res02','type'=>'POST','data'=>array('dato'=>$value['contador'])),array('id'=>'quitar-'. uniqid())); ?></td> <td align="left"><?php echo $value['codigo']; ?></td> <td align="left"><?php echo $value['insumo']; ?></td> <td align="left"><?php echo $value['cantidad']; ?></td> <td align="left"><?php echo $value['observaciones']; ?></td> </tr> <?php } the error occurred because I lost the continuity in the keys everytime I delete a middle array
Opencart reduce load time while fetching too many data's from database
I'm using attribute filter option in my store. For this i'm using below codes in admin view template. This'll fetch all attributes form database and using jquery tabs i'm hiding all inactive ones. The weired problem what i'm facing is LOADING TIME . I'm having more than 5k products in my store. SO retrieving all attributes taking long time(I think so). Did anyone have any idea to reduce loading time in this case? <div id="tab-subcategory-<?php echo $category['category_id']; ?>" class="htabs-content"> <input name="VALORES_<?php echo $category['category_id']; ?>" type="checkbox" value="1" onclick="Selecbox(this);"/><?php echo $entry_all_values; ?> <input name="VALORES_<?php echo $category['category_id']; ?>" type="hidden" value="<?php echo $category['category_id']; ?>" /> <table width="100%" border="0" cellpadding="2" class="list"> <thead> <tr> <td class="left"><?php echo $entry_value; ?><img src="view/image/information.png" width="15" height="15" hspace="10" border="0" align="absmiddle" class="tooltip" title="<?php echo $entry_values_explanation; ?>" /></td> <td class="left"><?php echo $entry_separator; ?> <img src="view/image/information.png" width="15" height="15" hspace="10" border="0" align="absmiddle" class="tooltip" title="<?php echo $entry_separator_explanation; ?>" /></td> <td class="left"><?php echo $entry_examples; ?></td> </tr> </thead> <tbody> <?php foreach ($category['attributes'] as $attribute) { ?> <tr> <td class="left"> <?php if ($attribute['checked']) { ?> <input name="VALORES_<?php echo $category['category_id']; ?>[attributes][<?php echo $attribute['attribute_id']; ?>][attribute_id]" type="checkbox" value="<?php echo $attribute['attribute_id']; ?>" checked="checked" /><?php echo $attribute['name']; ?> <?php }else{ ?> <input name="VALORES_<?php echo $category['category_id']; ?>[attributes][<?php echo $attribute['attribute_id']; ?>][attribute_id]" type="checkbox" value="<?php echo $attribute['attribute_id']; ?>" /><?php echo $attribute['name']; ?> <?php } ?> </td> <td class="left"><input name="VALORES_<?php echo $category['category_id']; ?>[attributes][<?php echo $attribute['attribute_id']; ?>][separator]" type="text" value="<?php echo $attribute['separator']; ?>" size="5"/></td> <td class="left"> <?php foreach ($languages as $language) { ?> <select name="select" id="select<?php echo $language; ?>" style="width: 150px" > <?php if ($attribute['attribute_values'][$language['language_id']]){ natsort($attribute['attribute_values'][$language['language_id']]); foreach ($attribute['attribute_values'][$language['language_id']] as $valores_default){ ?> <option><?php echo trim($valores_default); ?></option> <?php } ?> <?php }else{ ?> <option> <?php echo $text_none; ?></option> <?php } ?> </select><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /><br /> <?php } ?> </td> </tr> <?php } ?> </tbody> </table> </div> <?php foreach ($category['children'] as $child) { ?> <div id="tab-subcategory-<?php echo $category['category_id']; ?>-<?php echo $child['category_id']; ?>" class="htabs-content"> <input name="VALORES_<?php echo $child['category_id']; ?>" type="checkbox" value="1" onclick="Selecbox(this);"/> <?php echo $entry_all_values; ?> <input name="VALORES_<?php echo $child['category_id']; ?>" type="hidden" value="<?php echo $child['category_id']; ?>" /> <table width="100%" border="0" cellpadding="2" class="list"> <thead> <tr> <td class="left"><?php echo $entry_value; ?><img src="view/image/information.png" width="15" height="15" hspace="10" border="0" align="absmiddle" class="tooltip" title="<?php echo $entry_values_explanation; ?>" /></td> <td class="left"><?php echo $entry_separator; ?><img src="view/image/information.png" width="15" height="15" hspace="10" border="0" align="absmiddle" class="tooltip" title="<?php echo $entry_separator_explanation; ?>" /></td> <td class="left"><?php echo $entry_examples; ?></td> </tr> </thead> <tbody> <?php foreach ($child['attributes'] as $attribute) { ?> <tr> <td class="left"> <?php if ($attribute['checked']) { ?> <input name="VALORES_<?php echo $child['category_id']; ?>[attributes][<?php echo $attribute['attribute_id']; ?>][attribute_id]" type="checkbox" value="<?php echo $attribute['attribute_id']; ?>" checked="checked" /><?php echo $attribute['name']; ?> <?php }else{ ?> <input name="VALORES_<?php echo $child['category_id']; ?>[attributes][<?php echo $attribute['attribute_id']; ?>][attribute_id]" type="checkbox" value="<?php echo $attribute['attribute_id']; ?>" /><?php echo $attribute['name']; ?> <?php } ?> </td> <td class="left"><input name="VALORES_<?php echo $child['category_id']; ?>[attributes][<?php echo $attribute['attribute_id']; ?>][separator]" type="text" value="<?php echo $attribute['separator']; ?>" size="5"/></td> <td class="left"> <?php foreach ($languages as $language) { ?> <select name="select" id="select<?php echo $language; ?>" style="width: 150px" > <?php if ($attribute['attribute_values'][$language['language_id']]){ natsort($attribute['attribute_values'][$language['language_id']]); foreach ($attribute['attribute_values'][$language['language_id']] as $valores_default){ ?> <option><?php echo trim($valores_default); ?></option> <?php } ?> <?php }else{ ?> <option> <?php echo $text_none; ?></option> <?php } ?> </select><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /><br /> <?php } ?> </td> </tr> <?php } ?> </tbody> </table> </div> <?php foreach ($child['sisters_id'] as $sister) { ?> <div id="tab-subcategory-<?php echo $category['category_id']; ?>-<?php echo $child['category_id']; ?>-<?php echo $sister['category_id']; ?>" class="htabs-content"> <input name="VALORES_<?php echo $sister['category_id']; ?>" type="checkbox" value="1" onclick="Selecbox(this);"/> <?php echo $entry_all_values; ?> <input name="VALORES_<?php echo $sister['category_id']; ?>" type="hidden" value="<?php echo $sister['category_id']; ?>" /> <table width="100%" border="0" cellpadding="2" class="list"> <thead> <tr> <td class="left"><?php echo $entry_value; ?><img src="view/image/information.png" width="15" height="15" hspace="10" border="0" align="absmiddle" class="tooltip" title="<?php echo $entry_values_explanation; ?>" /></td> <td class="left"><?php echo $entry_separator; ?><img src="view/image/information.png" width="15" height="15" hspace="10" border="0" align="absmiddle" class="tooltip" title="<?php echo $entry_separator_explanation; ?>" /></td> <td class="left"><?php echo $entry_examples; ?></td> </tr> </thead> <tbody> <?php foreach ($sister['attributes'] as $attribute) { ?> <tr> <td class="left"> <?php if ($attribute['checked']) { ?> <input name="VALORES_<?php echo $sister['category_id']; ?>[attributes][<?php echo $attribute['attribute_id']; ?>][attribute_id]" type="checkbox" value="<?php echo $attribute['attribute_id']; ?>" checked="checked" /><?php echo $attribute['name']; ?> <?php }else{ ?> <input name="VALORES_<?php echo $sister['category_id']; ?>[attributes][<?php echo $attribute['attribute_id']; ?>][attribute_id]" type="checkbox" value="<?php echo $attribute['attribute_id']; ?>" /><?php echo $attribute['name']; ?> <?php } ?> </td> <td class="left"><input name="VALORES_<?php echo $sister['category_id']; ?>[attributes][<?php echo $attribute['attribute_id']; ?>][separator]" type="text" value="<?php echo $attribute['separator']; ?>" size="5"/></td> <td class="left"> <?php foreach ($languages as $language) { ?> <select name="select" id="select<?php echo $language; ?>" style="width: 150px" > <?php if ($attribute['attribute_values'][$language['language_id']]){ natsort($attribute['attribute_values'][$language['language_id']]); foreach ($attribute['attribute_values'][$language['language_id']] as $valores_default){ ?> <option><?php echo trim($valores_default); ?></option> <?php } ?> <?php }else{ ?> <option> <?php echo $text_none; ?></option> <?php } ?> </select><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /><br /> <?php } ?> </td> </tr> <?php } ?> </tbody> </table> </div> <?php } ?> <?php } ?>