uc_order.install 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the uc_order module.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function uc_order_schema() {
  10. $schema = array();
  11. $schema['uc_orders'] = array(
  12. 'description' => 'Stores Ubercart order information.',
  13. 'fields' => array(
  14. 'order_id' => array(
  15. 'description' => 'Primary key: the order ID.',
  16. 'type' => 'serial',
  17. 'unsigned' => TRUE,
  18. 'not null' => TRUE,
  19. ),
  20. 'uid' => array(
  21. 'description' => 'The {user}.uid of the customer that placed the order.',
  22. 'type' => 'int',
  23. 'unsigned' => TRUE,
  24. 'not null' => TRUE,
  25. 'default' => 0,
  26. ),
  27. 'order_status' => array(
  28. 'description' => 'The {uc_order_statuses}.order_status_id indicating the order status.',
  29. 'type' => 'varchar',
  30. 'length' => 32,
  31. 'not null' => TRUE,
  32. 'default' => '',
  33. ),
  34. 'order_total' => array(
  35. 'description' => 'The total amount to be paid for the order.',
  36. 'type' => 'numeric',
  37. 'precision' => 16,
  38. 'scale' => 5,
  39. 'not null' => TRUE,
  40. 'default' => 0.0,
  41. ),
  42. 'product_count' => array(
  43. 'description' => 'The total product quantity of the order.',
  44. 'type' => 'int',
  45. 'unsigned' => TRUE,
  46. 'not null' => TRUE,
  47. 'default' => 0,
  48. ),
  49. 'primary_email' => array(
  50. 'description' => 'The email address of the customer.',
  51. 'type' => 'varchar',
  52. 'length' => 96,
  53. 'not null' => TRUE,
  54. 'default' => '',
  55. ),
  56. 'delivery_first_name' => array(
  57. 'description' => 'The first name of the person receiving shipment.',
  58. 'type' => 'varchar',
  59. 'length' => 255,
  60. 'not null' => TRUE,
  61. 'default' => '',
  62. ),
  63. 'delivery_last_name' => array(
  64. 'description' => 'The last name of the person receiving shipment.',
  65. 'type' => 'varchar',
  66. 'length' => 255,
  67. 'not null' => TRUE,
  68. 'default' => '',
  69. ),
  70. 'delivery_phone' => array(
  71. 'description' => 'The phone number at the delivery location.',
  72. 'type' => 'varchar',
  73. 'length' => 255,
  74. 'not null' => TRUE,
  75. 'default' => '',
  76. ),
  77. 'delivery_company' => array(
  78. 'description' => 'The company at the delivery location.',
  79. 'type' => 'varchar',
  80. 'length' => 255,
  81. 'not null' => TRUE,
  82. 'default' => '',
  83. ),
  84. 'delivery_street1' => array(
  85. 'description' => 'The street address of the delivery location.',
  86. 'type' => 'varchar',
  87. 'length' => 255,
  88. 'not null' => TRUE,
  89. 'default' => '',
  90. ),
  91. 'delivery_street2' => array(
  92. 'description' => 'The second line of the street address.',
  93. 'type' => 'varchar',
  94. 'length' => 255,
  95. 'not null' => TRUE,
  96. 'default' => '',
  97. ),
  98. 'delivery_city' => array(
  99. 'description' => 'The city of the delivery location.',
  100. 'type' => 'varchar',
  101. 'length' => 255,
  102. 'not null' => TRUE,
  103. 'default' => '',
  104. ),
  105. 'delivery_zone' => array(
  106. 'description' => 'The state/zone/province id of the delivery location.',
  107. 'type' => 'int',
  108. 'size' => 'medium',
  109. 'unsigned' => TRUE,
  110. 'not null' => TRUE,
  111. 'default' => 0,
  112. ),
  113. 'delivery_postal_code' => array(
  114. 'description' => 'The postal code of the delivery location.',
  115. 'type' => 'varchar',
  116. 'length' => 255,
  117. 'not null' => TRUE,
  118. 'default' => '',
  119. ),
  120. 'delivery_country' => array(
  121. 'description' => 'The country ID of the delivery location.',
  122. 'type' => 'int',
  123. 'size' => 'medium',
  124. 'unsigned' => TRUE,
  125. 'not null' => TRUE,
  126. 'default' => 0,
  127. ),
  128. 'billing_first_name' => array(
  129. 'description' => 'The first name of the person paying for the order.',
  130. 'type' => 'varchar',
  131. 'length' => 255,
  132. 'not null' => TRUE,
  133. 'default' => '',
  134. ),
  135. 'billing_last_name' => array(
  136. 'description' => 'The last name of the person paying for the order.',
  137. 'type' => 'varchar',
  138. 'length' => 255,
  139. 'not null' => TRUE,
  140. 'default' => '',
  141. ),
  142. 'billing_phone' => array(
  143. 'description' => 'The phone number for the billing address.',
  144. 'type' => 'varchar',
  145. 'length' => 255,
  146. 'not null' => TRUE,
  147. 'default' => '',
  148. ),
  149. 'billing_company' => array(
  150. 'description' => 'The company of the billing address.',
  151. 'type' => 'varchar',
  152. 'length' => 255,
  153. 'not null' => TRUE,
  154. 'default' => '',
  155. ),
  156. 'billing_street1' => array(
  157. 'description' => 'The street address where the bill will be sent.',
  158. 'type' => 'varchar',
  159. 'length' => 255,
  160. 'not null' => TRUE,
  161. 'default' => '',
  162. ),
  163. 'billing_street2' => array(
  164. 'description' => 'The second line of the street address.',
  165. 'type' => 'varchar',
  166. 'length' => 255,
  167. 'not null' => TRUE,
  168. 'default' => '',
  169. ),
  170. 'billing_city' => array(
  171. 'description' => 'The city where the bill will be sent.',
  172. 'type' => 'varchar',
  173. 'length' => 255,
  174. 'not null' => TRUE,
  175. 'default' => '',
  176. ),
  177. 'billing_zone' => array(
  178. 'description' => 'The state/zone/province ID where the bill will be sent.',
  179. 'type' => 'int',
  180. 'size' => 'medium',
  181. 'unsigned' => TRUE,
  182. 'not null' => TRUE,
  183. 'default' => 0,
  184. ),
  185. 'billing_postal_code' => array(
  186. 'description' => 'The postal code where the bill will be sent.',
  187. 'type' => 'varchar',
  188. 'length' => 255,
  189. 'not null' => TRUE,
  190. 'default' => '',
  191. ),
  192. 'billing_country' => array(
  193. 'description' => 'The country ID where the bill will be sent.',
  194. 'type' => 'int',
  195. 'size' => 'medium',
  196. 'unsigned' => TRUE,
  197. 'not null' => TRUE,
  198. 'default' => 0,
  199. ),
  200. 'payment_method' => array(
  201. 'description' => 'The method of payment.',
  202. 'type' => 'varchar',
  203. 'length' => 32,
  204. 'not null' => TRUE,
  205. 'default' => '',
  206. ),
  207. 'data' => array(
  208. 'description' => 'A serialized array of extra data.',
  209. 'type' => 'text',
  210. 'serialize' => TRUE,
  211. ),
  212. 'created' => array(
  213. 'description' => 'The Unix timestamp indicating when the order was created.',
  214. 'type' => 'int',
  215. 'not null' => TRUE,
  216. 'default' => 0,
  217. ),
  218. 'modified' => array(
  219. 'description' => 'The Unix timestamp indicating when the order was last modified.',
  220. 'type' => 'int',
  221. 'not null' => TRUE,
  222. 'default' => 0,
  223. ),
  224. 'host' => array(
  225. 'description' => 'Host IP address of the person paying for the order.',
  226. 'type' => 'varchar',
  227. 'length' => 255,
  228. 'not null' => TRUE,
  229. 'default' => '',
  230. ),
  231. 'currency' => array(
  232. 'description' => 'The ISO currency code for the order.',
  233. 'type' => 'char',
  234. 'length' => 3,
  235. 'not null' => TRUE,
  236. 'default' => '',
  237. ),
  238. ),
  239. 'indexes' => array(
  240. 'uid' => array('uid'),
  241. 'order_status' => array('order_status'),
  242. ),
  243. 'primary key' => array('order_id'),
  244. 'foreign keys' => array(
  245. 'users' => array(
  246. 'table' => 'users',
  247. 'columns' => array('uid' => 'uid'),
  248. ),
  249. 'uc_order_statuses' => array(
  250. 'table' => 'uc_order_statuses',
  251. 'columns' => array('order_status' => 'order_status_id'),
  252. ),
  253. ),
  254. );
  255. $schema['uc_order_admin_comments'] = array(
  256. 'description' => 'Comments on orders that only administrators can see.',
  257. 'fields' => array(
  258. 'comment_id' => array(
  259. 'description' => 'Primary key: the comment ID.',
  260. 'type' => 'serial',
  261. 'unsigned' => TRUE,
  262. 'not null' => TRUE,
  263. ),
  264. 'order_id' => array(
  265. 'description' => 'The {uc_orders}.order_id of the order.',
  266. 'type' => 'int',
  267. 'unsigned' => TRUE,
  268. 'not null' => TRUE,
  269. 'default' => 0,
  270. ),
  271. 'uid' => array(
  272. 'description' => 'The {user}.uid of the author of the comment.',
  273. 'type' => 'int',
  274. 'unsigned' => TRUE,
  275. 'not null' => TRUE,
  276. 'default' => 0,
  277. ),
  278. 'message' => array(
  279. 'description' => 'The comment body.',
  280. 'type' => 'text',
  281. ),
  282. 'created' => array(
  283. 'description' => 'The Unix timestamp indicating when the comment was created.',
  284. 'type' => 'int',
  285. 'not null' => TRUE,
  286. 'default' => 0,
  287. ),
  288. ),
  289. 'indexes' => array(
  290. 'order_id' => array('order_id'),
  291. ),
  292. 'primary key' => array('comment_id'),
  293. 'foreign keys' => array(
  294. 'uc_orders' => array(
  295. 'table' => 'uc_orders',
  296. 'columns' => array('order_id' => 'order_id'),
  297. ),
  298. 'users' => array(
  299. 'table' => 'users',
  300. 'columns' => array('uid' => 'uid'),
  301. ),
  302. ),
  303. );
  304. $schema['uc_order_comments'] = array(
  305. 'description' => 'Comments on the order that the customer can see.',
  306. 'fields' => array(
  307. 'comment_id' => array(
  308. 'description' => 'Primary key: the comment ID.',
  309. 'type' => 'serial',
  310. 'unsigned' => TRUE,
  311. 'not null' => TRUE,
  312. ),
  313. 'order_id' => array(
  314. 'description' => 'The {uc_orders}.order_id of the order.',
  315. 'type' => 'int',
  316. 'unsigned' => TRUE,
  317. 'not null' => TRUE,
  318. 'default' => 0,
  319. ),
  320. 'uid' => array(
  321. 'description' => 'The {users}.uid of the user who made the comment.',
  322. 'type' => 'int',
  323. 'unsigned' => TRUE,
  324. 'not null' => TRUE,
  325. 'default' => 0,
  326. ),
  327. 'order_status' => array(
  328. 'description' => 'The status the order had when the comment was made, from {uc_order_statuses}.order_status_id.',
  329. 'type' => 'varchar',
  330. 'length' => 32,
  331. 'not null' => TRUE,
  332. 'default' => '',
  333. ),
  334. 'notified' => array(
  335. 'description' => 'A flag indicating whether the comment was emailed to the customer. 1 => Yes. 0 => No.',
  336. 'type' => 'int',
  337. 'size' => 'tiny',
  338. 'not null' => TRUE,
  339. 'default' => 0,
  340. ),
  341. 'message' => array(
  342. 'description' => 'The comment body.',
  343. 'type' => 'text',
  344. ),
  345. 'created' => array(
  346. 'description' => 'The Unix timestamp indicating when the comment was created.',
  347. 'type' => 'int',
  348. 'not null' => TRUE,
  349. 'default' => 0,
  350. ),
  351. ),
  352. 'indexes' => array(
  353. 'order_id' => array('order_id'),
  354. ),
  355. 'primary key' => array('comment_id'),
  356. 'foreign keys' => array(
  357. 'uc_orders' => array(
  358. 'table' => 'uc_orders',
  359. 'columns' => array('order_id' => 'order_id'),
  360. ),
  361. 'users' => array(
  362. 'table' => 'users',
  363. 'columns' => array('uid' => 'uid'),
  364. ),
  365. ),
  366. );
  367. $schema['uc_order_line_items'] = array(
  368. 'description' => 'Order line items other than products.',
  369. 'fields' => array(
  370. 'line_item_id' => array(
  371. 'description' => 'Primary key: the line item ID.',
  372. 'type' => 'serial',
  373. 'unsigned' => TRUE,
  374. 'not null' => TRUE,
  375. ),
  376. 'order_id' => array(
  377. 'description' => 'The {uc_orders}.order_id.',
  378. 'type' => 'int',
  379. 'unsigned' => TRUE,
  380. 'not null' => TRUE,
  381. 'default' => 0,
  382. ),
  383. 'type' => array(
  384. 'description' => 'The line item type.',
  385. 'type' => 'varchar',
  386. 'length' => 32,
  387. 'not null' => TRUE,
  388. 'default' => '',
  389. ),
  390. 'title' => array(
  391. 'description' => 'The label of the line item.',
  392. 'type' => 'varchar',
  393. 'length' => 255,
  394. 'not null' => TRUE,
  395. 'default' => '',
  396. ),
  397. 'amount' => array(
  398. 'description' => "The amount of the line item in the store's currency.",
  399. 'type' => 'numeric',
  400. 'precision' => 16,
  401. 'scale' => 5,
  402. 'not null' => TRUE,
  403. 'default' => 0.0,
  404. ),
  405. 'weight' => array(
  406. 'description' => 'The sort criteria of line items.',
  407. 'type' => 'int',
  408. 'size' => 'small',
  409. 'not null' => TRUE,
  410. 'default' => 0,
  411. ),
  412. 'data' => array(
  413. 'description' => 'A serialized array of extra data.',
  414. 'type' => 'text',
  415. 'serialize' => TRUE,
  416. ),
  417. ),
  418. 'indexes' => array(
  419. 'order_id' => array('order_id'),
  420. ),
  421. 'primary key' => array('line_item_id'),
  422. 'foreign keys' => array(
  423. 'uc_orders' => array(
  424. 'table' => 'uc_orders',
  425. 'columns' => array('order_id' => 'order_id'),
  426. ),
  427. ),
  428. );
  429. $schema['uc_order_log'] = array(
  430. 'description' => 'Record of changes made to an order.',
  431. 'fields' => array(
  432. 'order_log_id' => array(
  433. 'description' => 'Primary key: the log entry ID.',
  434. 'type' => 'serial',
  435. 'unsigned' => TRUE,
  436. 'not null' => TRUE,
  437. ),
  438. 'order_id' => array(
  439. 'description' => 'The {uc_orders}.order_id.',
  440. 'type' => 'int',
  441. 'unsigned' => TRUE,
  442. 'not null' => TRUE,
  443. 'default' => 0,
  444. ),
  445. 'uid' => array(
  446. 'description' => 'The {users}.uid of the user who made the changes.',
  447. 'type' => 'int',
  448. 'unsigned' => TRUE,
  449. 'not null' => TRUE,
  450. 'default' => 0,
  451. ),
  452. 'changes' => array(
  453. 'description' => 'The description of what was changed.',
  454. 'type' => 'text',
  455. ),
  456. 'created' => array(
  457. 'description' => 'The Unix timestamp indicating when the change was made.',
  458. 'type' => 'int',
  459. 'not null' => TRUE,
  460. 'default' => 0,
  461. ),
  462. ),
  463. 'indexes' => array(
  464. 'order_id' => array('order_id'),
  465. ),
  466. 'primary key' => array('order_log_id'),
  467. 'foreign keys' => array(
  468. 'uc_orders' => array(
  469. 'table' => 'uc_orders',
  470. 'columns' => array('order_id' => 'order_id'),
  471. ),
  472. 'users' => array(
  473. 'table' => 'users',
  474. 'columns' => array('uid' => 'uid'),
  475. ),
  476. ),
  477. );
  478. $schema['uc_order_products'] = array(
  479. 'description' => 'The products that have been ordered.',
  480. 'fields' => array(
  481. 'order_product_id' => array(
  482. 'description' => 'Primary key: the ordered product ID.',
  483. 'type' => 'serial',
  484. 'unsigned' => TRUE,
  485. 'not null' => TRUE,
  486. ),
  487. 'order_id' => array(
  488. 'description' => 'The {uc_orders}.order_id.',
  489. 'type' => 'int',
  490. 'unsigned' => TRUE,
  491. 'not null' => TRUE,
  492. 'default' => 0,
  493. ),
  494. 'nid' => array(
  495. 'description' => 'The {node}.nid of the product.',
  496. 'type' => 'int',
  497. 'unsigned' => TRUE,
  498. 'not null' => TRUE,
  499. 'default' => 0,
  500. ),
  501. 'title' => array(
  502. 'description' => 'The product title, from {node}.title.',
  503. 'type' => 'varchar',
  504. 'length' => 255,
  505. 'not null' => TRUE,
  506. 'default' => '',
  507. ),
  508. 'model' => array(
  509. 'description' => 'The product model/SKU, from {uc_products}.model.',
  510. 'type' => 'varchar',
  511. 'length' => 255,
  512. 'not null' => TRUE,
  513. 'default' => '',
  514. ),
  515. 'qty' => array(
  516. 'description' => 'The number of the same product ordered.',
  517. 'type' => 'int',
  518. 'unsigned' => TRUE,
  519. 'not null' => TRUE,
  520. 'default' => 0,
  521. ),
  522. 'cost' => array(
  523. 'description' => 'The cost to the store for the product.',
  524. 'type' => 'numeric',
  525. 'precision' => 16,
  526. 'scale' => 5,
  527. 'not null' => TRUE,
  528. 'default' => 0.0,
  529. ),
  530. 'price' => array(
  531. 'description' => 'The price paid for the ordered product.',
  532. 'type' => 'numeric',
  533. 'precision' => 16,
  534. 'scale' => 5,
  535. 'not null' => TRUE,
  536. 'default' => 0.0,
  537. ),
  538. 'weight' => array(
  539. 'description' => 'The physical weight.',
  540. 'type' => 'float',
  541. 'not null' => TRUE,
  542. 'default' => 0.0,
  543. ),
  544. 'weight_units' => array(
  545. 'description' => 'Unit of measure for the weight field.',
  546. 'type' => 'varchar',
  547. 'length' => 255,
  548. 'not null' => TRUE,
  549. 'default' => 'lb',
  550. ),
  551. 'data' => array(
  552. 'description' => 'A serialized array of extra data.',
  553. 'type' => 'text',
  554. 'serialize' => TRUE,
  555. ),
  556. ),
  557. 'indexes' => array(
  558. 'order_id' => array('order_id'),
  559. 'qty' => array('qty'),
  560. 'nid' => array('nid'),
  561. ),
  562. 'primary key' => array('order_product_id'),
  563. 'foreign keys' => array(
  564. 'uc_orders' => array(
  565. 'table' => 'uc_orders',
  566. 'columns' => array('order_id' => 'order_id'),
  567. ),
  568. 'node' => array(
  569. 'table' => 'node',
  570. 'columns' => array('nid' => 'nid'),
  571. ),
  572. ),
  573. );
  574. $schema['uc_order_statuses'] = array(
  575. 'description' => 'Statuses the order can have during its lifecycle.',
  576. 'fields' => array(
  577. 'order_status_id' => array(
  578. 'description' => 'Primary key: the order status ID.',
  579. 'type' => 'varchar',
  580. 'length' => 32,
  581. 'not null' => TRUE,
  582. 'default' => '',
  583. ),
  584. 'title' => array(
  585. 'description' => 'The status title.',
  586. 'type' => 'varchar',
  587. 'length' => 48,
  588. 'not null' => TRUE,
  589. 'default' => '',
  590. ),
  591. 'state' => array(
  592. 'description' => 'The base order state with which the status is associated.',
  593. 'type' => 'varchar',
  594. 'length' => 32,
  595. 'not null' => TRUE,
  596. 'default' => '',
  597. ),
  598. 'weight' => array(
  599. 'description' => 'The sort criteria for statuses.',
  600. 'type' => 'int',
  601. 'size' => 'small',
  602. 'not null' => TRUE,
  603. 'default' => 0,
  604. ),
  605. 'locked' => array(
  606. 'description' => 'A flag indicating whether users can delete the status. 0 => Yes. 1 => No.',
  607. 'type' => 'int',
  608. 'size' => 'tiny',
  609. 'unsigned' => TRUE,
  610. 'not null' => TRUE,
  611. 'default' => 0,
  612. ),
  613. ),
  614. 'primary key' => array('order_status_id'),
  615. );
  616. return $schema;
  617. }
  618. /**
  619. * Implements hook_install().
  620. */
  621. function uc_order_install() {
  622. $t = get_t();
  623. $query = db_insert('uc_order_statuses')
  624. ->fields(array(
  625. 'order_status_id',
  626. 'title',
  627. 'state',
  628. 'weight',
  629. 'locked',
  630. ));
  631. $values = array(
  632. array(
  633. 'order_status_id' => 'abandoned',
  634. 'title' => $t('Abandoned'),
  635. 'state' => 'canceled',
  636. 'weight' => -30,
  637. 'locked' => 1,
  638. ),
  639. array(
  640. 'order_status_id' => 'canceled',
  641. 'title' => $t('Canceled'),
  642. 'state' => 'canceled',
  643. 'weight' => -20,
  644. 'locked' => 1,
  645. ),
  646. array(
  647. 'order_status_id' => 'in_checkout',
  648. 'title' => $t('In checkout'),
  649. 'state' => 'in_checkout',
  650. 'weight' => -10,
  651. 'locked' => 1,
  652. ),
  653. array(
  654. 'order_status_id' => 'pending',
  655. 'title' => $t('Pending'),
  656. 'state' => 'post_checkout',
  657. 'weight' => 0,
  658. 'locked' => 1,
  659. ),
  660. array(
  661. 'order_status_id' => 'processing',
  662. 'title' => $t('Processing'),
  663. 'state' => 'post_checkout',
  664. 'weight' => 5,
  665. 'locked' => 1,
  666. ),
  667. array(
  668. 'order_status_id' => 'completed',
  669. 'title' => $t('Completed'),
  670. 'state' => 'completed',
  671. 'weight' => 20,
  672. 'locked' => 1,
  673. ),
  674. );
  675. foreach ($values as $record) {
  676. $query->values($record);
  677. }
  678. $query->execute();
  679. }
  680. /**
  681. * Implements hook_uninstall().
  682. */
  683. function uc_order_uninstall() {
  684. db_delete('variable')
  685. ->condition('name', 'uc_state_%', 'LIKE')
  686. ->execute();
  687. variable_del('uc_order_capitalize_addresses');
  688. variable_del('uc_cust_order_invoice_template');
  689. }
  690. /**
  691. * Implements hook_update_last_removed().
  692. */
  693. function uc_order_update_last_removed() {
  694. // 7.x-3.0-beta2 and earlier were installed with schema version 0,
  695. // which causes update.php to fail.
  696. return drupal_get_installed_schema_version('uc_order') == 0 ? 0 : 6015;
  697. }
  698. /**
  699. * Remove unused setting.
  700. */
  701. function uc_order_update_6016() {
  702. variable_del('uc_ubrowser_product_select');
  703. }
  704. /**
  705. * Increase the maximum length of product and line item titles.
  706. */
  707. function uc_order_update_7000() {
  708. db_change_field('uc_order_products', 'title', 'title', array(
  709. 'description' => 'The product title, from {node}.title.',
  710. 'type' => 'varchar',
  711. 'length' => 255,
  712. 'not null' => TRUE,
  713. 'default' => '',
  714. ));
  715. db_change_field('uc_order_line_items', 'title', 'title', array(
  716. 'description' => 'The label of the line item.',
  717. 'type' => 'varchar',
  718. 'length' => 255,
  719. 'not null' => TRUE,
  720. 'default' => '',
  721. ));
  722. }
  723. /**
  724. * Add currency code field.
  725. */
  726. function uc_order_update_7001() {
  727. // Column may have been added by uc_order_update_6018() in 6.x-2.x.
  728. if (!db_field_exists('uc_orders', 'currency')) {
  729. db_add_field('uc_orders', 'currency', array(
  730. 'type' => 'char',
  731. 'length' => 3,
  732. 'not null' => TRUE,
  733. 'default' => '',
  734. ));
  735. db_update('uc_orders')
  736. ->fields(array('currency' => variable_get('uc_currency_code', 'USD')))
  737. ->execute();
  738. }
  739. }
  740. /**
  741. * Add indexes so product and customer reports are usable with large datasets.
  742. */
  743. function uc_order_update_7002() {
  744. // Indexes may have been added by uc_order_update_6019() in 6.x-2.x.
  745. if (!db_index_exists('uc_order_products', 'qty')) {
  746. db_add_index('uc_order_products', 'qty', array('qty'));
  747. }
  748. if (!db_index_exists('uc_order_products', 'nid')) {
  749. db_add_index('uc_order_products', 'nid', array('nid'));
  750. }
  751. }
  752. /**
  753. * Increase maximum order item quantity.
  754. */
  755. function uc_order_update_7003() {
  756. db_change_field('uc_order_products', 'qty', 'qty', array(
  757. 'description' => 'The number of the same product ordered.',
  758. 'type' => 'int',
  759. 'unsigned' => TRUE,
  760. 'not null' => TRUE,
  761. 'default' => 0,
  762. ));
  763. }
  764. /**
  765. * Add weight units to order products.
  766. */
  767. function uc_order_update_7004(&$sandbox) {
  768. if (!isset($sandbox['progress'])) {
  769. if (db_field_exists('uc_order_products', 'weight_units')) {
  770. return;
  771. }
  772. $sandbox['progress'] = 0;
  773. $sandbox['current_nid'] = 0;
  774. $sandbox['max'] = db_query("SELECT COUNT(DISTINCT nid) FROM {uc_products}")->fetchField();
  775. db_add_field('uc_order_products', 'weight_units', array(
  776. 'description' => 'Unit of measure for the weight field.',
  777. 'type' => 'varchar',
  778. 'length' => 255,
  779. 'not null' => TRUE,
  780. 'default' => 'lb',
  781. ));
  782. db_update('uc_order_products')
  783. ->fields(array('weight_units' => variable_get('uc_weight_unit', 'lb')))
  784. ->condition('nid', 0)
  785. ->execute();
  786. }
  787. $t = get_t();
  788. $limit = 200;
  789. $result = db_query_range("SELECT n.nid, n.title, p.weight_units FROM {node} n JOIN {uc_products} p ON n.vid = p.vid WHERE n.nid > :current ORDER BY n.nid", 0, $limit, array(':current' => $sandbox['current_nid']));
  790. foreach ($result as $node) {
  791. db_update('uc_order_products')
  792. ->fields(array('weight_units' => $node->weight_units))
  793. ->condition('nid', $node->nid)
  794. ->execute();
  795. $sandbox['progress']++;
  796. $sandbox['current_nid'] = $node->nid;
  797. $sandbox['message'] = $t('Copied weight units from %title.', array('%title' => $node->title));
  798. }
  799. if ($sandbox['progress'] < $sandbox['max']) {
  800. $sandbox['#finished'] = min(0.99, $sandbox['progress'] / $sandbox['max']);
  801. }
  802. else {
  803. $sandbox['#finished'] = 1;
  804. }
  805. }
  806. /**
  807. * Remove deprecated manufacturer column.
  808. */
  809. function uc_order_update_7005() {
  810. db_drop_field('uc_order_products', 'manufacturer');
  811. }
  812. /**
  813. * Remove unused variable.
  814. */
  815. function uc_order_update_7006() {
  816. variable_del('uc_order_number_displayed');
  817. }
  818. /**
  819. * Add 'abandoned' order status.
  820. */
  821. function uc_order_update_7007() {
  822. db_merge('uc_order_statuses')
  823. ->key(array('order_status_id' => 'abandoned'))
  824. ->fields(array(
  825. 'title' => t('Abandoned'),
  826. 'state' => 'canceled',
  827. 'weight' => -30,
  828. 'locked' => 1,
  829. ))
  830. ->execute();
  831. db_update('uc_orders')
  832. ->fields(array('order_status' => 'abandoned'))
  833. ->condition('order_status', 'in_checkout')
  834. ->condition('modified', REQUEST_TIME - 600, '<')
  835. ->execute();
  836. }
  837. /**
  838. * Delete unwanted sensitive data.
  839. */
  840. function uc_order_update_7300() {
  841. $result = db_query("SELECT order_id, data FROM {uc_orders} WHERE data LIKE '%s:4:\"pass\"%'");
  842. while ($row = $result->fetchObject()) {
  843. $data = unserialize($row->data);
  844. if (isset($data['new_user']['pass'])) {
  845. unset($data['new_user']['pass']);
  846. db_update('uc_orders')
  847. ->fields(array('data' => serialize($data)))
  848. ->condition('order_id', $row->order_id)
  849. ->execute();
  850. }
  851. }
  852. variable_del('uc_order_cron_last');
  853. }
  854. /**
  855. * Convert view invoices checkbox to permission.
  856. */
  857. function uc_order_update_7301() {
  858. if (variable_get('uc_cust_view_order_invoices', TRUE)) {
  859. // user_role_grant_permissions() is not allowed during upgrades from D6.
  860. db_merge('role_permission')
  861. ->key(array(
  862. 'rid' => DRUPAL_AUTHENTICATED_RID,
  863. 'permission' => 'view own invoices',
  864. ))
  865. ->fields(array(
  866. 'module' => 'uc_order',
  867. ))
  868. ->execute();
  869. }
  870. variable_del('uc_cust_view_order_invoices');
  871. }
  872. /**
  873. * Remove unused order pane settings.
  874. */
  875. function uc_order_update_7302() {
  876. db_delete('variable')
  877. ->condition('name', 'uc_order_pane_%', 'LIKE')
  878. ->execute();
  879. }