uc_order.info.inc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /**
  3. * @file
  4. * Entity Metadata hooks
  5. */
  6. /**
  7. * Implements hook_entity_property_info().
  8. */
  9. function uc_order_entity_property_info() {
  10. $address_info = uc_address_property_info();
  11. return array(
  12. 'uc_order' => array(
  13. 'properties' => array(
  14. 'order_id' => array(
  15. 'type' => 'integer',
  16. 'label' => t('Order ID'),
  17. 'description' => t('Primary key: the order ID.'),
  18. 'query callback' => 'entity_metadata_table_query',
  19. ),
  20. 'uid' => array(
  21. 'type' => 'integer',
  22. 'label' => t('User ID'),
  23. 'description' => t('The unique ID of the customer who placed the order.'),
  24. 'clear' => array('customer'),
  25. 'query callback' => 'entity_metadata_table_query',
  26. 'setter permission' => 'edit orders',
  27. ),
  28. 'customer' => array(
  29. 'type' => 'user',
  30. 'label' => t('Customer'),
  31. 'description' => t('The user who placed the order.'),
  32. 'getter callback' => 'uc_order_uc_order_get_properties',
  33. 'setter callback' => 'uc_order_uc_order_set_properties',
  34. 'setter permission' => 'edit orders',
  35. 'clear' => array('uid'),
  36. ),
  37. 'delivery_address' => array(
  38. 'type' => 'struct',
  39. 'label' => t('Delivery address'),
  40. 'description' => t('The destination of the shipped products.'),
  41. 'getter callback' => 'uc_order_address_property_get',
  42. 'setter callback' => 'uc_order_address_property_set',
  43. 'setter permission' => 'edit orders',
  44. 'property info' => $address_info,
  45. ),
  46. 'billing_address' => array(
  47. 'type' => 'struct',
  48. 'label' => t('Billing address'),
  49. 'description' => t('The destination of the bill and invoice.'),
  50. 'getter callback' => 'uc_order_address_property_get',
  51. 'setter callback' => 'uc_order_address_property_set',
  52. 'setter permission' => 'edit orders',
  53. 'property info' => $address_info,
  54. ),
  55. 'order_status' => array(
  56. 'type' => 'text',
  57. 'label' => t('Order status'),
  58. 'description' => t('The status of the order.'),
  59. 'required' => TRUE,
  60. 'options list' => 'uc_order_status_options_list',
  61. 'setter permission' => 'edit orders',
  62. 'query callback' => 'entity_metadata_table_query',
  63. ),
  64. 'order_total' => array(
  65. 'type' => 'decimal',
  66. 'label' => t('Order total'),
  67. 'description' => t('The total amount due for the order.'),
  68. 'getter callback' => 'uc_order_get_total',
  69. 'query callback' => 'entity_metadata_table_query',
  70. ),
  71. 'primary_email' => array(
  72. 'type' => 'text',
  73. 'label' => t('Primary email'),
  74. 'description' => t('The primary email address of the customer.'),
  75. 'setter permission' => 'edit orders',
  76. 'query callback' => 'entity_metadata_table_query',
  77. ),
  78. 'payment_method' => array(
  79. 'type' => 'text',
  80. 'label' => t('Payment method'),
  81. 'description' => t('The method of payment.'),
  82. 'query callback' => 'entity_metadata_table_query',
  83. ),
  84. 'created' => array(
  85. 'type' => 'date',
  86. 'label' => t('Date created'),
  87. 'description' => t('The date the order was placed.'),
  88. 'query callback' => 'entity_metadata_table_query',
  89. ),
  90. 'modified' => array(
  91. 'type' => 'date',
  92. 'label' => t('Date modified'),
  93. 'description' => t('The date the order was most recently changed.'),
  94. 'query callback' => 'entity_metadata_table_query',
  95. ),
  96. 'host' => array(
  97. 'type' => 'text',
  98. 'label' => t('Host IP'),
  99. 'description' => t('Host IP address of the person paying for the order.'),
  100. 'query callback' => 'entity_metadata_table_query',
  101. ),
  102. 'products' => array(
  103. 'type' => 'list<uc_order_product>',
  104. 'label' => t('Products'),
  105. 'description' => t('The products that have been ordered.'),
  106. 'setter permission' => 'edit orders',
  107. 'getter callback' => 'uc_order_get_product_list',
  108. 'clear' => array('order_total'),
  109. ),
  110. ),
  111. ),
  112. );
  113. }
  114. /**
  115. * Metadata controller class for uc_order_product entities.
  116. */
  117. class UcOrderProductMetadataController extends EntityDefaultMetadataController {
  118. public function entityPropertyInfo() {
  119. $props = parent::entityPropertyInfo();
  120. // Copy the descriptions from the schema. Drupal discards this information, so we have to
  121. // call uc_order_schema() directly.
  122. module_load_include('install', 'uc_order', 'uc_order');
  123. $schema = uc_order_schema();
  124. foreach ($schema['uc_order_products']['fields'] as $name => $info) {
  125. if (is_array($props['uc_order_product']['properties'][$name]) && !empty($info['description'])) {
  126. $props['uc_order_product']['properties'][$name]['description'] = $info['description'];
  127. }
  128. }
  129. // Add the 'node' property.
  130. $props['uc_order_product']['properties']['node'] = array(
  131. 'type' => 'node',
  132. 'label' => t('Node'),
  133. 'description' => t('The node representing the product.'),
  134. 'getter callback' => 'uc_order_product_node_property_get',
  135. 'setter callback' => 'uc_order_product_node_property_set',
  136. );
  137. return $props;
  138. }
  139. }