Tuesday, April 8, 2014

Creating the template file at the admin section [Creating Custom OpenCart Modules]

Navigate to admin/view/template/total/ and create tips.tpl and insert the following code:
<?php echo $header; ?>
<div id="content">
<div class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<?php echo $breadcrumb['separator']; ?><a href="<?php echo 
  $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
<?php } ?>
</div>
<?php if ($error_warning) { ?>
<div class="warning"><?php echo $error_warning; ?></div>
<?php } ?>
<div class="box">
<div class="heading">
<h1><imgsrc="view/image/total.png" alt="" /><?php echo $heading_title;
?></h1>
<div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><a href="<?php echo    $cancel; ?>" class="button"><?php echo $button_cancel; ?></a></div>
</div>
<div class="content">
<form action="<?php echo $action; ?>" method="post"
enctype="multipart/form-data" id="form">
<table class="form">
<tr>
<td><?php echo $entry_status; ?></td>
<td><select name="tips_status">
<?php if ($tips_status) { ?>
<option value="1" selected="selected"><?php echo $text_enabled; ?></ option>
<option value="0"><?php echo $text_disabled; ?></option>
<?php } else { ?>
<option value="1"><?php echo $text_enabled; ?></option>
<option value="0" selected="selected"><?php echo $text_disabled; ?></ option> <?php } ?>
</select></td>
</tr>
<tr>
<td><?php echo $entry_sort_order; ?></td>
<td><input type="text" name="tips_sort_order" value="<?php echo $tips_ sort_order; ?>" size="1" /></td>
</tr>
</table>
</form>
</div>
</div>
</div>
<?php echo $footer; ?>

Changes made in the cart file at the frontend

Navigate to catalog/view/theme/default/template/checkout/ and open cart. tpl and paste the following code just before the <?php if ($voucher_status) { ?> code.
<?php if ($this->config->get('tips_status')==1) { ?>
<tr class="highlight">
<td><?php if ($next == 'tips') { ?>
<input type="radio" name="next" value="tips" id="use_tips"    checked="checked" />
 <?php } else { ?>
<input type="radio" name="next" value="tips" id="use_tips" />
<?php } ?></td>
<td>Enter the Tips</td>
</tr>
<?php } ?>
The preceding code will show a radio button followed by the Enter the Tips text. On selecting this radio button, div with the id of tips is displayed.
Now just before the <div id="voucher" class="content"> line, paste the following code:
<div id="tips" class="content" style="display: <?php echo ($next 
  == 'tips' ? 'block' : 'none'); ?>;">
<form action="<?php echo $action; ?>" method="post"    enctype="multipart/form-data">        Enter your amount&nbsp;
<input type="text" name="tips" value="" />
<input type="hidden" name="next" value="tips" /> &nbsp;
<input type="submit" value="Apply Tips" class="button" />
</form>
</div>
It shows the Enter your amount form and an Apply Tips button.

Changes in the shopping cart page to show tips

Navigate to catalog/controller/checkout/ and open cart.php. Look for // Voucher and paste the following lines of code before it:
// Tips   
if (isset($this->request->post['tips'])) {
  $this->session->data['tips'] = $this->request->post['tips'];
  $this->session->data['success'] = $this->language
    ->get('text_tips');
  $this->redirect($this->url->link('checkout/cart'));
}
It activates the session for total extension. While installing the Order Total module, it is saved on the extension table as total just like the Tips module gets saved as shown in the following screenshot:


So once the session of tips is activated, the entire total is calculated and we do not need to work out another. We just need to activate the session of the tips, which we have done with the preceding code. With this, our Order Total module is complete.

Summary

In this chapter, we learned the ways to manage data. This was achieved by creating pages, listing it out, inserting the data to the database and retrieving it either to display or to edit, and finally deleting the data. Likewise, we showed you how to list the data at the frontend by making the page. At the end, we created the Order Total Tips module and showed you how it changed the order totals. Using this, you will be able to create modules and pages to manage the data across OpenCart.

No comments:

Post a Comment