PageRenderTime 40ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/inc/amfphp/Amfphp/Services/ec_admin_productimporter.php

https://github.com/EmranAhmed/wp-easycart
PHP | 713 lines | 490 code | 105 blank | 118 comment | 114 complexity | 810aa482cc6c78532e72d98e7d8bb4e2 MD5 | raw file
  1. <?php
  2. /*
  3. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  5. //All Code and Design is copyrighted by Level Four Development, llc
  6. //
  7. //Level Four Development, LLC provides this code "as is" without warranty of any kind, either express or implied,
  8. //including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
  9. //
  10. //Only licnesed users may use this code and storfront for live purposes. All other use is prohibited and may be
  11. //subject to copyright violation laws. If you have any questions regarding proper use of this code, please
  12. //contact Level Four Development, llc and EasyCart prior to use.
  13. //
  14. //All use of this storefront is subject to our terms of agreement found on Level Four Development, llc's website.
  15. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  16. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. */
  18. class ec_admin_productimporter
  19. {
  20. function ec_admin_productimporter() {
  21. /*load our connection settings
  22. if( file_exists( '../../../../wp-easycart-data/connection/ec_conn.php' ) ) {
  23. require_once('../../../../wp-easycart-data/connection/ec_conn.php');
  24. } else {
  25. require_once('../../../connection/ec_conn.php');
  26. };*/
  27. //set our connection variables
  28. $dbhost = DB_HOST;
  29. $dbname = DB_NAME;
  30. $dbuser = DB_USER;
  31. $dbpass = DB_PASSWORD;
  32. global $wpdb;
  33. define ('WP_PREFIX', $wpdb->prefix);
  34. require_once( "../../classes/core/ec_db.php" );
  35. require_once '../administration/excel_reader2.php';
  36. //make a connection to our database
  37. $this->conn = mysql_connect($dbhost, $dbuser, $dbpass);
  38. mysql_select_db ($dbname);
  39. mysql_query("SET CHARACTER SET utf8", $this->conn);
  40. mysql_query("SET NAMES 'utf8'", $this->conn);
  41. }
  42. //secure all of the services for logged in authenticated users only
  43. public function _getMethodRoles($methodName){
  44. if ($methodName == 'productimport') return array('admin');
  45. else return null;
  46. }
  47. //HELPER - used to escape out SQL calls
  48. function escape($sql)
  49. {
  50. $args = func_get_args();
  51. foreach($args as $key => $val)
  52. {
  53. $args[$key] = mysql_real_escape_string($val);
  54. }
  55. $args[0] = $sql;
  56. return call_user_func_array('sprintf', $args);
  57. }
  58. public function productimport() {
  59. $excel = new Spreadsheet_Excel_Reader("../administration/productimportfile.xls", false);
  60. // read spreadsheet data
  61. $excel->read('../administration/productimportfile.xls');
  62. if(!mysql_error()) {
  63. // iterate over spreadsheet rows and columns
  64. // first check all the data
  65. $errorfound = false;
  66. for ($x=2; $x<=$excel->sheets[0]['numRows']; $x++) {
  67. //1 product_id
  68. //2 model_number
  69. if ($excel->sheets[0]['cells'][$x][2] == '') {
  70. $errorfound = true;
  71. return "Error at record ".$x.", all products require a unique model number." ;
  72. }
  73. //3 post_id
  74. //4 activate_in_store
  75. if (!is_numeric($excel->sheets[0]['cells'][$x][4]) || ($excel->sheets[0]['cells'][$x][4] != 0 && $excel->sheets[0]['cells'][$x][4] != 1)) {
  76. $errorfound = true;
  77. return "Error at record ".$x.", activate in store must be either 1 - active or 0 - not active" ;
  78. }
  79. //5 title
  80. if ($excel->sheets[0]['cells'][$x][5] == '') {
  81. $errorfound = true;
  82. return "Error at record ".$x.", all products require a title." ;
  83. }
  84. //6 description
  85. if ($excel->sheets[0]['cells'][$x][6] == '') {
  86. $errorfound = true;
  87. return "Error at record ".$x.", all products require a description." ;
  88. }
  89. //7 specifications
  90. //8 price
  91. if ($excel->sheets[0]['cells'][$x][8] == '' || !is_numeric($excel->sheets[0]['cells'][$x][8])) {
  92. $errorfound = true;
  93. return "Error at record ".$x.", all products require you enter a valid price for the item. Do not enter currency signs or thousands seperators." ;
  94. }
  95. //9 list_price
  96. if (!is_numeric($excel->sheets[0]['cells'][$x][9])) {
  97. $errorfound = true;
  98. return "Error at record ".$x.", if you include a list price, it must be in numeric format. Do not enter currency signs or thousands seperators." ;
  99. }
  100. //10 vat_rate
  101. //11 handling_price
  102. //12 stock_quantity
  103. if ($excel->sheets[0]['cells'][$x][12] == '' || !is_numeric($excel->sheets[0]['cells'][$x][12])) {
  104. $errorfound = true;
  105. return "Error at record ".$x.", all products require you enter a stock quantity for the product." ;
  106. }
  107. //13 weight
  108. //14 width
  109. //15 height
  110. //16 length
  111. //17 seo_description
  112. //18 seo_keywords
  113. //19 use_specifications
  114. if (!is_numeric($excel->sheets[0]['cells'][$x][19]) || ($excel->sheets[0]['cells'][$x][19] != 0 && $excel->sheets[0]['cells'][$x][19] != 1)) {
  115. $errorfound = true;
  116. return "Error at record ".$x.", use specifications must be either a 1 - selected or 0 - not selected." ;
  117. }
  118. //20 use_customer_reviews
  119. if (!is_numeric($excel->sheets[0]['cells'][$x][20]) || ($excel->sheets[0]['cells'][$x][20] != 0 && $excel->sheets[0]['cells'][$x][20] != 1)) {
  120. $errorfound = true;
  121. return "Error at record ".$x.", use customer reviews must be either a 1 - selected or 0 - not selected." ;
  122. }
  123. //21 manufacturer_id
  124. //22 download_file_name
  125. //23 image1
  126. //24 image2
  127. //25 image3
  128. //26 image4
  129. //27 image5
  130. //28 option_id_1
  131. //29 option_id_2
  132. //30 option_id_3
  133. //31 option_id_4
  134. //32 option_id_5
  135. //33 use_advanced_optionset
  136. if (!is_numeric($excel->sheets[0]['cells'][$x][33]) || ($excel->sheets[0]['cells'][$x][33] != 0 && $excel->sheets[0]['cells'][$x][33] != 1)) {
  137. $errorfound = true;
  138. return "Error at record ".$x.", use advanced optionsets must be either a 1 - selected or 0 - not selected." ;
  139. }
  140. //34 menulevel1_id_1
  141. //35 menulevel1_id_2
  142. //36 menulevel1_id_3
  143. //37 menulevel2_id_1
  144. //38 menulevel2_id_2
  145. //39 menulevel2_id_3
  146. //40 menulevel3_id_1
  147. //41 menulevel3_id_2
  148. //42 menulevel3_id_3
  149. //43 featured_product_id_1
  150. //44 featured_product_id_2
  151. //45 featured_product_id_3
  152. //46 featured_product_id_4
  153. //47 is_giftcard
  154. if (!is_numeric($excel->sheets[0]['cells'][$x][47]) || ($excel->sheets[0]['cells'][$x][47] != 0 && $excel->sheets[0]['cells'][$x][47] != 1)) {
  155. $errorfound = true;
  156. return "Error at record ".$x.", is giftcard must be either a 1 - selected or 0 - not selected." ;
  157. }
  158. //48 is_download
  159. if (!is_numeric($excel->sheets[0]['cells'][$x][48]) || ($excel->sheets[0]['cells'][$x][48] != 0 && $excel->sheets[0]['cells'][$x][48] != 1)) {
  160. $errorfound = true;
  161. return "Error at record ".$x.", is download must be either a 1 - selected or 0 - not selected." ;
  162. }
  163. //49 is_donation
  164. if (!is_numeric($excel->sheets[0]['cells'][$x][49]) || ($excel->sheets[0]['cells'][$x][49] != 0 && $excel->sheets[0]['cells'][$x][49] != 1)) {
  165. $errorfound = true;
  166. return "Error at record ".$x.", is donation must be either a 1 - selected or 0 - not selected." ;
  167. }
  168. //50 is_special
  169. if (!is_numeric($excel->sheets[0]['cells'][$x][50]) || ($excel->sheets[0]['cells'][$x][50] != 0 && $excel->sheets[0]['cells'][$x][50] != 1)) {
  170. $errorfound = true;
  171. return "Error at record ".$x.", is special must be either a 1 - selected or 0 - not selected." ;
  172. }
  173. //51 is_taxable
  174. if (!is_numeric($excel->sheets[0]['cells'][$x][51]) || ($excel->sheets[0]['cells'][$x][51] != 0 && $excel->sheets[0]['cells'][$x][51] != 1)) {
  175. $errorfound = true;
  176. return "Error at record ".$x.", is taxable must be either a 1 - selected or 0 - not selected." ;
  177. }
  178. //52 is_subscription_item
  179. if (!is_numeric($excel->sheets[0]['cells'][$x][52]) || ($excel->sheets[0]['cells'][$x][52] != 0 && $excel->sheets[0]['cells'][$x][52] != 1)) {
  180. $errorfound = true;
  181. return "Error at record ".$x.", is subscription item must be either a 1 - selected or 0 - not selected." ;
  182. }
  183. //53 is_preorder
  184. //54 added_to_db_date
  185. //55 show_on_startup
  186. if (!is_numeric($excel->sheets[0]['cells'][$x][55]) || ($excel->sheets[0]['cells'][$x][55] != 0 && $excel->sheets[0]['cells'][$x][55] != 1)) {
  187. $errorfound = true;
  188. return "Error at record ".$x.", show on store startup must be either a 1 - selected or 0 - not selected." ;
  189. }
  190. //56 use_optionitem_images
  191. if (!is_numeric($excel->sheets[0]['cells'][$x][56]) || ($excel->sheets[0]['cells'][$x][56] != 0 && $excel->sheets[0]['cells'][$x][56] != 1)) {
  192. $errorfound = true;
  193. return "Error at record ".$x.", use optionitem images must be either a 1 - selected or 0 - not selected." ;
  194. }
  195. //57 use_optionitem_quantity_tracking
  196. if (!is_numeric($excel->sheets[0]['cells'][$x][57]) || ($excel->sheets[0]['cells'][$x][57] != 0 && $excel->sheets[0]['cells'][$x][57] != 1)) {
  197. $errorfound = true;
  198. return "Error at record ".$x.", use optionitem quantity tracking must be either a 1 - selected or 0 - not selected." ;
  199. }
  200. //58 views
  201. //59 last_viewed
  202. //60 show_stock_quantity
  203. if (!is_numeric($excel->sheets[0]['cells'][$x][60]) || ($excel->sheets[0]['cells'][$x][60] != 0 && $excel->sheets[0]['cells'][$x][60] != 1)) {
  204. $errorfound = true;
  205. return "Error at record ".$x.", show stock quantity must be either a 1 - selected or 0 - not selected." ;
  206. }
  207. //61 maximum_downloads_allowed
  208. //62 download_timelimit_seconds
  209. //63 QB list_id
  210. //64 QB edit_sequence
  211. //65 subscription_bill_length
  212. //66 subscription_bill_period
  213. //67 trial_period_days
  214. //68 stripe_plan_added
  215. //69 subscription_plan_id
  216. //70 allow_multiple_subscription_purchases
  217. //71 membership_page
  218. }
  219. //if we made it through validation, then begin inserting or updating data
  220. if($errorfound == false) {
  221. for ($x=2; $x<=$excel->sheets[0]['numRows']; $x++) {
  222. //Create SQL Query
  223. $sql = $this->escape("SELECT ec_product.product_id FROM ec_product WHERE ec_product.product_id = '".$excel->sheets[0]['cells'][$x][1]."'");
  224. // Run query on database
  225. $result = mysql_query($sql);
  226. //if results, then we found an existing product, do update
  227. if(mysql_num_rows($result) > 0) {
  228. //update product
  229. $sql = $this->escape("UPDATE ec_product SET
  230. ec_product.product_id = '%s',
  231. ec_product.model_number = '%s',
  232. ec_product.post_id = '%s',
  233. ec_product.activate_in_store = '%s',
  234. ec_product.title = '%s',
  235. ec_product.description = '%s',
  236. ec_product.specifications = '%s',
  237. ec_product.price = '%s',
  238. ec_product.list_price = '%s',
  239. ec_product.vat_rate = '%s',
  240. ec_product.handling_price = '%s',
  241. ec_product.stock_quantity = '%s',
  242. ec_product.weight = '%s',
  243. ec_product.width = '%s',
  244. ec_product.height = '%s',
  245. ec_product.length = '%s',
  246. ec_product.seo_description = '%s',
  247. ec_product.seo_keywords = '%s',
  248. ec_product.use_specifications = '%s',
  249. ec_product.use_customer_reviews = '%s',
  250. ec_product.manufacturer_id = '%s',
  251. ec_product.download_file_name = '%s',
  252. ec_product.image1 = '%s',
  253. ec_product.image2 = '%s',
  254. ec_product.image3 = '%s',
  255. ec_product.image4 = '%s',
  256. ec_product.image5 = '%s',
  257. ec_product.option_id_1 = '%s',
  258. ec_product.option_id_2 = '%s',
  259. ec_product.option_id_3 = '%s',
  260. ec_product.option_id_4 = '%s',
  261. ec_product.option_id_5 = '%s',
  262. ec_product.use_advanced_optionset = '%s',
  263. ec_product.menulevel1_id_1 = '%s',
  264. ec_product.menulevel1_id_2 = '%s',
  265. ec_product.menulevel1_id_3 = '%s',
  266. ec_product.menulevel2_id_1 = '%s',
  267. ec_product.menulevel2_id_2 = '%s',
  268. ec_product.menulevel2_id_3 = '%s',
  269. ec_product.menulevel3_id_1 = '%s',
  270. ec_product.menulevel3_id_2 = '%s',
  271. ec_product.menulevel3_id_3 = '%s',
  272. ec_product.featured_product_id_1 = '%s',
  273. ec_product.featured_product_id_2 = '%s',
  274. ec_product.featured_product_id_3 = '%s',
  275. ec_product.featured_product_id_4 = '%s',
  276. ec_product.is_giftcard = '%s',
  277. ec_product.is_download = '%s',
  278. ec_product.is_donation = '%s',
  279. ec_product.is_special = '%s',
  280. ec_product.is_taxable = '%s',
  281. ec_product.is_subscription_item = '%s',
  282. ec_product.is_preorder = '%s',
  283. ec_product.added_to_db_date = '%s',
  284. ec_product.show_on_startup = '%s',
  285. ec_product.use_optionitem_images = '%s',
  286. ec_product.use_optionitem_quantity_tracking = '%s',
  287. ec_product.views = '%s',
  288. ec_product.last_viewed = '%s',
  289. ec_product.show_stock_quantity = '%s',
  290. ec_product.maximum_downloads_allowed = '%s',
  291. ec_product.download_timelimit_seconds = '%s',
  292. ec_product.list_id = '%s',
  293. ec_product.edit_sequence = '%s',
  294. ec_product.subscription_bill_length = '%s',
  295. ec_product.subscription_bill_period = '%s',
  296. ec_product.trial_period_days = '%s',
  297. ec_product.stripe_plan_added = '%s',
  298. ec_product.subscription_plan_id = '%s',
  299. ec_product.allow_multiple_subscription_purchases = '%s',
  300. ec_product.membership_page = '%s'
  301. WHERE product_id = '".$excel->sheets[0]['cells'][$x][1]."'",
  302. mysql_real_escape_string($excel->sheets[0]['cells'][$x][1]),
  303. mysql_real_escape_string($excel->sheets[0]['cells'][$x][2]),
  304. mysql_real_escape_string($excel->sheets[0]['cells'][$x][3]),
  305. mysql_real_escape_string($excel->sheets[0]['cells'][$x][4]),
  306. mysql_real_escape_string($excel->sheets[0]['cells'][$x][5]),
  307. $excel->sheets[0]['cells'][$x][6],
  308. $excel->sheets[0]['cells'][$x][7],
  309. mysql_real_escape_string($excel->sheets[0]['cells'][$x][8]),
  310. mysql_real_escape_string($excel->sheets[0]['cells'][$x][9]),
  311. mysql_real_escape_string($excel->sheets[0]['cells'][$x][10]),
  312. mysql_real_escape_string($excel->sheets[0]['cells'][$x][11]),
  313. mysql_real_escape_string($excel->sheets[0]['cells'][$x][12]),
  314. mysql_real_escape_string($excel->sheets[0]['cells'][$x][13]),
  315. mysql_real_escape_string($excel->sheets[0]['cells'][$x][14]),
  316. mysql_real_escape_string($excel->sheets[0]['cells'][$x][15]),
  317. mysql_real_escape_string($excel->sheets[0]['cells'][$x][16]),
  318. mysql_real_escape_string($excel->sheets[0]['cells'][$x][17]),
  319. mysql_real_escape_string($excel->sheets[0]['cells'][$x][18]),
  320. mysql_real_escape_string($excel->sheets[0]['cells'][$x][19]),
  321. mysql_real_escape_string($excel->sheets[0]['cells'][$x][20]),
  322. mysql_real_escape_string($excel->sheets[0]['cells'][$x][21]),
  323. mysql_real_escape_string($excel->sheets[0]['cells'][$x][22]),
  324. mysql_real_escape_string($excel->sheets[0]['cells'][$x][23]),
  325. mysql_real_escape_string($excel->sheets[0]['cells'][$x][24]),
  326. mysql_real_escape_string($excel->sheets[0]['cells'][$x][25]),
  327. mysql_real_escape_string($excel->sheets[0]['cells'][$x][26]),
  328. mysql_real_escape_string($excel->sheets[0]['cells'][$x][27]),
  329. mysql_real_escape_string($excel->sheets[0]['cells'][$x][28]),
  330. mysql_real_escape_string($excel->sheets[0]['cells'][$x][29]),
  331. mysql_real_escape_string($excel->sheets[0]['cells'][$x][30]),
  332. mysql_real_escape_string($excel->sheets[0]['cells'][$x][31]),
  333. mysql_real_escape_string($excel->sheets[0]['cells'][$x][32]),
  334. mysql_real_escape_string($excel->sheets[0]['cells'][$x][33]),
  335. mysql_real_escape_string($excel->sheets[0]['cells'][$x][34]),
  336. mysql_real_escape_string($excel->sheets[0]['cells'][$x][35]),
  337. mysql_real_escape_string($excel->sheets[0]['cells'][$x][36]),
  338. mysql_real_escape_string($excel->sheets[0]['cells'][$x][37]),
  339. mysql_real_escape_string($excel->sheets[0]['cells'][$x][38]),
  340. mysql_real_escape_string($excel->sheets[0]['cells'][$x][39]),
  341. mysql_real_escape_string($excel->sheets[0]['cells'][$x][40]),
  342. mysql_real_escape_string($excel->sheets[0]['cells'][$x][41]),
  343. mysql_real_escape_string($excel->sheets[0]['cells'][$x][42]),
  344. mysql_real_escape_string($excel->sheets[0]['cells'][$x][43]),
  345. mysql_real_escape_string($excel->sheets[0]['cells'][$x][44]),
  346. mysql_real_escape_string($excel->sheets[0]['cells'][$x][45]),
  347. mysql_real_escape_string($excel->sheets[0]['cells'][$x][46]),
  348. mysql_real_escape_string($excel->sheets[0]['cells'][$x][47]),
  349. mysql_real_escape_string($excel->sheets[0]['cells'][$x][48]),
  350. mysql_real_escape_string($excel->sheets[0]['cells'][$x][49]),
  351. mysql_real_escape_string($excel->sheets[0]['cells'][$x][50]),
  352. mysql_real_escape_string($excel->sheets[0]['cells'][$x][51]),
  353. mysql_real_escape_string($excel->sheets[0]['cells'][$x][52]),
  354. mysql_real_escape_string($excel->sheets[0]['cells'][$x][53]),
  355. mysql_real_escape_string($excel->sheets[0]['cells'][$x][54]),
  356. mysql_real_escape_string($excel->sheets[0]['cells'][$x][55]),
  357. mysql_real_escape_string($excel->sheets[0]['cells'][$x][56]),
  358. mysql_real_escape_string($excel->sheets[0]['cells'][$x][57]),
  359. mysql_real_escape_string($excel->sheets[0]['cells'][$x][58]),
  360. mysql_real_escape_string($excel->sheets[0]['cells'][$x][59]),
  361. mysql_real_escape_string($excel->sheets[0]['cells'][$x][60]),
  362. mysql_real_escape_string($excel->sheets[0]['cells'][$x][61]),
  363. mysql_real_escape_string($excel->sheets[0]['cells'][$x][62]),
  364. mysql_real_escape_string($excel->sheets[0]['cells'][$x][63]),
  365. mysql_real_escape_string($excel->sheets[0]['cells'][$x][64]),
  366. mysql_real_escape_string($excel->sheets[0]['cells'][$x][65]),
  367. mysql_real_escape_string($excel->sheets[0]['cells'][$x][66]),
  368. mysql_real_escape_string($excel->sheets[0]['cells'][$x][67]),
  369. mysql_real_escape_string($excel->sheets[0]['cells'][$x][68]),
  370. mysql_real_escape_string($excel->sheets[0]['cells'][$x][69]),
  371. mysql_real_escape_string($excel->sheets[0]['cells'][$x][70]),
  372. mysql_real_escape_string($excel->sheets[0]['cells'][$x][71]));
  373. if (!mysql_query($sql)) {
  374. //error out
  375. break;
  376. } else {
  377. //Enqueue Quickbooks Add Product
  378. if( file_exists( "../../../../wp-easycart-quickbooks/QuickBooks.php" ) ){
  379. $quickbooks = new ec_quickbooks( );
  380. $quickbooks->update_product( $excel->sheets[0]['cells'][$x][2] ); //model_number
  381. }
  382. // Insert a WordPress Custom post type post.
  383. $post = array( 'ID' => $excel->sheets[0]['cells'][$x][3],
  384. 'post_content' => "[ec_store modelnumber=\"" . $excel->sheets[0]['cells'][$x][2] . "\"]",
  385. 'post_status' => "publish",
  386. 'post_title' => $GLOBALS['language']->convert_text( $excel->sheets[0]['cells'][$x][5] ),
  387. 'post_type' => "ec_store",
  388. 'post_name' => str_replace(' ', '-', $GLOBALS['language']->convert_text( $excel->sheets[0]['cells'][$x][5] ) ),
  389. );
  390. $post_id = wp_update_post( $post );
  391. //if using stripe and is subscription
  392. if (get_option( 'ec_option_payment_process_method' ) == 'stripe' && $excel->sheets[0]['cells'][$x][52] == '1') {
  393. //create an object for call to stripe
  394. $stripe_plan = (object)array(
  395. "product_id" => $excel->sheets[0]['cells'][$x][1],
  396. "title" => $excel->sheets[0]['cells'][$x][5]);
  397. $stripe = new ec_stripe;
  398. $response = $stripe->update_plan($stripe_plan);
  399. if ($response == false) {
  400. //try to insert it then
  401. //create an object for call to stripe
  402. $stripe_plan = (object)array(
  403. "price" => $excel->sheets[0]['cells'][$x][8],
  404. "product_id" => $excel->sheets[0]['cells'][$x][1],
  405. "title" => $excel->sheets[0]['cells'][$x][5],
  406. "subscription_bill_period" => $excel->sheets[0]['cells'][$x][66],
  407. "subscription_bill_length" => $excel->sheets[0]['cells'][$x][65],
  408. "trial_period_days" => $excel->sheets[0]['cells'][$x][67]);
  409. $stripe = new ec_stripe;
  410. $response = $stripe->insert_plan($stripe_plan);
  411. }
  412. }
  413. }
  414. } else {
  415. //insert product
  416. // Insert a WordPress Custom post type post.
  417. $sql_product = sprintf("SELECT ec_product.product_id, ec_product.title, ec_product.model_number FROM ec_product WHERE ec_product.model_number = '%s'", $excel->sheets[0]['cells'][$x][1] );
  418. $result_get_product = mysql_query( $sql_product );
  419. $product = mysql_fetch_assoc( $result_get_product );
  420. $post = array( 'post_content' => "[ec_store modelnumber=\"" . $product['model_number'] . "\"]",
  421. 'post_status' => "publish",
  422. 'post_title' => $product['title'],
  423. 'post_type' => "ec_store"
  424. );
  425. $post_id = wp_insert_post( $post, $wp_error );
  426. $db = new ec_db( );
  427. $db->update_product_post_id( $product['product_id'], $post_id );
  428. $sql = $this->escape("INSERT into ec_product(
  429. ec_product.product_id,
  430. ec_product.model_number,
  431. ec_product.post_id,
  432. ec_product.activate_in_store,
  433. ec_product.title,
  434. ec_product.description,
  435. ec_product.specifications,
  436. ec_product.price,
  437. ec_product.list_price,
  438. ec_product.vat_rate,
  439. ec_product.handling_price,
  440. ec_product.stock_quantity,
  441. ec_product.weight,
  442. ec_product.width,
  443. ec_product.height,
  444. ec_product.length,
  445. ec_product.seo_description,
  446. ec_product.seo_keywords,
  447. ec_product.use_specifications,
  448. ec_product.use_customer_reviews,
  449. ec_product.manufacturer_id,
  450. ec_product.download_file_name,
  451. ec_product.image1,
  452. ec_product.image2,
  453. ec_product.image3,
  454. ec_product.image4,
  455. ec_product.image5,
  456. ec_product.option_id_1,
  457. ec_product.option_id_2,
  458. ec_product.option_id_3,
  459. ec_product.option_id_4,
  460. ec_product.option_id_5,
  461. ec_product.use_advanced_optionset,
  462. ec_product.menulevel1_id_1,
  463. ec_product.menulevel1_id_2,
  464. ec_product.menulevel1_id_3,
  465. ec_product.menulevel2_id_1,
  466. ec_product.menulevel2_id_2,
  467. ec_product.menulevel2_id_3,
  468. ec_product.menulevel3_id_1,
  469. ec_product.menulevel3_id_2,
  470. ec_product.menulevel3_id_3,
  471. ec_product.featured_product_id_1,
  472. ec_product.featured_product_id_2,
  473. ec_product.featured_product_id_3,
  474. ec_product.featured_product_id_4,
  475. ec_product.is_giftcard,
  476. ec_product.is_download,
  477. ec_product.is_donation,
  478. ec_product.is_special,
  479. ec_product.is_taxable,
  480. ec_product.is_subscription_item,
  481. ec_product.is_preorder,
  482. ec_product.added_to_db_date,
  483. ec_product.show_on_startup,
  484. ec_product.use_optionitem_images,
  485. ec_product.use_optionitem_quantity_tracking,
  486. ec_product.views,
  487. ec_product.last_viewed,
  488. ec_product.show_stock_quantity,
  489. ec_product.maximum_downloads_allowed,
  490. ec_product.download_timelimit_seconds,
  491. ec_product.list_id,
  492. ec_product.edit_sequence,
  493. ec_product.subscription_bill_length,
  494. ec_product.subscription_bill_period,
  495. ec_product.trial_period_days,
  496. ec_product.stripe_plan_added,
  497. ec_product.subscription_plan_id,
  498. ec_product.allow_multiple_subscription_purchases,
  499. ec_product.membership_page
  500. )
  501. values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s', '%s')",
  502. mysql_real_escape_string($excel->sheets[0]['cells'][$x][1]),
  503. mysql_real_escape_string($excel->sheets[0]['cells'][$x][2]),
  504. mysql_real_escape_string($post_id),
  505. mysql_real_escape_string($excel->sheets[0]['cells'][$x][4]),
  506. mysql_real_escape_string($excel->sheets[0]['cells'][$x][5]),
  507. $excel->sheets[0]['cells'][$x][6],
  508. $excel->sheets[0]['cells'][$x][7],
  509. mysql_real_escape_string($excel->sheets[0]['cells'][$x][8]),
  510. mysql_real_escape_string($excel->sheets[0]['cells'][$x][9]),
  511. mysql_real_escape_string($excel->sheets[0]['cells'][$x][10]),
  512. mysql_real_escape_string($excel->sheets[0]['cells'][$x][11]),
  513. mysql_real_escape_string($excel->sheets[0]['cells'][$x][12]),
  514. mysql_real_escape_string($excel->sheets[0]['cells'][$x][13]),
  515. mysql_real_escape_string($excel->sheets[0]['cells'][$x][14]),
  516. mysql_real_escape_string($excel->sheets[0]['cells'][$x][15]),
  517. mysql_real_escape_string($excel->sheets[0]['cells'][$x][16]),
  518. mysql_real_escape_string($excel->sheets[0]['cells'][$x][17]),
  519. mysql_real_escape_string($excel->sheets[0]['cells'][$x][18]),
  520. mysql_real_escape_string($excel->sheets[0]['cells'][$x][19]),
  521. mysql_real_escape_string($excel->sheets[0]['cells'][$x][20]),
  522. mysql_real_escape_string($excel->sheets[0]['cells'][$x][21]),
  523. mysql_real_escape_string($excel->sheets[0]['cells'][$x][22]),
  524. mysql_real_escape_string($excel->sheets[0]['cells'][$x][23]),
  525. mysql_real_escape_string($excel->sheets[0]['cells'][$x][24]),
  526. mysql_real_escape_string($excel->sheets[0]['cells'][$x][25]),
  527. mysql_real_escape_string($excel->sheets[0]['cells'][$x][26]),
  528. mysql_real_escape_string($excel->sheets[0]['cells'][$x][27]),
  529. mysql_real_escape_string($excel->sheets[0]['cells'][$x][28]),
  530. mysql_real_escape_string($excel->sheets[0]['cells'][$x][29]),
  531. mysql_real_escape_string($excel->sheets[0]['cells'][$x][30]),
  532. mysql_real_escape_string($excel->sheets[0]['cells'][$x][31]),
  533. mysql_real_escape_string($excel->sheets[0]['cells'][$x][32]),
  534. mysql_real_escape_string($excel->sheets[0]['cells'][$x][33]),
  535. mysql_real_escape_string($excel->sheets[0]['cells'][$x][34]),
  536. mysql_real_escape_string($excel->sheets[0]['cells'][$x][35]),
  537. mysql_real_escape_string($excel->sheets[0]['cells'][$x][36]),
  538. mysql_real_escape_string($excel->sheets[0]['cells'][$x][37]),
  539. mysql_real_escape_string($excel->sheets[0]['cells'][$x][38]),
  540. mysql_real_escape_string($excel->sheets[0]['cells'][$x][39]),
  541. mysql_real_escape_string($excel->sheets[0]['cells'][$x][40]),
  542. mysql_real_escape_string($excel->sheets[0]['cells'][$x][41]),
  543. mysql_real_escape_string($excel->sheets[0]['cells'][$x][42]),
  544. mysql_real_escape_string($excel->sheets[0]['cells'][$x][43]),
  545. mysql_real_escape_string($excel->sheets[0]['cells'][$x][44]),
  546. mysql_real_escape_string($excel->sheets[0]['cells'][$x][45]),
  547. mysql_real_escape_string($excel->sheets[0]['cells'][$x][46]),
  548. mysql_real_escape_string($excel->sheets[0]['cells'][$x][47]),
  549. mysql_real_escape_string($excel->sheets[0]['cells'][$x][48]),
  550. mysql_real_escape_string($excel->sheets[0]['cells'][$x][49]),
  551. mysql_real_escape_string($excel->sheets[0]['cells'][$x][50]),
  552. mysql_real_escape_string($excel->sheets[0]['cells'][$x][51]),
  553. mysql_real_escape_string($excel->sheets[0]['cells'][$x][52]),
  554. mysql_real_escape_string($excel->sheets[0]['cells'][$x][53]),
  555. mysql_real_escape_string($excel->sheets[0]['cells'][$x][54]),
  556. mysql_real_escape_string($excel->sheets[0]['cells'][$x][55]),
  557. mysql_real_escape_string($excel->sheets[0]['cells'][$x][56]),
  558. mysql_real_escape_string($excel->sheets[0]['cells'][$x][57]),
  559. mysql_real_escape_string($excel->sheets[0]['cells'][$x][58]),
  560. mysql_real_escape_string($excel->sheets[0]['cells'][$x][59]),
  561. mysql_real_escape_string($excel->sheets[0]['cells'][$x][60]),
  562. mysql_real_escape_string($excel->sheets[0]['cells'][$x][61]),
  563. mysql_real_escape_string($excel->sheets[0]['cells'][$x][62]),
  564. mysql_real_escape_string($excel->sheets[0]['cells'][$x][63]),
  565. mysql_real_escape_string($excel->sheets[0]['cells'][$x][64]),
  566. mysql_real_escape_string($excel->sheets[0]['cells'][$x][65]),
  567. mysql_real_escape_string($excel->sheets[0]['cells'][$x][66]),
  568. mysql_real_escape_string($excel->sheets[0]['cells'][$x][67]),
  569. mysql_real_escape_string($excel->sheets[0]['cells'][$x][68]),
  570. mysql_real_escape_string($excel->sheets[0]['cells'][$x][69]),
  571. mysql_real_escape_string($excel->sheets[0]['cells'][$x][70]),
  572. mysql_real_escape_string($excel->sheets[0]['cells'][$x][71]));
  573. if (!mysql_query($sql)) {
  574. //error out
  575. break;
  576. } else {
  577. //Enqueue Quickbooks Add Product
  578. if( file_exists( "../../../../wp-easycart-quickbooks/QuickBooks.php" ) ){
  579. $quickbooks = new ec_quickbooks( );
  580. $quickbooks->add_product( $excel->sheets[0]['cells'][$x][1] ); //model_number
  581. }
  582. //if using stripe and is subscription, insert plan
  583. if (get_option( 'ec_option_payment_process_method' ) == 'stripe' && $excel->sheets[0]['cells'][$x][52] == '1') {
  584. //create an object for call to stripe
  585. $stripe_plan = (object)array(
  586. "price" => $excel->sheets[0]['cells'][$x][8],
  587. "product_id" => $product['product_id'],
  588. "title" => $excel->sheets[0]['cells'][$x][5],
  589. "subscription_bill_period" => $excel->sheets[0]['cells'][$x][66],
  590. "subscription_bill_length" => $excel->sheets[0]['cells'][$x][65],
  591. "trial_period_days" => $excel->sheets[0]['cells'][$x][67]);
  592. $stripe = new ec_stripe;
  593. $response = $stripe->insert_plan($stripe_plan);
  594. }
  595. }
  596. }
  597. }
  598. if(!mysql_error()) {
  599. $returnArray[] ="success";
  600. return($returnArray); //return array results if there are some
  601. } else {
  602. return 'Error at record '.$x.', Please Check Excel File: ' . mysql_error();
  603. }
  604. }
  605. }
  606. }
  607. }//close class
  608. ?>