trouble with update_option() in WordPress import settings function - wordpress

I am having a bit of trouble with an import/export option I'm building into my theme. Hopefully I explain this well, let me start with the function.
function ifeature_import_options() {
$options = get_option('ifeature');
$import = $options['if_import_code'];
if ($import != '');
$options_array = (unserialize($import));
foreach( $options_array as $option_name => $option_value ) {
update_option( $option_name, $option_value );
}
}
if_import_code returns the serialized output of $options (which the user enters into a textarea in my options panel), and I've tested that $options_array is properly unserializing the import code as it prints the following:
Array ( [if_menu_color] => Pink [if_font] => Arial [if_css_options] =>
[if_favicon] => [if_ga_code] => [if_import_code] => [if_export_code]
=> b:0; [if_logo] => [if_menuicon] => [if_header_contact] =>
[if_facebook] => [if_twitter] => [if_linkedin] => [if_youtube] =>
[if_googlemaps] => [if_email] => [if_rsslink] => [if_home_description]
=> [if_home_keywords] => [if_home_title] => [if_callout_title] =>
[if_callout_text] => [if_callout_img] => [if_callout_image_link] =>
[if_slider_type] => posts [if_slider_placement] => feature
[if_slider_category] => [if_slider_posts_number] => [if_slider_height]
=> [if_slider_delay] => [if_slider_animation] => random
[if_footer_text] => [if_hide_callout] => 0 [if_show_fb_like] => 0
[if_hide_slider] => 0 [if_hide_boxes] => 0 [if_hide_link] => 0
[if_slider_navigation] => 0 )
So I have the new array that needs to be written to my options, but the update_options code I've used isn't working. What am I missing?

$options_array = unserialize($importOptions);
foreach ($options_array as $option_name=>$value) {
if ($value != '') update_option( $key, $value );
}

Related

DoCapture API returns ACK => Success but PAYMENTSTATUS => Pending and PENDINGREASON is paymentreview

I am authorizing payment through a wordpress website[woocommerce - 2.4.12]. After that I am using "DoCapture Api" for Capture Authorized payment to automate the system.
https://developer.paypal.com/docs/classic/api/merchant/DoCapture_API_Operation_NVP/
I am using below code in wordpress/woocommerce[2.4.12]
function get_capture_request( $order, $amount = null ) {
$request = array(
'VERSION' => '84.0',
'SIGNATURE' => 'SIGNATURE',
'USER' => 'USER',
'PWD' => 'PWD',
'METHOD' => 'DoCapture',
'AUTHORIZATIONID' => get_post_meta($order->id, '_transaction_id', true ),
'AMT' => number_format( is_null( $amount ) ? $order->get_total() : $amount, 2, '.', '' ),
'CURRENCYCODE' => 'CAD',
'COMPLETETYPE' => 'Complete',
);
return apply_filters( 'woocommerce_paypal_capture_request', $request, $order, $amount );
}
$sandbox = 'https://api-3t.sandbox.paypal.com/nvp';
$raw_response = wp_safe_remote_post($sandbox,
array(
'method' => 'POST',
'body' => get_capture_request( $order, $amount ),
'timeout' => 70,
'user-agent' => 'WooCommerce/' . WC()->version,
'httpversion' => '1.1',
)
);
In response I am getting below response.
stdClass Object
(
[AUTHORIZATIONID] => AUTHORIZATIONID
[TIMESTAMP] => 2019-09-15T08:52:50Z
[CORRELATIONID] => CORRELATIONID
[ACK] => Success
[VERSION] => 84.0
[BUILD] => 53497452
[TRANSACTIONID] => TRANSACTIONID
[PARENTTRANSACTIONID] => PARENTTRANSACTIONID
[PAYMENTTYPE] => instant
[ORDERTIME] => 2019-09-15T08:52:48Z
[AMT] => 6.24
[FEEAMT] => 0.48
[CURRENCYCODE] => CAD
[PAYMENTSTATUS] => Pending
[PENDINGREASON] => paymentreview
[REASONCODE] => None
[SHIPPINGMETHOD] => Default
[PROTECTIONELIGIBILITY] => Ineligible
[PROTECTIONELIGIBILITYTYPE] => None
)
but I don't know why I am getting PAYMENTSTATUS Pending and also in pending reason there is no "paymentreview" option[ https://developer.paypal.com/docs/classic/api/merchant/DoCapture-API-Operation-NVP/ ].
Can any one guide me what is the problem here?
Thank in advance.

