What are the correct parameters for Magento Product Attribute creation in Perl - perl

I've got several calls working already, but for the life of me I can't figure out how to make product_attribute.create work. I'm always getting a 102 Invalid request parameters or 623 Wrong Method Signature.
making the call like this my $res = $self->_useragent->call( call => $self->_session, #{$payload} ); (note: useragent is a XML::RPC object.
This Dumper $payload;
$VAR1 = [
'product_attribute.create',
[
'test',
{
'frontend_label' => [
{
'label' => 'Test ME',
'store_id' => 0
}
],
'scope' => 'store',
'frontend_input' => 'text'
}
]
];
I've read the API Documentation but figuring out what the call should look like in Perl is tricky.

I'm not familiar with the XML-RPC library you're using in perl, but he error you're seeing is a Magento API exception, configured in
<!--File: app/code/core/Mage/Catalog/etc/api.xml -->
<!-- ... -->
<invalid_parameters>
<code>102</code>
<message>Invalid request parameters.</message>
</invalid_parameters>
<!-- ... -->
Using the exception's name, you can find the place Magento threw it
#File: app/code/core/Mage/Catalog/Model/Product/Attribute/Api.php
//...
if (empty($data['attribute_code']) || !is_array($data['frontend_label'])) {
$this->_fault('invalid_parameters');
}
//...
So, my guess is your call is correct, you're just missing an attribute_code.

After some digging through Magento's code, I copied this from the test suite and it converted to perl, it appears to work. maybe all attributes are required.
$VAR1 = [
'product_attribute.create',
[
{
'default_value' => '1',
'is_configurable' => 0,
'used_in_product_listing' => 0,
'is_visible_on_front' => 0,
'apply_to' => [
'simple'
],
'is_comparable' => 0,
'is_used_for_promo_rules' => 0,
'is_required' => 0,
'scope' => 'store',
'is_unique' => 0,
'frontend_input' => 'text',
'is_searchable' => 0,
'attribute_code' => 'unique_code',
'is_visible_in_advanced_search' => 0,
'frontend_label' => [
{
'label' => 'some label',
'store_id' => '0'
}
]
}
]
];
Further experimentation somewhat based on Alan Storm's Answer, suggest that the following fields are required, as I was not able to successfully create a request without all of these fields at minimum being defined.
$VAR1 = [
'product_attribute.create',
[
{
'frontend_input' => 'text',
'attribute_code' => 'test1374438470',
'frontend_label' => [
{
'store_id' => 0,
'label' => 'Test ME'
}
]
}
]
];

Related

TYPO3 TCA label with UserFunc - how to get HTML formatted label?

I want to format the title showing in a list of TCA items which can contain italic text. But whatever I try, I get only unformatted text - even from RTE text fields.
My base information is "partA", "partB", "partC" and I need a title like "partA : partC - part B"
My Code so far:
<?php
return [
'ctrl' => [
'title' => 'LLL:EXT:myext/Resources/Private/Language/myext.xlf:tx_myext_domain_model_myitem',
'label' => 'partC',
'label_alt' => 'partA',
'formattedLabel_userFunc' => T395\myExt\Classes\UserFuncs\MyBEUserFuncs::class.'->getFullMyitemTitle',
'formattedLabel_userFunc_options' => [
'sys_file' => [
'partC','partA','partB'
]
],
'iconfile' => 'fileadmin/Resource/icons/svgs/myext.svg',
],
'columns' => [
'partC' => [
'label' => 'LLL:EXT:myext/Resources/Private/Language/myext.xlf:tx_myext_domain_model_myitem.partC',
'config' => [
'type' => 'text',
'enableRichtext' => true,
],
],
'partA' => [
'label' => 'LLL:EXT:myext/Resources/Private/Language/myext.xlf:tx_myext_domain_model_myitem.partA',
'config' => [
'type' => 'input',
'size' => '5',
'eval' => 'trim',
],
],
'partB' => [
'label' => 'LLL:EXT:myext/Resources/Private/Language/myext.xlf:tx_myext_domain_model_myitem.partC',
'config' => [
'type' => 'input',
'size' => '5',
'eval' => 'trim',
],
],
],
'types' => [
'0' => ['showitem' => 'partA,partB,partC'],
],
];
And the UF:
<?php
T395\myExt\Classes\UserFuncs;
class MyBEUserFuncs
{
public function getFullMyitemTitle(&$params, &$pObj)
{
echo "Hello World!";
$params['title'] = $params['row']['partA'].' : '.$params['row']['partC'].' - '.$params['row']['partB'];
}
}
Even the echo is not showing. Changing the formattedLabel_userFunc to label_userFunc results in getting a string in right order - but right without any text formats like <i> etc but showing them as text. I'm sure, I'm missing something, but I can't figure out what it is - I was also unable to find any code snippets or examples showing the right way - and the docs from TYPO3 saying only that exists formattedLabel_userFunc and it has options - but no proper example there. Hope you can help me. Thank you!
in the documentation for formattedlabel_userfunc you can find:
[...] return formatted HTML for the label and used only for the labels of inline (IRRE) records.
and for label_userfunc there is the warning:
The title is passed later on through htmlspecialchars() so it may not include any HTML formatting.

Simple Command Controller with TYPO3

I want to set up a simple CommandController but I always get a error Message in the backend.
ext_emconf.php
<?php
$EM_CONF[$_EXTKEY] = [
'title' => 'mytask',
'description' => '',
'category' => 'plugin',
'author' => '',
'author_email' => '',
'state' => 'alpha',
'internal' => '',
'uploadfolder' => '0',
'createDirs' => '',
'clearCacheOnLoad' => 0,
'version' => '1.0.0',
'constraints' => [
'depends' => [
'typo3' => '7.6.0-7.6.99',
],
'conflicts' => [],
'suggests' => [],
],
];
ext_localconf.php
<?php
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers']
[$_EXTKEY] = \TYPO3\CMS\mytask\Command\SimpleCommandController::class;
?>
My command class in /Classes/Command/SimpleCommandController.php
<?php
namespace TYPO3\Mytask\Command;
use \TYPO3\CMS\Extbase\Mvc\Controller\CommandController;
class SimpleCommandController extends CommandController {
public function simpleCommand(){
error_log("Hallo");
}
}
?>
I'm able to find the extension in the backend but when I enable it I get a error message and can't use the backend anymore.
Oops, an error occurred!
syntax error, unexpected '$GLOBALS' (T_VARIABLE)
The extension has only these 3 files.
Just try to increase the array without an extension key:
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = \TYPO3\CMS\mytask\Command\SimpleCommandController::class;

Perl printing of a hash gives ARRAY(xxxxxxx)

I know there are many questions already with this kind of subject, but as far as I know (perl beginner so I could be wrong), I'm not using an array so I don't understand where this output comes from
$VAR1 = {
'BridgeMode' => {
'Ten-GigabitEthernet1/0/5' => {
'Description' => 'poort1',
'Duplex' => 'F(a)',
'Interface' => 'Ten-GigabitEthernet1/0/5',
'Link' => 'UP',
'PVID' => '100',
'Speed' => '10G(a)',
'Type' => 'A',
'Vlan100' => {
'UntaggedPorts' => [
'Ten-GigabitEthernet1/0/5'
]
},
'vlanID' => [
'Vlan100'
]
},
Above is the content of my dumper and this is my print statement:
my $untaggedInterface = $data{BridgeMode}{"Ten-GigabitEthernet1/0/5"}{Vlan100}{UntaggedPorts} ;
print "Untagged: $untaggedInterface \n" ;
I would expect that the print statement would print "Ten-GigabitEthernet1/0/5" but instead it shows this:
Untagged: ARRAY(0x24a8ec0)
edit - it is possible that there exists an tagged and an untagged:
$VAR1 = {
'BridgeMode' => {
'Ten-GigabitEthernet1/0/12' => {
'Description' => 'poort5',
'Duplex' => 'F(a)',
'Interface' => 'Ten-GigabitEthernet1/0/12',
'Link' => 'UP',
'PVID' => '100',
'Speed' => '10G(a)',
'Type' => 'H',
'Vlan100' => {
'UntaggedPorts' => [
'Ten-GigabitEthernet1/0/12'
]
},
'Vlan107' => {
'TaggedPorts' => [
'Ten-GigabitEthernet1/0/12'
]
},
edit: printing the content of the array
my #untaggedInterface = $data{BridgeMode}{"Ten-GigabitEthernet1/0/5"}{Vlan100}{UntaggedPorts} ;
print join(", ", #untaggedInterface) ;
stil gives
ARRAY(0x1c03a68)
You would get the expected result if you had the following, i.e. a string instead of a string array:
'UntaggedPorts' => 'Ten-GigabitEthernet1/0/12'
Otherwise, you must specify the index of the array element:
my $untaggedInterface = $data{BridgeMode}{"Ten-GigabitEthernet1/0/5"}{Vlan100}{UntaggedPorts}[0];

Yii2 multiple models in one form js validating

I have two fileds, that are uses two different instances of the same model class.
Test Case Video
$form->field($billing_address, 'zip',
[
'selectors' => [
'input' => '#billing-zip',
'container' => '#billing-container',
],
'options' => ['id' => 'billing-container'],
])->textInput(['maxlength' => 11,
'name'=> 'Billing_Address[zip]',
'id'=>'billing-zip']);
//Shipping
$form->field($shipping_address, 'zip',
[
'selectors' => [
'input' => '#shipping-zip',
'container' => '#shipping-container',
],
'options' => ['id' => 'shipping-container'],
])->textInput(['maxlength' => 11,
'name'=> 'Shipping_Address[zip]',
'id'=>'shipping-zip']);
When I finish filling fields, errors are shown for only fields that has errors.
But when I push submit, if one of zip fields has errors, error appears for all zip fields
public function rules()
{
return [
[['zip'], 'string', 'max' => 23],
];
}
I think you can use something like this in your controller:
if( Model::loadMultiple($model_array, Yii::$app->request->post()) && Model::validateMultiple($model_array) && $model->validate()){
//your stuff
}
where $model_array are an array of models
$model_array['model1'] = new YourModelClass();
$model_array['model2'] = new YourModelClass();
Documentation

Populating $form_input with 'select' element options?

I'm trying to understand the data-structure required to populate a
form with 'select' element values (options).
When I dump (Data::Dumper) the FormFu object, I see that the object structure
looks similar to the following:
'name' => 'EmailDL',
'_options' => [
{
'label_attributes' => {},
'value' => 'm',
'container_attributes' => {},
'label' => 'Male',
'attributes' => {}
},
{
'label_attributes' => {},
'value' => 'f',
'container_attributes' => {},
'label' => 'Female',
'attributes' => {}
}
],
Seeing this, I figured that the way to structure $form_input (being that $form_input = \%cgivars) would be something like the following:
'Firstname' => 'Faisal',
'EmailDL' => [
{
'value' => 'myvalue',
'label' => 'mylabel'
}
],
However this doesn't seem to work. I've found that structuring $form_input correctly, and then issuing a $fu->default_values($form_input) to be simple and effective, except in this instance when I'm trying to include the select/options sub-structure.
So the question is: How should I structure 'EmailDL' above to correctly populate 'select' options when doing $fu->default_values($form_input) or $fu->process($form_input)?
To set the options you use the options call,
$fu->get_all_element('EmailDL')->options([ [ 'myvalue', 'mylabel' ],
[ 'val2', 'label2' ] ]);
If you then want to set one of those values you can use the default_values.
$fu->default_values({ EmailDL => 'val2' });
Further help is available here in the Element::Group documentation. Note the code examples are in the text of the help.