CRM-16367 (api-contribution_product & product) add contribution product api and make...
authorEileen McNaughton <eileen@fuzion.co.nz>
Sun, 3 May 2015 08:31:49 +0000 (20:31 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Sun, 3 May 2015 08:31:49 +0000 (20:31 +1200)
api/v3/ContributionProduct.php [new file with mode: 0644]
api/v3/Product.php

diff --git a/api/v3/ContributionProduct.php b/api/v3/ContributionProduct.php
new file mode 100644 (file)
index 0000000..52856b1
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.6                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ * This api exposes CiviCRM premium products attached to contributions.
+ *
+ * Premiums are used as incentive gifts on contribution pages.
+ * Use chaining to create a premium and related products in one api call.
+ *
+ * @package CiviCRM_APIv3
+ */
+
+/**
+ * Save a contribution product.
+ *
+ * @param array $params
+ *
+ * @throws API_Exception
+ * @return array
+ */
+function civicrm_api3_contribution_product_create($params) {
+  return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
+
+/**
+ * Get a contribution product.
+ *
+ * @param array $params
+ *
+ * @return array
+ *   Array of retrieved product property values.
+ */
+function civicrm_api3_contribution_product_get($params) {
+  return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
+
+/**
+ * Delete a contribution product.
+ *
+ * @param array $params
+ *
+ * @throws API_Exception
+ * @return array
+ *   Array of deleted values.
+ */
+function civicrm_api3_contribution_product_delete($params) {
+  return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
index be38fd2b6f2ad06631cb275f82f672b8fce2f22d..cf32e8827ded2c7e1191e838ad8f75f8b864a020 100644 (file)
@@ -46,6 +46,18 @@ function civicrm_api3_product_create($params) {
   return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
 }
 
+/**
+ * Adjust Metadata for Create action.
+ *
+ * The metadata is used for setting defaults, documentation & validation.
+ *
+ * @param array $params
+ *   Array of parameters determined by getfields.
+ */
+function _civicrm_api3_product_create_spec(&$params) {
+  $params['is_active']['api.default'] = 1;
+}
+
 /**
  * Get a product.
  *