public function alterSchema(Schema $schema)
 {
     $customizedType = Inflector::singularize($schema->name());
     $customFields = $this->find()->cache('custom_fields_' . $this->connection()->configName());
     /** @var \Muffin\Webservice\Model\Resource[] $customFields */
     foreach ($customFields as $customField) {
         if ($customField->customized_type !== $customizedType) {
             continue;
         }
         $columnKeys = ['type' => $customField->field_format, 'default' => $customField->default_value, 'custom_field_id' => $customField->id, 'custom_field_filterable' => $customField->is_filter];
         $schema->addColumn(Schema::nameToField($customField->name), $columnKeys);
     }
     return $schema;
 }
 public function testNameToField()
 {
     $this->assertEquals('quote_send', $this->schema->nameToField('Quote send'));
     $this->assertEquals('invoice_send', $this->schema->nameToField('Invoice send'));
     $this->assertEquals('invoice', $this->schema->nameToField('Invoice'));
 }
 protected function _transformResource(array $result, Endpoint $endpoint)
 {
     $properties = [];
     foreach ($result as $field => $value) {
         if ($field === 'custom_fields') {
             // Loop over custom fields
             foreach ($value as $customField) {
                 // Get the alias for the custom field
                 $customFieldField = Schema::nameToField($customField['name']);
                 // Lookup the field in the schema
                 $column = $endpoint->schema()->column($customFieldField);
                 // If no value has been given set it to null
                 if (!isset($customField['value'])) {
                     $properties[$customFieldField] = null;
                     continue;
                 }
                 // Cast value to correct type and set it as property
                 $properties[$customFieldField] = $this->castValue($customField['value'], $column['type']);
             }
             continue;
         }
         $column = $endpoint->schema()->column($field);
         if (!$column) {
             $properties[$field] = $value;
             continue;
         }
         $properties[$field] = $this->castValue($value, $column['type']);
     }
     return $this->_createResource($endpoint->resourceClass(), $properties);
 }