1

I'm making a module in which the user can add review scores from another site.

It currently looks like this.

current And I want to add a function like this: desired

Does anyone know how I can achieve this?

4
  • You need to this in system configuration or product level etc? Commented Jan 24, 2018 at 13:50
  • @DhirenVasoya These values will be displayed on the website as star rating
    – Alle
    Commented Jan 24, 2018 at 13:54
  • You need this in configuration level or product level. Commented Jan 24, 2018 at 13:57
  • @DhirenVasoya system configuration level
    – Alle
    Commented Jan 24, 2018 at 14:16

1 Answer 1

1

What you are looking for is what Magento defines under adminhtml/system_config_backend_serialized_array. This will allow you to create an input table in the admin with a user defined number of rows.

This is used for example in Configuration > GENERAL > Design and looks like this: enter image description here

Add this to your Vendorname/Modulename/etc/system.xml (make sure you update the module name and node labels accordingly):

<config>
    <tabs>
    <vendor translate="label" module="vendorname_modulename">
        <label>Tab Name</label>
        <sort_order>100</sort_order> 
        <show_in_default>1</show_in_default>
        <show_in_website>1</show_in_website>
        <show_in_store>1</show_in_store>
    </vendor>
</tabs> 
    <sections>
        <modulename_settings translate="label" module="vendorname_modulename">
            <groups>
                <label>Group Label</label>
                <tab>vendor</tab>
                <frontend_type>text</frontend_type>
                <sort_order>100</sort_order>
                <show_in_default>1</show_in_default>
                <show_in_website>1</show_in_website>
                <show_in_store>1</show_in_store>
                <some_options translate="label">
                    <label>Section Label</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>100</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <params module="vendorname_modulename">
                            <label>Table Label</label>
                            <frontend_model>vendorname_modulename/adminhtml_system_config_source_table</frontend_model>
                            <backend_model>adminhtml/system_config_backend_serialized_array</backend_model>
                            <sort_order>200</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>0</show_in_website>
                            <show_in_store>0</show_in_store>
                        </params>
                    </fields>
                </some_options>
                <!-- [...] -->
            </groups>
        </modulename_settings>
        <!-- [...] -->
    </sections>
</config>

Then, as specified in the frontend_model (=Block!) node, create Vendorname/Modulename/Block/Adminhtml/System/Config/Source/Table.php and put this inside:

<?php   
class Vendorname_Modulename_Block_Adminhtml_System_Config_Source_Table extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract { 

    public function _prepareToRender() {

        $this->addColumn('column_a', array(
            'label'     => 'Column A',
            'style'     => 'width:200px',
        ));
        $this->addColumn('column_b', array(
            'label'     => 'Column B',
            'style'     => 'width:200px',
        ));

        $this->_addAfter = false;
        $this->_addButtonLabel = 'Add line';

    }
}

You then can get the content of this table like always using Mage::getStoreConfig() - but in order to utilize the values you will have to unserialize() it.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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