Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Multi-Product Update v1.00 Revitalised


MatthewRitchie

Recommended Posts

Multi-Product Update v1.00

 

http://www.oscommerce.com/community/contributions,2415

 

I have put quite a bit of work into reworking this contribution and adding some new features and fixing old ones...

 

However, just after I uploaded it I found a serious bug!!!!!

 

WARNING:

 

when you hit 'update' submit button, field data is eatten up and lost from the database. I will work on it futher but...

 

WARNING

 

use only with a practice/development osc shop copy, one which you dont mind if data is lost! ALWAYS uesfull to have at one side...

 

I have 12+ ;o)

 

Any way, I have left all previous reworked files in the contribution zip numbered from [1] to [15]

 

file [15] is the latest and not quite working file so heed the WARNING above.

 

the other files are in various states of undress so to speak.

 

 

 

OH, much horrid junk has been cleared from the previous upload. BOY did it cause serious square eyes and pounding heads...

 

I have also heavilly commented the file and rearranged the 'HOUSE' style to make it easier to read..

 

many Thanks for now

 

Matthew John Ritchie

 

www.bluegreenenterprises.com --- see demo (no admin access at present otherwise you could see my secret bits) ;o) teehee.

Link to comment
Share on other sites

NOTE:

 

IMAGE included in zip

 

the files in zip are numbered 1 - 15

 

it is best to upload all to the test site and adjust the address bar url appropriately for each file.

 

as you will see with my method of programming all external data such as the header names as defined in the language folder is within this one file.

all files relate back to themselves! no external filename defined pointer needed.

 

Oh you could use something like a link table in admin to help you navigate through each test run

 

please see the '''new links''' file in zip as a demo - write your own...

 

THUS each product_updates[xx].php is compleatly STAND ALONE so it is easy to edit quickly etc

the only requirements are for admin includes application top to be correctly referenced so you can have access to functions

 

this will be fine if these files reside in the admin folder....

 

;o)

 

matt - going pubbing now -_- -_- -_- zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

Edited by MatthewRitchie
Link to comment
Share on other sites

Right - discovered why product data is being lost:

 

product_updates[15].php when run in admin allows you to show or hide columbs by clicking an icon like you would with the product status.

 

when a particular column is hidden and the update button is hit, when you un-hide that column again all the results are zeroed.

 

i.e. hiding product prices column, click update, unhide prices and they will be zero.

 

I think i know where the problem is:

 

in the code above the doctype there is a check to update only those items,textboxes that have changed.

 

when a column is hidden this code is still looking for that column data, if it is not found then the code assumes that the data is actually zero because the post array contains no update data

 

therefore all the product details are subsequently updated with prices at zero. OUCH!!!

 

when hiding certain columns i have built a new database table such as:

 

