Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Purchases Add-on


Recommended Posts

Hi guys!

 

I'm trying to make a purchases add-on whereby admin users of oscommerce can store what they've bought from their suppliers on the website. I've looked around and didn't see any current add-ons which offer this service. I'm using v2.3.3. To be honest, I'm still pretty new to coding and everything so I'm trying it out for a project and maybe for future use by myself.

 

My knowledge of how to link the database to the php code isn't there so my database has been coming up with blank entries. What I did was to just copy bits of database codes I could understand from the categories.php file.

 

Javascript functions where I can enter the price, shipping cost and quantity, which will result in the total cost "magically" appearing in the text box is also missing. Tried it out but couldn't get it to work so I deleted it.

 

I'm not too sure what the php code is for making a form so I kept to another file I made which I'd rather not and make it look as "oscommerce-y" as possible.

 

And, I've no idea how the save button works.

 

Thanks in advance for taking time to read my lump of code.

 

This is what I've done so far.

 

<?php

require('includes/application_top.php');

require(DIR_WS_CLASSES . 'currencies.php');

$currencies = new currencies();

require(DIR_WS_INCLUDES . 'template_top.php');

 

$sql_data_array = array('products_name' => tep_db_prepare_input($HTTP_POST_VARS['products_name']),

'products_id' => (int)tep_db_prepare_input($HTTP_POST_VARS['products_id']),

'purchase_date_of_input' => tep_db_prepare_input($HTTP_POST_VARS['purchase_date_of_input']),

'purchase_date' => tep_db_prepare_input($HTTP_POST_VARS['purchase_date']),

'price_per_piece' => tep_db_prepare_input($HTTP_POST_VARS['price_per_piece']),

'purchase_quantity' => (int)tep_db_prepare_input($HTTP_POST_VARS['purchase_quantity']),

'shipping_cost' => tep_db_prepare_input($HTTP_POST_VARS['shipping_cost']),

'total_cost' => tep_db_prepare_input($HTTP_POST_VARS['total_cost']),

'manufacturers_id' => (int)tep_db_prepare_input($HTTP_POST_VARS['manufacturers_id']),

'purchase_remarks' => tep_db_prepare_input($HTTP_POST_VARS['purchase_remarks']));

 

tep_db_perform(TABLE_PURCHASES, $sql_data_array);

 

$purchases = $sql_data_array;

 

tep_db_query("insert into " . TABLE_PURCHASES . " (products_name, products_id, purchase_date_of_input, purchase_date, price_per_piece, purchase_quantity, shipping_cost, total_cost, manufacturers_id, purchase_remarks) values ('" . tep_db_input($purchases['products_name']) . "', '" . (int)tep_db_input($purchases['products_id']) . "', '" . tep_db_input($purchases['purchase_date_of_input']) . "', '" . tep_db_input($purchases['purchase_date']) . "', '" . tep_db_input($purchases['price_per_piece']) . "', '" . (int)tep_db_input($purchases['purchase_quantity']) . "', '" . tep_db_input($purchases['shipping_cost']) . "', '" . tep_db_input($purchases['total_cost']) . "', '" . (int)$purchases['manufacturers_id'] . "', '" . tep_db_input($purchases['purchase_remarks']) . "')");

 

$parameters = array('products_name' => '',

'products_id' => '',

'purchase_date_of_input' => '',

'purchase_date' => '',

'price_per_piece' => '',

'purchase_quantity' => '',

'shipping_cost' => '',

'total_cost' => '',

'manufacturers_id' => '',

'purchase_remarks' => '');

 

$pInfo = new objectInfo($parameters);

 

$manufacturers_array = array(array('id' => '', 'text' => TEXT_NONE));

$manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");

while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {

$manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'],

'text' => $manufacturers['manufacturers_name']);

}

 

$products_array = array(array('id' => '', 'text' => TEXT_NONE));

$products_query = tep_db_query("select products_id, products_name from " . TABLE_PRODUCTS_DESCRIPTION . " order by products_name");

while ($products = tep_db_fetch_array($products_query)) {

$products_array[] = array('id' => $products['products_id'],

'text' => $products['products_name']);

}

 

$products_id = $purchases['products_id'];

$products_quantity = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");

$purchase_quantity = $purchases['purchase_quantity'];

if ($products_quantity == false) {

tep_db_query("insert into " . TABLE_PRODUCTS . " (products_quantity) values ('" . (int)$purchase_quantity . "')");

} else {

$total_quantity = $products_quantity + $purchase_quantity;

tep_db_query("insert into " . TABLE_PRODUCTS . " (products_quantity) values ('" . (int)$total_quantity . "')");

}

 

