sunnysideup /
silverstripe-ecommerce
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * @description: each order has a billing address. |
||
| 5 | * |
||
| 6 | * |
||
| 7 | * |
||
| 8 | * @authors: Nicolaas [at] Sunny Side Up .co.nz |
||
| 9 | * @package: ecommerce |
||
| 10 | * @sub-package: address |
||
| 11 | * @inspiration: Silverstripe Ltd, Jeremy |
||
| 12 | **/ |
||
| 13 | class BillingAddress extends OrderAddress |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * what variables are accessible through http://mysite.com/api/ecommerce/v1/BillingAddress/. |
||
| 17 | * |
||
| 18 | * @var array |
||
| 19 | */ |
||
| 20 | private static $api_access = array( |
||
|
0 ignored issues
–
show
Comprehensibility
introduced
by
Loading history...
|
|||
| 21 | 'view' => array( |
||
| 22 | 'Prefix', |
||
| 23 | 'FirstName', |
||
| 24 | 'Surname', |
||
| 25 | 'Address', |
||
| 26 | 'Address2', |
||
| 27 | 'City', |
||
| 28 | 'PostalCode', |
||
| 29 | 'RegionCode', |
||
| 30 | 'Country', |
||
| 31 | 'Phone', |
||
| 32 | 'Email', |
||
| 33 | ), |
||
| 34 | ); |
||
| 35 | |||
| 36 | /** |
||
| 37 | * standard SS variable. |
||
| 38 | * |
||
| 39 | * @return array |
||
| 40 | */ |
||
| 41 | private static $db = array( |
||
|
0 ignored issues
–
show
|
|||
| 42 | 'Prefix' => 'Varchar(10)', |
||
| 43 | 'FirstName' => 'Varchar(100)', |
||
| 44 | 'Surname' => 'Varchar(100)', |
||
| 45 | 'Address' => 'Varchar(255)', |
||
| 46 | 'Address2' => 'Varchar(200)', |
||
| 47 | 'City' => 'Varchar(100)', |
||
| 48 | 'PostalCode' => 'Varchar(30)', |
||
| 49 | 'Country' => 'Varchar(4)', |
||
| 50 | 'RegionCode' => 'Varchar(100)', |
||
| 51 | 'Phone' => 'Varchar(50)', |
||
| 52 | 'Email' => 'Varchar(250)', |
||
| 53 | 'Obsolete' => 'Boolean', |
||
| 54 | 'OrderID' => 'Int', //NOTE: we have this here for faster look-ups and to make addresses behave similar to has_many dataobjects |
||
| 55 | ); |
||
| 56 | |||
| 57 | /** |
||
| 58 | * HAS_ONE =array(ORDER => ORDER); |
||
| 59 | * we place this relationship here |
||
| 60 | * (rather than in the parent class: OrderAddress) |
||
| 61 | * because that makes for a cleaner relationship |
||
| 62 | * (otherwise we ended up with a "has two" relationship in Order). |
||
| 63 | **/ |
||
| 64 | private static $has_one = array( |
||
|
0 ignored issues
–
show
|
|||
| 65 | 'Region' => 'EcommerceRegion', |
||
| 66 | ); |
||
| 67 | |||
| 68 | /** |
||
| 69 | * standard SS static definition. |
||
| 70 | **/ |
||
| 71 | private static $belongs_to = array( |
||
|
0 ignored issues
–
show
|
|||
| 72 | 'Order' => 'Order', |
||
| 73 | ); |
||
| 74 | |||
| 75 | /** |
||
| 76 | * standard SS static definition. |
||
| 77 | */ |
||
| 78 | private static $default_sort = [ |
||
|
0 ignored issues
–
show
|
|||
| 79 | 'ID' => 'DESC' |
||
| 80 | ]; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * standard SS variable. |
||
| 84 | * |
||
| 85 | * @return array |
||
| 86 | */ |
||
| 87 | private static $indexes = array( |
||
|
0 ignored issues
–
show
|
|||
| 88 | 'Obsolete' => true, |
||
| 89 | 'OrderID' => true, |
||
| 90 | 'Country' => true |
||
| 91 | ); |
||
| 92 | |||
| 93 | /** |
||
| 94 | * standard SS variable. |
||
| 95 | * |
||
| 96 | * @return array |
||
| 97 | */ |
||
| 98 | private static $casting = array( |
||
|
0 ignored issues
–
show
|
|||
| 99 | 'FullCountryName' => 'Varchar', |
||
| 100 | ); |
||
| 101 | |||
| 102 | /** |
||
| 103 | * standard SS variable. |
||
| 104 | * |
||
| 105 | * @return array |
||
| 106 | */ |
||
| 107 | private static $searchable_fields = array( |
||
|
0 ignored issues
–
show
|
|||
| 108 | 'OrderID' => array( |
||
| 109 | 'field' => 'NumericField', |
||
| 110 | 'title' => 'Order Number', |
||
| 111 | ), |
||
| 112 | 'Email' => 'PartialMatchFilter', |
||
| 113 | 'FirstName' => 'PartialMatchFilter', |
||
| 114 | 'Surname' => 'PartialMatchFilter', |
||
| 115 | 'Address' => 'PartialMatchFilter', |
||
| 116 | 'City' => 'PartialMatchFilter', |
||
| 117 | 'Country' => 'PartialMatchFilter', |
||
| 118 | 'Obsolete', |
||
| 119 | ); |
||
| 120 | |||
| 121 | /** |
||
| 122 | * standard SS variable. |
||
| 123 | * |
||
| 124 | * @return array |
||
| 125 | */ |
||
| 126 | private static $summary_fields = array( |
||
|
0 ignored issues
–
show
|
|||
| 127 | 'Order.Title', |
||
| 128 | 'FirstName', |
||
| 129 | 'Surname', |
||
| 130 | 'City', |
||
| 131 | 'PostalCode', |
||
| 132 | 'Country', |
||
| 133 | 'Phone' |
||
| 134 | ); |
||
| 135 | |||
| 136 | /** |
||
| 137 | * standard SS variable. |
||
| 138 | * |
||
| 139 | * @return array |
||
| 140 | */ |
||
| 141 | private static $field_labels = array( |
||
|
0 ignored issues
–
show
|
|||
| 142 | 'Order.Title' => 'Order', |
||
| 143 | 'Obsolete' => 'Do not use for future transactions', |
||
| 144 | 'Email' => 'Email' |
||
| 145 | ); |
||
| 146 | |||
| 147 | /** |
||
| 148 | * standard SS variable. |
||
| 149 | * |
||
| 150 | * @return string |
||
| 151 | */ |
||
| 152 | private static $singular_name = 'Billing Address'; |
||
|
0 ignored issues
–
show
|
|||
| 153 | public function i18n_singular_name() |
||
| 154 | { |
||
| 155 | return _t('BillingAddress.BILLINGADDRESS', 'Billing Address'); |
||
| 156 | } |
||
| 157 | |||
| 158 | /** |
||
| 159 | * standard SS variable. |
||
| 160 | * |
||
| 161 | * @return string |
||
| 162 | */ |
||
| 163 | private static $plural_name = 'Billing Addresses'; |
||
|
0 ignored issues
–
show
|
|||
| 164 | public function i18n_plural_name() |
||
| 165 | { |
||
| 166 | return _t('BillingAddress.BILLINGADDRESSES', 'Billing Addresses'); |
||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Standard SS variable. |
||
| 171 | * |
||
| 172 | * @var string |
||
| 173 | */ |
||
| 174 | private static $description = 'The details of the person buying the order.'; |
||
| 175 | |||
| 176 | /** |
||
| 177 | * method for casted variable. |
||
| 178 | * |
||
| 179 | *@return string |
||
| 180 | **/ |
||
| 181 | public function FullCountryName() |
||
| 182 | { |
||
| 183 | return $this->getFullCountryName(); |
||
| 184 | } |
||
| 185 | public function getFullCountryName() |
||
| 186 | { |
||
| 187 | return EcommerceCountry::find_title($this->Country); |
||
|
0 ignored issues
–
show
The property
Country does not exist on object<BillingAddress>. Since you implemented __get, maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. Loading history...
|
|||
| 188 | } |
||
| 189 | |||
| 190 | /** |
||
| 191 | *@return FieldList |
||
| 192 | **/ |
||
| 193 | public function getCMSFields() |
||
| 194 | { |
||
| 195 | $fields = parent::getCMSFields(); |
||
| 196 | $fields->replaceField('OrderID', new ReadonlyField('OrderID', _t('BillingAddress.ORDERID', 'Order #'))); |
||
| 197 | $fields->replaceField('Email', new EmailField('Email', _t('BillingAddress.EMAIL', 'Email'))); |
||
| 198 | //We remove both the RegionCode and RegionID field and then add only the one we need directly after the country field. |
||
| 199 | $fields->removeByName('RegionCode'); |
||
| 200 | $fields->removeByName('RegionID'); |
||
| 201 | $fields->insertBefore($this->getRegionField('RegionID'), 'Country'); |
||
|
0 ignored issues
–
show
'Country' is of type string, but the function expects a object<FormField>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 202 | $fields->replaceField('Country', $this->getCountryField('Country')); |
||
| 203 | |||
| 204 | return $fields; |
||
| 205 | } |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @param Member $member |
||
|
0 ignored issues
–
show
Should the type for parameter
$member not be null|Member?
This check looks for It makes a suggestion as to what type it considers more descriptive. Most often this is a case of a parameter that can be null in addition to its declared types. Loading history...
|
|||
| 209 | * |
||
| 210 | * @return FieldList |
||
| 211 | **/ |
||
| 212 | public function getFields(Member $member = null) |
||
| 213 | { |
||
| 214 | $fields = parent::getEcommerceFields(); |
||
|
0 ignored issues
–
show
It seems like you call parent on a different method (
getEcommerceFields() instead of getFields()). Are you sure this is correct? If so, you might want to change this to $this->getEcommerceFields().
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The Loading history...
|
|||
| 215 | $headerTitle = _t('BillingAddress.DELIVERY_AND_BILLING_ADDRESS', 'Delivery and Billing Address'); |
||
| 216 | $fields->push( |
||
| 217 | HeaderField::create( |
||
| 218 | 'BillingDetails', |
||
| 219 | $headerTitle, |
||
| 220 | 3 |
||
| 221 | ) |
||
| 222 | ->setAttribute('data-title-with-shipping-address', _t('BillingAddress.BILLING_ADDRESS_ONLY', 'Billing Address Only')) |
||
| 223 | ->setAttribute('data-title-with-shipping-address_default', $headerTitle) |
||
| 224 | ); |
||
| 225 | $fields->push(new TextField('Phone', _t('BillingAddress.PHONE', 'Phone'))); |
||
| 226 | $billingFields = new CompositeField(); |
||
| 227 | $hasPreviousAddresses = false; |
||
|
0 ignored issues
–
show
$hasPreviousAddresses is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 228 | if ($member && Member::currentUser()) { |
||
| 229 | if ($member->exists() && !$member->IsShopAdmin()) { |
||
| 230 | $this->FillWithLastAddressFromMember($member, true); |
||
| 231 | if (EcommerceConfig::get('BillingAddress', 'allow_selection_of_previous_addresses_in_checkout')) { |
||
| 232 | $addresses = $member->previousOrderAddresses($this->baseClassLinkingToOrder(), $this->ID, $onlyLastRecord = false, $keepDoubles = false); |
||
| 233 | //we want MORE than one here not just one. |
||
| 234 | if ($addresses->count() > 1) { |
||
| 235 | $fields->push( |
||
| 236 | SelectOrderAddressField::create( |
||
| 237 | 'SelectBillingAddressField', |
||
| 238 | _t('BillingAddress.SELECTBILLINGADDRESS', 'Select Billing Address'), |
||
| 239 | $addresses |
||
| 240 | ) |
||
| 241 | ); |
||
| 242 | $hasPreviousAddresses = true; |
||
|
0 ignored issues
–
show
$hasPreviousAddresses is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 243 | } |
||
| 244 | } |
||
| 245 | } |
||
| 246 | } |
||
| 247 | |||
| 248 | $mappingArray = $this->Config()->get('fields_to_google_geocode_conversion'); |
||
| 249 | if (is_array($mappingArray) && count($mappingArray)) { |
||
| 250 | if (!class_exists('GoogleAddressField')) { |
||
| 251 | user_error('You must install the Sunny Side Up google_address_field module OR remove entries from: BillingAddress.fields_to_google_geocode_conversion'); |
||
| 252 | } |
||
| 253 | $billingFields->push( |
||
| 254 | $billingEcommerceGeocodingField = GoogleAddressField::create( |
||
| 255 | 'BillingEcommerceGeocodingField', |
||
| 256 | _t('BillingAddress.FIND_ADDRESS', 'Find address'), |
||
| 257 | Session::get('BillingEcommerceGeocodingFieldValue') |
||
| 258 | ) |
||
| 259 | ); |
||
| 260 | $billingEcommerceGeocodingField->setFieldMap($mappingArray); |
||
| 261 | //$billingFields->push(new HiddenField('Address2', "NOT SET", "NOT SET")); |
||
| 262 | //$billingFields->push(new HiddenField('City', "NOT SET", "NOT SET")); |
||
| 263 | } |
||
| 264 | $billingFields->push(new TextField('Address', _t('BillingAddress.ADDRESS', 'Address'))); |
||
| 265 | $billingFields->push(new TextField('Address2', _t('BillingAddress.ADDRESS2', ''))); |
||
| 266 | $billingFields->push(new TextField('City', _t('BillingAddress.CITY', 'Town'))); |
||
| 267 | $billingFields->push($this->getPostalCodeField('PostalCode')); |
||
| 268 | $billingFields->push($this->getRegionField('RegionID', 'RegionCode')); |
||
| 269 | $billingFields->push($this->getCountryField('Country')); |
||
| 270 | $billingFields->addExtraClass('billingFields'); |
||
| 271 | $billingFields->addExtraClass('orderAddressHolder'); |
||
| 272 | $this->makeSelectedFieldsReadOnly($billingFields); |
||
| 273 | $fields->push($billingFields); |
||
| 274 | $this->extend('augmentEcommerceBillingAddressFields', $fields); |
||
| 275 | |||
| 276 | return $fields; |
||
| 277 | } |
||
| 278 | |||
| 279 | /** |
||
| 280 | * Return which billing address fields should be required on {@link OrderFormAddress}. |
||
| 281 | * |
||
| 282 | * @return array |
||
| 283 | */ |
||
| 284 | public function getRequiredFields() |
||
| 285 | { |
||
| 286 | return $this->Config()->get('required_fields'); |
||
| 287 | } |
||
| 288 | |||
| 289 | /* |
||
| 290 | * standard SS method |
||
| 291 | * sets the country to the best known country {@link EcommerceCountry} |
||
| 292 | **/ |
||
| 293 | //function populateDefaults() { |
||
| 294 | //parent::populateDefaults(); |
||
| 295 | //$this->Country = EcommerceCountry::get_country(false, $this->OrderID); |
||
| 296 | //} |
||
| 297 | } |
||
| 298 |