CREATE TABLE IF NOT EXISTS `multi_product_update` (
 `mpu_col_id` int(5) NOT NULL auto_increment,
 `mpu_col_name` varchar(15) NOT NULL,
 `mpu_col_display_name` varchar(30) NOT NULL,
 `mpu_col_status` tinyint(1) NOT NULL,
 PRIMARY KEY  (`mpu_col_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=13;

--
-- Dumping data for table `multi_product_update`
--

INSERT INTO `multi_product_update` (`mpu_col_id`, `mpu_col_name`, `mpu_col_display_name`, `mpu_col_status`) VALUES
(1, 'id', 'ID', 1),
(3, 'manuf', 'Manufacturer', 0),
(4, 'name', 'Name', 1),
(5, 'status', 'Status', 1),
(6, 'image', 'Image Path/Filename', 1),
(7, 'model', 'Model', 1),
(8, 'weight', 'Weight', 1),
(9, 'price', 'Price', 1),
(10, 'qty', 'Qty', 1),
(11, 'idvshp', ' Idv. Product Shiping Price', 1),
(12, 'modif', 'Date Last Modified', 0);

 

to hide table elements/columns i do a quick db scan on the above like so:

 

<?php

$sql_coloumns 	= "SELECT * FROM multi_product_update";
$col_result	= tep_db_query($sql_coloumns);

$column_detials = array();

while ($show_col = tep_db_fetch_array($col_result)) {

$col_id			= $show_col['mpu_col_id'];
$col_name		= $show_col['mpu_col_name'];
$col_display_name	= $show_col['mpu_col_display_name'];
$col_status		= $show_col['mpu_col_status'];

echo $col_display_name . ' ';
COL_status_icons($col_id, $col_status, $query_string_parameters);
$column_details[$col_name] = $col_status;

}
?>

 

this results in the array:

 

COLUMN DETAILS

Array

(

[id] => 1

[manuf] => 1

[name] => 1

[status] => 1

[image] => 1

[model] => 1

[weight] => 1

[price] => 1

[qty] => 1

[idvshp] => 1

[modif] => 1

)

 

to hide columns i do:

 

by the way td open / close are:

 define('TD_OPEN', 	  '<td class="dataTableContent" width=1%>');
 define('TD_CLOSE', 	  '</td>');
 define('TD_OPEN_H',  '<td class="dataTableHeadingContent" align="center" width=1%>');

	if( $column_details['id'] 	== 1){ 	echo TD_OPEN_H . TABLE_HEADING_PRODUCT_ID 	. TD_CLOSE; }
	if( $column_details['manuf'] 	== 1){ 	echo TD_OPEN_H . TABLE_HEADING_PMAN 		. TD_CLOSE; }
	if( $column_details['name'] 	== 1){ 	echo TD_OPEN_H . TABLE_HEADING_PNAME 	. TD_CLOSE; }
	if( $column_details['status'] 	== 1){ 	echo TD_OPEN_H . TABLE_HEADING_STATUS 	. TD_CLOSE; }
	if( $column_details['image'] 	== 1){ 	echo TD_OPEN_H . 'Path Image/Filename' 		. TD_CLOSE; }
	if( $column_details['model'] 	== 1){ 	echo TD_OPEN_H . TABLE_HEADING_PMODEL 	. TD_CLOSE; }
	if( $column_details['weight'] 	== 1){ 	echo TD_OPEN_H . TABLE_HEADING_PWEIGHT 	. TD_CLOSE; }
	if( $column_details['price'] 	== 1){ 	echo TD_OPEN_H . TABLE_HEADING_PPRICE 	. TD_CLOSE; }
	if( $column_details['qty'] 	== 1){ 	echo TD_OPEN_H . TABLE_HEADING_PQTY 		. TD_CLOSE; }
	if( $column_details['idvshp'] 	== 1){ 	echo TD_OPEN_H . '£ INDVSHP' 			. TD_CLOSE; }
	if( $column_details['modif'] 	== 1){ 	echo TD_OPEN_H . TABLE_HEADING_PDATE 	. TD_CLOSE; }

 

now the problem code above dock type is:

 

action = update

foreach ($_POST['event_record'] as $id => $row) {

// converting date_in_seconds into mysql date
$seconds_in_date = date("Y-m-d H:i:s", $date_in_seconds); 

############################################
#						#
#	Get all products first to make sure we are		#
#	not updating products that did not change		#
#						#
############################################

$products_query = tep_db_query("SELECT * from " . TABLE_PRODUCTS);
$products = array();

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

	$products[$product['products_id']] = array(

		'products_id' 	=> $product['products_id'],
		'products_price' 	=> number_format($product['products_price'], 2, '.', ''),
		'products_weight' 	=> number_format($product['products_weight'], 2, '.', ''),
		'products_quantity' 	=> number_format($product['products_quantity'], 0,'.', ''),
		'products_model' 	=> $product['products_model'],
		'products_image' 	=> $product['products_image'],
		'products_status' 	=> $product['products_status'],
		'products_ship_price' 	=> $product['products_ship_price']
	);

} // END WHILE


###################################################
#							#
#	strcasecmp — Binary safe case-insensitive string comparison	#
#							#
#	str1 - The first string					#
#	str2 - The second string				#
#							#
#	Returns						#
#		< 0 if str1 is less than str2			#
#		> 0 if str1 is greater than str2			#
#		and 0 if they are equal.			#
#							#
#	NOTE:	|| = OR					#
#	E.G.	if( A != 0 OR B != 0 OR c != 0) then do { UPDATE }.	#
#							#
###################################################

if( 
	strcasecmp($products[$row['products_id']]['products_price']	,$row['products_price']) 	!= 0 || 
	strcasecmp($products[$row['products_id']]['products_model']	,$row['products_model']) 	!= 0 || 
	strcasecmp($products[$row['products_id']]['products_weight']	,$row['products_weight']) 	!= 0 || 
	strcasecmp($products[$row['products_id']]['products_quantity']	,$row['products_quantity']) 	!= 0 ||
	strcasecmp($products[$row['products_id']]['products_image']	,$row['products_image']) 	!= 0 ||
	strcasecmp($products[$row['products_id']]['products_status']	,$row['products_status']) 	!= 0 || 
	strcasecmp($products[$row['products_id']]['products_ship_price']	,$row['products_ship_price'])	!= 0
) {

############################################
#						#
#	UPDATE QUERY				#
#						#
############################################

tep_db_query(	

	"UPDATE " 
	. TABLE_PRODUCTS 
	. " SET "
	. "products_price = '" 		. $row['products_price'] 	. "', " 
	. "products_model = '" 	. $row['products_model'] 	. "', " 
	. "products_weight = '" 	. $row['products_weight'] 	. "', " 
	. "products_quantity = '" 	. $row['products_quantity'] 	. "', " 
	. "products_image = '" 	. $row['products_image'] 	. "', " 
	. "products_status = '" 	. $row['products_status'] 	. "', "
	. "products_ship_price = '" 	. $row['products_ship_price'] 	. "', "
	. "products_last_modified = '" 	. $seconds_in_date 		. "'  " 
	. "where " 
	. "products_id = '" 		. $row['products_id'] 		. "'"

); // END UPDATE QUERY

$products_updated = true;

} // END IF strcasecmp

$date_in_seconds++;


} // END FOREACH POST EVENT RECORD

 

the piece that is of most interest is:

 

	if( 
	strcasecmp($products[$row['products_id']]['products_price']	,$row['products_price']) 	!= 0 || 
	strcasecmp($products[$row['products_id']]['products_model']	,$row['products_model']) 	!= 0 || 
	strcasecmp($products[$row['products_id']]['products_weight']	,$row['products_weight']) 	!= 0 || 
	strcasecmp($products[$row['products_id']]['products_quantity']	,$row['products_quantity']) 	!= 0 ||
	strcasecmp($products[$row['products_id']]['products_image']	,$row['products_image']) 	!= 0 ||
	strcasecmp($products[$row['products_id']]['products_status']	,$row['products_status']) 	!= 0 || 
	strcasecmp($products[$row['products_id']]['products_ship_price']	,$row['products_ship_price'])	!= 0
) {

 

and:

 

	tep_db_query(	

	"UPDATE " 
	. TABLE_PRODUCTS 
	. " SET "
	. "products_price = '" 		. $row['products_price'] 	. "', " 
	. "products_model = '" 	. $row['products_model'] 	. "', " 
	. "products_weight = '" 	. $row['products_weight'] 	. "', " 
	. "products_quantity = '" 	. $row['products_quantity'] 	. "', " 
	. "products_image = '" 	. $row['products_image'] 	. "', " 
	. "products_status = '" 	. $row['products_status'] 	. "', "
	. "products_ship_price = '" 	. $row['products_ship_price'] 	. "', "
	. "products_last_modified = '" 	. $seconds_in_date 		. "'  " 
	. "where " 
	. "products_id = '" 		. $row['products_id'] 		. "'"

); // END UPDATE QUERY

 

because when a column is hidden and update clicked i need to remove that column strcasecmp and update info is it is left unaffected.....

 

any suggestions would be much appreciated, however i will be pondering it for a few hours today....

 

Matthew John Ritchie

www.bluegreenenterprises.com

Link to comment
Share on other sites

I have encountered another quizical point

 

assuming you load product updates 15 a fresh (nothing added on to the get query string in address bar, and then start clicking update button:

 

ist updtae click:

 

19 Fox There's Something About Mary --- all updateable fields are blanked and zeroed. 2008-12-13 15:37:13

 

get query string === ?page=&search=&listing=

 

2nd update click:

 

nothing else affected just:

 

19 Fox There's Something About Mary --- 2008-12-13 15:37:48 (last modified datetime is changed)

 

now this continues with every next click on update

 

however when you arrange the list order products by id 1 - 27 and click update

 

23 GT Interactive The Wheel Of Time --- 2008-12-13 15:41:13

 

3rd click updATE

 

23 GT Interactive The Wheel Of Time --- 2008-12-13 15:41:56 (last modified datetime changes again)

 

this quirk continues, just the one product is updated each time update is clicked, then when a order listing shows in query string a second, third, fourth etc product looses its information.

 

 

most notably, when the entire list is ordered by the product image, each update click produces the result of removing data from one product each click.

 

a reason for this happening has not yet been ascertained

 

ANY SUGGESTIONS ARE WELCOME HERE!

 

MANY THANKS FOR NOW

 

Matthew John Ritchie

 

www.bluegreenenterprises.com

Link to comment
Share on other sites

ok partially there...

 

this is a beginning to curing the above problems:

 

the code below needs to be above the doctype and in this order so icon clicks work in the right sequence:

 

#################################################
#						#
#   SHOW/HIDE MULTI_PRODUCT_UPDATE COLUMNS	#
#						#
#################################################


// Sets the status of a product
 function set_mpu_col_status($col_id, $col_status) {
if ($col_status == '1') {
  return tep_db_query("update " . DB_TABLE_MPU . " set mpu_col_status = '1' where mpu_col_id = '" . (int)$col_id . "'");
} elseif ($col_status == '0') {
  return tep_db_query("update " . DB_TABLE_MPU . " set mpu_col_status = '0' where mpu_col_id = '" . (int)$col_id . "'");
} else {
  return -1;
}
 }


 if (isset($_GET['action']) && ($_GET['action'] == 'COL')) {
set_mpu_col_status($_GET['ID'], $_GET['ST']);
 }


#################################################
#						#
#	MPU COLUMN STATUS ICON			#
#						#
#################################################

 function COL_status_icons($id = '', $status = '', $parameters = ''){

if ($status == '1') {
	echo  '<a href="' . tep_href_link(FILENAME_PRODUCT_UPDATES, 	'action=COL&ST=0&ID=' . $id .'&'. $parameters, 'NONSSL') . '">' 
	. tep_image(DIR_WS_IMAGES . 'icon_status_green.gif', 'Deactivate', 10, 10) . '</a>' . '   ';
} else {
	echo '<a href="' . tep_href_link(FILENAME_PRODUCT_UPDATES, 	'action=COL&ST=1&ID=' . $id .'&'. $parameters, 'NONSSL') . '">' 
	. tep_image(DIR_WS_IMAGES . 'icon_status_red.gif', 'Activate', 10, 10) . '</a>' . '   ';
}
 }



$sql_coloumns 	= "SELECT * FROM multi_product_update";
$col_result	= tep_db_query($sql_coloumns);
$show_col 	= tep_db_fetch_array($col_result);

$column_detials = array();

do {

$col_id			= $show_col['mpu_col_id'];
$col_name		= $show_col['mpu_col_name'];
$col_display_name	= $show_col['mpu_col_display_name'];
$col_status		= $show_col['mpu_col_status'];

$column_details[$col_name]['id'] 	= $col_id;
$column_details[$col_name]['name'] 	= $col_name;
$column_details[$col_name]['disname'] 	= $col_display_name;
$column_details[$col_name]['status'] 	= $col_status;

$show_col = tep_db_fetch_array($col_result);

}while($show_col);

 

 

now below in the main page you need:

 

<tr>
<td>
<?php

?>

<br><br>

<?PHP
foreach($column_details as $key => $value){
	echo $column_details[$key]['disname'].' ';
COL_status_icons($column_details[$key]['id'], $column_details[$key]['status'], $query_string_parameters);
}
?>

<br><br>

<?php // echo 'COLUMN DETAILS<PRE>'; print_r($column_details); echo '</PRE>'; ?>
<?php // echo 'POST <PRE>'; print_r($_POST); echo '</PRE>'; ?>
<?php // echo 'GET<PRE>'; print_r($_GET); echo '</PRE>'; ?>

</td>
</tr>

 

sorry it looks horrid at the moment.

 

the reason for this is to get the column details array above the code that checks for updates then does only the updates needed.

why? Ah well this is so that the array details can be used to '''turn off''' certain parts of the updates code so it doesnt try to update any columns that are not actuall present on the screen.

 

lol teehee square eyes and all that melarky......

 

unfortunately i have not got round to editing the updates code yet --- also there is beginning to be a heck of a lot of repetition in this array checking '''fun''' which could be placed in a function but still that is a little way off.

 

MATTHEWJOHNRITCHIE

bluegreenenterprises.com

Link to comment
Share on other sites

Ok - first issue mostly resolved, that was the zeroing of columns that were hidden

 

latest edition in product_updates[19].php, --- there is an echo statement at line 308 [[[echo $sql_do_update . '<BR>' . $query_string_parameters;]]]

 

that throughs up the error:

 

UPDATE products SET products_price = '', products_model = '', products_weight = '', products_quantity = '', products_image = '', products_status = '1', products_ship_price = '', products_last_modified = '2008-12-14 15:11:37' where products_id = '19'

action=update&ST=1&ID=7&

Warning: Cannot modify header information - headers already sent by (output started at /home/bluegree/public_html/OSC_TEST_GCO_GCODEv145a/rc1_GCOv145a/admin/product_updates[19].php:308) in /home/bluegree/public_html/OSC_TEST_GCO_GCODEv145a/rc1_GCOv145a/admin/includes/functions/general.php on line 22

 

but by commenting this out you can avoid this error message.

 

zip contains file update from [15] to [19] but only [19] is needed.

 

remaining problem:

 

on first load, and first click of update button without editing any data one product's data is errased, you can actually see this happening in the error above to 'theres something about mary'

 

the quizical point is that it is item id/number 19 towards the bottom of the page, hence I have no idea yet why it is being picked up and changed.

 

secondly - when update button is clicked, the get query string in the url has 'listing=' amended to it. I believe this is due to the sorting arrows code but still the answer is alluding me.

 

I am looking in to the functions tep_get_all_get_params() and tep_href_output() ??? to see if i can use these purposefully to alleviate the get array parameter problems.

 

 

so for now have a look through [19] and let me know your thoughts here:

 

http://www.oscommerce.com/forums/index.php?showtopic=323536

 

Many thanks

 

MatthewJohnRitchie

bluegreenenterprises.com

Link to comment
Share on other sites

OK just happened upon a wierd quirk...

 

I currently have my maximum setting for search results at 50 rows per page, i.e. to show all the products on one page.

 

now, if i reduce this to 20 as it was origionally, most of the problems seem to vanish BUT...

 

back at 50 results per page I have noticed that depending on the sorting order, it is predominately the 23rd item in the list that is errased.

 

Oh and new released version i am now at is number [21].

Link to comment
Share on other sites

I am now fully convinced that (I AM GOING BONKERS) and that the above statement is accurate

 

my assumptions then are that because the updated item is always the 23rd on the list and that items 24 to 27 are left unaffected because the code breaks at item number 23 hence 24 to 27 are not outputed in the echo statements for print_r($products); and , print_r($row); on each loop of the foreach post[event_record]

 

i am still using 50 as my maximun for search results listing

 

this leads me to the possibile conclusion that the functions used to split the page results are causing the iritating quirks above.

 

next attempts will have the split page results removed to see what happens, however for shops with thousands of products this will result in a very long page.

 

 

WRONG

 

just tried it with split page results and associated items removed but still have item 23 losing its data each time update is hit.

 

I am thinking of giving up at this point and reverting the results listing to only 20 per page and concenterting on why all produtc items are updated with modified date when a column is missing, this shouldnt happen so there is a problem still in the code to chew on.

 

;o)

 

matthewjohnritchie

bluegreenenterprises.com

Edited by MatthewRitchie
Link to comment
Share on other sites

DAM LOST MY LAST POST AND DONT FEEL LIKE TYPING IT OUT AGAIN.

 

new release v1_6

 

features :- see for yourself

 

individual shipping prices per product code is fully commented out

 

this version will work on you store

 

do not set max search results in config to more that 22/23 that bug still exists and i dont know why

 

fully tested

 

SQL FOR DB IS IN THE FILE AT THE TOP...

 

go get it..........................

 

http://addons.oscommerce.com/info/2415

Edited by MatthewRitchie
Link to comment
Share on other sites

OH, THIS IS PROBABLE THE LAST TIME I WILL BE VISITING THIS TOPIC SO IF YOU HAVE QUESTIONS PM ME OR GOTO MY WEBSITE WHERE I MAY DO A WRITE UP AND SOME INSTRUCTIONS. ALSO THERE IS A DIRECT CONTACT PAGE FOR ME THERE.

 

ENJOY

 

MATTHEWJOHNRITHIE

BLUEGREENENTERPRISES

Link to comment
Share on other sites

  • 1 year later...

Very looks like a nice contrib. Haven't realy used it yet. But first thoughts a couple of things I think that could be better and I'll be working on it.

 


  1.  
  2. Isolate categories.
  3. Jump to isolated category.
  4. Include button for changing image.
  5. show current image
  6. Just maybe show current selected image to upload
  7. oh and upload new image
  8. maybe get some AJAX working in here.

 

If these things are done this would be truly one of the most powerful tools in OScommerce.

Link to comment
Share on other sites

  • 1 month later...

DAM LOST MY LAST POST AND DONT FEEL LIKE TYPING IT OUT AGAIN.

 

new release v1_6

 

features :- see for yourself

 

individual shipping prices per product code is fully commented out

 

this version will work on you store

 

do not set max search results in config to more that 22/23 that bug still exists and i dont know why

 

fully tested

 

SQL FOR DB IS IN THE FILE AT THE TOP...

 

go get it..........................

 

http://addons.oscommerce.com/info/2415

 

i just downloaded product_updates[22].php and where/how do i install it?

Link to comment
Share on other sites

  • 2 months later...

i just downloaded product_updates[22].php and where/how do i install it?

 

 

Rename to product_updates.php and place in catalog/admin/ to update a current install.

 

BTW, you will need to download the full package in the contribution section to perform the full install and update with this file.

 

Thanks for all the work MatthewRitchie!

Edited by bbaez
Link to comment
Share on other sites

  • 2 months later...

Hi,

 

I've been using this contribution for quite a while now but I've just realised today that everything works fine... changing, saving etc... but I'm missing some product... I should have about 810 different products and only 684 get listed. I have pages that are blank where the rest of my products should appear but I can't access them or update them. Anyone every encounter this?

 

Thanks

Link to comment
Share on other sites

  • 2 years later...

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...