?>

<script type="text/javascript"><!--

 

//--></script>

 

<?php //echo tep_draw_form('inputPurchases', FILENAME_ADD_PRODUCT_INFO, 'cPath=' . $cPath . (isset($HTTP_GET_VARS['pID']) ? '&pID=' . $HTTP_GET_VARS['pID'] : '') . '&action=' . $form_action, 'post', 'enctype="multipart/form-data"'); ?>

<form name="inputPurchase" action = "addProductPurchaseProcess.php" method = "post">

 

<table border="0" width="100%" cellspacing="0" cellpadding="2">

<tr>

<td><table border="0" width="100%" cellspacing="0" cellpadding="0">

<tr>

<td class="pageHeading"><?php echo TEXT_HEADING_NEW_PURCHASE; ?></td>

<td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>

</tr>

</table></td>

</tr>

<tr>

<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>

</tr>

<tr>

<td><table border="0" cellspacing="0" cellpadding="2">

<tr>

<td class="main"><?php echo TEXT_DATE_OF_INPUT; ?></td>

<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('purchase_date_of_input', date('Y-m-d'), 'id="purchase_date_of_input"') . ' <small>(YYYY-MM-DD)</small>'; ?></td>

</tr>

<tr>

<td class="main"><?php echo TEXT_DATE_OF_PURCHASE; ?></td>

<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('purchase_date', $pInfo->purchase_date, 'id="purchase_date"') . ' <small>(YYYY-MM-DD)</small>'; ?></td>

</tr>

<tr>

<td class="main"><?php echo TEXT_PRODUCTS_MANUFACTURER; ?></td>

<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_pull_down_menu('manufacturers_id', $manufacturers_array, $pInfo->manufacturers_id); ?></td>

</tr>

<tr>

<td class="main"><?php echo TEXT_PRODUCT_NAME; ?></td>

<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_pull_down_menu('products_id', $products_array, $pInfo->products_id); ?></td>

</tr>

<tr bgcolor="#ebebff">

<td class="main"><?php echo TEXT_PRICE_PER_PIECE; ?></td>

<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('price_per_piece', $pInfo->price_per_piece, 'onkeyup="updateTotal()"'); ?></td>

</tr>

<tr bgcolor="#ebebff">

<td class="main"><?php echo TEXT_PURCHASE_QUANTITY; ?></td>

<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('purchase_quantity', $pInfo->purchase_quantity, 'onkeyup="updateTotal()"'); ?></td>

</tr>

<tr bgcolor="#ebebff">

<td class="main"><?php echo TEXT_SHIPPING_COST; ?></td>

<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('shipping_cost', $pInfo->shipping_cost, 'onkeyup="updateTotal()"'); ?></td>

</tr>

<script type="text/javascript"><!--

 

//--></script>

<tr bgcolor="#ebebff">

<td class="main"><?php echo TEXT_TOTAL_COST; ?></td>

<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('total_cost', $pInfo->total_cost); ?></td>

</tr>

<tr>

<td class="main" valign="top"><?php echo TEXT_PURCHASE_REMARKS; ?></td>

<td><table border="0" cellspacing="0" cellpadding="0">

<tr>

<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' '; ?></td>

<td class="main"><?php echo tep_draw_textarea_field('purchase_remarks[' . $languages[$i]['id'] . ']', 'soft', '70', '15', (empty($pInfo->products_id) ? '' : tep_get_purchases($pInfo->products_id, $languages[$i]['id']))); ?></td>

</tr>

</table></td>

</tr>

</table>

</tr>

<tr>

<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>

</tr>

<tr>

<td class="smallText" align="right"><?php echo tep_draw_hidden_field('purchase_date_of_input', (tep_not_null($pInfo->purchase_date_of_input) ? $pInfo->purchase_date_of_input : date('Y-m-d'))) . tep_draw_button(IMAGE_SAVE, 'disk', null, 'primary', array('params' => 'onclick="this.form.action.value=\'list\';this.form.submit();"')) . tep_draw_button(IMAGE_CANCEL, 'close', tep_href_link(FILENAME_ADD_PRODUCT_INFO)); ?></td>

</tr>

</table>

<!--<input type = "submit" />!-->

<script type="text/javascript">

$('#purchase_date').datepicker({

dateFormat: 'yy-mm-dd'

});

</script>

</form>

<?php

require('includes/application_bottom.php');

require(DIR_WS_INCLUDES . 'template_bottom.php');

?>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...