MoneyField isChanged always returning true

I have a DataObject Confirmation that looks like this:
<?php
class Confirmation extends DataObject
{
private static $db = array(
'Reimbursement' => 'Money',
'SomeText' => 'Varchar(255)'
);
private static $has_one = array(
'Page' => 'Page'
);
public function getCMSFields()
{
$fields = parent::getCMSFields();
$reimbursementField = MoneyField::create('Reimbursement');
$someTextField = TextField::create('SomeText');
$reimbursementField->setAllowedCurrencies(array('SEK'));
$fields->addFieldsToTab(
'Root.Main',
array(
$reimbursementField,
$someTextField
)
);
return $fields;
}
public function onBeforeWrite()
{
parent::onBeforeWrite();
if($this->isChanged('Reimbursement')) SS_Log::log( print_r ( 'changed', true ), SS_Log::WARN );
}
}
if($this->isChanged('Reimbursement')) in the onBeforeWrite() function will always evaluate to true. Regardless of what is being changed. Even when saving without making any changes - it will fire the log function.
Edit: Checking the stacktrace with SS_Backtrace::backtrace() in Money.php's setValue() function I find that every time I save the Confirmation DataObject, setValue() is called without passing the $markChanged parameter set to false, from DataObject.php line 1281, resulting in the $isChanged flag being set to true, and the field always behaving as if it has changed.
When logging DataObject's getChangedFields() function I get the output below (when saving without making any changes). Notice the Reimbursement field being present, and before being empty. What am I missing here?
[22-Mar-2016 16:28:07] Warning at framework/model/DataObject.php line 2597: Array
(
[Reimbursement] => Array
(
[before] =>
[after] => Money Object
(
[currency:protected] => SEK
[amount:protected] => 25000
[isChanged:protected] => 1
[locale:protected] =>
[currencyLib:protected] => Zend_Currency Object
(
[_options:protected] => Array
(
[position] => 8
[script] =>
[format] =>
[display] => 2
[precision] => 2
[name] => svensk krona
[currency] => SEK
[symbol] => kr
[locale] => sv_SE
[value] => 0
[service] =>
[tag] => Zend_Locale
)
)
[allowedCurrencies:protected] =>
[value:protected] =>
[tableName:protected] =>
[name:protected] => Reimbursement
[arrayValue:protected] =>
[defaultVal:protected] =>
[failover:protected] =>
[customisedObject:protected] =>
[objCache:ViewableData:private] => Array
(
)
[class] => Money
[extension_instances:protected] => Array
(
)
[beforeExtendCallbacks:protected] => Array
(
)
[afterExtendCallbacks:protected] => Array
(
)
)
[level] => 2
)
)

How to redirect after view rendering is complete in cakephp 2.3

