Skip to content

Commit

Permalink
Configuration API (#823)
Browse files Browse the repository at this point in the history
Replace the use of self::variable_name with the Configuration API so that properties can be set via config yaml
  • Loading branch information
AntonyThorpe authored May 2, 2024
1 parent d4237d8 commit f444899
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Forms/RestrictionRegionCountryDropdownField.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public function __construct($name, $title = null, $source = null, $value = "")
$source = SiteConfig::current_site_config()->getCountriesList(true);
parent::__construct($name, $title, $source, $value);
$this->setHasEmptyDefault(true);
$this->setEmptyString(self::$defaultname);
$this->setEmptyString(static::config()->get('defaultname'));
}
}
6 changes: 3 additions & 3 deletions src/Model/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,14 @@ public function getCountryField()

/**
* Get an array of data fields that must be populated for model to be valid.
* Required fields can be customised via self::$required_fields
* Required fields can be customised via private static $required_fields
*/
public function getRequiredFields()
{
$fields = self::config()->required_fields;
//hack to allow overriding arrays in ss config
if (self::$required_fields != $fields) {
foreach (self::$required_fields as $requirement) {
if (static::config()->get('required_fields') != $fields) {
foreach (static::config()->get('required_fields') as $requirement) {
if (($key = array_search($requirement, $fields)) !== false) {
unset($fields[$key]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public function getModifier($className, $forcecreate = false)
*/
public function setTotal($val)
{
$this->setField('Total', round($val, self::$rounding_precision));
$this->setField('Total', round($val, static::config()->get('rounding_precision')));
}

/**
Expand Down Expand Up @@ -807,7 +807,7 @@ public function getReference()
protected function onBeforeWrite()
{
parent::onBeforeWrite();
if (!$this->getField('Reference') && in_array($this->Status, self::$placed_status)) {
if (!$this->getField('Reference') && in_array($this->Status, static::config()->get('placed_status'))) {
$this->generateReference();
}

Expand Down
6 changes: 3 additions & 3 deletions src/Tasks/ShopMigrationTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public function up()
public function migrateOrders()
{
$start = $count = 0;
$batch = Order::get()->sort('Created', 'ASC')->limit($start, self::$batch_size);
$batch = Order::get()->sort('Created', 'ASC')->limit($start, static::config()->get('batch_size'));
while ($batch->exists()) {
foreach ($batch as $order) {
$this->migrate($order);
echo '. ';
$count++;
}
$start += self::$batch_size;
$batch = $batch->limit($start, self::$batch_size);
$start += static::config()->get('batch_size');
$batch = $batch->limit($start, static::config()->get('batch_size'));
};
echo "$count orders updated.\n<br/>";
}
Expand Down

0 comments on commit f444899

Please sign in to comment.