we are using SAOP clients for a while now without a problem. But now we are facing the following challenge and I can't find the answer. We need to send the following XML structure:
<Cards>
<CardDetails>
<Name>string</Name>
<Address>string</String>
</CardDetails>
<CardDetails>
<Name>string</Name>
<Address>string</String>
</CardDetails>
</Cards>
As you van see we need two instances of 'CardDetails'. Creating a PHP array will only allow me to send 1.
$data = array(
'Cards' => array(
'CardDetails' => array(
'Name' => 'test name',
'Address' => 'test address'
),
'CardDetails' => array(
'Name' => 'second test name',
'Address' => 'second test address'
)
)
));
Of course, only the second address will be used. But what would be the solution to make this work?
Thanks a lot!
Use php dom to create xml from an array , here is a good example of it http://www.ibm.com/developerworks/library/os-xmldomphp/
And what function/class are you using to turn array to xml?
Try this structure:
$data = array(
'Cards' => array(
'CardDetails' => array(
array(
'Name' => 'test name',
'Address' => 'test address'
),
array(
'Name' => 'second test name',
'Address' => 'second test address'
)
)
)
);
If this doesn't work and you can modify serializing function, just check if current key is numerical. If it is, use parent key name for tag.
Related
I'm so beginner in Prestashop 1.7, I wanted to add a dropdown select section in my banner module to select the way to open the banner link.
but the selected value is never passed to the HTML, the code below IS passed but the one under isn't, can you please assist me?
[enter image description here][1]
array(
'type' => 'text',
'lang' => true,
'label' => $this->trans('Banner description', array(), 'Modules.Banner.Admin'),
'name' => 'BANNER_DESC',
'desc' => $this->trans('Please enter a short but meaningful description for the banner.', array(), 'Modules.Banner.Admin')
)
array(
'type' => 'select', //select
'lang' => true,
'label' => $this->trans('Banner tab', array(), 'Modules.Banner.Admin'),
'name' => 'BANNER_TAB',
'required'=>'true',
'options' => array(
'query' => array(
array('key' => '_blank', 'name' => 'New tab'),
array('key' => '_self', 'name' => 'Same tab'),
),
'id' => 'key',
'name' => 'name'
),
'desc' => $this->trans('Please select the way to open the link.', array(), 'Modules.Banner.Admin')
)
This is how it looks in the Backoffice:
Here
You not only need to add a new field to your form but also handle saving the data from it.
Take a look at a few examples:
https://github.com/PrestaShop/ps_featuredproducts/blob/dev/ps_featuredproducts.php#L122
Notice how the module author managed to save each configuration field from the form. This is what you need to do.
If you want to have access to data in your view, you have to pass it:
https://github.com/PrestaShop/ps_featuredproducts/blob/dev/ps_featuredproducts.php#L244
Maybe after you added a new field, you forgot to handle the saving + passing to the view?
I go through this documentation "https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/journalentry"
And tried to add journal entry with line having customer as shown in the below code:
$journal_entry_create['TxnDate'] = date('Y-m-d');
$journal_entry_line = array(
'Amount' => $amount,
'DetailType' => 'JournalEntryLineDetail',
'JournalEntryLineDetail' => array(
'PostingType' => Credit,
'Entity' => array(
'Type' => 'Customer',
'EntityRef' => array(
'type' => 'Customer',
'value' => "2",
'name' => 'Abc'
)
),
'AccountRef' => array(
'name' => 'Account Name',
'value' => '1'
),
)
);
$journal_entry_lines[] = $journal_entry_line;
$journal_entry_create['Line'] = $journal_entry_lines;
$journal_entry_receipt_create = QBJournalEntry::create($journal_entry_create);
$journal_entry_receipt_create_result = $dataService->Add($journal_entry_receipt_create);
Without EntityRef its working fine but when I add EntityRef its giving me error "Message: Passed array has no key for 'Value' when contructing an ReferenceType"
Only just came across this problem myself. They did fix this issue but didn't seem to document it at all or tell anyone. Found the fix in the source code. You need to use "JournalEntryEntity" instead of "Entity" under "JournalEntryLineDetail", like so:
'JournalEntryLineDetail' => array(
'PostingType' => "Credit",
'JournalEntryEntity' => array(
'Type' => 'Customer',
'EntityRef' => array(
'value' => "2"
)
),
'AccountRef' => array(
'name' => 'Account Name',
'value' => '1'
),
)
Also I used the FacadeHelper from the V3 of the PHP SDK (I'm not sure if it'll work with the method you were using):
use QuickBooksOnline\API\Facades\FacadeHelper;
...
$journal_entry_receipt_create = FacadeHelper::reflectArrayToObject('JournalEntry', $journal_entry_create);
$journal_entry_receipt_create_result = $dataService->Add($journal_entry_receipt_create);
I know this is probably too late for you OP but hopefully it helps someone else!
I need to send emails to multiple recipients. The number of recipients will vary depending on the data in the db.
Mandrill allows me to only add multiple recipients using an array.
Below is what works for multiple recipients
//email array that needs to be added to the 'to' key
$emailArray = ["example#example.com","test#test.com","hello#test.com","world#test.com"];
$mandrill = new Mandrill('xxxxxxxxxxxxxxx');
$message = array(
'subject' => 'Thanks for signing up',
'from_email' => 'support#test.com',
'to' => array(
array(
'email' => 'hello#test.com',
'name' => 'Hello Test'
),
array(
'email' => 'goodbye#test.com',
'name' => 'Goodbye Test',
)
),
'global_merge_vars' => array(
array(
'name' => 'FIRSTNAME',
'content' => 'JOHN'
),
array(
'name' => 'LASTNAME',
'content' => 'DOE')
));
//print_r($message);
$template_name = 'hello-world';
print_r($mandrill->messages->sendTemplate($template_name, $template_content, $message));
Below is what i need to generate dynamically depending on the length of the emailArray
to' => array(
//the below array should be dynamically generated
array(
'email' => 'hello#test.com',
'name' => 'Hello Test'
),
array(
'email' => 'goodbye#test.com',
'name' => 'Goodbye Test',
)
)
Here is the array. Currently with fixed values.
//email array that needs to be added to the 'to' key
$emailArray = ["example#example.com","test#test.com","hello#test.com","world#test.com"];
My questions is How do generate the 'To' values based on the length of the email array?
is there a way i can implode the entire array script?
An effective way would be to use array_map I have added in some code that also takes an array of names as well (I couldn't see where you were getting the names from in your code).
$toAddresses = array('example#example.com','test#test.com','hello#test.com','world#test.com');
$names = array('Exmaple', 'Test', 'Hello', 'World');
$mandrillTo = array_map( function ($address, $name) {
return array(
'email' => $address,
'name' => $name
);
},
$toAddresses,
$names
);
This passes the 0th element from each array into the function and returns an array of two values, then passes the 1st, 2nd etc and returns each result in a new array ($mandrillTo)
I want to store information like below with a key like key = activity window then other info under it, then another key etc..
key: 'activity window'
name: 'Recent Activity'
iconCls: 'activity'
module: 'activity-win'
any idea how to put this into a multi dimensional array?
$data = array(
'activity window' => array(
'name' => 'Recent Activity',
'iconCls' => 'activity',
'module' => 'activity-win'
)
);
Is this what you're looking for, or have I completely misunderstood your question?
Like this:
$myArray = array(
'activity window' => array(
'name' => 'Recent Activity',
'iconCls' => 'activity',
'module' => 'activity-win',
),
array(
...
),
);
You can also add on to the array:
$myArray['new key'] = array(
'name' => 'New Name',
'module' => 'New Module',
);
I've created a custom node type in Drupal 7, using the hook_node_info method in the install file:
// declare the new node type
function foo_node_info ( ) {
return array(
'foo' => array(
'name' => t('Foo entry'),
'base' => 'node_content',
'description' => t('For use to store foo entries.'),
));
} // END function foo_node_info
and I'm trying to save that type in the module file using the following code:
// INSERT the stuff
node_save(node_submit((object)array(
'type' => 'foo',
'is_new' => true,
'uid' => 1,
'title' => 'Title, blah blah blah',
'url' => 'url here, just pretend',
'body' => '<p>test</p>',
)));
My issue, is that the url, and body fields aren't saving. Any idea what I'm doing wrong?
So, after a ton of digging, it turns out that the way I was entering the custom fields in the node_save was wrong. The node_save needs to look like the following:
node_save(node_submit((object)array(
'type' => 'foo',
'is_new' => true,
'uid' => 1,
'title' => 'the title',
'url' => array(
'und' => array(array(
'summary' => '',
'value' => 'url value',
'format' => 2,
))),
'body' => array(
'und' => array(array(
'summary' => '',
'value' => 'the body goes here',
'format' => 2,
))),
)));
Notice that for the custom fields, the array structure has to match what was previously going on with CCK (pretty much exactly). The first key in the array describing the field value is the language for the content.
I've used 'und' here only because that's what I saw going into the database when entering the data through a form.