here are some tips on how add more fields to your product information/dashboard table using the wp-ecommerce plugin for wordpress. first thing to do is back up all your store files and your database. in this sample, let's try to think we are selling some gemstones. and we will adding fields like...'stone weight', 'stone color', 'stone shape'.. etc..
before we start coding, we must add some tables on our database first. we are going to use phpMyAdmin in this case. most of the time you'll find phpMyAdmin on cpanel of your host.
find 'wp_wpsc_product_list' in the tables list and go to its structure and then add your desired fields for your items... i have these...
now lets go over the codes.. on the file wpsc-admin/includes/display-items-function.php find the lines below and add your fields again... it should be the same on what you have put on your database table...
$wpsc_product_defaults =array (
'id' => '0',
'name' => '',
'description' => '',
'additional_description' => '',
'stone_weight' => '',
'stone_shape' => '',
'stone_colour' => '',
'stone_clarity' => '',
..... ..... more fields here ..... 'stone_dimension2' => '',
'price' => '0.00',
'weight' => '0',
'weight_unit' => 'pound',
then on the same file (display-items-function.php).... find these lines
<tr>
<td class='itemfirstcol' colspan='2'>
<div style='display: none'>
<strong ><?php echo __('Additional Description', 'wpsc'); ?>:</strong><br />
<textarea name='additional_description' id='additional_description' cols='40' rows='5' ><?php echo stripslashes($product_data['additional_description']); ?></textarea>
</div>
</td>
</tr>
and below or above add your own codes like this...
<tr>
<td class='itemfirstcol'>
<strong ><?php echo __('Weight', 'wpsc'); ?> :</strong><br />
</td>
<td class='itemfirstcol1'>
<input type='text' class='text' size='17' name='stone_weight' value='<?php echo $product_data['stone_weight']; ?>' /> ct
</td>
</tr>
<tr>
<td class='itemfirstcol'>
<strong ><?php echo __('Shape', 'wpsc'); ?> :</strong><br />
</td>
<td class='itemfirstcol1'>
<input type='text' class='text' size='17' name='stone_shape' value='<?php echo $product_data['stone_shape']; ?>' />
</td>
</tr>
.......... compelete the rest of your input box.....the output would be similar to this if you go add or edit product
the next file you are going to edit is the wpsc-admin/includes/product-function.php. just find the this line and add your fields again similar to what you have input on the 'wp_wpsc_product_list' table
$product_columns = array(
'name' => '',
'description' => '',
'additional_description' => '',
'stone_weight' => '',
'stone_shape' => '',
'stone_colour' => '',
'stone_clarity' => '',
'stone_treatment' => '',
.....
..... more of your fields here
.....
'price' => null,
'weight' => null,
'weight_unit' => '',then we are going to edit is wpsc-admin/ajax-and-init.php. find this line around 695 and insert your codes like so -
$sql = " INSERT INTO ".WPSC_TABLE_PRODUCT_LIST."( `name` , `description` , `additional_description` , `stone_weight` , `stone_shape` , `stone_colour` , `stone_clarity` , `stone_treatment` , `stone_certificate` , `ect............` , `price` , `weight` , `weight_unit` , `pnp` , `international_pnp` , `file` , `image` , `quantity_limited` , `quantity` , `special` , `special_price` , 0`display_frontpage` , `notax` , `active` , `publish`, `donation` , `no_shipping` , `thumbnail_image` , `thumbnail_state` ) SELECT `name` , `description` , `additional_description` , `stone_weight` , `stone_shape` , `stone_colour` , `stone_clarity` , `stone_treatment` , `stone_certificate` , `ect............` , `price` , `weight` , `weight_unit` , `pnp` , `international_pnp` , `file` , `image` , `quantity_limited` , `quantity` , `special` , `special_price` , `display_frontpage` , `notax` , `active` , `publish`, `donation` , `no_shipping` , `thumbnail_image` , `thumbnail_state` FROM ".WPSC_TABLE_PRODUCT_LIST." WHERE id = '".$product_id."' ";
and the last file you are going to edit is wpcs-includes/processing.functions.php. find the function
function wpsc_add_product($product_values)and insert your codes
$insertsql .= "`description` = '".$wpdb->escape($product_values['description'])."',";
$insertsql .= "`additional_description` = '".$wpdb->escape($product_values['additional_description'])."',";
$insertsql .= "`stone_weight` = '".$wpdb->escape($product_values['stone_weight'])."',";
$insertsql .= "`stone_shape` = '".$wpdb->escape($product_values['stone_shape'])."',";
$insertsql .= "`stone_colour` = '".$wpdb->escape($product_values['stone_colour'])."',";
$insertsql .= "`stone_clarity` = '".$wpdb->escape($product_values['stone_clarity'])."',";
$insertsql .= "`stone_treatment` = '".$wpdb->escape($product_values['stone_treatment'])."',";
.....
..... more of the fields here
.....
now the question is... how are you going to display that on your product-page. you have to add some codes to wpsc_query.php and grid_view.php/single_product.php
on the wpsc-includes/wpcs_query.php, you can several of this functions..
// weight
function wpsc_the_product_stone_weight() {
global $wpsc_query;
return $wpsc_query->product['stone_weight'];
}
// shape
function wpsc_the_product_stone_shape() {
global $wpsc_query;
return $wpsc_query->product['stone_shape'];
}
// colour
function wpsc_the_product_stone_colour() {
global $wpsc_query;
return $wpsc_query->product['stone_colour'];
}
and lastly on your grid_view.php or single_product.php call these functions you made on wpsc_query.php inside the loop like this one...<?php echo wpsc_the_product_stone_weight(); ?>
here is my output:
0 comments:
Post a Comment