Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Product Code Suffix on Product Attributes


Guest

Recommended Posts

I've done a search of the forums and contributions but as yet cant find a contribution or code modification that will allow a suffix to be added to the product code on checkout when a product attribute is added.

 

For Instance:

 

Say I was selling apples and my code for a standard apple was APP

 

The customer chose Green Ones from the attribure list of red green or yellow.

 

My code for buying std green apples is APP/G

 

Say the customer then decided he wanted large green apples the suffix that would need to be added to the product code would then be APP-L/G

 

At the moment there isnt a way of doing this and the product code stays as the standard product code, with the additional attributes being displayed in the description part. I find that I have to double check all my orders to make sure I have remembered to add the correct suffix to my codes when passing them to the supplier or to the warehouse. This sometimes means that customers sometimes recieve the standard products without the additional attributes they selected.

 

Im sure it cant be that hard to do for a coder..? (which Im not)

 

Any help with this would be much apprieciated.

Link to comment
Share on other sites

OK,

 

I've managed to add the field code suffix to the attributes table in the database and also in the admin as follows:

 

*********** In catalog/admin/products_attributes.php **************

 

Find:

 

case 'add_product_attributes':
	$products_id = tep_db_prepare_input($HTTP_POST_VARS['products_id']);
	$options_id = tep_db_prepare_input($HTTP_POST_VARS['options_id']);
	$values_id = tep_db_prepare_input($HTTP_POST_VARS['values_id']);
	$value_price = tep_db_prepare_input($HTTP_POST_VARS['value_price']);
	$price_prefix = tep_db_prepare_input($HTTP_POST_VARS['price_prefix']);

 

Change to:

 

case 'add_product_attributes':
	$products_id = tep_db_prepare_input($HTTP_POST_VARS['products_id']);
	$options_id = tep_db_prepare_input($HTTP_POST_VARS['options_id']);
	$values_id = tep_db_prepare_input($HTTP_POST_VARS['values_id']);
	$code_suffix = tep_db_prepare_input($HTTP_POST_VARS['code_suffix']);
	$value_price = tep_db_prepare_input($HTTP_POST_VARS['value_price']);
	$price_prefix = tep_db_prepare_input($HTTP_POST_VARS['price_prefix']);

 

 

##########################################################

Find

 

tep_db_query("insert into " . TABLE_PRODUCTS_ATTRIBUTES . " values ('', '" . (int)$products_id . "', '" . (int)$options_id . "', 

'" . (int)$values_id . "', '" . tep_db_input($value_price) . "', '" . tep_db_input($price_prefix) . "')");

 

Change to:

 

tep_db_query("insert into " . TABLE_PRODUCTS_ATTRIBUTES . " values ('', '" . (int)$products_id . "', '" . (int)$options_id . "', 

'" . (int)$values_id . "', '" . tep_db_input($code_suffix) . "', '" . tep_db_input($value_price) . "', '" . 

tep_db_input($price_prefix) . "')");

 

 

##########################################################

Find:

 

case 'update_product_attribute':
	$products_id = tep_db_prepare_input($HTTP_POST_VARS['products_id']);
	$options_id = tep_db_prepare_input($HTTP_POST_VARS['options_id']);
	$values_id = tep_db_prepare_input($HTTP_POST_VARS['values_id']);
	$value_price = tep_db_prepare_input($HTTP_POST_VARS['value_price']);
	$price_prefix = tep_db_prepare_input($HTTP_POST_VARS['price_prefix']);
	$attribute_id = tep_db_prepare_input($HTTP_POST_VARS['attribute_id']);

 

Change to:

 

case 'update_product_attribute':
	$products_id = tep_db_prepare_input($HTTP_POST_VARS['products_id']);
	$options_id = tep_db_prepare_input($HTTP_POST_VARS['options_id']);
	$values_id = tep_db_prepare_input($HTTP_POST_VARS['values_id']);
	$code_suffix = tep_db_prepare_input($HTTP_POST_VARS['code_suffix']);
	$value_price = tep_db_prepare_input($HTTP_POST_VARS['value_price']);
	$price_prefix = tep_db_prepare_input($HTTP_POST_VARS['price_prefix']);
	$attribute_id = tep_db_prepare_input($HTTP_POST_VARS['attribute_id']);

 

 

