uc_order.views.inc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. <?php
  2. /**
  3. * @file
  4. * Views hooks and callback registries.
  5. */
  6. /**
  7. * Implements hook_views_data().
  8. */
  9. function uc_order_views_data() {
  10. // Orders table.
  11. $data['uc_orders']['table']['group'] = t('Order');
  12. $data['uc_orders']['table']['base'] = array(
  13. 'field' => 'order_id',
  14. 'title' => t('Orders'),
  15. 'help' => t('Orders placed in your Ubercart store.'),
  16. 'access query tag' => 'uc_order_access',
  17. );
  18. // Pull in user fields directly.
  19. $data['users']['table']['join']['uc_orders'] = array(
  20. 'left_field' => 'uid',
  21. 'field' => 'uid',
  22. );
  23. // Order ID field.
  24. $data['uc_orders']['order_id'] = array(
  25. 'title' => t('Order ID'),
  26. 'help' => t('The order ID.'),
  27. 'field' => array(
  28. 'handler' => 'uc_order_handler_field_order_id',
  29. 'click sortable' => TRUE,
  30. ),
  31. 'sort' => array(
  32. 'handler' => 'views_handler_sort',
  33. ),
  34. 'filter' => array(
  35. 'handler' => 'views_handler_filter_numeric',
  36. ),
  37. 'argument' => array(
  38. 'handler' => 'views_handler_argument_numeric',
  39. 'name field' => 'title',
  40. 'numeric' => TRUE,
  41. 'validate type' => 'order_id',
  42. ),
  43. );
  44. // Order status field.
  45. $data['uc_orders']['order_status'] = array(
  46. 'title' => t('Order status'),
  47. 'help' => t('The order status.'),
  48. 'field' => array(
  49. 'handler' => 'uc_order_handler_field_order_status',
  50. 'click sortable' => TRUE,
  51. ),
  52. 'sort' => array(
  53. 'handler' => 'views_handler_sort',
  54. ),
  55. 'filter' => array(
  56. 'handler' => 'uc_order_handler_filter_order_status',
  57. ),
  58. );
  59. // Expose the uid as a relationship.
  60. $data['uc_orders']['uid'] = array(
  61. 'title' => t('Customer'),
  62. 'help' => t('Relate an order to the user who placed it.'),
  63. 'relationship' => array(
  64. 'base' => 'users',
  65. 'field' => 'uid',
  66. 'handler' => 'views_handler_relationship',
  67. 'label' => t('customer'),
  68. ),
  69. );
  70. // Expose the uid as a relationship to users.
  71. $data['users']['uc_orders'] = array(
  72. 'title' => t('Orders'),
  73. 'help' => t('Relate a user to the orders they have placed. This relationship will create one record for each order placed by the user.'),
  74. 'relationship' => array(
  75. 'base' => 'uc_orders',
  76. 'base field' => 'uid',
  77. 'relationship field' => 'uid',
  78. 'handler' => 'views_handler_relationship',
  79. 'label' => t('orders'),
  80. ),
  81. );
  82. // Changed field handler to display as a price
  83. $data['uc_orders']['order_total'] = array(
  84. 'title' => t('Order total'),
  85. 'help' => t('The total amount to be paid for the order.'),
  86. 'field' => array(
  87. 'handler' => 'uc_order_handler_field_money_amount',
  88. 'click sortable' => TRUE,
  89. 'float' => TRUE,
  90. ),
  91. 'sort' => array(
  92. 'handler' => 'views_handler_sort',
  93. ),
  94. 'filter' => array(
  95. 'handler' => 'views_handler_filter_numeric',
  96. ),
  97. );
  98. $data['uc_orders']['order_total_cost'] = array(
  99. 'title' => t('Total cost'),
  100. 'help' => t('The total cost of the products in the order.'),
  101. 'field' => array(
  102. 'handler' => 'uc_order_handler_field_order_cost',
  103. 'float' => TRUE,
  104. ),
  105. );
  106. $data['uc_orders']['payment_method'] = array(
  107. 'title' => t('Payment method'),
  108. 'help' => t('The method of payment.'),
  109. 'field' => array(
  110. 'handler' => 'uc_order_handler_field_payment_method',
  111. 'click sortable' => TRUE,
  112. ),
  113. 'sort' => array(
  114. 'handler' => 'views_handler_sort',
  115. ),
  116. 'filter' => array(
  117. 'handler' => 'uc_order_handler_filter_payment_method',
  118. ),
  119. );
  120. $data['uc_orders']['cc_type'] = array(
  121. 'title' => t('Credit card type'),
  122. 'help' => t('Credit card type used, if the payment method was credit.'),
  123. 'real field' => 'data',
  124. 'field' => array(
  125. 'handler' => 'uc_order_handler_field_order_cc_data',
  126. 'cc field' => 'cc_type',
  127. ),
  128. );
  129. $data['uc_orders']['cc_number'] = array(
  130. 'title' => t('Credit card number'),
  131. 'help' => t('Credit card number (last 4) used, if the payment method was credit.'),
  132. 'real field' => 'data',
  133. 'field' => array(
  134. 'handler' => 'uc_order_handler_field_order_cc_data',
  135. 'cc field' => 'cc_number',
  136. ),
  137. );
  138. $data['uc_orders']['product_count'] = array(
  139. 'title' => t('Product count'),
  140. 'help' => t('The total number of products in the order.'),
  141. 'field' => array(
  142. 'handler' => 'views_handler_field_numeric',
  143. 'click sortable' => TRUE,
  144. ),
  145. 'sort' => array(
  146. 'handler' => 'views_handler_sort',
  147. ),
  148. 'filter' => array(
  149. 'handler' => 'views_handler_filter_numeric',
  150. ),
  151. );
  152. $data['uc_orders']['created'] = array(
  153. 'title' => t('Creation date'),
  154. 'help' => t('The date and time the order was created.'),
  155. 'field' => array(
  156. 'handler' => 'views_handler_field_date',
  157. 'click sortable' => TRUE,
  158. ),
  159. 'sort' => array(
  160. 'handler' => 'views_handler_sort_date',
  161. ),
  162. 'filter' => array(
  163. 'handler' => 'views_handler_filter_date',
  164. ),
  165. );
  166. $data['uc_orders']['modified'] = array(
  167. 'title' => t('Last modified'),
  168. 'help' => t('The time the order was last modified.'),
  169. 'field' => array(
  170. 'handler' => 'views_handler_field_date',
  171. 'click sortable' => TRUE,
  172. ),
  173. 'sort' => array(
  174. 'handler' => 'views_handler_sort_date',
  175. ),
  176. 'filter' => array(
  177. 'handler' => 'views_handler_filter_date',
  178. ),
  179. );
  180. // Use the sleeker Date module views handler if available.
  181. if (module_exists('date_views')) {
  182. $data['uc_orders']['created']['filter'] = array(
  183. 'handler' => 'date_views_filter_handler_simple',
  184. 'is date' => TRUE,
  185. );
  186. $data['uc_orders']['modified']['filter'] = array(
  187. 'handler' => 'date_views_filter_handler_simple',
  188. 'is date' => TRUE,
  189. );
  190. }
  191. $data['uc_orders']['actions'] = array(
  192. 'title' => t('Actions'),
  193. 'help' => t('Clickable links to actions a user may perform on an order.'),
  194. 'field' => array(
  195. 'handler' => 'uc_order_handler_field_order_actions',
  196. 'click sortable' => FALSE,
  197. ),
  198. );
  199. $data['uc_orders']['primary_email'] = array(
  200. 'title' => t('Email address'),
  201. 'help' => t('The email address of the customer.'),
  202. 'field' => array(
  203. 'handler' => 'views_handler_field_user_mail',
  204. 'click sortable' => TRUE,
  205. ),
  206. 'sort' => array(
  207. 'handler' => 'views_handler_sort',
  208. ),
  209. 'filter' => array(
  210. 'handler' => 'views_handler_filter_string',
  211. ),
  212. );
  213. $addresses = array(
  214. 'billing' => t('Billing address'),
  215. 'delivery' => t('Delivery address'),
  216. );
  217. $fields = array(
  218. 'first_name' => t('First name'),
  219. 'last_name' => t('Last name'),
  220. 'phone' => t('Phone number'),
  221. 'company' => t('Company'),
  222. 'street1' => t('Street address 1'),
  223. 'street2' => t('Street address 2'),
  224. 'city' => t('City'),
  225. 'postal_code' => t('Postal code'),
  226. );
  227. foreach ($addresses as $prefix => $address) {
  228. $group = t('Order') . ': ' . $address;
  229. foreach ($fields as $field => $label) {
  230. $data['uc_orders'][$prefix . '_' . $field] = array(
  231. 'group' => $group,
  232. 'title' => $label,
  233. 'help' => t('The !field of the !address of the order.', array('!field' => drupal_strtolower($label), '!address' => drupal_strtolower($address))),
  234. 'field' => array(
  235. 'handler' => 'views_handler_field',
  236. 'click sortable' => TRUE,
  237. ),
  238. 'sort' => array(
  239. 'handler' => 'views_handler_sort',
  240. ),
  241. 'filter' => array(
  242. 'handler' => 'views_handler_filter_string',
  243. ),
  244. );
  245. }
  246. $data['uc_orders'][$prefix . '_full_name'] = array(
  247. 'group' => $group,
  248. 'title' => t('Full name'),
  249. 'help' => t('The !field of the !address of the order.', array('!field' => t('full name'), '!address' => drupal_strtolower($address))),
  250. 'field' => array(
  251. 'additional fields' => array(
  252. $prefix . '_first_name',
  253. $prefix . '_last_name'
  254. ),
  255. 'handler' => 'uc_order_handler_field_order_fullname',
  256. 'prefix' => $prefix,
  257. ),
  258. );
  259. $data[$prefix . '_countries']['table']['group'] = $group;
  260. $data[$prefix . '_countries']['table']['join']['uc_orders'] = array(
  261. 'table' => 'uc_countries',
  262. 'left_field' => $prefix . '_country',
  263. 'field' => 'country_id',
  264. );
  265. $data[$prefix . '_countries']['country_id'] = array(
  266. 'title' => t('ISO country code (numeric)'),
  267. 'help' => t('The !field of the !address of the order.', array('!field' => t('numeric ISO country code'), '!address' => drupal_strtolower($address))),
  268. 'argument' => array(
  269. 'handler' => 'views_handler_argument_numeric',
  270. 'name field' => 'country_iso_code_2',
  271. 'numeric' => TRUE,
  272. 'validate type' => 'country_id',
  273. ),
  274. 'filter' => array(
  275. 'handler' => 'views_handler_filter_numeric',
  276. ),
  277. );
  278. $data[$prefix . '_countries']['country_name'] = array(
  279. 'title' => t('Country'),
  280. 'help' => t('The !field of the !address of the order.', array('!field' => t('country name'), '!address' => drupal_strtolower($address))),
  281. 'field' => array(
  282. 'handler' => 'views_handler_field',
  283. 'click sortable' => TRUE,
  284. ),
  285. 'sort' => array(
  286. 'handler' => 'views_handler_sort',
  287. ),
  288. 'filter' => array(
  289. 'handler' => 'views_handler_filter_string',
  290. ),
  291. );
  292. $data[$prefix . '_countries']['country_iso_code_2'] = array(
  293. 'title' => t('ISO country code (2 characters)'),
  294. 'help' => t('The !field of the !address of the order.', array('!field' => t('ISO country code'), '!address' => drupal_strtolower($address))),
  295. 'field' => array(
  296. 'handler' => 'views_handler_field',
  297. 'click sortable' => TRUE,
  298. ),
  299. 'sort' => array(
  300. 'handler' => 'views_handler_sort',
  301. ),
  302. 'filter' => array(
  303. 'handler' => 'views_handler_filter_string',
  304. ),
  305. );
  306. $data[$prefix . '_countries']['country_iso_code_3'] = array(
  307. 'title' => t('ISO country code (3 characters)'),
  308. 'help' => t('The !field of the !address of the order.', array('!field' => t('ISO country code'), '!address' => drupal_strtolower($address))),
  309. 'field' => array(
  310. 'handler' => 'views_handler_field',
  311. 'click sortable' => TRUE,
  312. ),
  313. 'sort' => array(
  314. 'handler' => 'views_handler_sort',
  315. ),
  316. 'filter' => array(
  317. 'handler' => 'views_handler_filter_string',
  318. ),
  319. );
  320. $data[$prefix . '_zones']['table']['group'] = $group;
  321. $data[$prefix . '_zones']['table']['join']['uc_orders'] = array(
  322. 'table' => 'uc_zones',
  323. 'left_field' => $prefix . '_zone',
  324. 'field' => 'zone_id',
  325. );
  326. $data[$prefix . '_zones']['zone_name'] = array(
  327. 'title' => t('State/Province'),
  328. 'help' => t('The !field of the !address of the order.', array('!field' => t('state or province'), '!address' => drupal_strtolower($address))),
  329. 'field' => array(
  330. 'handler' => 'views_handler_field',
  331. 'click sortable' => TRUE,
  332. ),
  333. 'sort' => array(
  334. 'handler' => 'views_handler_sort',
  335. ),
  336. 'filter' => array(
  337. 'handler' => 'views_handler_filter_string',
  338. ),
  339. );
  340. $data[$prefix . '_zones']['zone_code'] = array(
  341. 'title' => t('State/Province code'),
  342. 'help' => t('The !field of the !address of the order.', array('!field' => t('state or province code'), '!address' => drupal_strtolower($address))),
  343. 'field' => array(
  344. 'handler' => 'views_handler_field',
  345. 'click sortable' => TRUE,
  346. ),
  347. 'sort' => array(
  348. 'handler' => 'views_handler_sort',
  349. ),
  350. 'filter' => array(
  351. 'handler' => 'views_handler_filter_string',
  352. ),
  353. );
  354. }
  355. $data['uc_orders']['total_weight'] = array(
  356. 'title' => t('Total weight'),
  357. 'help' => t('The physical weight of all the products (weight * quantity) in the order.'),
  358. 'real field' => 'weight',
  359. 'field' => array(
  360. 'handler' => 'uc_order_handler_field_order_weight_total',
  361. 'additional fields' => array(
  362. 'order_id' => 'order_id',
  363. ),
  364. 'float' => TRUE,
  365. ),
  366. );
  367. // Ordered products.
  368. // Get the standard EntityAPI Views data table.
  369. $data['uc_order_products'] = entity_views_table_definition('uc_order_product');
  370. // Remove undesirable fields
  371. foreach(array('data') as $bad_field) {
  372. if (isset($data['uc_order_products'][$bad_field])) {
  373. unset($data['uc_order_products'][$bad_field]);
  374. }
  375. }
  376. // Fix incomplete fields
  377. $data['uc_order_products']['weight_units']['title'] = t('Weight units');
  378. $data['uc_order_products']['table']['group'] = t('Ordered product');
  379. $data['uc_order_products']['table']['base'] = array(
  380. 'field' => 'order_product_id',
  381. 'title' => t('Ordered products'),
  382. 'help' => t('Products that have been ordered in your Ubercart store.'),
  383. );
  384. // Pull in node fields directly.
  385. $data['node']['table']['join']['uc_order_products'] = array(
  386. 'left_field' => 'nid',
  387. 'field' => 'nid',
  388. );
  389. // Pull in order fields directly.
  390. $data['uc_orders']['table']['join']['uc_order_products'] = array(
  391. 'left_field' => 'order_id',
  392. 'field' => 'order_id',
  393. );
  394. // Expose products to their orders as a relationship.
  395. $data['uc_orders']['products'] = array(
  396. 'relationship' => array(
  397. 'title' => t('Products'),
  398. 'help' => t('Relate products to an order. This relationship will create one record for each product ordered.'),
  399. 'handler' => 'views_handler_relationship',
  400. 'base' => 'uc_order_products',
  401. 'base field' => 'order_id',
  402. 'relationship field' => 'order_id',
  403. 'label' => t('products'),
  404. ),
  405. );
  406. // Expose nodes to ordered products as a relationship.
  407. $data['uc_order_products']['nid'] = array(
  408. 'title' => t('Nid'),
  409. 'help' => t('The nid of the ordered product. If you need more fields than the nid: Node relationship'),
  410. 'relationship' => array(
  411. 'title' => t('Node'),
  412. 'help' => t('Relate product to node.'),
  413. 'handler' => 'views_handler_relationship',
  414. 'base' => 'node',
  415. 'field' => 'nid',
  416. 'label' => t('node'),
  417. ),
  418. 'filter' => array(
  419. 'handler' => 'views_handler_filter_numeric',
  420. ),
  421. 'argument' => array(
  422. 'handler' => 'views_handler_argument_node_nid',
  423. ),
  424. 'field' => array(
  425. 'handler' => 'views_handler_field_node',
  426. ),
  427. );
  428. // Expose orders to ordered products as a relationship.
  429. $data['uc_order_products']['order_id'] = array(
  430. 'title' => t('Order ID'),
  431. 'help' => t('The order ID of the ordered product. If you need more fields than the order ID: Order relationship'),
  432. 'relationship' => array(
  433. 'title' => t('Order'),
  434. 'help' => t('Relate product to order.'),
  435. 'handler' => 'views_handler_relationship',
  436. 'base' => 'uc_orders',
  437. 'field' => 'order_id',
  438. 'label' => t('order'),
  439. ),
  440. 'filter' => array(
  441. 'handler' => 'views_handler_filter_numeric',
  442. ),
  443. 'argument' => array(
  444. 'handler' => 'views_handler_argument_numeric',
  445. ),
  446. 'field' => array(
  447. 'handler' => 'uc_order_handler_field_order_id',
  448. ),
  449. );
  450. $data['uc_order_products']['model'] = array(
  451. 'title' => t('SKU'),
  452. 'help' => t('The product model/SKU.'),
  453. 'field' => array(
  454. 'handler' => 'views_handler_field',
  455. 'click sortable' => TRUE,
  456. ),
  457. 'sort' => array(
  458. 'handler' => 'views_handler_sort',
  459. ),
  460. 'filter' => array(
  461. 'handler' => 'views_handler_filter_string',
  462. ),
  463. 'argument' => array(
  464. 'handler' => 'views_handler_argument_string',
  465. ),
  466. );
  467. $data['uc_order_products']['qty'] = array(
  468. 'title' => t('Quantity'),
  469. 'help' => t('The quantity ordered.'),
  470. 'field' => array(
  471. 'handler' => 'views_handler_field',
  472. 'click sortable' => TRUE,
  473. ),
  474. 'sort' => array(
  475. 'handler' => 'views_handler_sort',
  476. ),
  477. 'filter' => array(
  478. 'handler' => 'views_handler_filter_numeric',
  479. ),
  480. );
  481. $data['uc_order_products']['price'] = array(
  482. 'title' => t('Price'),
  483. 'help' => t('The price paid for one product.'),
  484. 'field' => array(
  485. 'handler' => 'uc_order_handler_field_money_amount',
  486. 'click sortable' => TRUE,
  487. 'float' => TRUE,
  488. ),
  489. 'sort' => array(
  490. 'handler' => 'views_handler_sort',
  491. ),
  492. 'filter' => array(
  493. 'handler' => 'views_handler_filter_numeric',
  494. ),
  495. );
  496. $data['uc_order_products']['total_price'] = array(
  497. 'title' => t('Total price'),
  498. 'help' => t('The price paid for all the products (price * quantity).'),
  499. 'real field' => 'price',
  500. 'field' => array(
  501. 'handler' => 'uc_order_handler_field_money_total',
  502. 'click sortable' => TRUE,
  503. 'float' => TRUE,
  504. ),
  505. 'sort' => array(
  506. 'handler' => 'uc_order_handler_sort_total',
  507. ),
  508. 'filter' => array(
  509. 'handler' => 'uc_order_handler_filter_total',
  510. ),
  511. );
  512. $data['uc_order_products']['cost'] = array(
  513. 'title' => t('Cost'),
  514. 'help' => t('The cost to the store for one product.'),
  515. 'field' => array(
  516. 'handler' => 'uc_order_handler_field_money_amount',
  517. 'click sortable' => TRUE,
  518. 'float' => TRUE,
  519. ),
  520. 'sort' => array(
  521. 'handler' => 'views_handler_sort',
  522. ),
  523. 'filter' => array(
  524. 'handler' => 'views_handler_filter_numeric',
  525. ),
  526. );
  527. $data['uc_order_products']['total_cost'] = array(
  528. 'title' => t('Total cost'),
  529. 'help' => t('The cost to the store for all the products (cost * quantity).'),
  530. 'real field' => 'cost',
  531. 'field' => array(
  532. 'handler' => 'uc_order_handler_field_money_total',
  533. 'click sortable' => TRUE,
  534. 'float' => TRUE,
  535. ),
  536. 'sort' => array(
  537. 'handler' => 'uc_order_handler_sort_total',
  538. ),
  539. 'filter' => array(
  540. 'handler' => 'uc_order_handler_filter_total',
  541. ),
  542. );
  543. $data['uc_order_products']['weight'] = array(
  544. 'title' => t('Weight'),
  545. 'help' => t('The physical weight of one product.'),
  546. 'field' => array(
  547. 'additional fields' => array(
  548. 'weight_units' => array(
  549. 'field' => 'weight_units',
  550. ),
  551. ),
  552. 'handler' => 'uc_product_handler_field_weight',
  553. 'float' => TRUE,
  554. ),
  555. );
  556. $data['uc_order_products']['total_weight'] = array(
  557. 'title' => t('Total weight'),
  558. 'help' => t('The physical weight of all the products (weight * quantity).'),
  559. 'real field' => 'weight',
  560. 'field' => array(
  561. 'additional fields' => array(
  562. 'weight_units' => array(
  563. 'field' => 'weight_units',
  564. ),
  565. ),
  566. 'handler' => 'uc_order_handler_field_weight_total',
  567. 'float' => TRUE,
  568. ),
  569. );
  570. $data['uc_order_products']['title'] = array(
  571. 'title' => t('Title'),
  572. 'help' => t('The title of the product.'),
  573. 'field' => array(
  574. 'handler' => 'views_handler_field',
  575. 'click sortable' => TRUE,
  576. ),
  577. 'sort' => array(
  578. 'handler' => 'views_handler_sort',
  579. ),
  580. 'filter' => array(
  581. 'handler' => 'views_handler_filter_string',
  582. ),
  583. 'argument' => array(
  584. 'handler' => 'views_handler_argument_string',
  585. ),
  586. );
  587. // Order comments table.
  588. // TODO: refactor this into a groupwise max relationship.
  589. $data['uc_order_comments']['table']['group'] = t('Order comments');
  590. $data['uc_order_comments']['table']['join'] = array(
  591. 'uc_orders' => array(
  592. 'left_field' => 'order_id',
  593. 'field' => 'order_id',
  594. ),
  595. 'uc_order_products' => array(
  596. 'left_table' => 'uc_orders',
  597. 'left_field' => 'order_id',
  598. 'field' => 'order_id',
  599. ),
  600. );
  601. $data['uc_order_comments']['message'] = array(
  602. 'title' => t('Comment'),
  603. 'help' => t('The comment body.'),
  604. 'field' => array(
  605. 'handler' => 'views_handler_field',
  606. 'click sortable' => TRUE,
  607. ),
  608. );
  609. // Support for any module's line item, if new modules defines other line items
  610. // the views cache will have to be rebuilt
  611. // Although new line items views support should be defined on each module,
  612. // I don't think this wider apporach would harm. At most, it will duplicate
  613. // line items
  614. $line_items = array();
  615. foreach (_uc_line_item_list() as $line_item) {
  616. if (!in_array($line_item['id'], array('subtotal', 'tax_subtotal', 'total', 'generic')) && $line_item['stored']) {
  617. $line_items[$line_item['id']] = $line_item['title'];
  618. }
  619. }
  620. foreach ($line_items as $line_item_id => $line_item_desc) {
  621. $data['uc_order_line_items_' . $line_item_id]['table']['join']['uc_orders'] = array(
  622. 'table' => 'uc_order_line_items',
  623. 'left_field' => 'order_id',
  624. 'field' => 'order_id',
  625. 'extra' => array(
  626. array(
  627. 'field' => 'type',
  628. 'value' => $line_item_id,
  629. ),
  630. ),
  631. );
  632. $data['uc_order_line_items_' . $line_item_id]['table']['join']['uc_order_products'] = $data['uc_order_line_items_' . $line_item_id]['table']['join']['uc_orders'];
  633. $data['uc_order_line_items_' . $line_item_id]['table']['join']['uc_order_products']['left_table'] = 'uc_orders';
  634. $data['uc_order_line_items_' . $line_item_id]['table']['group'] = t('Order: Line item');
  635. $data['uc_order_line_items_' . $line_item_id]['title'] = array(
  636. 'title' => t('!line_item_desc title', array('!line_item_desc' => $line_item_desc)),
  637. 'help' => t('!line_item_desc order line item', array('!line_item_desc' => $line_item_desc)),
  638. 'field' => array(
  639. 'handler' => 'views_handler_field',
  640. 'click sortable' => TRUE,
  641. ),
  642. 'filter' => array(
  643. 'handler' => 'views_handler_filter_string',
  644. ),
  645. );
  646. $data['uc_order_line_items_' . $line_item_id]['amount'] = array(
  647. 'title' => t('!line_item_desc amount', array('!line_item_desc' => $line_item_desc)),
  648. 'help' => t('!line_item_desc order line item', array('!line_item_desc' => $line_item_desc)),
  649. 'field' => array(
  650. 'handler' => 'uc_order_handler_field_money_amount',
  651. 'click sortable' => TRUE,
  652. 'float' => TRUE,
  653. ),
  654. 'filter' => array(
  655. 'handler' => 'views_handler_filter_numeric',
  656. ),
  657. );
  658. }
  659. return $data;
  660. }
  661. /**
  662. * Implements hook_views_plugins().
  663. */
  664. function uc_order_views_plugins() {
  665. return array(
  666. 'row' => array(
  667. 'uc_order_invoice' => array(
  668. 'title' => t('Invoice'),
  669. 'help' => t('Display the order with standard invoice view.'),
  670. 'handler' => 'uc_order_plugin_row_invoice',
  671. 'theme' => 'uc_order_view_row_invoice',
  672. 'theme path' => drupal_get_path('module', 'uc_order') . '/views',
  673. 'base' => array('uc_orders'), // only works with 'uc_orders' as base.
  674. 'type' => 'normal',
  675. ),
  676. ),
  677. 'argument validator' => array(
  678. 'user_or_permission' => array(
  679. 'title' => t('Current user or user has permission'),
  680. 'handler' => 'uc_order_plugin_argument_validate_user_perm',
  681. ),
  682. ),
  683. );
  684. }
  685. /**
  686. * Preprocesses a views row invoice plugin.
  687. *
  688. * @see uc_order-view-row-invoice.tpl.php
  689. */
  690. function template_preprocess_uc_order_view_row_invoice(&$vars) {
  691. $order_id = $vars['row']->{$vars['field_alias']};
  692. if (module_exists('uc_credit')) {
  693. // Clear credit cache, otherwise the load function below will return
  694. // the same cached credit information for all the subsequent orders
  695. // invoices
  696. uc_credit_cache('clear');
  697. }
  698. $order = uc_order_load($order_id);
  699. $build = array(
  700. '#theme' => 'uc_order',
  701. '#order' => $order,
  702. '#op' => 'view',
  703. '#template' => variable_get('uc_cust_order_invoice_template', 'customer'),
  704. );
  705. $vars['invoice'] = theme('uc_order_invoice_page', array('content' => drupal_render($build)));
  706. }