Recording Offline Payments

  • Posts: 3
  • Thank you received: 1
10 years 7 months ago #150877

-- url of the page with the problem -- : n/a
-- HikaShop version -- : 1312231536
-- Joomla version -- : 3.2.3
-- PHP version -- : 5.3.28
-- Browser(s) name and version -- : n/a
-- Error-message(debug-mod must be tuned on) -- : Error_message n/a

I have some customers that pay in full via the paypal plugin before their order is shipped, but I also have some customers that make cash down payments and do not pay the remainder until after they receive their order.

I need to be able to manually record partial payments made in cash from the backend, but I want the information to be stored the same way as paypal payments are stored - for consistency's sake.

My though process was to add a field to the "Edit order additional information" popup located on the edit order page. The field would updated the history_amount field in the __hikashop_history table.

I think that is the only place in the database that I would need to record the payment amount, but I could be wrong. Also, I am not sure which file(s) to edit to accomplish this and would rather not spend hours looking for it if I don't have to.

If someone could please chime in to point me in the right direction or perhaps even suggest an easier method I would greatly appreciate it.

I am, of course, happy to share my modifications so others with similar needs can benefit, I will post back to this thread once I have some workable code.

Thank you in advance!

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 3
  • Thank you received: 1
10 years 7 months ago #150880

Made this addition to administrator/components/com_hikashop/views/order/tmpl/edit_additional.php around line 187:

<dd class="hikashop_orderadditional_history">
			<span>
			<input onchange="window.orderMgr.orderadditional_history_changed(this);" type="checkbox" id="hikashop_history_orderadditional_store" name="data[history][store_data]" value="1"/>
			<label for="hikashop_history_orderadditional_store" style="display:inline-block">
				<?php echo JText::_('SET_HISTORY_MESSAGE');?>
			</label>
			</span>
			<br/>
			<textarea id="hikashop_history_orderadditional_msg" name="data[history][msg]" style="display:none;"></textarea>
		</dd>
		
<!-- start addition by pk -->
		<dd class="hikashop_orderadditional_history">
			<span>
			<input onchange="window.orderMgr.orderadditional_history_amt_changed(this);" type="checkbox" id="hikashop_history_amt_orderadditional_store" name="data[history][store_data]" value="1"/>
			<label for="hikashop_history_amt_orderadditional_store" style="display:inline-block">
				<?php echo JText::_('Record Payment');?>
			</label>
			</span>
			<br/>
			<input type="text" id="hikashop_history_amt_orderadditional" name="data[history][amt]" style="display:none;" />
		</dd>
<!-- end addition by pk -->		
		
		<dd class="hikashop_orderadditional_usermsg">

Made this addition to same file around line 213:
<!-- start addition by pk -->
<script type="text/javascript">
if(!window.orderMgr)
	window.orderMgr = {};
window.orderMgr.orderadditional_history_amt_changed = function(el) {
	var fields = ['hikashop_history_amt_orderadditional'], displayValue = '';
	if(!el.checked) displayValue = 'none';
	window.hikashop.setArrayDisplay(fields, displayValue);
}
</script>
<!-- end addition by pk -->

I have a field now, but am not sure how to make it update the correct database field. I have tried looking at the following files, but nothing is jumping out at me ...

administrator/components/com_hikashop/controllers/order.php,
administrator/components/com_hikashop/classes/order.php
administrator/components/com_hikashop/classes/field.php

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
10 years 7 months ago #150993

Hi,

You need to add your custom code to save it near the end of the saveForm function of administrator/components/com_hikashop/classes/order.php

Note that in your first piece of code, your input has the same name as the input of the history message input which shouldn't be the case.

Please Log in or Create an account to join the conversation.

  • Posts: 3
  • Thank you received: 1
10 years 7 months ago #151013

Thank you for pointing me in the right direct Nicolas!

File Attachment:

File Name: h28c022b.zip
File Size:48 KB



Attached is a zip archive of the files I edited and a readme.txt file that shows where they go in the filesystem. All edits are wrapped in comments. I am sure it can be improved upon (specifically the automation of the currency code when entering payments). Very limited testing was done on a shared hosting environment with apache server running PHP 5.3 with IE 8, Chrome 33 and Firefox 26. (that means I tried it once in each browser and it worked).

Summary of Edits:

Corrected the name attribute on the checkbox added to edit_additional.php. (code in previous post)