###########################################################

Find

 

tep_db_query("update " . TABLE_PRODUCTS_ATTRIBUTES . " set products_id = '" . (int)$products_id . "', options_id = '" . 

(int)$options_id . "', options_values_id = '" . (int)$values_id . "', options_values_price = '" . tep_db_input($value_price) . "', 

price_prefix = '" . tep_db_input($price_prefix) . "' where products_attributes_id = '" . (int)$attribute_id . "'");

 

Change to:

 

tep_db_query("update " . TABLE_PRODUCTS_ATTRIBUTES . " set products_id = '" . (int)$products_id . "', options_id = '" . 

(int)$options_id . "', options_values_id = '" . (int)$values_id . "', code_suffix = '" . tep_db_input($code_suffix) . "', 

options_values_price = '" . tep_db_input($value_price) . "', price_prefix = '" . tep_db_input($price_prefix) . "' where 

products_attributes_id = '" . (int)$attribute_id . "'");

 

 

###########################################################

Find

 

		<td><form name="attributes" action="<?php echo tep_href_link(FILENAME_PRODUCTS_ATTRIBUTES, 'action=' . $form_action . '&option_page=' . $option_page . '&value_page=' . $value_page . '&attribute_page=' . $attribute_page); ?>" method="post"><table border="0" width="100%" cellspacing="0" cellpadding="2">
	  <tr>
		<td colspan="7" class="smallText">

 

 

Change to:

 

		<td><form name="attributes" action="<?php echo tep_href_link(FILENAME_PRODUCTS_ATTRIBUTES, 'action=' . $form_action . '&option_page=' . $option_page . '&value_page=' . $value_page . '&attribute_page=' . $attribute_page); ?>" method="post"><table border="0" width="100%" cellspacing="0" cellpadding="2">
	  <tr>
		<td colspan="8" class="smallText">

 

 

###########################################################

Find

 

			<td colspan="7"><?php echo tep_black_line(); ?></td>
	  </tr>
<tr class="dataTableHeadingRow">
		<td class="dataTableHeadingContent"> <?php echo TABLE_HEADING_ID; ?> </td>
		<td class="dataTableHeadingContent"> <?php echo TABLE_HEADING_PRODUCT; ?> </td>
		<td class="dataTableHeadingContent"> <?php echo TABLE_HEADING_OPT_NAME; ?> </td>
		<td class="dataTableHeadingContent"> <?php echo TABLE_HEADING_OPT_VALUE; ?> </td>
		<td class="dataTableHeadingContent" align="right"> <?php echo TABLE_HEADING_OPT_PRICE; ?> </td>
		<td class="dataTableHeadingContent" align="center"> <?php echo TABLE_HEADING_OPT_PRICE_PREFIX; ?> </td>
		<td class="dataTableHeadingContent" align="center"> <?php echo TABLE_HEADING_ACTION; ?> </td>
	  </tr>
	  <tr>
		<td colspan="7"><?php echo tep_black_line(); ?></td>
	  </tr>

 

 

Change to:

 

			<td colspan="8"><?php echo tep_black_line(); ?></td>
	  </tr>
<tr class="dataTableHeadingRow">
		<td class="dataTableHeadingContent"> <?php echo TABLE_HEADING_ID; ?> </td>
		<td class="dataTableHeadingContent"> <?php echo TABLE_HEADING_PRODUCT; ?> </td>
		<td class="dataTableHeadingContent"> <?php echo TABLE_HEADING_OPT_NAME; ?> </td>
		<td class="dataTableHeadingContent"> <?php echo TABLE_HEADING_OPT_VALUE; ?> </td>
		<td class="dataTableHeadingContent" align="center"> <?php echo TABLE_HEADING_OPT_CODE_SUFFIX; ?> </td>
		<td class="dataTableHeadingContent" align="right"> <?php echo TABLE_HEADING_OPT_PRICE; ?> </td>
		<td class="dataTableHeadingContent" align="center"> <?php echo TABLE_HEADING_OPT_PRICE_PREFIX; ?> </td>
		<td class="dataTableHeadingContent" align="center"> <?php echo TABLE_HEADING_ACTION; ?> </td>
	  </tr>
	  <tr>
		<td colspan="8"><?php echo tep_black_line(); ?></td>
	  </tr>

 

 

###########################################################

Find

 

<td align="right" class="smallText"> <input type="text" name="value_price" value="<?php echo 

$attributes_values['options_values_price']; ?>" size="6"> </td>
		<td align="center" class="smallText"> <input type="text" name="price_prefix" value="<?php echo 

$attributes_values['price_prefix']; ?>" size="2"> </td>

 

 

Change to:

 

<td align="center" class="smallText"> <input type="text" name="code_suffix" value="<?php echo 

$attributes_values['code_suffix']; ?>" size="6"> </td>
<td align="right" class="smallText"> <input type="text" name="value_price" value="<?php echo 

$attributes_values['options_values_price']; ?>" size="6"> </td>
		<td align="center" class="smallText"> <input type="text" name="price_prefix" value="<?php echo 

$attributes_values['price_prefix']; ?>" size="2"> </td>

 

 

#############################################################

Find

 

<td class="smallText"> <b><?php echo $attributes_values["products_attributes_id"]; ?></b> </td>
		<td class="smallText"> <b><?php echo $products_name_only; ?></b> </td>
		<td class="smallText"> <b><?php echo $options_name; ?></b> </td>
		<td class="smallText"> <b><?php echo $values_name; ?></b> </td>
		<td align="right" class="smallText"> <b><?php echo $attributes_values["options_values_price"]; ?></b> </td>
		<td align="center" class="smallText"> <b><?php echo $attributes_values["price_prefix"]; ?></b> </td>

 

 

Change to:

 

<td class="smallText"> <b><?php echo $attributes_values["products_attributes_id"]; ?></b> </td>
		<td class="smallText"> <b><?php echo $products_name_only; ?></b> </td>
		<td class="smallText"> <b><?php echo $options_name; ?></b> </td>
		<td class="smallText"> <b><?php echo $values_name; ?></b> </td>
		<td align="center" class="smallText"> <b><?php echo $attributes_values["code_suffix"]; ?></b> </td>
		<td align="right" class="smallText"> <b><?php echo $attributes_values["options_values_price"]; ?></b> </td>
		<td align="center" class="smallText"> <b><?php echo $attributes_values["price_prefix"]; ?></b> </td>

 

 

#############################################################

Find

 

<td class="smallText"> <?php echo $attributes_values["products_attributes_id"]; ?> </td>
		<td class="smallText"> <?php echo $products_name_only; ?> </td>
		<td class="smallText"> <?php echo $options_name; ?> </td>
		<td class="smallText"> <?php echo $values_name; ?> </td>
		<td align="right" class="smallText"> <?php echo $attributes_values["options_values_price"]; ?> </td>
		<td align="center" class="smallText"> <?php echo $attributes_values["price_prefix"]; ?> </td>

 

 

Change to:

 

<td class="smallText"> <?php echo $attributes_values["products_attributes_id"]; ?> </td>
		<td class="smallText"> <?php echo $products_name_only; ?> </td>
		<td class="smallText"> <?php echo $options_name; ?> </td>
		<td class="smallText"> <?php echo $values_name; ?> </td>
		<td align="center" class="smallText"> <?php echo $attributes_values["code_suffix"]; ?> </td>
		<td align="right" class="smallText"> <?php echo $attributes_values["options_values_price"]; ?> </td>
		<td align="center" class="smallText"> <?php echo $attributes_values["price_prefix"]; ?> </td>

 

 

#############################################################

Find

 

 

  if ($action != 'update_attribute') {
?>
	  <tr>
		<td colspan="7"><?php echo tep_black_line(); ?></td>
	  </tr>

 

 

Change to:

 

 

  if ($action != 'update_attribute') {
?>
	  <tr>
		<td colspan="8"><?php echo tep_black_line(); ?></td>
	  </tr>

 

 

#############################################################

Find

 

</select> </td>
		<td align="right" class="smallText"> <input type="text" name="value_price" size="6"> </td>
		<td align="right" class="smallText"> <input type="text" name="price_prefix" size="2" value="+"> </td>
		<td align="center" class="smallText"> <?php echo tep_image_submit('button_insert.gif', IMAGE_INSERT); 

?> </td>
	  </tr>

 

 

Change to:

 

</select> </td>
		<td align="center" class="smallText"> <input type="text" name="code_suffix" size="6" value="+"> </td>
		<td align="right" class="smallText"> <input type="text" name="value_price" size="6"> </td>
		<td align="right" class="smallText"> <input type="text" name="price_prefix" size="2" value="+"> </td>
		<td align="center" class="smallText"> <?php echo tep_image_submit('button_insert.gif', IMAGE_INSERT); 

?> </td>
	  </tr>

 

 

#############################################################

Find

 

 <tr>
		<td colspan="7"><?php echo tep_black_line(); ?></td>
	  </tr>
	</table></form></td>
  </tr>
</table></td>
<!-- products_attributes_eof //-->

 

 

Change to:

 

 

 <tr>
		<td colspan="8"><?php echo tep_black_line(); ?></td>
	  </tr>
	</table></form></td>
  </tr>
</table></td>
<!-- products_attributes_eof //-->

 

 

#############################################################

 

*********** In catalog/admin/includes/languages/english/products_attributes.php **************

 

 

Find

 

define('TABLE_HEADING_OPT_PRICE', 'Value Price');
define('TABLE_HEADING_OPT_PRICE_PREFIX', 'Prefix');

 

 

Change to:

 

define('TABLE_HEADING_OPT_CODE_SUFFIX', 'Code Suffix');
define('TABLE_HEADING_OPT_PRICE', 'Value Price');
define('TABLE_HEADING_OPT_PRICE_PREFIX', 'Prefix');

 

 

#############################################################

In your database run the following SQL Statement

 

ALTER TABLE `products_attributes` ADD `code_suffix` char(11) NOT NULL default '' AFTER `options_values_id`;

 

 

 

Now all I have to do is work out how to display this new product code suffix after my standard product code when viewing the shopping cart etc..

Also when viewing the product listings it would be nice to display the product code with the default attribute code suffix added if any.

 

Also if you notice anything I've missed in the above code or errors then please let me know..

 

AND if you are good with php / OsCommerce and you know the best way to adding the code suffix to my shopping cart and product listings etc then please dont hesitiate to give me a few hints..

 

Cheers

Link to comment
Share on other sites

i.e

 

Anywhere where a product [model] appears I need [model]


for instance in catalog/admin/invoice.php
(also appears in order.php and packingslip.php)

it has the line

[code]<td class="dataTableContent" valign="top">' . $order->products[$i]['model'] . '</td>' . "\n";

 

now how would I bring the code suffix in and add it to the end of the model code?

 

Do I need to alter any classes etc?

 

This is the part where I get stuck when I need to bring things in from a database and display them how Id like..

 

All help would be much appreciated..

 

Thanks in advance..

 

P.S also need it in the email order confirmation that is sent to the customer

Link to comment
Share on other sites

The following is my orders class in admin/includes/classes/order.php

 

$index = 0;
  $orders_products_query = tep_db_query("select orders_products_id, products_name, products_model, products_price, products_tax, products_quantity, final_price from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$order_id . "'");
  while ($orders_products = tep_db_fetch_array($orders_products_query)) {
	$this->products[$index] = array('qty' => $orders_products['products_quantity'],
									'name' => $orders_products['products_name'],
									'model' => $orders_products['products_model'],
									'tax' => $orders_products['products_tax'],
									'price' => $orders_products['products_price'],
									'final_price' => $orders_products['final_price']);

	$subindex = 0;
	$attributes_query = tep_db_query("select products_options, products_options_values, options_values_price, price_prefix from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$order_id . "' and orders_products_id = '" . (int)$orders_products['orders_products_id'] . "'");
	if (tep_db_num_rows($attributes_query)) {
	  while ($attributes = tep_db_fetch_array($attributes_query)) {
		$this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options'],
																 'value' => $attributes['products_options_values'],
																 'prefix' => $attributes['price_prefix'],
																 'price' => $attributes['options_values_price']);

 

Would I need to change the query in this also? say to the following:

 

$attributes_query = tep_db_query("select products_options, products_options_values, code_suffix, options_values_price, price_prefix from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$order_id . "' and orders_products_id = '" . (int)$orders_products['orders_products_id'] . "'");
	if (tep_db_num_rows($attributes_query)) {
	  while ($attributes = tep_db_fetch_array($attributes_query)) {
		$this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options'],
																 'value' => $attributes['products_options_values'],
																 'prefix' => $attributes['code_suffix'],
																 'prefix' => $attributes['price_prefix'],
																 'price' => $attributes['options_values_price']);

Link to comment
Share on other sites

ok I changed my invoice code to:

 

<td class="dataTableContent" valign="top">' . $order->products[$i]['model']['suffix'] . '</td>' . "\n";

 

And in my orders class I made the following chage to the attributes query

 

$attributes_query = tep_db_query("select products_options, products_options_values, code_suffix, options_values_price, price_prefix from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$order_id . "' and orders_products_id = '" . (int)$orders_products['orders_products_id'] . "'");
	if (tep_db_num_rows($attributes_query)) {
	  while ($attributes = tep_db_fetch_array($attributes_query)) {
		$this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options'],
																 'value' => $attributes['products_options_values'],
																 'suffix' => $attributes['code_suffix'],
																 'prefix' => $attributes['price_prefix'],
																 'price' => $attributes['options_values_price']);

 

But when I go to view my invoice I get the following arror

 

1054 - Unknown column 'code_suffix' in 'field list'

select products_options, products_options_values, code_suffix, options_values_price, price_prefix from orders_products_attributes where orders_id = '7' and orders_products_id = '12'

[TEP STOP]

Link to comment
Share on other sites

DUH,

 

Silly oversight of me.. forgot to add the following SQL statement:

 

ALTER TABLE `orders_products_attributes` ADD `code_suffix` char(11) NOT NULL default '' AFTER `products_options_values`;

 

Ok so does anyone know to get my attributes suffix code to be displayed next to the product code in say invoice..

 

ie

 

<td class="dataTableContent" valign="top">' . $order->products[$i]['model']***need my suffix here*** . '</td>' . "\n";

 

Im completely at a loss now and at the end of my limited skills.

 

Any help please..

 

how about pretty please.

Link to comment
Share on other sites

Come on guys and girls, i thought the last bit would be easy for someone to say "hey, dummy all you gotta do it put this code in there."

 

 

******goes to find a teach yourself php book********

Link to comment
Share on other sites

OK,

 

With much much help from Velveeta aka Richard I was able to get this accomplished.

 

You can now have a base code for a product and a following suffix code for each additional attribute.

 

The attribute suffix codes are also given a sort option :P

 

so now you can have the following:

 

Apple: AP1

green apple: AP1/G

large apple: AP1/L

large green apple: AP1/G-L (if there are two attributes selected the sort option wil allow you to select which way round they should be, either AP1/G-L or AP1/L-G etc)

 

Ill put a step by step guide on how to do this along with the modified stock MS2 files for unmodified stores in the contribution section tomorrow.

 

As for now, I've got to make the girlfiend happy. It is valentines after all.

 

Hope this helps all the people who need different codes for products with attributes without having to make totaly seperate products for each one.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...