/public/productGet.php

https://github.com/ciniki/customers · PHP · 119 lines · 82 code · 6 blank · 31 comment · 12 complexity · d3974fab0dab6e26881341ac6ad26e10 MD5 · raw file

  1. <?php
  2. //
  3. // Description
  4. // ===========
  5. // This method will return all the information about an membership products.
  6. //
  7. // Arguments
  8. // ---------
  9. // api_key:
  10. // auth_token:
  11. // tnid: The ID of the tenant the membership products is attached to.
  12. // product_id: The ID of the membership products to get the details for.
  13. //
  14. // Returns
  15. // -------
  16. //
  17. function ciniki_customers_productGet($ciniki) {
  18. //
  19. // Find all the required and optional arguments
  20. //
  21. ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'prepareArgs');
  22. $rc = ciniki_core_prepareArgs($ciniki, 'no', array(
  23. 'tnid'=>array('required'=>'yes', 'blank'=>'no', 'name'=>'Tenant'),
  24. 'product_id'=>array('required'=>'yes', 'blank'=>'no', 'name'=>'Membership Products'),
  25. ));
  26. if( $rc['stat'] != 'ok' ) {
  27. return $rc;
  28. }
  29. $args = $rc['args'];
  30. //
  31. // Make sure this module is activated, and
  32. // check permission to run this function for this tenant
  33. //
  34. ciniki_core_loadMethod($ciniki, 'ciniki', 'customers', 'private', 'checkAccess');
  35. $rc = ciniki_customers_checkAccess($ciniki, $args['tnid'], 'ciniki.customers.productGet');
  36. if( $rc['stat'] != 'ok' ) {
  37. return $rc;
  38. }
  39. //
  40. // Load tenant settings
  41. //
  42. ciniki_core_loadMethod($ciniki, 'ciniki', 'tenants', 'private', 'intlSettings');
  43. $rc = ciniki_tenants_intlSettings($ciniki, $args['tnid']);
  44. if( $rc['stat'] != 'ok' ) {
  45. return $rc;
  46. }
  47. $intl_timezone = $rc['settings']['intl-default-timezone'];
  48. $intl_currency_fmt = numfmt_create($rc['settings']['intl-default-locale'], NumberFormatter::CURRENCY);
  49. $intl_currency = $rc['settings']['intl-default-currency'];
  50. ciniki_core_loadMethod($ciniki, 'ciniki', 'users', 'private', 'dateFormat');
  51. $date_format = ciniki_users_dateFormat($ciniki, 'php');
  52. //
  53. // Return default for new Membership Products
  54. //
  55. if( $args['product_id'] == 0 ) {
  56. $product = array('id'=>0,
  57. 'name'=>'',
  58. 'short_name'=>'',
  59. 'code'=>'',
  60. 'permalink'=>'',
  61. 'type'=>'10',
  62. 'status'=>'10',
  63. 'flags'=>'0',
  64. 'months'=>12,
  65. 'sequence'=>'1',
  66. 'primary_image_id'=>'',
  67. 'synopsis'=>'',
  68. 'description'=>'',
  69. 'unit_amount'=>'',
  70. );
  71. }
  72. //
  73. // Get the details for an existing Membership Products
  74. //
  75. else {
  76. $strsql = "SELECT ciniki_customer_products.id, "
  77. . "ciniki_customer_products.name, "
  78. . "ciniki_customer_products.short_name, "
  79. . "ciniki_customer_products.code, "
  80. . "ciniki_customer_products.permalink, "
  81. . "ciniki_customer_products.type, "
  82. . "ciniki_customer_products.status, "
  83. . "ciniki_customer_products.flags, "
  84. . "ciniki_customer_products.months, "
  85. . "ciniki_customer_products.sequence, "
  86. . "ciniki_customer_products.primary_image_id, "
  87. . "ciniki_customer_products.synopsis, "
  88. . "ciniki_customer_products.description, "
  89. . "ciniki_customer_products.unit_amount "
  90. . "FROM ciniki_customer_products "
  91. . "WHERE ciniki_customer_products.tnid = '" . ciniki_core_dbQuote($ciniki, $args['tnid']) . "' "
  92. . "AND ciniki_customer_products.id = '" . ciniki_core_dbQuote($ciniki, $args['product_id']) . "' "
  93. . "";
  94. ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryArrayTree');
  95. $rc = ciniki_core_dbHashQueryArrayTree($ciniki, $strsql, 'ciniki.customers', array(
  96. array('container'=>'products', 'fname'=>'id',
  97. 'fields'=>array('name', 'short_name', 'code', 'permalink', 'type', 'status', 'flags', 'months', 'sequence',
  98. 'primary_image_id', 'synopsis', 'description', 'unit_amount',
  99. ),
  100. ),
  101. ));
  102. if( $rc['stat'] != 'ok' ) {
  103. return array('stat'=>'fail', 'err'=>array('code'=>'ciniki.customers.403', 'msg'=>'Membership Products not found', 'err'=>$rc['err']));
  104. }
  105. if( !isset($rc['products'][0]) ) {
  106. return array('stat'=>'fail', 'err'=>array('code'=>'ciniki.customers.418', 'msg'=>'Unable to find Membership Products'));
  107. }
  108. $product = $rc['products'][0];
  109. $product['unit_amount'] = '$' . number_format($product['unit_amount'], 2);
  110. }
  111. return array('stat'=>'ok', 'product'=>$product);
  112. }
  113. ?>