magento multiselect product attribute not showing option labels on frontend - attributes

I have checked lot and tried many things, but I am still not getting the product multiselect selected values label on product view page.
I have product attribute called package which is multiselect,
Code that create the product attribute
$this->addAttribute(
'catalog_product',
'package',
array(
'group' => 'Package',
'backend' => 'eav/entity_attribute_backend_array',
'frontend' => '',
'class' => '',
'default' => '',
'label' => 'Package',
'input' => 'multiselect',
'type' => 'text',
'source' => 'npm_recurrex/package_source',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'is_visible' => 1,
'required' => 0,
'searchable' => 0,
'filterable' => 0,
'unique' => 0,
'comparable' => 0,
'visible_on_front' => 0,
'user_defined' => 1,
)
);
this works fine, I am successfully saving the product.
But in frontend product view page when I say
Mage::log(print_r($_product->getData('package'), true));
Its prints the result as 1,2
But I wanted to display option labels of multiselect not option id's.
So I tried with this code
Mage::log(print_r($_product->getAttributeText('package'), true));
It prints nothing, just blank space :(.
I have checked this link but no use.
I am confused with this, Where I am wrong? and what is the wrong thing?
Can anybody explain me what is happening in my case?

If you need to show Drop Down or Multiple select value of an attribute product you should do something like this:
$attributes = $_product->getAttributes();
$customAttributeValue = $attributes['custom_attribute']->getFrontend()->getValue($_product);
Mage::log($customAttributeValue);

Related

Typo3: Where can i get list of TCA types?

I have bodytext and image so like this type of list where can I found? Can I get page list in select box?
$GLOBALS['TCA']['tt_content']['types']['text_image_left'] = [
'showitem' => '
--palette--;palette.general;general,
header, subheader, header_layout,menu,
bodytext;bodytext_formlabel,
--div--;tabs.images,
image,
--div--;tabs.appearance,
--palette--;palette.frames;frames,
--div--;tabs.access,
hidden;field.default.hidden,
--div--;tabs.extended
',
'columnsOverrides' => ['bodytext' => ['config' => ['enableRichtext' => true]]]
];
Hm, not sure if I get your question right. You asked
1. for a list of TCA types
2. how to get a list of pages in a select field (?)
You can find the complete TCA Documentation here:
https://docs.typo3.org/m/typo3/reference-tca/master/en-us/
Interesting part for you is the [column][*][config] part:
https://docs.typo3.org/m/typo3/reference-tca/master/en-us/ColumnsConfig/Index.html
In order to create a select with a page list, you need following kind of configuration.
I would suggest to use "group" type for field.
'page' => [
'exclude' => true,
'label' => 'List of Pages',
'config' => [
'type' => 'group',
'internal_type' => 'db',
'allowed' => 'pages',
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
]
]

creates programmatically a taxonomy in drupal 6

I am new to drupal, I need to create in my .install custom module file a taxonomy, and assign this taxonomy to a specific content type. Any idea how to do it ? Thanks !
I assume that with "create a taxonomy" you mean "create a taxonomy vocabulary". If this is the case, you need to populate an array such as:
$vocabulary = array(
'name' => t('<VOCABULARY_NAME>'),
'multiple' => 0, // or 1, if you need multiple terms associated to any single node
'required' => 0, // or 1, if the association is required
'hierarchy' => 1, // or 0, if is a tag-like term
'relations' => 0,
'module' => '<YOUR_MODULE_NAME>',
'weight' => 0,
'nodes' => array('<YOUR_NODE_TYPE>' => 1),
);
and save the vocabulary by issuing
** EDIT **
$ret = taxonomy_save_vocabulary($vocabulary);
If $ret == 1 you have correctly saved your vocabulary and $vocabulary['vid'] will have the vid of the newly created vocabulary. If you want to add terms to it, you create arrays:
$term = array(
'vid' => <VOCABULARY_VID>,
'name' => "<TERM NAME>",
'description' => "An optional description for the term",
'weight' => <AN_INTEGER_OPTIONAL_VALUE_FOR_WEIGHT>,
);
$ret = taxonomy_save_term($term);
and again $ret will be set to a status value of your save operation and $term['tid'] will be the term id of the new term.

Using multiselect module in custom module (drupal 6)

Im programming my own module in Drupal 6 and create a form, but I need something to select data from a list. I am trying to use multiselect module. I can show the field with options, but on submit I cant get the selected options.
I made the following:
$element = array(
'#type' => 'field_multi_select',
'#title' => 'Field name',
'#description' => 'description',
'#multiple' => true,
'required' => true,
'#field_name' => 'field_select',
'#columns' => array('value'),
'#value' => array(array('value' => null)),
'#process' => array('multiselect_select_process'),
'#enable'=>true,
'module' => 'module name' // set here you current module name
);
$form['#field_info']['field_multi_select'] = $element;
$element = multiselect_select_process($element, NULL, $form_state, $form);

Ajax request in magento module

I developing magneto module, In this module i want to make a ajax request in admin panel.I don't understand were to add script and controllers.please help me.
My requirement:
When change the select box(On change) i want add some field in the form.
Mycode:
/app/code/local/<Namespace>/<Module>/Block/Adminhtml/<Module>/Edit/Tab/Form.php
$fieldset->addField('type', 'select', array(
'label' => Mage::helper('<Module>')->__('Article Type'),
'name' => 'status',
'values' => array(
array(
'value' => '',
'label' => Mage::helper('<Module>')->__('Choose'),
),
array(
'value' => 1,
'label' => Mage::helper('<Module>')->__('Normal'),
),
array(
'value' => 2,
'label' => Mage::helper('<Module>')->__('video'),
),
),
'required' => true
));
I am creating fields using this.
How can i add another field on change.
Where should i add script
Where should i add controller
I created this module using this instructions
Let this field always be on the form. But make it invisible and show when you need it.
In the same template where the form is.
Place controller in your module. On stackoverflow you can find many questions about creating your own magento module and controller.

add custom order attribute to the order from in magento admin

I've added a custom order attribute and updated the onepage checkout page.
Now I'm trying to add this attribute to the new order form in the admin.
I'm trying to extend Mage_Adminhtml_Block_Sales_Order_Create_Form_Account and add a new field in the _prepareForm() method similar to the way the Group and Email fields are added.
How do I get the order attribute?
I've tried several ways but nothing works.
This is how I'm creating the custom order attribute in the mysql-install file:
$attribute = array(
'type' => 'int',
'label' => 'myattr',
'visible' => false,
'required' => false,
'user_defined' => false,
'searchable' => false,
'filterable' => false,
'comparable' => false,
);
$installer->addAttribute('order', 'myattr', $attribute);
and this is how I'm trying to get the attribute:
$res = Mage::getSingleton('core/resource');
$eav = Mage::getModel('eav/config');
$attr = $eav->getAttribute('sales/order', 'myattr');
or with this:
$entityType = Mage::getModel('eav/config')->getEntityType('order');
$entityTypeId = $entityType->getEntityTypeId();
$attribute = Mage::getResourceModel('eav/entity_attribute_collection')
->setCodeFilter('myattr')
->setEntityTypeFilter($entityTypeId)
->getFirstItem();
or this:
$order = Mage::getResourceSingleton('sales/order');
$myAttr = $order->getAttribute('myattr');
None of them work.
Have you verified that the attribute is being added to eav_attribute table in the database with the correct entity_type_id? (I think sales_order is 11 by default, but don't assume that)
At first glance, it looks like you should be using
$installer->addAttribute('sales/order', 'myattr', $attribute);
HTH,
JD
Sales/Order used to use the EAV Model which supports attributes, that was before 1.4.0 or so not sure.
I think now you should do:
$installer->getConnection()->addColumn($installer->getTable('sales/order'), 'my_column', 'decimal(12,4)');
you can still add the attribute as static field
$installer->addAttribute('order', 'my_column', array('type'=>'static'));
What I noticed after much trial-and-error was that the new attribute must have a default (non-null) value in order to work. Somehow the attribute is not writable if it has a 'NULL' value in the database. So using this attribute options array worked for me:
$attribute = array(
'type' => 'int',
'label' => 'myattr',
'default' => 0,
'visible' => false,
'required' => false,
'user_defined' => true,
'searchable' => false,
'filterable' => false,
'comparable' => false );

Resources