Added the following code to order.php around line 657:
			if(!empty($data['history']['store_pmt'])) {
				if(isset($data['history']['amount'])){
					$order->history->history_amount = $data['history']['amount'];
					$order->history->history_type = 'payment';
				}
				else{
					$order->history->history_amount = @$data['history']['history_amount'];
					$order->history->history_type = 'payment';
				}
			}

Added the following line to en-GB.com_hikashop,ini around line 1816:
SET_HISTORY_PMT_AMT="Set payment amount (Format: '1.00USD')"

Added the following two code snippets to the front end order template 'show.php' under Display->Views to display payments made to users when they log in and view the order:
<tr>
	<td colspan='<?php echo $colspan;?>'>
	</td>
	<td class='hikashop_order_total_title key'>
		<label>Payments</label>
	</td>
	<td class='hikashop_order_total_value' >
<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName(array('history_amount', 'history_data','history_created')));
$query->from($db->quoteName('#__hikashop_history'));
$conditions = array(
    $db->quoteName('history_order_id') . '=\'' . $this->element->order_id . '\'', 
    $db->quoteName('history_type') . '=\'payment\''
);
$query->where($conditions);
$db->setQuery($query);
$db->setQuery($query);
$row = $db->loadRowList();
$numRows = count($row);
$i=0;
$myTotalPmts = 0;
while ($i<$numRows){
	preg_match('/[A-Za-z]/', $row[$i][0], $matches, PREG_OFFSET_CAPTURE);
	$myPayAmt = substr($row[$i][0],0,$matches[0][1]);
	$myTotalPmts = $myTotalPmts + $myPayAmt;
	$i++;
}
setlocale(LC_MONETARY, 'en_US');
echo money_format('%n',$myTotalPmts);
?>
	</td>
</tr>
<?php
$myTotal = substr($this->order->order_full_price,0,-1);
$myDueAmt = $myTotal - $myTotalPmts;
?>
<tr>
	<td colspan='<?php echo $colspan;?>'>
	</td>
	<td class='hikashop_order_total_title key'>
		<label>Total Due</label>
	</td>
	<td class='hikashop_order_total_value' >
		<?php echo money_format('%n', $myDueAmt);?>
	</td>
</tr>
		<tr>
          	<td>
              <fieldset>
                 <legend>Payment Information</legend>
					<table cellpadding="1" width="100%">
						<thead>
							<tr>
                              <th style="text-align:left;">Date</th>
							  <th style="text-align:left;">Amount</th>
                              <th style="text-align:left;">Details</th>
                          	</tr>
                      	</thead>
                      	<tbody>
<?php
$i = 0;
while ($i<$numRows){
	echo "<tr><td>";
	echo date_format(date_create($row[i][2]), 'm-d-Y');
	echo "</td><td>";
	preg_match('/[A-Za-z]/', $row[$i][0], $matches, PREG_OFFSET_CAPTURE);
	$myPayAmt = substr($row[$i][0],0,$matches[0][1]);
	echo money_format('%n', $myPayAmt); 
	echo "</td><td>";
	echo $row[$i][1];
	echo "</td></tr>";
	$i++;
}
?>
                      	</tbody>
	                </table>
              </fieldset>
          	</td>
		</tr>
		<tr>
          	<td>
				<fieldset>
                <legend>Shipping Information</legend>
					<table cellpadding="1" width="100%">
						<thead>
							<tr>
                              <th style="text-align:left;">Shipper</th>
							  <th style="text-align:left;">Tracking Number</th>
                          	</tr>
                      	</thead>
                      	<tbody>
							<tr>
								<td>
									<?php echo $this->element->order_shipping_method;?>
								</td>
								<td>
									<?php
									switch ($this->element->order_shipping_method){
										case 'usps':
											echo "<a target='_blank' href='https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1=" . $this->element->tracking_number . "'>" . $this->element->tracking_number . "</a>";
											break;
										case 'ups':
											echo "<a target='_blank' href='http://wwwapps.ups.com/WebTracking/track?track=yes&trackNums=" . $this->element->tracking_number . "'>" . $this->element->tracking_number . "</a>";
											break;
										case 'fedex':
											echo "<a target='_blank' href='http://www.fedex.com/Tracking?action=track&tracknumbers=" . $this->element->tracking_number . "'>" . $this->element->tracking_number . "</a>";
											break;
									}
									?>
								</td>
							</tr>
						</tbody>
					</table>
				</fieldset>
			</td>
		</tr>

Attachments:
The following user(s) said Thank You: nicolas

Please Log in or Create an account to join the conversation.

Time to create page: 0.060 seconds
Powered by Kunena Forum