Skip to content
Snippets Groups Projects
Commit 071ecfec authored by Patrick Schmalstig's avatar Patrick Schmalstig
Browse files

Add eCommerce support for karma (remove member comments support)

parent 4d800144
No related branches found
No related tags found
No related merge requests found
......@@ -69,8 +69,6 @@ Members can be assigned good karma when another member sends them points. Additi
Members can be assigned good karma when other members send them virtual gifts.
[*][b]idolisr[/b]
You can configure that members only receive good karma for receiving points from others if they received them for an Idolisr role.
[*][b]member_comments[/b]
Members can be assigned good karma when another member comments on their profile.
[*][b]ecommerce[/b]
Members can receive good karma based on how much they spend on your store. This can work for both points and currency.
[/list]
......
......@@ -109,7 +109,7 @@ ACTIVITY_SEND_POINTS=Sent {2} points to {7} for "{1}"
_ACTIVITY_RECEIVE_POINTS=Received {2} points for "{1}"
ACTIVITY_RECEIVE_POINTS=Received {2} points from {7} for "{1}"
POINTS_PER_CURRENCY_UNIT=Points per unit of currency
CONFIG_OPTION_points_per_currency_unit=The number of points equivalent to one unit of currency. For example, 100 would mean 100 points is worth one dollar/pound. This option is not currently used by any bundled software code, but made available to non-bundled addons as a standard.
CONFIG_OPTION_points_per_currency_unit=The number of points equivalent to one unit of currency (in the site's configured currency). For example, 100 would mean 100 points is worth one dollar/pound or whichever unit is used by default by the site. This option is not used by bundled code (most everything offering purchase by points have a separate "points" cost option) but is available to non-bundled addons as a standard.
RATING_CONTENT=Rating content
ACTIVITY_RATED=Rated a {1}, '{2}'
VOTING=Voting in website polls
......
......@@ -52,7 +52,7 @@ CONFIG_OPTION_karma_giftr=For each time a member receives a virtual gift from an
KARMA_MEMBER_COMMENTS=Member comments multiplier
CONFIG_OPTION_karma_member_comments=For each time a member receives a comment on their profile, they will receive good karma equal to the commenter's karmic influence multiplied by this value. Set to '0' to disable earning good karma for member comments.
KARMA_ECOMMERCE=eCommerce purchases karma
CONFIG_OPTION_karma_ecommerce=When a member purchases something, they will receive 1 good karma for every specified amount of currency they spent. If they instead spent points, the “Points per unit of currency” option will be used to convert the amount spent to currency to determine how much good karma to award. Set to '0' to disable earning good karma for purchases.
CONFIG_OPTION_karma_ecommerce=When a member purchases something, they will receive 1 good karma for every specified amount of currency they spent (in the site currency). This excludes tax, shipping, and other fees. If they used points on a purchase, the “Points per unit of currency” option will be used to convert the amount spent in points to currency to determine how much good karma to award. Set to '0' to disable earning good karma for purchases.
KARMA_THRESHOLD=Karma bar threshold
CONFIG_OPTION_karma_threshold=The karma bar for every member will be filled completely once their karma exceeds this amount (for those who can view bad karma, we take the maximum of either good or bad karma). Set to '0' for the bar to always be completely filled (useful if you have “View good and bad karma values separately” privilege set for everyone and you just want to display the ratio of good to bad karma)
DESCRIPTION_PRIVACY_KARMA=Handle data pertaining to the karma you received or influenced on other members. These cannot be purged except by staff to preserve the integrity of the karma system.
......
......@@ -140,6 +140,11 @@ function currency_convert($amount, ?string $from_currency = null, ?string $to_cu
$map = get_currency_map();
// TODO: We do not currently support point conversions, so just bail with the amount
if (($from_currency == 'POINTS') || ($to_currency == 'POINTS')) {
return $amount;
}
// Check from currency
if (!array_key_exists($from_currency, $map) && (($from_currency != 'POINTS') || !addon_installed('points'))) {
attach_message(do_lang_tempcode('UNKNOWN_CURRENCY', escape_html($from_currency)), 'warn', false, true);
......
......@@ -151,7 +151,6 @@ Karma and its API can be further extended for additional functionality. For exam
'points',
'giftr',
'idolisr',
'member_comments',
'ecommerce',
],
'conflicts_with' => [],
......@@ -202,7 +201,6 @@ Karma and its API can be further extended for additional functionality. For exam
'sources_custom/hooks/systems/config/karma_influence_warnings.php',
'sources_custom/hooks/systems/config/karma_influence_warnings_amount.php',
'sources_custom/hooks/systems/config/karma_likes.php',
'sources_custom/hooks/systems/config/karma_member_comments.php',
'sources_custom/hooks/systems/config/karma_points.php',
'sources_custom/hooks/systems/config/karma_points_idolisr.php',
'sources_custom/hooks/systems/config/karma_threshold.php',
......
<?php /*
Composr
Copyright (c) Christopher Graham, 2004-2024
See docs/LICENSE.md for full licensing information.
*/
/**
* @license http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
* @copyright Christopher Graham
* @package karma
*/
/**
* Hook class.
*/
class Hook_config_karma_member_comments
{
/**
* Gets the details relating to the config option.
*
* @return ?array The details (null: disabled)
*/
public function get_details() : ?array
{
return [
'human_name' => 'KARMA_MEMBER_COMMENTS',
'type' => 'integer',
'category' => 'FEATURE',
'group' => 'KARMA',
'explanation' => 'CONFIG_OPTION_karma_member_comments',
'shared_hosting_restricted' => '0',
'order_in_category_group' => 6,
'list_options' => '',
'required' => true,
'public' => false,
'addon' => 'karma',
];
}
/**
* Gets the default value for the config option.
*
* @return ?string The default value (null: option is disabled)
*/
public function get_default() : ?string
{
// TODO: Implement when member comments are working
return null;
if (!addon_installed('karma') || get_forum_type() != 'cns') {
return null;
}
if (!addon_installed('member_comments')) {
return null;
}
return '1';
}
}
......@@ -226,5 +226,39 @@ class Hook_contentious_overrides_karma
"
);
}
// eCommerce purchases
if (($codename == 'ecommerce') && (strpos($path, 'sources_custom/') === false)) {
if ($code === null) {
$code = clean_php_file_for_eval(file_get_contents($path));
}
// Add karma when making a purchase
insert_code_before__by_command(
$code,
"handle_confirmed_transaction",
"return [\$type_code, \$member_id];",
"// Award karma
if ((\$status == 'Completed') && (addon_installed('karma'))) {
require_code('karma');
require_code('karma2');
\$karma_rate = intval(get_option('karma_ecommerce'));
if (\$karma_rate > 0) {
\$karma_to_award = 0;
if ((\$price_points > 0) && addon_installed('points')) {
\$points_rate = intval(get_option('points_per_currency_unit'));
if (\$points_rate > 0) {
\$points_to_currency = floatval(\$price_points / \$points_rate);
\$karma_to_award += intval(\$points_to_currency / \$karma_rate);
}
}
\$karma_to_award += intval(\$price / \$karma_rate);
add_karma('good', null, \$member_id, \$karma_to_award, 'Purchased ' . \$item_name, 'ecommerce', strval(\$txn_id));
}
}
"
);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment