Skip to content

Allow passing arguments to <options> methods - #19

Merged
sandermangel merged 1 commit into
magento-hackathon:masterfrom
mpchadwick:feature/option-method-arguments
May 11, 2016
Merged

sandermangel merged 1 commit into
magento-hackathon:masterfrom
mpchadwick:feature/option-method-arguments

Conversation

@mpchadwick

Copy link
Copy Markdown
Contributor

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

Development

Successfully merging this pull request may close these issues.

2 participants