OpenCart 🇺🇦

Метод Amazonus::parseCategoryTemplate(...)

Схема

public mixed parseCategoryTemplate ( $xml )

Аргументы

Аргумент Возможный тип Описание
$xml

Описание

Метод пока еще не документирован.

Исходный код

$simplexml = null;

libxml_use_internal_errors(true);
if(($simplexml = simplexml_load_string($xml)) == false) {
	return false;
}

$category = (string)$simplexml->filename;

$tabs = array();
foreach($simplexml->tabs->tab as $tab) {
	$attributes = $tab->attributes();
	$tabs[] = array(
		'id' => (string)$attributes['id'],
		'name' => (string)$tab->name,
	);
}

$fields = array();
$fieldTypes = array('required', 'desired', 'optional');
foreach ($fieldTypes as $type) {
	foreach ($simplexml->fields->$type->field as $field) {
		$attributes = $field->attributes();
		$fields[] = array(
			'name' => (string)$attributes['name'],
			'title' => (string)$field->title,
			'definition' => (string)$field->definition,
			'accepted' => (array)$field->accepted,
			'type' => (string)$type,
			'child' => false,
			'order' => isset($attributes['order']) ? (string)$attributes['order'] : '',
			'tab' => (string)$attributes['tab'],
		);
	}
	foreach ($simplexml->fields->$type->childfield as $field) {
		$attributes = $field->attributes();
		$fields[] = array(
			'name' => (string)$attributes['name'],
			'title' => (string)$field->title,
			'definition' => (string)$field->definition,
			'accepted' => (array)$field->accepted,
			'type' => (string)$type,
			'child' => true,
			'parent' => (array)$field->parent,
			'order' => isset($attributes['order']) ? (string)$attributes['order'] : '',
			'tab' => (string)$attributes['tab'],
		);
	}
}

foreach($fields as $index => $field) {
	$fields[$index]['unordered_index'] = $index;
}

usort($fields, array('Amazonus','compareFields'));

return array(
	'category' => $category,
	'fields' => $fields,
	'tabs' => $tabs,
);