PluginProbe
MyRewards / trunk
MyRewards vtrunk
5.7.8 5.7.7 5.7.6 trunk 1.2.2 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.1 2.2.0 2.3.0 2.4.0 2.4.1 2.5.0 2.6.4 2.6.6 3.0.0.0 3.1.0 3.1.2 3.1.2.1 3.10.4 3.10.9 All 165 releases
woorewards / include / events / sponsoredorderamount.php

sponsoredorderamount.php in MyRewards trunk, at include/events/sponsoredorderamount.php

96 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace LWS\WOOREWARDS\Events;
3
4 // don't call the file directly
5 if( !defined( 'ABSPATH' ) ) exit();
6
7
8 /** Sponsor earns points for each money spend by Sponsored on an order.
9 * Extends usual order amount to only change point destination. */
10 class SponsoredOrderAmount extends \LWS\WOOREWARDS\Events\OrderAmount
11 {
12 function getInformation()
13 {
14 return array_merge(parent::getInformation(), array(
15 'icon' => 'lws-icon-coins',
16 'short' => __("The customer will earn points when a person he referred spends money on your shop.", 'woorewards-lite'),
17 'help' => __("This method will only reward the Referrer, not the Referee", 'woorewards-lite'),
18 ));
19 }
20
21 function getClassname()
22 {
23 return 'LWS\WOOREWARDS\Events\SponsoredOrderAmount';
24 }
25
26 public function getDisplayType()
27 {
28 return _x("Referee spends money", "getDisplayType", 'woorewards-lite');
29 }
30
31 /** override */
32 function orderDone($order)
33 {
34 $sponsorship = new \LWS\WOOREWARDS\Core\Sponsorship();
35 $this->sponsorship = $sponsorship->getUsersFromOrder($order->order, $this->isGuestAllowed());
36
37 if( !$this->sponsorship->sponsor_id )
38 return $order;
39 return parent::orderDone($order);
40 }
41
42 /** @param $order (\WC_Order)
43 * @return (int) user ID */
44 function getPointsRecipient($order)
45 {
46 if( $this->sponsorship && $this->sponsorship->sponsor_id )
47 return $this->sponsorship->sponsor_id;
48 else
49 return false;
50 }
51
52 protected function getGainInfo($info, $order)
53 {
54 if ($this->sponsorship)
55 $info['sponsee'] = $this->sponsorship->sponsored_id;
56 return $info;
57 }
58
59 /** @param $order (\WC_Order)
60 * @param $amount (float) computed amount
61 * @return (\LWS\WOOREWARDS\Core\Trace) a reason for history */
62 function getPointsReason($order, $amount)
63 {
64 $price = \wp_kses(\wc_price($amount, array('currency' => $order->get_currency())), array());
65 return \LWS\WOOREWARDS\Core\Trace::byOrder($order)
66 ->setProvider($order->get_customer_id('edit'))
67 ->setReason(array(
68 'Referred friend %3$s spent %1$s from order #%2$s',
69 $price,
70 $order->get_order_number(),
71 $order->get_billing_email()
72 ), 'woorewards-lite'
73 );
74 }
75
76 /** Never call, only to have poedit/wpml able to extract the sentance. */
77 private function poeditDeclare()
78 {
79 /* translators: %1$s: amount spent, %2$s: order number, %3$s: friend name */
80 __('Referred friend %3$s spent %1$s from order #%2$s', 'woorewards-lite');
81 }
82
83 /** Event categories, used to filter out events from pool options.
84 * @return array with category_id => category_label. */
85 public function getCategories()
86 {
87 return array(
88 \LWS\WOOREWARDS\Core\Pool::T_STANDARD => __("Standard", 'woorewards-lite'),
89 \LWS\WOOREWARDS\Core\Pool::T_LEVELLING => __("Levelling", 'woorewards-lite'),
90 'achievement' => __("Achievement", 'woorewards-lite'),
91 'custom' => __("Events", 'woorewards-lite'),
92 'woocommerce' => __("WooCommerce", 'woorewards-lite'),
93 'sponsorship' => __("Available for referred", 'woorewards-lite')
94 );
95 }
96 }