I am using cakephp 2.3 and required to redirect user after the excel sheet is downloaded successfully. I am using the cake $this->response->type for setting the view as excel sheet generator.
public function admin_export_excel($task_lists = array()) {
$task_ids = $task_lists;
$global_task_array = array();
$this->loadModel('Task');
//-> For each task-id run the loop for fetching the related data to generate the report.
foreach ($task_ids as $index => $task_id) {
//-> Check if the task exists with the specified id.
$this->Task->id = $task_id;
if (!$this->Task->exists())
throw new NotFoundException('Task not found.');
//-> Now check if the logged user is the owner of the specified task.
$task_count = $this->Task->find('count', array('conditions' => array('Task.id' => $task_id,
'Task.user_id' => $this->Auth->user('id'))));
if ($task_count == 0)
throw new NotFoundException('Task not accessable.');
$task_data = $this->Task->find('first', array(
'conditions' => array(
'Task.id' => $task_id
),
'contain' => array(
'TaskForm' => array(
'fields' => array('TaskForm.id', 'TaskForm.reference_table')
),
'Project' => array(
'fields' => array('Project.id', 'Project.project_name')
),
'User' => array(
'fields' => array('User.id', 'User.company_name')
),
'Timezone' => array(
'fields' => array('Timezone.id', 'Timezone.name')
)
)
)
);
// debug($task_data);
$global_task_array[$index] = $task_data;
//-> End of Custom else conditions
unset($task_data);
}
$this->set('global_task_array', $global_task_array);
$this->response->type(array('xls' => 'application/vnd.ms-excel'));
$this->response->type('xls');
$this->render('admin_export_excel');
}
and my view file is
$this->PhpExcel->createWorksheet();
$this->PhpExcel->setDefaultFont('Calibri', 13);
$default = array(
array('label' => __('Task Id'), 'width' => 'auto'),
array('label' => __('Unique Code'), 'width' => 'auto'),
array('label' => __('Site Name'), 'width' => 'auto'),
array('label' => __('Area'), 'width' => 'auto'),
array('label' => __('Location'), 'width' => 'auto'),
array('label' => __('Sub Location'), 'width' => 'auto'),
array('label' => __('About Task'), 'width' => 'auto')
);
$this->PhpExcel->addTableHeader($default, array('name' => 'Cambria', 'bold' => true));
$this->PhpExcel->setDefaultFont('Calibri', 12);
foreach ($global_task_array as $index => $raw) {
$data = array(
$raw['Task']['id'],
$raw['Task']['unique_code'],
$raw['Task']['site_name'],
$raw['Task']['area'],
$raw['Task']['location'],
$raw['Task']['sub_location'],
$raw['Task']['about_task']
);
$this->PhpExcel->addTableRow($data);
}
$this->PhpExcel->addTableFooter();
$this->PhpExcel->output('Task-' . date('d-m-Y') . '.xlsx');
I have tried to use the cake afterFilter method for to redirect the user to other action after the excel sheet is generated but its not working.
public function afterFilter(){
parent::afterFilter();
if($this->request->params['action'] == 'admin_export_excel'){
$this->redirect(array('controller' => 'tasks', 'action' => 'index','admin' => true));
}
}
Any help will be appreciated. Thanks

Drupal first module -- 500 Internal Server Error

