Completed
Pull Request — 2 (#402)
by Jason
08:46
created
code/model/foxycart.cart_validation.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -43,6 +43,9 @@
 block discarded – undo
43 43
 		self::setSecret(FoxyCart::getStoreKey());
44 44
 	}
45 45
 
46
+	/**
47
+	 * @return string
48
+	 */
46 49
 	public static function getSecret(){
47 50
 		return FoxyCart::getStoreKey();
48 51
 	}
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -30,20 +30,20 @@  discard block
 block discarded – undo
30 30
 	// protected static $cart_url = 'https://yourdomain.foxycart.com/cart';
31 31
 	protected static $cart_url;
32 32
 
33
-	public static function setCartURL($storeName = null){
33
+	public static function setCartURL($storeName = null) {
34 34
 		self::$cart_url = 'https://'.$storeName.'.faxycart.com/cart';
35 35
 	}
36 36
 
37
-	public static function setSecret($secret = null){
37
+	public static function setSecret($secret = null) {
38 38
 		self::$secret = $secret;
39 39
 	}
40 40
 
41
-	public function __construct(){
41
+	public function __construct() {
42 42
 		self::setCartURL(FoxyCart::getFoxyCartStoreName());
43 43
 		self::setSecret(FoxyCart::getStoreKey());
44 44
 	}
45 45
 
46
-	public static function getSecret(){
46
+	public static function getSecret() {
47 47
 		return FoxyCart::getStoreKey();
48 48
 	}
49 49
 
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 				$codes[$pair['prefix']] = $pair['value'];
108 108
 			}
109 109
 		}
110
-		if ( ! count($codes)) {
110
+		if (!count($codes)) {
111 111
 			self::$log[] = '<strong style="color:#600;">No code found</strong> for the above link.';
112 112
 			return $fail;
113 113
 		}
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 
132 132
 		if ($output) {
133 133
 			echo self::$cart_url.'?'.$qs;
134
-		} else {
134
+		}else {
135 135
 			return self::$cart_url.'?'.$qs;
136 136
 		}
137 137
 	}
@@ -149,18 +149,18 @@  discard block
 block discarded – undo
149 149
 		if ($option_value == '--OPEN--') {
150 150
 			$hash = hash_hmac('sha256', $product_code.$option_name.$option_value, self::getSecret());
151 151
 			$value = ($urlencode) ? urlencode($option_name).'||'.$hash.'||open' : $option_name.'||'.$hash.'||open';
152
-		} else {
152
+		}else {
153 153
 			$hash = hash_hmac('sha256', $product_code.$option_name.$option_value, self::getSecret());
154 154
 			if ($method == 'name') {
155 155
 				$value = ($urlencode) ? urlencode($option_name).'||'.$hash : $option_name.'||'.$hash;
156
-			} else {
156
+			}else {
157 157
 				$value = ($urlencode) ? urlencode($option_value).'||'.$hash : $option_value.'||'.$hash;
158 158
 			}
159 159
 		}
160 160
 
161 161
 		if ($output) {
162 162
 			echo $value;
163
-		} else {
163
+		}else {
164 164
 			return $value;
165 165
 		}
166 166
 	}
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 						$value[2] = ($value[2] == '') ? '--OPEN--' : $value[2];
249 249
 						if ($type[2] == 'radio') {
250 250
 							$input_signed = preg_replace('%([\'"])'.preg_quote($value[2]).'\1%', '${1}'.self::fc_hash_value($code, $name[2], $value[2], 'value', FALSE)."$1", $input);
251
-						} else {
251
+						}else {
252 252
 							$input_signed = preg_replace('%([\'"])'.$prefix.preg_quote($name[2]).'\1%', '${1}'.$prefix.self::fc_hash_value($code, $name[2], $value[2], 'name', FALSE)."$1", $input);
253 253
 						}
254 254
 						self::$log[] = '<strong>INPUT:</strong> Code: <strong>'.htmlspecialchars($prefix.$code).
@@ -267,14 +267,14 @@  discard block
 block discarded – undo
267 267
 					$count['lists']++;
268 268
 					preg_match_all('%<option [^>]*value=([\'"])(.+?)\1[^>]*>(?:.*?)</option>%i', $list[0], $options, PREG_SET_ORDER);
269 269
 					self::$log[] = '<strong>Options:</strong> <pre>'.htmlspecialchars(print_r($options, true)).'</pre>';
270
-					unset( $form_part_signed );
270
+					unset($form_part_signed);
271 271
 					foreach ($options as $option) {
272
-						if( !isset($form_part_signed) ) $form_part_signed = $list[0];
272
+						if (!isset($form_part_signed)) $form_part_signed = $list[0];
273 273
 						$option_signed = preg_replace(
274 274
 							'%'.preg_quote($option[1]).preg_quote($option[2]).preg_quote($option[1]).'%',
275 275
 							$option[1].self::fc_hash_value($code, $list[2], $option[2], 'value', FALSE).$option[1],
276 276
 							$option[0]);
277
-						$form_part_signed = str_replace($option[0], $option_signed, $form_part_signed );
277
+						$form_part_signed = str_replace($option[0], $option_signed, $form_part_signed);
278 278
 						self::$log[] = '<strong>OPTION:</strong> Code: <strong>'.htmlspecialchars($prefix.$code).
279 279
 						               '</strong> :: Name: <strong>'.htmlspecialchars($prefix.$list[2]).
280 280
 						               '</strong> :: Value: <strong>'.htmlspecialchars($option[2]).
Please login to merge, or discard this patch.
code/objects/ProductImage.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-class ProductImage extends DataObject{
8
+class ProductImage extends DataObject {
9 9
 
10 10
 	private static $db = array(
11 11
 		'Title' => 'Text',
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 		'Title' => 'Caption'
25 25
 	);
26 26
 
27
-	public function getCMSFields(){
27
+	public function getCMSFields() {
28 28
 		$fields = FieldList::create(
29 29
             TextField::create('Title')
30 30
                 ->setTitle(_t('ProductImage.Title', 'Product Image Title')),
Please login to merge, or discard this patch.
code/objects/ProductCategory.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@
 block discarded – undo
55 55
 	public function requireDefaultRecords() {
56 56
 		parent::requireDefaultRecords();
57 57
 		$allCats = DataObject::get('ProductCategory');
58
-		if(!$allCats->count()){
58
+		if (!$allCats->count()) {
59 59
 			$cat = new ProductCategory();
60 60
 			$cat->Title = 'Default';
61 61
 			$cat->Code = 'DEFAULT';
Please login to merge, or discard this patch.
code/pages/OrderHistoryPage.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
     private static $plural_name = 'Order History Pages';
12 12
     private static $description = 'Show a customers past orders. Requires authentication';
13 13
 
14
-	public function getCMSFields(){
14
+	public function getCMSFields() {
15 15
 		$fields = parent::getCMSFields();
16 16
 
17 17
 
@@ -41,10 +41,10 @@  discard block
 block discarded – undo
41 41
     );
42 42
 
43 43
     public function checkMember() {
44
-        if(Member::currentUser()) {
44
+        if (Member::currentUser()) {
45 45
             return true;
46
-        } else {
47
-            return Security::permissionFailure ($this, _t (
46
+        }else {
47
+            return Security::permissionFailure($this, _t(
48 48
                 'AccountPage.CANNOTCONFIRMLOGGEDIN',
49 49
                 'Please login to view this page.'
50 50
             ));
Please login to merge, or discard this patch.
code/extensions/FoxyStripeSiteConfig.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-class FoxyStripeSiteConfig extends DataExtension{
3
+class FoxyStripeSiteConfig extends DataExtension {
4 4
 
5 5
 	private static $db = array(
6 6
 		'StoreName' => 'Varchar(255)',
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
         'ProductLimit' => 10
17 17
     );
18 18
 
19
-	public function updateCMSFields(FieldList $fields){
19
+	public function updateCMSFields(FieldList $fields) {
20 20
 
21 21
         // set TabSet names to avoid spaces from camel case
22 22
         $fields->addFieldToTab('Root', new TabSet('FoxyStripe', 'FoxyStripe'));
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
         ));
56 56
 
57 57
         // configuration warning
58
-		if(FoxyCart::store_name_warning()!==null){
58
+		if (FoxyCart::store_name_warning() !== null) {
59 59
 			$fields->insertBefore(LiteralField::create(
60 60
                 "StoreSubDomainHeaderWarning",
61 61
                 _t(
@@ -137,14 +137,14 @@  discard block
 block discarded – undo
137 137
 
138 138
         $siteConfig = SiteConfig::current_site_config();
139 139
 
140
-        if(!$siteConfig->StoreKey) {
140
+        if (!$siteConfig->StoreKey) {
141 141
             $key = FoxyCart::setStoreKey();
142
-            while(!ctype_alnum($key)){
142
+            while (!ctype_alnum($key)) {
143 143
                 $key = FoxyCart::setStoreKey();
144 144
             }
145 145
             $siteConfig->StoreKey = $key;
146 146
             $siteConfig->write();
147
-            DB::alteration_message($siteConfig->ClassName.": created FoxyCart Store Key " . $key, 'created');
147
+            DB::alteration_message($siteConfig->ClassName.": created FoxyCart Store Key ".$key, 'created');
148 148
         }
149 149
     }
150 150
 
Please login to merge, or discard this patch.
code/extensions/FoxyStripePageExtension.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@
 block discarded – undo
4 4
 
5 5
     // get FoxyCart Store Name for JS call
6 6
     public function getCartScript() {
7
-        return '<script src="https://cdn.foxycart.com/' . FoxyCart::getFoxyCartStoreName() . '/loader.js" async defer></script>';
7
+        return '<script src="https://cdn.foxycart.com/'.FoxyCart::getFoxyCartStoreName().'/loader.js" async defer></script>';
8 8
     }
9 9
 
10 10
 }
11 11
\ No newline at end of file
Please login to merge, or discard this patch.
code/controllers/FoxyStripe_Controller.php 2 patches
Doc Comments   +15 added lines patch added patch discarded remove patch
@@ -34,6 +34,9 @@  discard block
 block discarded – undo
34 34
 		}
35 35
 	}
36 36
 
37
+    /**
38
+     * @param string $encrypted
39
+     */
37 40
     public function handleDataFeed($encrypted, $decrypted){
38 41
         //handle encrypted & decrypted data
39 42
         $orders = new SimpleXMLElement($decrypted);
@@ -79,6 +82,10 @@  discard block
 block discarded – undo
79 82
         }
80 83
     }
81 84
 
85
+    /**
86
+     * @param SimpleXMLElement $orders
87
+     * @param DataObject $transaction
88
+     */
82 89
     public function parseOrderInfo($orders, $transaction) {
83 90
 
84 91
         foreach ($orders->transactions->transaction as $order) {
@@ -95,6 +102,10 @@  discard block
 block discarded – undo
95 102
         }
96 103
     }
97 104
 
105
+    /**
106
+     * @param SimpleXMLElement $orders
107
+     * @param DataObject $transaction
108
+     */
98 109
     public function parseOrderCustomer($orders, $transaction) {
99 110
 
100 111
         foreach ($orders->transactions->transaction as $order) {
@@ -133,6 +144,10 @@  discard block
 block discarded – undo
133 144
         }
134 145
     }
135 146
 
147
+    /**
148
+     * @param SimpleXMLElement $orders
149
+     * @param DataObject $transaction
150
+     */
136 151
     public function parseOrderDetails($orders, $transaction) {
137 152
 
138 153
         // remove previous OrderDetails so we don't end up with duplicates
Please login to merge, or discard this patch.
Spacing   +15 added lines, -17 removed lines patch added patch discarded remove patch
@@ -17,9 +17,8 @@  discard block
 block discarded – undo
17 17
 	    // handle POST from FoxyCart API transaction
18 18
 		if ((isset($_POST["FoxyData"]) OR isset($_POST['FoxySubscriptionData']))) {
19 19
 			$FoxyData_encrypted = (isset($_POST["FoxyData"])) ?
20
-                urldecode($_POST["FoxyData"]) :
21
-                urldecode($_POST["FoxySubscriptionData"]);
22
-			$FoxyData_decrypted = rc4crypt::decrypt(FoxyCart::getStoreKey(),$FoxyData_encrypted);
20
+                urldecode($_POST["FoxyData"]) : urldecode($_POST["FoxySubscriptionData"]);
21
+			$FoxyData_decrypted = rc4crypt::decrypt(FoxyCart::getStoreKey(), $FoxyData_encrypted);
23 22
 			self::handleDataFeed($FoxyData_encrypted, $FoxyData_decrypted);
24 23
 			
25 24
 			// extend to allow for additional integrations with Datafeed
@@ -27,14 +26,14 @@  discard block
 block discarded – undo
27 26
 			
28 27
 			return 'foxy';
29 28
 			
30
-		} else {
29
+		}else {
31 30
 			
32 31
 			return "No FoxyData or FoxySubscriptionData received.";
33 32
 			
34 33
 		}
35 34
 	}
36 35
 
37
-    public function handleDataFeed($encrypted, $decrypted){
36
+    public function handleDataFeed($encrypted, $decrypted) {
38 37
         //handle encrypted & decrypted data
39 38
         $orders = new SimpleXMLElement($decrypted);
40 39
 
@@ -43,12 +42,11 @@  discard block
 block discarded – undo
43 42
 
44 43
             if (isset($order->id)) {
45 44
                 ($transaction = Order::get()->filter('Order_ID', $order->id)->First()) ?
46
-                    $transaction :
47
-                    $transaction = Order::create();
45
+                    $transaction : $transaction = Order::create();
48 46
             }
49 47
 
50 48
             // save base order info
51
-            $transaction->Order_ID = (int) $order->id;
49
+            $transaction->Order_ID = (int)$order->id;
52 50
             $transaction->Response = $decrypted;
53 51
 
54 52
             // record transaction as order
@@ -103,7 +101,7 @@  discard block
 block discarded – undo
103 101
             if (isset($order->customer_email) && $order->is_anonymous == 0) {
104 102
 
105 103
                 // if Customer is existing member, associate with current order
106
-                if(Member::get()->filter('Email', $order->customer_email)->First()) {
104
+                if (Member::get()->filter('Email', $order->customer_email)->First()) {
107 105
 
108 106
                     $customer = Member::get()->filter('Email', $order->customer_email)->First();
109 107
 
@@ -116,7 +114,7 @@  discard block
 block discarded – undo
116 114
                     $customer->write();
117 115
                     */
118 116
 
119
-                } else {
117
+                }else {
120 118
 
121 119
                     // set PasswordEncryption to 'none' so imported, encrypted password is not encrypted again
122 120
                     Config::inst()->update('Security', 'password_encryption_algorithm', 'none');
@@ -227,24 +225,24 @@  discard block
 block discarded – undo
227 225
         // get current member if logged in. If not, create a 'fake' user with Customer_ID = 0
228 226
         // fake user will redirect to FC checkout, ask customer to log in
229 227
         // to do: consider a login/registration form here if not logged in
230
-        if($Member = Member::currentUser()) {
228
+        if ($Member = Member::currentUser()) {
231 229
             $Member = Member::currentUser();
232
-        } else {
230
+        }else {
233 231
             $Member = new Member();
234 232
             $Member->Customer_ID = 0;
235 233
         }
236 234
 
237
-        $auth_token = sha1($Member->Customer_ID . '|' . $timestampNew . '|' . FoxyCart::getStoreKey());
235
+        $auth_token = sha1($Member->Customer_ID.'|'.$timestampNew.'|'.FoxyCart::getStoreKey());
238 236
 
239 237
         $config = SiteConfig::current_site_config();
240 238
         if ($config->CustomSSL) {
241 239
             $link = FoxyCart::getFoxyCartStoreName();
242
-        } else {
243
-            $link = FoxyCart::getFoxyCartStoreName() . '.foxycart.com';
240
+        }else {
241
+            $link = FoxyCart::getFoxyCartStoreName().'.foxycart.com';
244 242
         }
245 243
 
246
-        $redirect_complete = 'https://' . $link . '/checkout?fc_auth_token=' . $auth_token .
247
-            '&fcsid=' . $fcsid . '&fc_customer_id=' . $Member->Customer_ID . '&timestamp=' . $timestampNew;
244
+        $redirect_complete = 'https://'.$link.'/checkout?fc_auth_token='.$auth_token.
245
+            '&fcsid='.$fcsid.'&fc_customer_id='.$Member->Customer_ID.'&timestamp='.$timestampNew;
248 246
 	
249 247
 	    $this->redirect($redirect_complete);
250 248
 
Please login to merge, or discard this patch.
code/forms/FoxyStripePurchaseForm.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
     private $product;
21 21
 
22 22
     /**
23
-     * @param $siteConfig
23
+     * @param SiteConfig|null $siteConfig
24 24
      * @return $this
25 25
      */
26 26
     public function setSiteConfig($siteConfig)
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
             $fields->push(HiddenField::create(ProductPage::getGeneratedValue($code, 'product_id',
121 121
                 $this->product->ID))->setValue($this->product->ID));
122 122
             $fields->push(HiddenField::create(ProductPage::getGeneratedValue($code, 'price',
123
-                $this->product->Price))->setValue($this->product->Price));//can't override id
123
+                $this->product->Price))->setValue($this->product->Price)); //can't override id
124 124
             $fields->push(HiddenField::create(ProductPage::getGeneratedValue($code, 'weight',
125 125
                 $this->product->Weight))->setValue($this->product->Weight));
126 126
 
@@ -148,11 +148,11 @@  discard block
 block discarded – undo
148 148
 
149 149
             $fields->push(DropdownField::create('quantity', 'Quantity', $quantity));
150 150
 
151
-            $fields->push(HeaderField::create('submitPrice', '$' . $this->product->Price, 4)->addExtraClass('submit-price'));
151
+            $fields->push(HeaderField::create('submitPrice', '$'.$this->product->Price, 4)->addExtraClass('submit-price'));
152 152
             $fields->push(HeaderField::create('unavailableText', 'Selection unavailable', 4)->addExtraClass('hidden unavailable-text'));
153 153
 
154 154
             $this->extend('updatePurchaseFormFields', $fields);
155
-        } else {
155
+        }else {
156 156
             $fields->push(HeaderField::create('submitPrice', 'Currently Out of Stock'), 4);
157 157
         }
158 158
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
     protected function getProductOptionSet()
190 190
     {
191 191
 
192
-        $assignAvailable = function ($self) {
192
+        $assignAvailable = function($self) {
193 193
             $this->extend('updateFoxyStripePurchaseForm', $form);
194 194
             $self->Available = ($self->getAvailability()) ? true : false;
195 195
         };
Please login to merge, or discard this patch.
code/form/FoxyStripeDropdownField.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
  * @package forms
49 49
  * @subpackage fields-basic
50 50
  */
51
-class FoxyStripeDropdownField extends DropdownField{
51
+class FoxyStripeDropdownField extends DropdownField {
52 52
 
53 53
 	/**
54 54
 	 * Mark certain elements as disabled,
@@ -56,12 +56,12 @@  discard block
 block discarded – undo
56 56
 	 *
57 57
 	 * @param array $items Collection of array keys, as defined in the $source array
58 58
 	 */
59
-	public function setDisabledItems($items){
59
+	public function setDisabledItems($items) {
60 60
 		$controller = Controller::curr();
61 61
 		$code = $controller->data()->Code;
62 62
 		$updated = [];
63
-		if(is_array($items) && !empty($items)){
64
-			foreach($items as $item){
63
+		if (is_array($items) && !empty($items)) {
64
+			foreach ($items as $item) {
65 65
 				array_push($updated, ProductPage::getGeneratedValue($code, $this->getName(), $item, 'value'));
66 66
 			}
67 67
 		}
@@ -76,8 +76,8 @@  discard block
 block discarded – undo
76 76
 		$controller = Controller::curr();
77 77
 		$code = $controller->data()->Code;
78 78
 		$updated = [];
79
-		if(is_array($source) && !empty($source)){
80
-			foreach($source as $key => $val){
79
+		if (is_array($source) && !empty($source)) {
80
+			foreach ($source as $key => $val) {
81 81
 				$updated[ProductPage::getGeneratedValue($code, $this->getName(), $key, 'value')] = $val;
82 82
 			}
83 83
 		}
Please login to merge, or discard this patch.