Jump to content

Make module settings in foreach cycle?


Recommended Posts

Hello everyone :)

 

I'm trying to make a module with some settings for every order status. I'm stuck with that settings. Here is the code with comments:

1. Get state name and id. Works well, as I assume

	public function getOrderStatusName()
	{
		$all_states = OrderState::getOrderStates($this->context->language->id);
		foreach ($all_states as $state)
		{
			$statuses[] = array(
				'id' => $state['id_order_state'],
				'state_name' => $state['name']
			);
		}
		return $statuses;
	}

2. Writing values to DB, works too

$statuses = $this->getOrderStatusName();
foreach ($statuses as $status)
{
	Configuration::updateValue('STATUS_'.$status['id'], 1);
}

3. Assign values and settings to Smarty. Maybe my mistake is here?

	public function hookDashboardZoneTwo($params)
	{
		$this->context->smarty->assign(
			array(
				'DASHPRODUCT_NBR_SHOW_LAST_ORDER' => Configuration::get('DASHPRODUCT_NBR_SHOW_LAST_ORDER'),
				'date_from' => Tools::displayDate($params['date_from']),
				'date_to' => Tools::displayDate($params['date_to']),
				'exportorders_config_form' => $this->renderConfigForm(),
			)
		);
		$statuses = $this->getOrderStatusName();
		foreach ($statuses as $status)
		{
			$this->context->smarty->assign(
				array(
					'STATUS_'.$status['id'] => Configuration::get('STATUS_'.$status['id'])
				)
			);
		}
		return $this->display(__FILE__, 'exportorders.tpl');
	}

4. Displaying settings switches in modules BackOffice. And here I have troubles. Switches are displayed, but smarty throws error: "undefined index "name""

$statuses = $this->getOrderStatusName();
$status_options = array(
	array( 'id' => 'status_on', 'value' => 1, 'label' => $this->l('Yes')),
	array( 'id' => 'status_off', 'value' => 0, 'label' => $this->l('No')),
	);
foreach ($statuses as $status)
{
	$fields_form['form']['input'][] = array(
		'id' => $status['id'],
		'type' => 'switch',
		'label' => $status['state_name'],
		'name' => 'STATUS_'.$status['id'],
		'is_bool' => true,
		'values' => $status_options,
	);
}

5. And finally loading settings from DB

$statuses = $this->getOrderStatusName();
foreach ($statuses as $status)
{
	$config1 = array('STATUS_'.$status['id'] => Configuration::get('STATUS_'.$status['id']));
	array_merge($config, $config1);
}

Where am I mistaking?

As for me it should work, but it doesn't  :(  :(  :(

I attach the module itself if you can help meexportorders.zip

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...