This is my first module. I have been trying to successfully install my module since a week now.
I have gone through every line. Even the schema is being installed and entry is made at system table. But still after enabling the module It shows 500 Internal Server Error until I delete the entry from system table.
Please guide me what I am doing wrong.
Note: sisattribute table is already created in drupal database
My .install file
<?php
/**
* #file
*/
function sisinstitute_install() {
drupal_install_schema('sisinstitute');
variable_set('node_options_sisinstitute', array('status'));
$attributes = array();
$attributes['Country'] = array(
'US' => 'United States of America',
'AD' => 'Andorra',
'AE' => 'United Arab Emirates',
'AF' => 'Afghanistan',
);
$s = "INSERT INTO {sisattribute} (domain, akey, avalue, weight) VALUES ('%s', '%s', '%s', %d)";
$prevdomain = '';
$weight = 0;
foreach ($attributes as $domain => $attribute) {
if ($domain != $prevdomain) $weight=0;
foreach ($attribute as $key => $value) {
db_query($s, $domain, $key, $value, $weight);
$weight++;
}
$prevdomain = $domain;
}
}
function sisinstitute_disable() {
drupal_set_message(t('Please note that they will now have reduced functionality, and will not be protected by previous access controls.'), 'warning');
}
function sisinstitute_uninstall() {
drupal_uninstall_schema('sisinstitute');
db_query($s = "DELETE FROM {sisattribute} WHERE domain IN ('Country')");
}
function sisinstitute_schema() {
$schema['sisinstitute'] = array(
'fields' => array(
'vid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
'nid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
'country' => array('type' => 'varchar', 'length' => 100),
'www' => array('type' => 'varchar', 'length' => 100),
'phone' => array('type' => 'varchar', 'length' => 100),
'email' => array('type' => 'varchar', 'length' => 50),
'provstate' => array('type' => 'varchar', 'length' => 50),
'zip' => array('type' => 'varchar', 'length' => 10),
'city' => array('type' => 'varchar', 'length' => 100),
'address' => array('type' => 'varchar', 'length' => 100),
'orglanguage' => array('type' => 'varchar', 'length' => 100),
'isactive' => array('type' => 'int', 'default' => 1),
),
'primary key' => array('vid'),
'indexes' => array(
'nid' => array('nid')
),
);
return $schema;
}
And my .module file:
<?php
// $Id$
/**
*#File
*Module for Institution support in SIS package
*/
/**
*hook_help()
*/
/**
*hook_menu()
*/
/**
*hook_perm()
*/
function sisinstitute_perm() {
return array('access institute', 'create institute', 'edit institute', 'delete institute', 'view belonged institute', 'view all institutes');
}
/**
*hook_access()
*/
function sisinstitute_access($op, $node. $account=NULL) {
if (empty($account)) {
global $user;
$account = $user;
}
if (is_numeric($node)) $node = node_load($node);
if (!isset($account->sisinstitute_nid) && module_exists('sisstudent')) {
_sisstudent_load($account);
}
if (!isset($account->sisinstitute_nid) && module_exists('sisstaff')) {
_sisstaff_load($account);
}
switch($op) {
case 'create': return user_access('create institute', $account);
case 'update': return user_access('edit institute', $account);
case 'delete': return user_access('delete institute', $account);
case 'view' : {
if (user_access('view all institutes', $account))
return TRUE;
elseif (user_access('view belonged institute', $account) && $account->sisinstitute_nid == $node->nid)
return TRUE;
else return FALSE;
}
}
}
/**
*hook_node_info()
*/
function sisinstitute_node_info() {
return array(
'sisinstitute' => array(
'name' => t('Institute'),
'module' => 'sisinstitute',
'description' => t("Institute for SIS"),
'title_label' => t("Name"),
'body_label' => t("Note"),
)
);
}
/**
*hook_form()
*/
function sisinstitute_form(&$node) {
$type = node_get_types('type', $node);
//$form['#attributes']['class'] = 'sismcomponent_node_form';
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
// '#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'title') : -18,
);
$form['isactive'] = array(
'#type' => 'checkbox',
'#title' => t('Active'),
'#default_value' => $node->isactive,
);
return $form;
}
Hmm Got it:-)(after 8 hours)
function sisinstitute_access($op, $node. $account=NULL) {
has a period instead of a comma after $node

how to load database content to dropdown options (select)

i'm still working on my own drupal 7 module, and i'm having some trouble. I'm trying to load database content to dropdown option (select), i have read and write the same code from drupal example, but my database still not loading, only empty option.
what i'm asking is there anything wrong on my code or is there any faster way to load database to dropdown option other than the drupal example???
here the code i'm working on
function prod_entry_load($entry = array()) {
$select = db_select('aa_1122','aa');
$select->fields('aa');
foreach ($entry as $field => $value) {
$select->condition($field, $value);
}
return $select->execute()->fetchAll();
}
function prod(){
return drupal_get_form('prod_form');
}
function prod_form($form_state){
$form = array(
'#prefix' => '<div id="updateform">',
'#suffix' => '</div>',
);
$entries = prod_entry_load();
$keyed_entries = array();
if (empty($entries)) {
$form['no_values'] = array(
'#value' => t("No entries exist in the table dbtng_example table."),
);
return $form;
}
foreach ($entries as $entry) {
$options[$entry->no] = t("#no: #name ", array('#no' => $entry->no, '#name' => $entry->name));
$keyed_entries[$entry->no] = $entry;
}
$default_entry = !empty($form_state['values']['no']) ? $keyed_entries[$form_state['values']['no']] : $entries[0];
$form_state['entries'] = $keyed_entries;
$form['no'] = array(
'#type' => 'select',
'#title' => t('Choose'),
'#default_value' => $default_entry->no,
'#ajax' => array(
'wrapper' => 'updateform',
'callback' => 'prod_form_update_callback',
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
'#ajax' => array(
'callback' => 'ajax_alert',
),
);
return $form;
}
function prod_form_update_callback($form, $form_state) {
$entry = $form_state['entries'][$form_state['values']['no']];
foreach (array('name') as $item) {
$form[$item]['#value'] = $entry->$item;
}
return $form;
}
You've just forgotten to add the #options key to your select element, the code should read like this:
$form['no'] = array(
'#type' => 'select',
'#title' => t('Choose'),
'#default_value' => $default_entry->no,
'#options' => $options, // This is the bit that was missing
'#ajax' => array(
'wrapper' => 'updateform',
'callback' => 'prod_form_update_callback',
),
);
You could shorten your query/options code slightly using a combination of string concatenation in MySQL and the db fetchAllKeyed() method:
$query = db_select('aa_1122', 'aa')->fields('aa', array('no'));
$query->addExpression("CONCAT(no, ': ', name)", 'display');
$options = $query->execute()->fetchAllKeyed();

Resources