Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing arguments to <options> methods #19

Conversation

@mpchadwick
Copy link
Contributor

@mpchadwick mpchadwick commented Feb 26, 2016

Allows you to write a method like this when working with dropdown EAV attributes

<?php

class Mpchadwick_GridControl_Model_Utility
{
    public function getDropdownAttributeLabelOptionArray($attribute)
    {
        $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $attribute);
        $options = $attribute->getSource()->getAllOptions(false);

        $map = [];
        foreach ($options as $option) {
            $map[$option['value']] = $option['label'];
        }

        return $map;
    }
}

Then you can re-use it whenever adding a dropdown attribute

<?xml version="1.0"?>
<gridcontrol>
    <grids>
        <productGrid>
           <manufacturer>
                <add>
                    <header>Brand</header>
                    <type>options</type>
                    <index>manufacturer</index>
                    <options>mpchadwick_gridconfig/utility::getDropdownAttributeLabelOptionArray('manufacturer')</options>
                </add>
                <after>name</after>
            </manufacturer>
        </productGrid>
    </grids>
</gridcontrol>

There might be other use cases I'm not thinking of...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants