RewardStream_ReferAFriend - Version 1.2.0

Version Notes

Fixed compatibility issues with common checkout extensions.
Added support for automatically generated reward codes.
Stability improvements.

Download this release

Release Info

Developer RewardStream
Extension RewardStream_ReferAFriend
Version 1.2.0
Comparing to
See all releases


Code changes from version 1.1.0 to 1.2.0

app/code/community/Rewardstream/Referafriend/Model/Observer.php CHANGED
@@ -5,75 +5,422 @@ class Rewardstream_Referafriend_Model_Observer
5
 
6
  public function salesOrderInvoicePayAfter ( Varien_Event_Observer $observer )
7
  {
 
8
  $status = Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_status' );
9
  if ( $status == 1 ) {
10
  $order = $observer->getEvent()->getInvoice()->getOrder();
11
 
 
12
  if ( $order->getBaseTotalDue() == 0 ) {
13
  $couponCode = $order['coupon_code'];
14
 
15
- // If this had an RS coupon code
16
- if ( substr( $couponCode, 0, 3 ) === 'ref' ) {
17
- $this->redeemOffer( $couponCode, $order );
18
  }
 
19
  }
20
  }
21
  }
22
 
 
 
 
 
 
23
 
24
- private function redeemOffer($offerCode, $order)
25
- {
26
- $total = $order['grand_total'];
27
- $subtotal = $order['subtotal'];
28
- $purchaseDate = ( new DateTime( $order['created_at'] ) )->format( DateTime::ATOM );
29
- $purchaseNumber = $order['increment_id'];
30
-
31
- if ( $order->getCustomerIsGuest() ) {
32
- $accountIdentifier = 'guestorder#' . $purchaseNumber;
33
- }
34
- else {
35
- $accountIdentifier = $order->getCustomerId();
36
  }
 
37
 
38
- $items = $order->getAllVisibleItems();
39
-
40
- $xmlData = '<Data>' .
41
- '<Code>' . $offerCode . '</Code>' .
42
- '<DateUsed>' . $purchaseDate . '</DateUsed>' .
43
- '<Account>' .
44
- '<Number>' . $accountIdentifier . '</Number>' .
45
- '<ActivationDate>' . $purchaseDate . '</ActivationDate>' .
46
- '</Account>' .
47
- '<Purchase>' .
48
- '<PurchaseNumber>' . $purchaseNumber . '</PurchaseNumber>' .
49
- '<SubTotal>' . floor( $subtotal ) . '</SubTotal>';
50
-
51
- foreach ( $items as $item ) {
52
- $sku = $item->getSku();
53
- $qty = $item->getQtyOrdered();
54
- $price = $item->getPrice();
55
- $xmlData .= '<Items><Product>' . $sku . '</Product><Quantity>' . floor( $qty ) . '</Quantity><Amount>' . number_format( $price, 2, '.', '' ) . '</Amount></Items>';
56
- }
57
 
58
- $xmlData .= '</Purchase></Data>';
 
 
 
 
 
 
 
 
 
 
59
 
 
60
 
 
 
 
 
 
 
 
 
61
  $helper = Mage::helper( 'rewardstream' );
62
  $apiUrl = 'https://' . Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_api_url' );
63
  $apiKey = Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_api_key' );
64
  $apiSecret = Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_secret_key' );
65
- $result = $helper->getDataCallAPI( $apiUrl . '/api/v2/custom/redeemOffer?api_key=' . $apiKey, "POST", $xmlData, "Basic " . $apiSecret );
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  $responseData = json_decode( $result, true );
68
 
69
- if ( $responseData['Error']['Code'] ) {
70
- Mage::log( 'Error calling RS redeemOffer API: ' . json_encode($responseData['Error']) );
71
- Mage::getSingleton( 'core/session' )->addError( 'Error redeeming offer in RewardStream system: ' . $responseData['Error']['Message'] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  }
73
- else {
74
- Mage::getSingleton( 'core/session' )->addSuccess( 'Successfully redeemed offer in RewardStream system.' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  }
76
  }
77
  }
78
 
 
79
  ?>
5
 
6
  public function salesOrderInvoicePayAfter ( Varien_Event_Observer $observer )
7
  {
8
+ // Is RewardStream extension enabled?
9
  $status = Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_status' );
10
  if ( $status == 1 ) {
11
  $order = $observer->getEvent()->getInvoice()->getOrder();
12
 
13
+ // Has order been completely paid?
14
  if ( $order->getBaseTotalDue() == 0 ) {
15
  $couponCode = $order['coupon_code'];
16
 
17
+ // Was there a RewardStream coupon code?
18
+ if ( substr( $couponCode, 0, 3 ) === 'ref' || substr( $couponCode, 0, 3 ) === 'rew') {
19
+ $this->redeemCode( $couponCode, $order );
20
  }
21
+
22
  }
23
  }
24
  }
25
 
26
+ public function createDiscountCode(Varien_Event_Observer $observer) {
27
+ $status = Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_status' );
28
+ if ( $status == 1 ) {
29
+ $quote = $observer->getQuote();
30
+ $couponCode = $quote->getCouponCode();
31
 
32
+ // Is there a coupon code in the discount codes input?
33
+ // Is the coupon code Rewardstream offer code?
34
+ if ( $couponCode && substr( $couponCode, 0, 3 ) === 'ref') {
35
+ $this->createOfferSalesrule( $couponCode );
36
+ }
37
+ // Is the coupon code Rewardstream reward code?
38
+ else if( $couponCode && substr( $couponCode, 0, 3 ) === 'rew') {
39
+ $this->createRewardSalesrule( $couponCode );
40
+ }
 
 
 
41
  }
42
+ }
43
 
44
+ /**
45
+ * API call to receive certificate based on coupon code
46
+ *
47
+ * @param $couponcode
48
+ * @return $certificate JSON object
49
+ */
50
+ private function getCertificate($couponCode){
51
+ $helper = Mage::helper( 'rewardstream' );
52
+ $apiUrl = 'https://' . Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_api_url' );
53
+ $apiKey = Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_api_key' );
54
+ $apiSecret = Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_secret_key' );
55
+
56
+ $response = $helper->getDataCallAPIJSON( $apiUrl . '/api/v2/members/all/certificates?j=GoodsId%20as%20Certificate&i=*, Certificate:*&q=' . urlencode('CertificateNumber="' . $couponCode . '"'), "GET", false, "Basic " . $apiSecret );
57
+ $decodedResponse= json_decode($response);
58
+ $certificate = $decodedResponse->records[0];
59
+ return $certificate;
60
+ }
 
 
61
 
62
+ /**
63
+ * Check certificate to see if code has been used
64
+ *
65
+ * @param $certificate
66
+ * @return boolean
67
+ */
68
+ public function is_code_valid( $certificate ){
69
+ if($certificate->RedeemedAmount < $certificate->IssueAmount){
70
+ return true;
71
+ }
72
+ return false;
73
 
74
+ }
75
 
76
+ /**
77
+ * Redeem code (POST to RewardStream API). Handles both offer codes and reward codes
78
+ *
79
+ * @params $couponCode, $order
80
+ *
81
+ */
82
+ private function redeemCode($couponCode, $order)
83
+ {
84
  $helper = Mage::helper( 'rewardstream' );
85
  $apiUrl = 'https://' . Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_api_url' );
86
  $apiKey = Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_api_key' );
87
  $apiSecret = Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_secret_key' );
 
88
 
89
+ //IF OFFER CODE
90
+ if(substr( $couponCode, 0, 3 ) === 'ref'){
91
+ $total = $order['grand_total'];
92
+ $subtotal = $order['subtotal'];
93
+ $purchaseDate = ( new DateTime( $order['created_at'] ) )->format( DateTime::ATOM );
94
+ $purchaseNumber = $order['increment_id'];
95
+
96
+ if ( $order->getCustomerIsGuest() ) {
97
+ $accountIdentifier = 'guestorder#' . $purchaseNumber;
98
+ }
99
+ else {
100
+ $accountIdentifier = $order->getCustomerId();
101
+ }
102
+
103
+ $items = $order->getAllVisibleItems();
104
+
105
+ $xmlData = '<Data>' .
106
+ '<Code>' . $couponCode . '</Code>' .
107
+ '<DateUsed>' . $purchaseDate . '</DateUsed>' .
108
+ '<Account>' .
109
+ '<Number>' . $accountIdentifier . '</Number>' .
110
+ '<ActivationDate>' . $purchaseDate . '</ActivationDate>' .
111
+ '</Account>' .
112
+ '<Purchase>' .
113
+ '<PurchaseNumber>' . $purchaseNumber . '</PurchaseNumber>' .
114
+ '<SubTotal>' . floor( $subtotal ) . '</SubTotal>';
115
+
116
+ foreach ( $items as $item ) {
117
+ $sku = $item->getSku();
118
+ $qty = $item->getQtyOrdered();
119
+ $price = $item->getPrice();
120
+ $xmlData .= '<Items><Product>' . $sku . '</Product><Quantity>' . floor( $qty ) . '</Quantity><Amount>' . number_format( $price, 2, '.', '' ) . '</Amount></Items>';
121
+ }
122
+
123
+ $xmlData .= '</Purchase></Data>';
124
+
125
+ $result = $helper->getDataCallAPI( $apiUrl . '/api/v2/custom/redeemOffer?api_key=' . $apiKey, "POST", $xmlData, "Basic " . $apiSecret );
126
+
127
+ $responseData = json_decode( $result, true );
128
+
129
+ if ( $responseData['Error']['Code'] ) {
130
+ Mage::log( 'Error calling RS redeemOffer API: ' . json_encode($responseData['Error']) );
131
+ Mage::getSingleton( 'core/session' )->addError( 'Error redeeming offer in RewardStream system: ' . $responseData['Error']['Message'] );
132
+ }
133
+ else {
134
+ Mage::getSingleton( 'core/session' )->addSuccess( 'Successfully redeemed offer in RewardStream system.' );
135
+ }
136
+
137
+ }
138
+
139
+ //If Reward Code
140
+ else if(substr( $couponCode, 0, 3 ) === 'rew'){
141
+ $certificate =$this->getCertificate($couponCode);
142
+ //Increase redeemedAmount in JSON
143
+ $incrementedRedeemedAmount = $certificate->RedeemedAmount + 1;
144
+
145
+ $userId = $certificate->UserId;
146
+ $certId = $certificate->Id;
147
+ //Set up data for API call
148
+ $args = array(
149
+ "RedeemedAmount" => $incrementedRedeemedAmount
150
+ );
151
+ $json_args = json_encode( $args );
152
+ $authorization_header = "Basic " . $apiSecret;
153
+ $url = $apiUrl . '/api/v2/users/'. $userId . '/certificates/' . $certId;
154
+
155
+ //Make API call
156
+ $result = $helper->getDataCallAPIJSON( $url, "POST", $json_args, $authorization_header );
157
+ $responseData = json_decode( $result, true );
158
+
159
+ //Handle response
160
+ if ( $responseData['Error']['Code'] ) {
161
+ Mage::log( 'Error calling RS users API: ' . json_encode($responseData['Error']) );
162
+ Mage::getSingleton( 'core/session' )->addError( 'Error redeeming reward in RewardStream system: ' . $responseData['Error']['Message'] );
163
+ }
164
+ else {
165
+ Mage::getSingleton( 'core/session' )->addSuccess( 'Successfully redeemed reward in RewardStream system.' );
166
+ }
167
+
168
+ }
169
+ }
170
+
171
+ /**
172
+ * This function will call the RS API, and create a new sales rule if:
173
+ * 1) The offer is valid
174
+ * 2) The offer code hasn't been used before
175
+ *
176
+ * @param $offerCode string The offer code
177
+ */
178
+ private function createOfferSalesrule($offerCode)
179
+ {
180
+ $helper = Mage::helper( 'rewardstream' );
181
+ $apiurl = 'https://' . Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_api_url' );
182
+ $apiKey = Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_api_key' );
183
+ $secretKey = Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_secret_key' );
184
+
185
+ $result = $helper->getDataCallAPI( $apiurl . '/api/v2/custom/getOffer?api_key=' . $apiKey . '&code=' . $offerCode, "GET", false, "Basic " . $secretKey );
186
  $responseData = json_decode( $result, true );
187
 
188
+ $rsOfferStatus = $responseData['Status'];
189
+
190
+ // If valid RS offer code, create coupon discount if necessary. Otherwise just apply code as normal and it will only work if there's a Magento coupon code already
191
+ if ( $rsOfferStatus == "valid" ) {
192
+ $rsDiscountValue = $responseData["Offer"]['Value'];
193
+ $rsOfferType = $responseData["Offer"]['Type'];
194
+ $rsMinimumPurchase = $responseData["Offer"]['MinimumPurchase'];
195
+ if ( $rsOfferType == "percent_off" ) {
196
+
197
+ $mgOfferType = "by_percent";
198
+ }
199
+ else if ( $rsOfferType == "dollar_off" ) {
200
+
201
+ $mgOfferType = "cart_fixed";
202
+ }
203
+ else if ( $rsOfferType == "free_ship" ) {
204
+
205
+ $mgOfferType = "free_ship";
206
+ }
207
+ else {
208
+ throw new InvalidArgumentException("Offer type \"" . $rsOfferType . "\" not supported by this version of the RewardStream Refer-A-Friend extension.");
209
+ }
210
+
211
+ $name = "rewardstream_" . $offerCode;
212
+ $rule = Mage::getModel( 'salesrule/rule' );
213
+ $coupon = Mage::getModel( 'salesrule/coupon' );
214
+ $couponAlreadyCreated = $coupon->getResource()->exists( $offerCode ); //check coupon code is already exist or not
215
+
216
+ if ( $couponAlreadyCreated == false ) {
217
+ // Get current website ID as that's the one it should be applicable to
218
+ $websiteId = Mage::app()->getWebsite()->getId();
219
+ // Get all customer group IDs, as this should be applicable to all
220
+ $customerGroupIds = Mage::getModel('customer/group')->getCollection()->getAllIds();
221
+ // Create the coupon as a Magento discount rule
222
+ if ( $mgOfferType != "free_ship" ) {
223
+ $rule->setName( $name )
224
+ ->setDescription( $name )
225
+ ->setFromDate( '' )
226
+ ->setCouponType( 2 )
227
+ ->setCouponCode( $offerCode )
228
+ ->setUsesPerCustomer( 1 )
229
+ ->setUsesPerCoupon( 1 )
230
+ ->setIsActive( 1 )
231
+ ->setCustomerGroupIds($customerGroupIds)
232
+ ->setConditionsSerialized( '' )
233
+ ->setActionsSerialized( '' )
234
+ ->setStopRulesProcessing( 0 )
235
+ ->setIsAdvanced( 1 )
236
+ ->setProductIds( '' )
237
+ ->setSortOrder( 0 )
238
+ ->setSimpleAction( $mgOfferType )
239
+ ->setDiscountAmount( $rsDiscountValue )
240
+ ->setDiscountQty( null )
241
+ ->setDiscountStep( 0 )
242
+ ->setSimpleFreeShipping( '0' )
243
+ ->setApplyToShipping( '0' )
244
+ ->setIsRss( 0 )
245
+ ->setWebsiteIds( array( $websiteId ) );
246
+
247
+ $actions = Mage::getModel( 'salesrule/rule_condition_product' )
248
+ ->setType( 'salesrule/rule_condition_product' )
249
+ ->setAttribute( 'quote_item_row_total' )
250
+ ->setOperator( '>=' )
251
+ ->setValue( $rsMinimumPurchase );
252
+
253
+ $rule->getActions()->addCondition( $actions );
254
+
255
+ $rule->save();
256
+ }
257
+ else
258
+ {
259
+ $rule->setName( $name )
260
+ ->setDescription( $name )
261
+ ->setFromDate( '' )
262
+ ->setCouponType( 2 )
263
+ ->setCouponCode( $offerCode )
264
+ ->setUsesPerCustomer( 1 )
265
+ ->setUsesPerCoupon( 1 )
266
+ ->setIsActive( 1 )
267
+ ->setCustomerGroupIds($customerGroupIds)
268
+ ->setConditionsSerialized( '' )
269
+ ->setActionsSerialized( '' )
270
+ ->setStopRulesProcessing( 0 )
271
+ ->setIsAdvanced( 1 )
272
+ ->setProductIds( '' )
273
+ ->setSortOrder( 0 )
274
+ ->setSimpleAction( 'by_percent' )
275
+ ->setDiscountAmount( '0' )
276
+ ->setDiscountQty( null )
277
+ ->setDiscountStep( 0 )
278
+ ->setSimpleFreeShipping( '1' )
279
+ ->setApplyToShipping( '0' )
280
+ ->setIsRss( 0 )
281
+ ->setWebsiteIds( array( $websiteId ) );
282
+
283
+ $actions = Mage::getModel( 'salesrule/rule_condition_product' )
284
+ ->setType( 'salesrule/rule_condition_product' )
285
+ ->setAttribute( 'quote_item_row_total' )
286
+ ->setOperator( '>=' )
287
+ ->setValue( $rsMinimumPurchase );
288
+
289
+ $rule->getActions()->addCondition( $actions );
290
+
291
+ $rule->save();
292
+ }
293
+ }
294
  }
295
+ }
296
+
297
+ /**
298
+ * This function will call the RS API, and create a new sales rule if:
299
+ * 1) The reward is valid
300
+ * 2) The reward code hasn't been used before
301
+ *
302
+ * @param $rewardCode string The reward code
303
+ * @throws Exception if offer
304
+ */
305
+ private function createRewardSalesrule($rewardCode)
306
+ {
307
+ $helper = Mage::helper( 'rewardstream' );
308
+ $apiurl = 'https://' . Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_api_url' );
309
+ $apiKey = Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_api_key' );
310
+ $secretKey = Mage::getStoreConfig( 'rewardstream_options/section_one/rewardstream_secret_key' );
311
+
312
+ $certificate = $this->getCertificate( $rewardCode );
313
+
314
+
315
+ if ( $this->is_code_valid( $certificate ) && isset( $certificate->CertificateNumber ) ) {
316
+
317
+ $rsRewardType = $certificate->Certificate->DiscountType;
318
+ $rsMinimumPurchase = $certificate->Certificate->MinimumPurchase ? $certificate->Certificate->MinimumPurchase : '';
319
+
320
+ switch ( $rsRewardType ) {
321
+ case 'percent_off':
322
+ $mgRewardType = 'by_percent';
323
+ $rsDiscountValue = (int) $certificate->Certificate->DiscountValue;
324
+ break;
325
+ case 'dollar_off':
326
+ $mgRewardType = 'cart_fixed';
327
+ $rsDiscountValue = (float) $certificate->Certificate->DiscountValue;
328
+ break;
329
+ case 'free_ship':
330
+ $mgRewardType = 'free_ship';
331
+ $rsDiscountValue = 0;
332
+ break;
333
+ default:
334
+ throw new Exception("Unsupported discount type: " . $certificate->Certificate->DiscountType);
335
+ }
336
+
337
+ $name = "rewardstream_" . $rewardCode;
338
+ $rule = Mage::getModel( 'salesrule/rule' );
339
+ $coupon = Mage::getModel( 'salesrule/coupon' );
340
+ $couponAlreadyCreated = $coupon->getResource()->exists( $rewardCode ); //check coupon code is already exist or not
341
+
342
+ if ( $couponAlreadyCreated == false ) {
343
+ // Get current website ID as that's the one it should be applicable to
344
+ $websiteId = Mage::app()->getWebsite()->getId();
345
+ // Get all customer group IDs, as this should be applicable to all
346
+ $customerGroupIds = Mage::getModel('customer/group')->getCollection()->getAllIds();
347
+ // Create the coupon as a Magento discount rule
348
+ if ( $mgRewardType != "free_ship" ) {
349
+ $rule->setName( $name )
350
+ ->setDescription( $name )
351
+ ->setFromDate( '' )
352
+ ->setCouponType( 2 )
353
+ ->setCouponCode( $rewardCode )
354
+ ->setUsesPerCustomer( 1 )
355
+ ->setUsesPerCoupon( 1 )
356
+ ->setIsActive( 1 )
357
+ ->setCustomerGroupIds($customerGroupIds)
358
+ ->setConditionsSerialized( '' )
359
+ ->setActionsSerialized( '' )
360
+ ->setStopRulesProcessing( 0 )
361
+ ->setIsAdvanced( 1 )
362
+ ->setProductIds( '' )
363
+ ->setSortOrder( 0 )
364
+ ->setSimpleAction( $mgRewardType )
365
+ ->setDiscountAmount( $rsDiscountValue )
366
+ ->setDiscountQty( null )
367
+ ->setDiscountStep( 0 )
368
+ ->setSimpleFreeShipping( '0' )
369
+ ->setApplyToShipping( '0' )
370
+ ->setIsRss( 0 )
371
+ ->setWebsiteIds( array( $websiteId ) );
372
+
373
+ $actions = Mage::getModel( 'salesrule/rule_condition_product' )
374
+ ->setType( 'salesrule/rule_condition_product' )
375
+ ->setAttribute( 'quote_item_row_total' )
376
+ ->setOperator( '>=' )
377
+ ->setValue( $rsMinimumPurchase );
378
+
379
+ $rule->getActions()->addCondition( $actions );
380
+
381
+ $rule->save();
382
+ }
383
+ else
384
+ {
385
+ $rule->setName( $name )
386
+ ->setDescription( $name )
387
+ ->setFromDate( '' )
388
+ ->setCouponType( 2 )
389
+ ->setCouponCode( $rewardCode )
390
+ ->setUsesPerCustomer( 1 )
391
+ ->setUsesPerCoupon( 1 )
392
+ ->setIsActive( 1 )
393
+ ->setCustomerGroupIds($customerGroupIds)
394
+ ->setConditionsSerialized( '' )
395
+ ->setActionsSerialized( '' )
396
+ ->setStopRulesProcessing( 0 )
397
+ ->setIsAdvanced( 1 )
398
+ ->setProductIds( '' )
399
+ ->setSortOrder( 0 )
400
+ ->setSimpleAction( 'by_percent' )
401
+ ->setDiscountAmount( '0' )
402
+ ->setDiscountQty( null )
403
+ ->setDiscountStep( 0 )
404
+ ->setSimpleFreeShipping( '1' )
405
+ ->setApplyToShipping( '0' )
406
+ ->setIsRss( 0 )
407
+ ->setWebsiteIds( array( $websiteId ) );
408
+
409
+ $actions = Mage::getModel( 'salesrule/rule_condition_product' )
410
+ ->setType( 'salesrule/rule_condition_product' )
411
+ ->setAttribute( 'quote_item_row_total' )
412
+ ->setOperator( '>=' )
413
+ ->setValue( $rsMinimumPurchase );
414
+
415
+ $rule->getActions()->addCondition( $actions );
416
+
417
+ $rule->save();
418
+ }
419
+ }
420
+
421
  }
422
  }
423
  }
424
 
425
+
426
  ?>
app/code/community/Rewardstream/Referafriend/etc/config.xml CHANGED
@@ -64,12 +64,26 @@
64
  </sales>
65
 
66
  </blocks>
67
- <rewrite>
68
- <Rewardstream_Referafriend>
69
- <from><![CDATA[#^/checkout/cart/couponPost#]]></from>
70
- <to>/rewardstream/cart/couponPost</to>
71
- </Rewardstream_Referafriend>
72
- </rewrite>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  </global>
74
  <adminhtml>
75
  <acl>
@@ -91,17 +105,6 @@
91
  </admin>
92
  </resources>
93
  </acl>
94
- <events>
95
- <sales_order_invoice_pay>
96
- <observers>
97
- <rewardstream_observers>
98
- <type>singleton</type>
99
- <class>rewardstream/observer</class>
100
- <method>salesOrderInvoicePayAfter</method>
101
- </rewardstream_observers>
102
- </observers>
103
- </sales_order_invoice_pay>
104
- </events>
105
  </adminhtml>
106
  <frontend>
107
  <layout>
64
  </sales>
65
 
66
  </blocks>
67
+ <events>
68
+ <sales_order_invoice_pay>
69
+ <observers>
70
+ <rewardstream_observers>
71
+ <type>singleton</type>
72
+ <class>rewardstream/observer</class>
73
+ <method>salesOrderInvoicePayAfter</method>
74
+ </rewardstream_observers>
75
+ </observers>
76
+ </sales_order_invoice_pay>
77
+ <sales_quote_collect_totals_before>
78
+ <observers>
79
+ <rewardstream_observers_sales_quote_collect_totals_after>
80
+ <type>singleton</type>
81
+ <class>rewardstream/observer</class>
82
+ <method>createDiscountCode</method>
83
+ </rewardstream_observers_sales_quote_collect_totals_after>
84
+ </observers>
85
+ </sales_quote_collect_totals_before>
86
+ </events>
87
  </global>
88
  <adminhtml>
89
  <acl>
105
  </admin>
106
  </resources>
107
  </acl>
 
 
 
 
 
 
 
 
 
 
 
108
  </adminhtml>
109
  <frontend>
110
  <layout>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>RewardStream_ReferAFriend</name>
4
- <version>1.1.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.rewardstream.com/magento/license">RewardStream Software License Agreement</license>
7
  <channel>community</channel>
@@ -9,11 +9,13 @@
9
  <summary>Get new customers by adding a fully automated word-of-mouth customer referral marketing solution to your store</summary>
10
  <description>Get new sales using the Refer A Friend extension. Launch a fully automated referral marketing program on your store with little-to-no IT. Customers can refer their friends and family to bring you new business. Automatically reward your existing customers for successful referrals and incentivize your new customers with special referral offers. Refer a Friend is a free Magento Extension and requires a paid service account with RewardStream.&#xD;
11
  </description>
12
- <notes>Content updates for our new interface</notes>
 
 
13
  <authors><author><name>RewardStream</name><user>RewardStream</user><email>plugin-support@rewardstream.com</email></author></authors>
14
- <date>2017-01-27</date>
15
- <time>01:36:01</time>
16
- <contents><target name="magecommunity"><dir name="Rewardstream"><dir name="Referafriend"><dir name="Block"><file name="Button.php" hash="2d412348e526ce8259cb767b5d795fd7"/><dir name="Customer"><dir name="Account"><file name="Navigation.php" hash="18a0c268359658bd7619ce7168159364"/></dir></dir><file name="Getstartedbutton.php" hash="7bfea148b21c68ea5228ff64f4d9991e"/><dir name="Sales"><dir name="Order"><file name="History.php" hash="880e07a11f94ceab5bd5e066a4cfa838"/><file name="Recent.php" hash="8c5c64cd158205a7a5bd053a3c7a3cf0"/></dir></dir><file name="Script.php" hash="13b06afd09fada61b761ea5ff4254ede"/></dir><dir name="Helper"><file name="Data.php" hash="6ac29ba1b21d0ca246df13a216da649e"/></dir><dir name="Model"><file name="Observer.php" hash="8cfe14b1a89190e418074f98f81bee0e"/><file name="Options.php" hash="1c4fa6b3e55cec4b096ebbaedacacb19"/><dir name="Resource"><dir name="Rewardstream"><file name="Collection.php" hash="aeeb1df3e3eb6bdeadce8aa29d98eea5"/></dir><file name="Rewardstream.php" hash="8fe9853ebbad43796b683582db550620"/></dir><file name="Rewardstream.php" hash="884edc2f2bd98d5794c9c2bd6b84b9a8"/></dir><dir name="controllers"><file name="CartController.php" hash="e8dd6101f0e36eeb4cde1931dc2e461f"/><file name="IndexController.php" hash="d3429574e292d9c7b9c55c6a060bcb30"/></dir><dir name="data"><dir name="rewardstream_setup"><file name="data-install-0.1.0.php" hash="ffa670c6e00b15f7197e017017aa5ac2"/></dir></dir><dir name="etc"><file name="config.xml" hash="be0f3fefd66b1593a7d6c0d93194a1a7"/><file name="system.xml" hash="4c382d84ff7c7ce434465593057132ba"/></dir><dir name="sql"><dir name="rewardstream_setup"><file name="install-0.1.0.php" hash="2ff36a8226dba730c568ce7bd5328b76"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="rewardstream.xml" hash="4c9a4575f0d44847032614368cf3924e"/></dir><dir name="template"><dir name="rewardstream"><file name="blockreward.phtml" hash="82e9d4d7d5592b40a9ada2ce3c8e1996"/><file name="general_script.phtml" hash="9386936cd1df44ccecb185e510417736"/><file name="rewardstream.phtml" hash="6f628a6916b1fffed4794276cd7c084d"/><file name="script.phtml" hash="a37b6436daeeb70f73c8dd03930ce1f9"/></dir></dir></dir></dir><dir name="rwd"><dir name="default"><dir name="layout"><file name="rewardstream.xml" hash="9453c01a065a609ba6b30e3e7420c97f"/></dir><dir name="template"><dir name="rewardstream"><file name="blockreward.phtml" hash="82e9d4d7d5592b40a9ada2ce3c8e1996"/><file name="general_script.phtml" hash="9386936cd1df44ccecb185e510417736"/><file name="rewardstream.phtml" hash="6f628a6916b1fffed4794276cd7c084d"/><file name="script.phtml" hash="a37b6436daeeb70f73c8dd03930ce1f9"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="RewardStream_ReferAFriend.xml" hash="d08d3aa024b2616e3a3792aeac0bc3cb"/></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="rewardstream"><dir name="css"><file name="rewardstream.css" hash="14e0164315bb6fec5354b331009b9793"/></dir></dir></dir></dir><dir name="rwd"><dir name="default"><dir name="rewardstream"><dir name="css"><file name="rewardstream.css" hash="14e0164315bb6fec5354b331009b9793"/></dir></dir></dir></dir></dir></target><target name="magemedia"><dir name="wysiwyg"><dir name="rewardstream"><file name="loading.gif" hash="dbd0f12f50cc2b56e2bce7daa36d00d0"/><file name="rewardstream-magento-store-default-image.jpg" hash="66004f46b67bbb30c8d4cd7e5fff1fa1"/><file name="sharing-is-caring.jpg" hash="079db8066ed86203bd78c52b20d6163e"/></dir></dir></target><target name="mageweb"><dir name="js"><dir name="rewardstream"><file name="RSUtility.js" hash="c56b4d2ca75647f8708ad59e6382e300"/><file name="jquery-1.10.2.min.js" hash="841dc30647f93349b7d8ef61deebe411"/><file name="noconflict.js" hash="12f820da0f5ba19abfb4f5fc270bb62c"/></dir></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.5.0.0</min><max>1.9</max></package></required></dependencies>
19
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>RewardStream_ReferAFriend</name>
4
+ <version>1.2.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.rewardstream.com/magento/license">RewardStream Software License Agreement</license>
7
  <channel>community</channel>
9
  <summary>Get new customers by adding a fully automated word-of-mouth customer referral marketing solution to your store</summary>
10
  <description>Get new sales using the Refer A Friend extension. Launch a fully automated referral marketing program on your store with little-to-no IT. Customers can refer their friends and family to bring you new business. Automatically reward your existing customers for successful referrals and incentivize your new customers with special referral offers. Refer a Friend is a free Magento Extension and requires a paid service account with RewardStream.&#xD;
11
  </description>
12
+ <notes>Fixed compatibility issues with common checkout extensions.&#xD;
13
+ Added support for automatically generated reward codes.&#xD;
14
+ Stability improvements.</notes>
15
  <authors><author><name>RewardStream</name><user>RewardStream</user><email>plugin-support@rewardstream.com</email></author></authors>
16
+ <date>2017-03-01</date>
17
+ <time>00:14:00</time>
18
+ <contents><target name="magecommunity"><dir name="Rewardstream"><dir name="Referafriend"><dir name="Block"><file name="Button.php" hash="2d412348e526ce8259cb767b5d795fd7"/><dir name="Customer"><dir name="Account"><file name="Navigation.php" hash="18a0c268359658bd7619ce7168159364"/></dir></dir><file name="Getstartedbutton.php" hash="7bfea148b21c68ea5228ff64f4d9991e"/><dir name="Sales"><dir name="Order"><file name="History.php" hash="880e07a11f94ceab5bd5e066a4cfa838"/><file name="Recent.php" hash="8c5c64cd158205a7a5bd053a3c7a3cf0"/></dir></dir><file name="Script.php" hash="13b06afd09fada61b761ea5ff4254ede"/></dir><dir name="Helper"><file name="Data.php" hash="6ac29ba1b21d0ca246df13a216da649e"/></dir><dir name="Model"><file name="Observer.php" hash="35e825fa556ac8ffcda84828784b0441"/><file name="Options.php" hash="1c4fa6b3e55cec4b096ebbaedacacb19"/><dir name="Resource"><dir name="Rewardstream"><file name="Collection.php" hash="aeeb1df3e3eb6bdeadce8aa29d98eea5"/></dir><file name="Rewardstream.php" hash="8fe9853ebbad43796b683582db550620"/></dir><file name="Rewardstream.php" hash="884edc2f2bd98d5794c9c2bd6b84b9a8"/></dir><dir name="controllers"><file name="CartController.php" hash="e8dd6101f0e36eeb4cde1931dc2e461f"/><file name="IndexController.php" hash="d3429574e292d9c7b9c55c6a060bcb30"/></dir><dir name="data"><dir name="rewardstream_setup"><file name="data-install-0.1.0.php" hash="ffa670c6e00b15f7197e017017aa5ac2"/></dir></dir><dir name="etc"><file name="config.xml" hash="baa8ed8409a5859f3fed6017157e8a33"/><file name="system.xml" hash="4c382d84ff7c7ce434465593057132ba"/></dir><dir name="sql"><dir name="rewardstream_setup"><file name="install-0.1.0.php" hash="2ff36a8226dba730c568ce7bd5328b76"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="rewardstream.xml" hash="4c9a4575f0d44847032614368cf3924e"/></dir><dir name="template"><dir name="rewardstream"><file name="blockreward.phtml" hash="82e9d4d7d5592b40a9ada2ce3c8e1996"/><file name="general_script.phtml" hash="9386936cd1df44ccecb185e510417736"/><file name="rewardstream.phtml" hash="6f628a6916b1fffed4794276cd7c084d"/><file name="script.phtml" hash="a37b6436daeeb70f73c8dd03930ce1f9"/></dir></dir></dir></dir><dir name="rwd"><dir name="default"><dir name="layout"><file name="rewardstream.xml" hash="9453c01a065a609ba6b30e3e7420c97f"/></dir><dir name="template"><dir name="rewardstream"><file name="blockreward.phtml" hash="82e9d4d7d5592b40a9ada2ce3c8e1996"/><file name="general_script.phtml" hash="9386936cd1df44ccecb185e510417736"/><file name="rewardstream.phtml" hash="6f628a6916b1fffed4794276cd7c084d"/><file name="script.phtml" hash="a37b6436daeeb70f73c8dd03930ce1f9"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="RewardStream_ReferAFriend.xml" hash="d08d3aa024b2616e3a3792aeac0bc3cb"/></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="rewardstream"><dir name="css"><file name="rewardstream.css" hash="14e0164315bb6fec5354b331009b9793"/></dir></dir></dir></dir><dir name="rwd"><dir name="default"><dir name="rewardstream"><dir name="css"><file name="rewardstream.css" hash="14e0164315bb6fec5354b331009b9793"/></dir></dir></dir></dir></dir></target><target name="magemedia"><dir name="wysiwyg"><dir name="rewardstream"><file name="loading.gif" hash="dbd0f12f50cc2b56e2bce7daa36d00d0"/><file name="rewardstream-magento-store-default-image.jpg" hash="66004f46b67bbb30c8d4cd7e5fff1fa1"/><file name="sharing-is-caring.jpg" hash="079db8066ed86203bd78c52b20d6163e"/></dir></dir></target><target name="mageweb"><dir name="js"><dir name="rewardstream"><file name="RSUtility.js" hash="c56b4d2ca75647f8708ad59e6382e300"/><file name="jquery-1.10.2.min.js" hash="841dc30647f93349b7d8ef61deebe411"/><file name="noconflict.js" hash="12f820da0f5ba19abfb4f5fc270bb62c"/></dir></dir></target></contents>
19
  <compatible/>
20
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.5.0.0</min><max>1.9</max></package></required></dependencies>
21
  </package>