1

I want to update programatically a plugin's setting:

public function init()
{   
     craft()->on('commerce_orders.onBeforeOrderComplete', function($event){
        // Set InvoiceNumber
        $newInvoiceNumber = $this->getSettings()->currentInvoiceNumber + 1;
        $myPlugin = craft()->plugins->getPlugin( 'Ultraschall' );
        craft()->plugins->savePluginSettings( $myPlugin, 
                                              array('currentInvoiceNumber', $newInvoiceNumber ));
    });
}

But I get this error:

PHP warning
array_key_exists() expects parameter 2 to be array, null given
/mnt/web209/c2/98/5363898/htdocs/dev.ultraschall-leinwand.de/craft/app/models/BaseModel.php(418)

417  // Is this the first time this extra attribute has been set?
418  else if (!array_key_exists($name, $this->_extraAttributeNames))
419  {
420     $this->_extraAttributeNames[] = $name;
421  }
422 
423  $this->_attributes[$name] = $value;
424  return true;

I have added defineSettings() and getSettingsHtml() to the Plugin and can change values via CP without problems.

Why do I get this error?

  • Can you post a bit more of the stack trace leading up to that error? Have you ever used xDebug? Great for figuring out stuff like this. – Brad Bell Aug 3 '17 at 6:17
2

I made a simple mistake by defining the array with the setting value. I wrote array('currentInvoiceNumber', $newInvoiceNumber) instead of array('currentInvoiceNumber' => $newInvoiceNumber).

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.