PageRenderTime 118ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/wp-e-commerce/wpsc-includes/processing.functions.php

https://gitlab.com/endomorphosis/reservationtelco
PHP | 974 lines | 743 code | 138 blank | 93 comment | 224 complexity | f8acbaeb98f39618719e1025ba6b9ded MD5 | raw file
  1. <?php
  2. /**
  3. * wpsc_decrement_claimed_stock method
  4. *
  5. * @param float a price
  6. * @return string a price with a currency sign
  7. */
  8. function wpsc_decrement_claimed_stock($purchase_log_id) {
  9. global $wpdb;
  10. $all_claimed_stock = $wpdb->get_results($wpdb->prepare("SELECT * FROM `".WPSC_TABLE_CLAIMED_STOCK."` WHERE `cart_id` IN('%s') AND `cart_submitted` IN('1')", $purchase_log_id), ARRAY_A);
  11. foreach((array)$all_claimed_stock as $claimed_stock) {
  12. // for people to have claimed stock, it must have been available to take, no need to look at the existing stock, just subtract from it
  13. // If this is ever wrong, and you get negative stock, do not fix it here, go find the real cause of the problem
  14. if($claimed_stock['variation_stock_id'] > 0) {
  15. $wpdb->query($wpdb->prepare("UPDATE `".WPSC_TABLE_VARIATION_PROPERTIES."` SET `stock` = (`stock` - %s) WHERE `id` = '%d' LIMIT 1", $claimed_stock['stock_claimed'], $claimed_stock['variation_stock_id']));
  16. $sql_query = "SELECT * FROM `".WPSC_TABLE_VARIATION_PROPERTIES."` WHERE `id` = '" . $claimed_stock['variation_stock_id'] . "'";
  17. $remaining_stock = $wpdb->get_row($sql_query, ARRAY_A);
  18. $sql_query1 = "SELECT * FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id` = '" . $remaining_stock['product_id'] . "'";
  19. $product_data = $wpdb->get_row($sql_query1, ARRAY_A);
  20. if($product_data["quantity_limited"] == 1 && $remaining_stock["stock"]==0 && get_product_meta($product_data['id'],'unpublish_oos',true) == 1){
  21. $sql_query = "SELECT * FROM `".WPSC_TABLE_VARIATION_PROPERTIES."` WHERE product_id='" . $product_data['id'] . "'";
  22. $variation_data = $wpdb->get_results($sql_query, ARRAY_A);
  23. $real_stock = 0;
  24. foreach ((array)$variation_data as $possible_stock){
  25. $real_stock += $possible_stock["stock"] * $possible_stock["visibility"];
  26. }
  27. if ($real_stock == 0)
  28. {
  29. wp_mail(get_option('admin_email'), $product_data["name"] . __(' is out of stock', 'wpsc'), __('Remaining stock of ', 'wpsc') . $product_data["name"] . __(' and its variations is 0. Product was unpublished.', 'wpsc'));
  30. $wpdb->query($wpdb->prepare("UPDATE `".WPSC_TABLE_PRODUCT_LIST."` SET `publish` = '0' WHERE `id` = '%d' LIMIT 1", $product_data['id']));
  31. }
  32. else{
  33. $sql_query2 = "SELECT `".WPSC_TABLE_VARIATION_VALUES."`.`name`, `".WPSC_TABLE_VARIATION_COMBINATIONS."`.`value_id` FROM `".WPSC_TABLE_VARIATION_COMBINATIONS."` INNER JOIN `".WPSC_TABLE_VARIATION_VALUES."` ON `".WPSC_TABLE_VARIATION_COMBINATIONS."`.`value_id`=`".WPSC_TABLE_VARIATION_VALUES."`.`id` WHERE `".WPSC_TABLE_VARIATION_COMBINATIONS."`.`priceandstock_id` = '" . $remaining_stock['id'] . "'";
  34. $variation_data = $wpdb->get_row($sql_query2, ARRAY_A);
  35. wp_mail(get_option('admin_email'), $product_data["name"] . " " . $variation_data["name"] . __(' is out of stock', 'wpsc'), __('Remaining stock of ', 'wpsc') . $product_data["name"] . " " . $variation_data["name"] . __(' is 0. Product variation was set to invisible.', 'wpsc'));
  36. $wpdb->query($wpdb->prepare("UPDATE `".WPSC_TABLE_VARIATION_VALUES_ASSOC."` SET `visible` = '0' WHERE `value_id` = '%d' AND `product_id` = '%d' LIMIT 1", $variation_data['value_id'], $product_data["id"]));
  37. }
  38. }
  39. }
  40. else {
  41. $wpdb->query($wpdb->prepare("UPDATE `".WPSC_TABLE_PRODUCT_LIST."` SET `quantity` = (`quantity` - %s) WHERE `id` = '%d' LIMIT 1", $claimed_stock['stock_claimed'], $claimed_stock['product_id']));
  42. $sql_query = "SELECT * FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id` = '" . $claimed_stock['product_id'] . "'";
  43. $remaining_stock = $wpdb->get_row($sql_query, ARRAY_A);
  44. if($remaining_stock["quantity_limited"] == 1 && $remaining_stock["quantity"]==0 && get_product_meta($claimed_stock['product_id'],'unpublish_oos',true) == 1){
  45. wp_mail(get_option('admin_email'), $remaining_stock["name"] . __(' is out of stock', 'wpsc'), __('Remaining stock of ', 'wpsc') . $remaining_stock["name"] . __(' is 0. Product was unpublished.', 'wpsc'));
  46. $wpdb->query($wpdb->prepare("UPDATE `".WPSC_TABLE_PRODUCT_LIST."` SET `publish` = '0' WHERE `id` = '%d' LIMIT 1", $claimed_stock['product_id']));}
  47. }
  48. }
  49. $wpdb->query($wpdb->prepare("DELETE FROM `".WPSC_TABLE_CLAIMED_STOCK."` WHERE `cart_id` IN ('%s')", $purchase_log_id));
  50. }
  51. /**
  52. * wpsc_get_currency_symbol
  53. * @param does not receive anything
  54. * @return returns the currency symbol used for the shop
  55. */
  56. function wpsc_get_currency_symbol(){
  57. global $wpdb;
  58. $currency_type = get_option('currency_type');
  59. $wpsc_currency_data = $wpdb->get_var("SELECT `symbol` FROM `".WPSC_TABLE_CURRENCY_LIST."` WHERE `id`='".$currency_type."' LIMIT 1") ;
  60. return $wpsc_currency_data;}
  61. /**
  62. * All the code below here needs commenting and looking at to see if it needs to be altered or disposed of.
  63. * Correspondingly, all the code above here has been commented, uses the wpsc prefix, and has been made for or modified to work with the object oriented cart code.
  64. */
  65. function nzshpcrt_currency_display($price_in, $tax_status, $nohtml = false, $id = false, $no_dollar_sign = false) {
  66. global $wpdb, $wpsc_currency_data;
  67. $currency_sign_location = get_option('currency_sign_location');
  68. $currency_type = get_option('currency_type');
  69. if(count($wpsc_currency_data) < 3) {
  70. $wpsc_currency_data = $wpdb->get_row("SELECT `symbol`,`symbol_html`,`code` FROM `".WPSC_TABLE_CURRENCY_LIST."` WHERE `id`='".$currency_type."' LIMIT 1",ARRAY_A) ;
  71. }
  72. $price_out = null;
  73. $price_out = number_format($price_in, 2, '.', ',');
  74. if($wpsc_currency_data['symbol'] != '') {
  75. if($nohtml == false) {
  76. $currency_sign = $wpsc_currency_data['symbol_html'];
  77. } else {
  78. $currency_sign = $wpsc_currency_data['symbol'];
  79. }
  80. } else {
  81. $currency_sign = $wpsc_currency_data['code'];
  82. }
  83. switch($currency_sign_location) {
  84. case 1:
  85. $output = $price_out.$currency_sign;
  86. break;
  87. case 2:
  88. $output = $price_out.' '.$currency_sign;
  89. break;
  90. case 4:
  91. $output = $currency_sign.' '.$price_out;
  92. break;
  93. case 3:
  94. default:
  95. $output = $currency_sign.$price_out;
  96. break;
  97. }
  98. if($nohtml == true) {
  99. $output = "".$output."";
  100. } else {
  101. $output = "<span class='pricedisplay'>".$output."</span>";
  102. //$output = "".$output."";
  103. }
  104. if($no_dollar_sign == true) {
  105. return $price_out;
  106. }
  107. return $output;
  108. }
  109. function nzshpcrt_find_total_price($purchase_id,$country_code) {
  110. global $wpdb;
  111. if(is_numeric($purchase_id)) {
  112. $purch_sql = "SELECT * FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `id`='".$purchase_id."'";
  113. $purch_data = $wpdb->get_row($purch_sql,ARRAY_A) ;
  114. $cartsql = "SELECT * FROM `".WPSC_TABLE_CART_CONTENTS."` WHERE `purchaseid`=".$purchase_id."";
  115. $cart_log = $wpdb->get_results($cartsql,ARRAY_A) ;
  116. if($cart_log != null) {
  117. $all_donations = true;
  118. $all_no_shipping = true;
  119. foreach($cart_log as $cart_row) {
  120. $productsql= "SELECT * FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id`=".$cart_row['prodid']."";
  121. $product_data = $wpdb->get_results($productsql,ARRAY_A);
  122. $variation_sql = "SELECT * FROM `".WPSC_TABLE_CART_ITEM_VARIATIONS."` WHERE `cart_id`='".$cart_row['id']."'";
  123. $variation_data = $wpdb->get_results($variation_sql,ARRAY_A);
  124. $variation_count = count($variation_data);
  125. $price = ($cart_row['price'] * $cart_row['quantity']);
  126. if($purch_data['shipping_country'] != '') {
  127. $country_code = $purch_data['shipping_country'];
  128. }
  129. if($cart_row['donation'] == 1) {
  130. $shipping = 0;
  131. } else {
  132. $all_donations = false;
  133. }
  134. if($cart_row['no_shipping'] == 1) {
  135. $shipping = 0;
  136. } else {
  137. $all_no_shipping = false;
  138. }
  139. if(($cart_row['donation'] != 1) && ($cart_row['no_shipping'] != 1)) {
  140. $shipping = nzshpcrt_determine_item_shipping($cart_row['prodid'], $cart_row['quantity'], $country_code);
  141. }
  142. $endtotal += $shipping + $price;
  143. }
  144. if(($all_donations == false) && ($all_no_shipping == false)){
  145. if($purch_data['base_shipping'] > 0) {
  146. $base_shipping = $purch_data['base_shipping'];
  147. } else {
  148. $base_shipping = nzshpcrt_determine_base_shipping(0, $country_code);
  149. }
  150. $endtotal += $base_shipping;
  151. }
  152. if($purch_data['discount_value'] > 0) {
  153. $endtotal -= $purch_data['discount_value'];
  154. if($endtotal < 0) {
  155. $endtotal = 0;
  156. }
  157. }
  158. }
  159. return $endtotal;
  160. }
  161. }
  162. function nzshpcrt_determine_item_shipping($product_id, $quantity, $country_code) {
  163. global $wpdb;
  164. if(is_numeric($product_id) && (get_option('do_not_use_shipping') != 1) && ($_SESSION['quote_shipping_method'] == 'flatrate')) {
  165. $sql = "SELECT * FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id`='$product_id' LIMIT 1";
  166. $product_list = $wpdb->get_row($sql,ARRAY_A) ;
  167. if($product_list['no_shipping'] == 0) {
  168. //if the item has shipping
  169. if($country_code == get_option('base_country')) {
  170. $additional_shipping = $product_list['pnp'];
  171. } else {
  172. $additional_shipping = $product_list['international_pnp'];
  173. }
  174. $shipping = $quantity * $additional_shipping;
  175. } else {
  176. //if the item does not have shipping
  177. $shipping = 0;
  178. }
  179. } else {
  180. //if the item is invalid or all items do not have shipping
  181. $shipping = 0;
  182. }
  183. return $shipping;
  184. }
  185. function nzshpcrt_determine_base_shipping($per_item_shipping, $country_code) {
  186. global $wpdb, $wpsc_shipping_modules;
  187. $custom_shipping = get_option('custom_shipping_options');
  188. if((get_option('do_not_use_shipping') != 1) && (count($custom_shipping) > 0)) {
  189. if(array_search($_SESSION['quote_shipping_method'], (array)$custom_shipping) === false) {
  190. //unset($_SESSION['quote_shipping_method']);
  191. }
  192. $shipping_quotes = null;
  193. if($_SESSION['quote_shipping_method'] != null) {
  194. // use the selected shipping module
  195. $shipping_quotes = $wpsc_shipping_modules[$_SESSION['quote_shipping_method']]->getQuote();
  196. } else {
  197. // otherwise select the first one with any quotes
  198. foreach((array)$custom_shipping as $shipping_module) {
  199. // if the shipping module does not require a weight, or requires one and the weight is larger than zero
  200. if(($custom_shipping[$shipping_module]->requires_weight != true) or (($custom_shipping[$shipping_module]->requires_weight == true) and (shopping_cart_total_weight() > 0))) {
  201. $_SESSION['quote_shipping_method'] = $shipping_module;
  202. $shipping_quotes = $wpsc_shipping_modules[$_SESSION['quote_shipping_method']]->getQuote();
  203. if(count($shipping_quotes) > 0) { // if we have any shipping quotes, break the loop.
  204. break;
  205. }
  206. }
  207. }
  208. }
  209. //echo "<pre>".print_r($_SESSION['quote_shipping_method'],true)."</pre>";
  210. if(count($shipping_quotes) < 1) {
  211. $_SESSION['quote_shipping_option'] = '';
  212. }
  213. if(($_SESSION['quote_shipping_option'] == null) && ($shipping_quotes != null)) {
  214. $_SESSION['quote_shipping_option'] = array_pop(array_keys(array_slice($shipping_quotes,0,1)));
  215. }
  216. foreach((array)$shipping_quotes as $shipping_quote) {
  217. foreach((array)$shipping_quote as $key=>$quote) {
  218. if($key == $_SESSION['quote_shipping_option']) {
  219. $shipping = $quote;
  220. }
  221. }
  222. }
  223. } else {
  224. $shipping = 0;
  225. }
  226. return $shipping;
  227. }
  228. function admin_display_total_price($start_timestamp = '', $end_timestamp = '') {
  229. global $wpdb;
  230. if(($start_timestamp != '') && ($end_timestamp != '')) {
  231. $sql = "SELECT SUM(`totalprice`) FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `processed` > '1' AND `date` BETWEEN '$start_timestamp' AND '$end_timestamp'";
  232. } else {
  233. $sql = "SELECT SUM(`totalprice`) FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `processed` > '1' AND `date` != ''";
  234. }
  235. $total = $wpdb->get_var($sql);
  236. return $total;
  237. }
  238. function calculate_product_price($product_id, $variations = false, $no_special=false) {
  239. global $wpdb;
  240. if(is_numeric($product_id)) {
  241. if(is_array($variations) && (count($variations) >= 1)) {
  242. $variation_count = count($variations);
  243. $variations = array_values($variations);
  244. array_walk($variations, 'wpsc_sanitise_keys');
  245. }
  246. /// the start of the normal price determining code.
  247. if($variation_count >= 1) {
  248. // if we have variations, grab the individual price for them.
  249. $variation_ids = $wpdb->get_col("SELECT `variation_id` FROM `".WPSC_TABLE_VARIATION_VALUES."` WHERE `id` IN ('".implode("','",$variations)."')");
  250. asort($variation_ids);
  251. $all_variation_ids = implode(",", $variation_ids);
  252. $priceandstock_id = $wpdb->get_var("SELECT `priceandstock_id` FROM `".WPSC_TABLE_VARIATION_COMBINATIONS."` WHERE `product_id` = '$product_id' AND `value_id` IN ( '".implode("', '",$variations )."' ) AND `all_variation_ids` IN('$all_variation_ids') GROUP BY `priceandstock_id` HAVING COUNT( `priceandstock_id` ) = '".count($variations)."' LIMIT 1");
  253. $price = $wpdb->get_var("SELECT `price` FROM `".WPSC_TABLE_VARIATION_PROPERTIES."` WHERE `id` = '{$priceandstock_id}' LIMIT 1");
  254. } else {
  255. $product_data = $wpdb->get_row("SELECT `price`,`special`,`special_price` FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id`='".$product_id."' LIMIT 1",ARRAY_A);
  256. // echo '<span style="color:#f00;">'.print_r($product_data, true).'</span><br />'.;
  257. if(($product_data['special_price'] > 0) && (($product_data['price'] - $product_data['special_price']) >= 0) && ($no_special == false)) {
  258. $price = $product_data['price'] - $product_data['special_price'];
  259. } else {
  260. $price = $product_data['price'];
  261. }
  262. }
  263. } else {
  264. $price = false;
  265. }
  266. $price = apply_filters('wpsc_do_convert_price', $price);
  267. return $price;
  268. }
  269. function check_in_stock($product_id, $variations, $item_quantity = 1) {
  270. global $wpdb;
  271. $product_id = (int)$product_id;
  272. $item_data = $wpdb->get_row("SELECT * FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id`='{$product_id}' LIMIT 1",ARRAY_A);
  273. $item_stock = null;
  274. $variation_count = count($variations);
  275. if($variation_count > 0) {
  276. foreach($variations as $variation_id) {
  277. if(is_numeric($variation_id)) {
  278. $variation_ids[] = $variation_id;
  279. }
  280. }
  281. if(count($variation_ids) > 0) {
  282. $actual_variation_ids = $wpdb->get_col("SELECT `variation_id` FROM `".WPSC_TABLE_VARIATION_VALUES."` WHERE `id` IN ('".implode("','",$variation_ids)."')");
  283. asort($actual_variation_ids);
  284. $all_variation_ids = implode(",", $actual_variation_ids);
  285. $priceandstock_id = $wpdb->get_var("SELECT `priceandstock_id` FROM `".WPSC_TABLE_VARIATION_COMBINATIONS."` WHERE `product_id` = '{$product_id}' AND `value_id` IN ( '".implode("', '",$variation_ids )."' ) AND `all_variation_ids` IN('$all_variation_ids') GROUP BY `priceandstock_id` HAVING COUNT( `priceandstock_id` ) = '".count($variation_ids)."' LIMIT 1");
  286. $variation_stock_data = $wpdb->get_row("SELECT * FROM `".WPSC_TABLE_VARIATION_PROPERTIES."` WHERE `id` = '{$priceandstock_id}' LIMIT 1", ARRAY_A);
  287. $item_stock = $variation_stock_data['stock'];
  288. }
  289. }
  290. if($item_stock === null) {
  291. $item_stock = $item_data['quantity'];
  292. }
  293. if((($item_data['quantity_limited'] == 1) && ($item_stock > 0) && ($item_stock >= $item_quantity)) || ($item_data['quantity_limited'] == 0)) {
  294. $output = true;
  295. } else {
  296. $output = false;
  297. }
  298. return $output;
  299. }
  300. function wpsc_item_process_image($id, $input_file, $output_filename, $width = 0, $height = 0, $resize_method = 1, $return_imageid = false) {
  301. // the function for processing images, takes a product_id, input_file outout file name, height and width
  302. global $wpdb;
  303. //$_FILES['image']['tmp_name']
  304. //$_FILES['image']['name']
  305. if(preg_match("/\.(gif|jp(e)*g|png){1}$/i",$output_filename) && apply_filters( 'wpsc_filter_file', $input_file )) {
  306. //$active_signup = apply_filters( 'wpsc_filter_file', $_FILES['image']['tmp_name'] );
  307. if(function_exists("getimagesize")) {
  308. $image_name = basename($output_filename);
  309. if(is_file((WPSC_IMAGE_DIR.$image_name))) {
  310. $name_parts = explode('.',basename($image_name));
  311. $extension = array_pop($name_parts);
  312. $name_base = implode('.',$name_parts);
  313. $dir = glob(WPSC_IMAGE_DIR."$name_base*");
  314. foreach($dir as $file) {
  315. $matching_files[] = basename($file);
  316. }
  317. $image_name = null;
  318. $num = 2;
  319. // loop till we find a free file name, first time I get to do a do loop in yonks
  320. do {
  321. $test_name = "{$name_base}-{$num}.{$extension}";
  322. if(!file_exists(WPSC_IMAGE_DIR.$test_name)) {
  323. $image_name = $test_name;
  324. }
  325. $num++;
  326. } while ($image_name == null);
  327. }
  328. //exit("<pre>".print_r($image_name,true)."</pre>");
  329. $new_image_path = WPSC_IMAGE_DIR.$image_name;
  330. // sometimes rename doesn't work, if the file is recently uploaded, use move_uploaded_file instead
  331. if(is_uploaded_file($input_file)) {
  332. move_uploaded_file($input_file, $new_image_path);
  333. } else {
  334. rename($input_file, $new_image_path);
  335. }
  336. $stat = stat( dirname( $new_image_path ));
  337. $perms = $stat['mode'] & 0000775;
  338. @ chmod( $new_image_path, $perms );
  339. switch($resize_method) {
  340. case 2:
  341. if($height < 1) {
  342. $height = get_option('product_image_height');
  343. }
  344. if($width < 1) {
  345. $width = get_option('product_image_width');
  346. }
  347. break;
  348. case 0:
  349. $height = (int)null;
  350. $width = (int)null;
  351. break;
  352. case 1:
  353. default:
  354. $height = (int)get_option('product_image_height');
  355. $width = (int)get_option('product_image_width');
  356. break;
  357. }
  358. if($width < 1) {
  359. $width = 96;
  360. }
  361. if($height < 1) {
  362. $height = 96;
  363. }
  364. image_processing($new_image_path, (WPSC_THUMBNAIL_DIR.$image_name), $width, $height);
  365. // }
  366. $sql = "INSERT INTO `".WPSC_TABLE_PRODUCT_IMAGES."` (`product_id`, `image`, `width`, `height`) VALUES ('{$id}', '{$image_name}', '{$width}', '{$height}' )";
  367. $wpdb->query($sql);
  368. $image_id = (int) $wpdb->insert_id;
  369. $updatelink_sql = "UPDATE `".WPSC_TABLE_PRODUCT_LIST."` SET `image` = '".$image_id."', `thumbnail_image` = '".$thumbnail_image."' WHERE `id` = '$id'";
  370. $wpdb->query($updatelink_sql);
  371. //exit($sql.'<br />image is about to be stored in the DB<br />'.$updatelink_sql);
  372. if(function_exists('getimagesize')) {
  373. $imagetype = getimagesize(WPSC_THUMBNAIL_DIR.$image_name);
  374. update_product_meta($id, 'thumbnail_width', $imagetype[0]);
  375. update_product_meta($id, 'thumbnail_height', $imagetype[1]);
  376. }
  377. $image = $wpdb->escape($image_name);
  378. } else {
  379. $image_name = basename($output_filename);
  380. if(is_file((WPSC_IMAGE_DIR.$image_name))) {
  381. $name_parts = explode('.',basename($image_name));
  382. $extension = array_pop($name_parts);
  383. $name_base = implode('.',$name_parts);
  384. $dir = glob(WPSC_IMAGE_DIR."$name_base*");
  385. foreach($dir as $file) {
  386. $matching_files[] = basename($file);
  387. }
  388. $image_name = null;
  389. $num = 2;
  390. // loop till we find a free file name
  391. do {
  392. $test_name = "{$name_base}-{$num}.{$extension}";
  393. if(!file_exists(WPSC_IMAGE_DIR.$test_name)) {
  394. $image_name = $test_name;
  395. }
  396. $num++;
  397. } while ($image_name == null);
  398. }
  399. $new_image_path = WPSC_IMAGE_DIR.$image_name;
  400. move_uploaded_file($input_file, $new_image_path);
  401. $stat = stat( dirname( $new_image_path ));
  402. $perms = $stat['mode'] & 0000775;
  403. @ chmod( $new_image_path, $perms );
  404. $image = $wpdb->escape($image_name);
  405. }
  406. } else {
  407. $image_data = $wpdb->get_row("SELECT `id`,`image` FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id`='".(int)$id."' LIMIT 1",ARRAY_A);
  408. $image = false;
  409. }
  410. if($return_imageid == true) {
  411. return array('image_id' => $image_id, 'filename' => $image);
  412. } else {
  413. return $image;
  414. }
  415. }
  416. function old_wpsc_item_process_file($mode = 'add') {
  417. global $wpdb;
  418. $files = $wpdb->get_results("SELECT * FROM ".WPSC_TABLE_PRODUCT_FILES." ORDER BY id ASC", ARRAY_A);
  419. if (is_array($files)){
  420. foreach($files as $file){
  421. $file_names[] = $file['filename'];
  422. $file_hashes[] = $file['idhash'];
  423. }
  424. }
  425. if(apply_filters( 'wpsc_filter_file', $_FILES['file']['tmp_name'] )) {
  426. // initialise $idhash to null to prevent issues with undefined variables and error logs
  427. $idhash = null;
  428. switch($mode) {
  429. case 'edit':
  430. /* if we are editing, grab the current file and ID hash */
  431. $product_id = $_POST['prodid'];
  432. $fileid_data = $wpdb->get_results("SELECT `file` FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id` = '$product_id' LIMIT 1",ARRAY_A);
  433. case 'add':
  434. default:
  435. /* if we are adding, make a new file row and get the ID of it */
  436. $timestamp = time();
  437. $query_results = $wpdb->query("INSERT INTO `".WPSC_TABLE_PRODUCT_FILES."` ( `filename` , `mimetype` , `idhash` , `date` ) VALUES ( '', '', '', '$timestamp');");
  438. $fileid = $wpdb->get_var("SELECT LAST_INSERT_ID() FROM `".WPSC_TABLE_PRODUCT_FILES."`");
  439. break;
  440. }
  441. /* if there is no idhash, generate it */
  442. if($idhash == null) {
  443. $idhash = sha1($fileid);
  444. if($idhash == '') {
  445. // if sha1 doesnt spit an error, but doesnt return anything either (it has done so on some servers)
  446. $idhash = md5($fileid);
  447. }
  448. }
  449. // if needed, we can add code here to stop hash doubleups in the unlikely event that they shoud occur
  450. $mimetype = wpsc_get_mimetype($_FILES['file']['tmp_name']);
  451. $filename = basename($_FILES['file']['name']);
  452. if (in_array($_FILES['file']['name'],(array)$file_names)){
  453. $i=0;
  454. $new_name = $_FILES['file']['name'].".old";
  455. while(file_exists(WPSC_FILE_DIR.$new_name)){
  456. $new_name = $_FILES['file']['name'].".old_".$i;
  457. $i++;
  458. }
  459. $old_idhash_id = array_search($_FILES['file']['name'],(array)$file_names);
  460. $old_idhash = $file_hashes[$old_idhash_id];
  461. while(!file_exists(WPSC_FILE_DIR.$old_idhash)){
  462. unset($file_hashes[$old_idhash_id]);
  463. unset($file_names[$old_idhash_id]);
  464. $old_idhash_id = array_search($_FILES['file']['name'],(array)$file_names);
  465. $old_idhash = $file_hashes[$old_idhash_id];
  466. }
  467. copy(WPSC_FILE_DIR.$old_idhash, WPSC_FILE_DIR.$new_name);
  468. unlink(WPSC_FILE_DIR.$old_idhash);
  469. }
  470. if(move_uploaded_file($_FILES['file']['tmp_name'],(WPSC_FILE_DIR.$idhash))) {
  471. $stat = stat( dirname( (WPSC_FILE_DIR.$idhash) ));
  472. $perms = $stat['mode'] & 0000666;
  473. @ chmod( (WPSC_FILE_DIR.$idhash), $perms );
  474. if(function_exists("make_mp3_preview")) {
  475. if((!isset($_FILES['preview_file']['tmp_name']))) {
  476. // if we can generate a preview file, generate it (most can't due to sox being rare on servers and sox with MP3 support being even rarer), thus this needs to be enabled by editing code
  477. make_mp3_preview((WPSC_FILE_DIR.$idhash), (WPSC_PREVIEW_DIR.$idhash.".mp3"));
  478. $preview_filepath = (WPSC_PREVIEW_DIR.$idhash.".mp3");
  479. } else if(file_exists($_FILES['preview_file']['tmp_name'])) {
  480. $preview_filename = basename($_FILES['preview_file']['name']);
  481. $preview_mimetype = wpsc_get_mimetype($_FILES['preview_file']['tmp_name']);
  482. copy($_FILES['preview_file']['tmp_name'], (WPSC_PREVIEW_DIR.$preview_filename));
  483. $preview_filepath = (WPSC_PREVIEW_DIR.$preview_filename);
  484. $wpdb->query("UPDATE `".WPSC_TABLE_PRODUCT_FILES."` SET `preview` = '".$wpdb->escape($preview_filename)."', `preview_mimetype` = '".$preview_mimetype."' WHERE `id` = '$fileid' LIMIT 1");
  485. }
  486. $stat = stat( dirname($preview_filepath));
  487. $perms = $stat['mode'] & 0000666;
  488. @ chmod( $preview_filepath, $perms );
  489. }
  490. $wpdb->query("UPDATE `".WPSC_TABLE_PRODUCT_FILES."` SET `filename` = '".$wpdb->escape($filename)."', `mimetype` = '$mimetype', `idhash` = '$idhash' WHERE `id` = '$fileid' LIMIT 1");
  491. }
  492. if($mode == 'edit') {
  493. //if we are editing, update the file ID in the product row, this cannot be done for add because the row does not exist yet.
  494. $wpdb->query("UPDATE `".WPSC_TABLE_PRODUCT_LIST."` SET `file` = '$fileid' WHERE `id` = '$product_id' LIMIT 1");
  495. }
  496. return $fileid;
  497. } else {
  498. return false;
  499. }
  500. }
  501. function old_wpsc_item_reassign_file($selected_product_file, $mode = 'add') {
  502. global $wpdb;
  503. // initialise $idhash to null to prevent issues with undefined variables and error logs
  504. $idhash = null;
  505. if($mode == 'edit') {
  506. /* if we are editing, grab the current file and ID hash */
  507. $product_id = (int)$_POST['prodid'];
  508. if($selected_product_file == '.none.') {
  509. // unlikely that anyone will ever upload a file called .none., so its the value used to signify clearing the product association
  510. $wpdb->query("UPDATE `".WPSC_TABLE_PRODUCT_LIST."` SET `file` = '0' WHERE `id` = '$product_id' LIMIT 1");
  511. return null;
  512. }
  513. // if we already use this file, there is no point doing anything more.
  514. $current_fileid = $wpdb->get_var("SELECT `file` FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id` = '$product_id' LIMIT 1",ARRAY_A);
  515. if($current_fileid > 0) {
  516. $current_file_data = $wpdb->get_row("SELECT `id`,`idhash` FROM `".WPSC_TABLE_PRODUCT_FILES."` WHERE `id` = '$current_fileid' LIMIT 1",ARRAY_A);
  517. if(basename($selected_product_file) == $file_data['idhash']) {
  518. return $current_fileid;
  519. }
  520. }
  521. }
  522. $selected_product_file = basename($selected_product_file);
  523. if(file_exists(WPSC_FILE_DIR.$selected_product_file)) {
  524. $timestamp = time();
  525. $file_data = $wpdb->get_row("SELECT * FROM `".WPSC_TABLE_PRODUCT_FILES."` WHERE `idhash` IN('".$wpdb->escape($selected_product_file)."') LIMIT 1", ARRAY_A);
  526. $fileid = (int)$file_data['id'];
  527. if($fileid < 1) { // if the file does not have a database row, add one.
  528. $mimetype = wpsc_get_mimetype(WPSC_FILE_DIR.$selected_product_file);
  529. $filename = $idhash = $selected_product_file;
  530. $timestamp = time();
  531. $wpdb->query("INSERT INTO `".WPSC_TABLE_PRODUCT_FILES."` ( `filename` , `mimetype` , `idhash` , `date` ) VALUES ( '{$filename}', '{$mimetype}', '{$idhash}', '{$timestamp}');");
  532. $fileid = $wpdb->get_var("SELECT `id` FROM `".WPSC_TABLE_PRODUCT_FILES."` WHERE `date` = '{$timestamp}' AND `filename` IN ('{$filename}')");
  533. }
  534. if($mode == 'edit') {
  535. //if we are editing, update the file ID in the product row, this cannot be done for add because the row does not exist yet.
  536. $wpdb->query("UPDATE `".WPSC_TABLE_PRODUCT_LIST."` SET `file` = '$fileid' WHERE `id` = '$product_id' LIMIT 1");
  537. }
  538. }
  539. return $fileid;
  540. }
  541. function wpsc_get_mimetype($file, $check_reliability = false) {
  542. // Sometimes we need to know how useless the result from this is, hence the "check_reliability" parameter
  543. if(file_exists($file)) {
  544. if(function_exists('finfo_open') && function_exists('finfo_file')) {
  545. // fileinfo apparently works best, wish it was included with PHP by default
  546. $finfo_handle = finfo_open(FILEINFO_MIME);
  547. $mimetype = finfo_file($finfo_handle,$file);
  548. $is_reliable = true;
  549. } else if(function_exists('mime_content_type') && (mime_content_type($file) != '')) {
  550. //obsolete, but probably second best due to completeness
  551. $mimetype = mime_content_type($file);
  552. $is_reliable = true;
  553. } else {
  554. //included with plugin, uses the extention, limited and odd list, last option
  555. $mimetype_class = new mimetype();
  556. $mimetype = $mimetype_class->getType($file);
  557. $is_reliable = false;
  558. }
  559. } else {
  560. $mimetype = false;
  561. $is_reliable = false;
  562. }
  563. if($check_reliability == true) {
  564. return array('mime_type' =>$mimetype, 'is_reliable' => $is_reliable );
  565. } else {
  566. return $mimetype;
  567. }
  568. }
  569. function shopping_cart_total_weight() {
  570. global $wpdb;
  571. $cart = $_SESSION['nzshpcrt_cart'];
  572. $total_weight=0;
  573. foreach((array)$cart as $item) {
  574. $weight = array();
  575. $variations = $item->product_variations;
  576. if(count($variations) > 0) {
  577. $variation_ids = $wpdb->get_col("SELECT `variation_id` FROM `".WPSC_TABLE_VARIATION_VALUES."` WHERE `id` IN ('".implode("','",$variations)."')");
  578. asort($variation_ids);
  579. $all_variation_ids = implode(",", $variation_ids);
  580. $priceandstock_id = $wpdb->get_var("SELECT `priceandstock_id` FROM `".WPSC_TABLE_VARIATION_COMBINATIONS."` WHERE `product_id` = '".(int)$item->product_id."' AND `value_id` IN ( '".implode("', '",$variations )."' ) AND `all_variation_ids` IN('{$all_variation_ids}') GROUP BY `priceandstock_id` HAVING COUNT( `priceandstock_id` ) = '".count($variations)."' LIMIT 1");
  581. $weight = $wpdb->get_row("SELECT `weight`, `weight_unit` FROM `".WPSC_TABLE_VARIATION_PROPERTIES."` WHERE `id` = '{$priceandstock_id}' LIMIT 1", ARRAY_A);
  582. }
  583. if(($weight == null) || ($weight['weight'] == null) && ($weight['weight_unit'] == null)) {
  584. $weight=$wpdb->get_row("SELECT `weight`, `weight_unit` FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE id='{$item->product_id}'", ARRAY_A);
  585. }
  586. switch($weight['weight_unit']) {
  587. case "kilogram":
  588. $weight = $weight['weight'] / 0.45359237;
  589. break;
  590. case "gram":
  591. $weight = $weight['weight'] / 453.59237;
  592. break;
  593. case "once":
  594. case "ounce":
  595. $weight = $weight['weight'] / 16;
  596. break;
  597. default:
  598. $weight = $weight['weight'];
  599. break;
  600. }
  601. $subweight = $weight*$item->quantity;
  602. $total_weight+=$subweight;
  603. }
  604. return $total_weight;
  605. }
  606. function wpsc_convert_weights($weight, $unit) {
  607. if (is_array($weight)) {
  608. $weight = $weight['weight'];
  609. }
  610. switch($unit) {
  611. case "kilogram":
  612. $weight = $weight / 0.45359237;
  613. break;
  614. case "gram":
  615. $weight = $weight / 453.59237;
  616. break;
  617. case "once":
  618. case "ounce":
  619. $weight = $weight / 16;
  620. break;
  621. default:
  622. $weight = $weight;
  623. break;
  624. }
  625. return $weight;
  626. }
  627. function wpsc_ping() {
  628. $services = get_option('ping_sites');
  629. $services = explode("\n", $services);
  630. foreach ( (array) $services as $service ) {
  631. $service = trim($service);
  632. if($service != '' ) {
  633. wpsc_send_ping($service);
  634. }
  635. }
  636. }
  637. function wpsc_send_ping($server) {
  638. global $wp_version;
  639. include_once(ABSPATH . WPINC . '/class-IXR.php');
  640. // using a timeout of 3 seconds should be enough to cover slow servers
  641. $client = new IXR_Client($server, ((!strlen(trim($path)) || ('/' == $path)) ? false : $path));
  642. $client->timeout = 3;
  643. $client->useragent .= ' -- WordPress/'.$wp_version;
  644. // when set to true, this outputs debug messages by itself
  645. $client->debug = false;
  646. $home = trailingslashit( get_option('product_list_url') );
  647. $rss_url = get_option('siteurl')."/index.php?rss=true&amp;action=product_list";
  648. if ( !$client->query('weblogUpdates.extendedPing', get_option('blogname'), $home, $rss_url ) ) {
  649. $client->query('weblogUpdates.ping', get_option('blogname'), $home);
  650. }
  651. }
  652. function wpsc_add_product($product_values) {
  653. global $wpdb;
  654. // takes an array, inserts it into the database as a product
  655. $success = false;
  656. $insertsql = "INSERT INTO `".WPSC_TABLE_PRODUCT_LIST."` SET";
  657. $insertsql .= "`name` = '".$wpdb->escape($product_values['name'])."',";
  658. $insertsql .= "`description` = '".$wpdb->escape($product_values['description'])."',";
  659. $insertsql .= "`additional_description` = '".$wpdb->escape($product_values['additional_description'])."',";
  660. $insertsql .= "`price` = '".$wpdb->escape($product_values['price'])."',";
  661. $insertsql .= "`quantity_limited` = '".$wpdb->escape($product_values['quantity_limited'])."',";
  662. $insertsql .= "`quantity` = '".$wpdb->escape($product_values['quantity'])."',";
  663. $insertsql .= "`special` = '".$wpdb->escape($product_values['special'])."',";
  664. $insertsql .= "`special_price` = '".$wpdb->escape($product_values['special_price'])."',";
  665. $insertsql .= "`weight` = '".$wpdb->escape($product_values['weight'])."',";
  666. $insertsql .= "`weight_unit` = '".$wpdb->escape($product_values['weight_unit'])."',";
  667. $insertsql .= "`no_shipping` = '".$wpdb->escape($product_values['no_shipping'])."',";
  668. $insertsql .= "`pnp` = '".$wpdb->escape($product_values['pnp'])."',";
  669. $insertsql .= "`international_pnp` = '".$wpdb->escape($product_values['international_pnp'])."',";
  670. $insertsql .= "`donation` = '".$wpdb->escape($product_values['donation'])."',";
  671. $insertsql .= "`display_frontpage` = '".$wpdb->escape($product_values['display_frontpage'])."',";
  672. $insertsql .= "`notax` = '".$wpdb->escape($product_values['notax'])."',";
  673. $insertsql .= "`image` = '0',";
  674. $insertsql .= "`file` = '0',";
  675. $insertsql .= "`thumbnail_state` = '0' ;";
  676. //Insert the data
  677. if($wpdb->query($insertsql)) {
  678. // if we succeeded, we have a product id, we wants it for the next stuff
  679. $product_id = $wpdb->get_var("SELECT LAST_INSERT_ID() AS `id` FROM `".WPSC_TABLE_PRODUCT_LIST."` LIMIT 1");
  680. // add the tags
  681. if(function_exists('wp_insert_term')) {
  682. product_tag_init();
  683. $tags = $product_values['product_tag'];
  684. if ($tags!="") {
  685. $tags = explode(',',$tags);
  686. foreach($tags as $tag) {
  687. $tt = wp_insert_term((string)$tag, 'product_tag');
  688. }
  689. $return = wp_set_object_terms($product_id, $tags, 'product_tag');
  690. }
  691. }
  692. $image = wpsc_item_process_image($product_id, $product_values['image_path'], basename($product_values['image_path']), $product_values['width'], $product_values['height'], $product_values['image_resize']);
  693. if(($image != null)) {
  694. $wpdb->query("UPDATE `".WPSC_TABLE_PRODUCT_LIST."` SET `image` = '".$wpdb->escape($image)."' WHERE `id`='".$product_id."' LIMIT 1");
  695. }
  696. // add the product meta values
  697. if($product_values['productmeta_values'] != null) {
  698. foreach((array)$product_values['productmeta_values'] as $key => $value) {
  699. if(get_product_meta($product_id, $key) != false) {
  700. update_product_meta($product_id, $key, $value);
  701. } else {
  702. add_product_meta($product_id, $key, $value);
  703. }
  704. }
  705. }
  706. // and the custom meta values
  707. if($product_values['new_custom_meta'] != null) {
  708. foreach((array)$product_values['new_custom_meta']['name'] as $key => $name) {
  709. $value = $product_values['new_custom_meta']['value'][(int)$key];
  710. if(($name != '') && ($value != '')) {
  711. add_product_meta($product_id, $name, $value, false, true);
  712. }
  713. }
  714. }
  715. // Add the tidy url name
  716. $tidied_name = trim($product_values['name']);
  717. $tidied_name = strtolower($tidied_name);
  718. $url_name = sanitize_title($tidied_name);
  719. $similar_names = $wpdb->get_row("SELECT COUNT(*) AS `count`, MAX(REPLACE(`meta_value`, '".$wpdb->escape($url_name)."', '')) AS `max_number` FROM `".WPSC_TABLE_PRODUCTMETA."` WHERE `meta_key` IN ('url_name') AND `meta_value` REGEXP '^(".$wpdb->escape($url_name)."){1}(\d)*$' ",ARRAY_A);
  720. $extension_number = '';
  721. if($similar_names['count'] > 0) {
  722. $extension_number = (int)$similar_names['max_number']+1;
  723. }
  724. $url_name .= $extension_number;
  725. add_product_meta($product_id, 'url_name', $url_name,true);
  726. // Add the varations and associated values
  727. $variations_procesor = new nzshpcrt_variations;
  728. if($product_values['variation_values'] != null) {
  729. $variations_procesor->add_to_existing_product($product_id,$product_values['variation_values']);
  730. }
  731. if($product_values['variation_priceandstock'] != null) {
  732. $variations_procesor->update_variation_values($product_id, $product_values['variation_priceandstock']);
  733. }
  734. // Add the selelcted categories
  735. $item_list = '';
  736. if(count($product_values['category']) > 0) {
  737. foreach($product_values['category'] as $category_id) {
  738. $category_id = (int)$category_id;
  739. $check_existing = $wpdb->get_var("SELECT `id` FROM `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."` WHERE `product_id` = ".$product_id." AND `category_id` = '$category_id' LIMIT 1");
  740. if($check_existing == null) {
  741. $wpdb->query("INSERT INTO `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."` ( `product_id` , `category_id` ) VALUES ( '".$product_id."', '".$category_id."');");
  742. }
  743. }
  744. }
  745. $success = true;
  746. }
  747. return $success;
  748. }
  749. function wpsc_sanitise_keys($value) {
  750. /// Function used to cast array items to integer.
  751. return (int)$value;
  752. }
  753. /*
  754. * this function checks every product on the products page to see if it has any stock remaining
  755. * it is executed through the wpsc_product_alert filter
  756. */
  757. function wpsc_check_stock($state, $product) {
  758. global $wpdb;
  759. // if quantity is enabled and is zero
  760. $out_of_stock = false;
  761. // only do anything if the quantity is limited.
  762. if($product['quantity_limited'] == 1) {
  763. $excluded_values = '';
  764. // get the variation IDs associated with this product
  765. $variation_ids = $wpdb->get_col("SELECT `variation_id` FROM `".WPSC_TABLE_VARIATION_ASSOC."` WHERE `type` IN ('product') AND `associated_id` IN ('{$product['id']}')");
  766. // if there are any, look through them for items out of stock
  767. if(count($variation_ids) > 0) {
  768. // sort and comma seperate them
  769. asort($variation_ids);
  770. $all_variation_ids = implode(",", $variation_ids);
  771. // get the visible variation values associated with this product
  772. $enabled_values = $wpdb->get_col("SELECT `value_id` FROM `".WPSC_TABLE_VARIATION_VALUES_ASSOC."` WHERE `product_id` IN('{$product['id']}') AND `visible` IN ('1')");
  773. // get the priceandstock IDs using the variation and variation value IDs
  774. $priceandstock_ids = $wpdb->get_col("SELECT `priceandstock_id` FROM `".WPSC_TABLE_VARIATION_COMBINATIONS."` WHERE `product_id` = '{$product['id']}' AND `all_variation_ids` IN('$all_variation_ids') AND `value_id` IN (".implode(",", $enabled_values).") GROUP BY `priceandstock_id` HAVING COUNT( `priceandstock_id` ) = '".count($variation_ids)."'");
  775. // count the variation combinations with a stock of zero
  776. if(count($priceandstock_ids) > 0) {
  777. $items_out_of_stock = $wpdb->get_var("SELECT COUNT(*) FROM `".WPSC_TABLE_VARIATION_PROPERTIES."` WHERE `id` IN(".implode(",", $priceandstock_ids).") AND `stock` IN (0)");
  778. }
  779. if($items_out_of_stock > 0) {
  780. $out_of_stock = true;
  781. }
  782. } else if(($product['quantity'] == 0)) { // otherwise, use the stock from the products list table
  783. $out_of_stock = true;
  784. }
  785. }
  786. if($out_of_stock === true) {
  787. $state['state'] = true;
  788. $state['messages'][] = __('This product has no available stock', 'wpsc');
  789. }
  790. return array('state' => $state['state'], 'messages' => $state['messages']);
  791. }
  792. /*
  793. * if UPS is on, this function checks every product on the products page to see if it has a weight
  794. * it is executed through the wpsc_product_alert filter
  795. */
  796. function wpsc_check_weight($state, $product) {
  797. global $wpdb;
  798. $custom_shipping = (array)get_option('custom_shipping_options');
  799. $has_no_weight = false;
  800. // only do anything if UPS is on and shipping is used
  801. $weightRelatedShippingModules = array('ups','usps','weightrate');
  802. if((array_intersect($weightRelatedShippingModules, $custom_shipping))&& ($product['no_shipping'] != 1)) {
  803. // exit('true?');
  804. $excluded_values = '';
  805. // get the variation IDs associated with this product
  806. $variation_ids = $wpdb->get_col("SELECT `variation_id` FROM `".WPSC_TABLE_VARIATION_ASSOC."` WHERE `type` IN ('product') AND `associated_id` IN ('{$product['id']}')");
  807. // if there are any, look through them for itemswith no weight
  808. if(count($variation_ids) > 0) {
  809. // sort and comma seperate them
  810. asort($variation_ids);
  811. $all_variation_ids = implode(",", $variation_ids);
  812. // get the visible variation values associated with this product
  813. $enabled_values = $wpdb->get_col("SELECT `value_id` FROM `".WPSC_TABLE_VARIATION_VALUES_ASSOC."` WHERE `product_id` IN('{$product['id']}') AND `visible` IN ('1')");
  814. // get the priceandstock IDs using the variation and variation value IDs
  815. $priceandstock_ids = $wpdb->get_col("SELECT `priceandstock_id` FROM `".WPSC_TABLE_VARIATION_COMBINATIONS."` WHERE `product_id` = '{$product['id']}' AND `all_variation_ids` IN('$all_variation_ids') AND `value_id` IN (".implode(",", $enabled_values).") GROUP BY `priceandstock_id` HAVING COUNT( `priceandstock_id` ) = '".count($variation_ids)."'");
  816. // count the variation combinations with a weight of zero
  817. if(count($priceandstock_ids) > 0) {
  818. $unweighted_items = $wpdb->get_var("SELECT COUNT(*) FROM `".WPSC_TABLE_VARIATION_PROPERTIES."` WHERE `id` IN(".implode(",", $priceandstock_ids).") AND `weight` IN (0)");
  819. if($unweighted_items > 0) {
  820. $has_no_weight = true;
  821. }
  822. }
  823. } else if(($product['weight'] == 0)) { // otherwise, use the stock from the products list table
  824. $has_no_weight = true;
  825. //echo "<pre>".print_r($product,true)."</pre>";
  826. }
  827. if($has_no_weight === true) {
  828. $state['state'] = true;
  829. $state['messages'][] = __('One or more of your shipping modules does not support products without a weight set. Please either disable shipping for this product or give it a weight', 'wpsc');
  830. }
  831. }
  832. return array('state' => $state['state'], 'messages' => $state['messages']);
  833. }
  834. add_filter('wpsc_product_alert', 'wpsc_check_stock', 10, 2);
  835. add_filter('wpsc_product_alert', 'wpsc_check_weight', 10, 2);
  836. ?>