Вопрос

I have an admin module that currently pulls all customer groups into a multiselect box using the following code (I think!):

class Netzarbeiter_GroupsCatalog2_Model_Entity_Attribute_Source_Customergroup_Withdefault
    extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{   
    /**
     * Return all options for the customergroups_groups attributes, i.e. a list of all
     * customer groups with the additional options USE DEFAULT and NONE
     *
     * @return array
     */
    public function getAllOptions()
    {
        if (is_null($this->_options)) {
            $this->_options = array(
                array(
                    'value' => Netzarbeiter_GroupsCatalog2_Helper_Data::USE_DEFAULT,
                    'label' => Mage::helper('netzarbeiter_groupscatalog2')->__(
                        Netzarbeiter_GroupsCatalog2_Helper_Data::LABEL_DEFAULT
                    )
                ),
                array(
                    'value' => Netzarbeiter_GroupsCatalog2_Helper_Data::USE_NONE,
                    'label' => Mage::helper('netzarbeiter_groupscatalog2')->__(
                        Netzarbeiter_GroupsCatalog2_Helper_Data::LABEL_NONE
                    )
                )
            );
            foreach (Mage::helper('netzarbeiter_groupscatalog2')->getGroups() as $group) {
                /* @var $group Mage_Customer_Model_Group */
                $this->_options[] = array(
                    'value' => $group->getId(),
                    'label' => $group->getCode(),
                );
            }
        }
        return $this->_options;
    }

    /**
     * Get the label for an option value. If the value is a comma
     * separated string or an array, return an array of matching
     * option labels.
     *
     * @param string|integer $value
     * @return string|array
     */
    public function getOptionText($value)
    {
        $options = $this->getAllOptions();

        if (is_scalar($value) && strpos($value, ',')) {
            $value = explode(',', $value);
        }
        if (is_array($value)) {
            $values = array();
            foreach ($options as $item) {
                if (in_array($item['value'], $value)) {
                    $values[] = $item['label'];
                }
            }
            return $values;
        } else {
            foreach ($options as $item) {
                if ($item['value'] == $value) {
                    return $item['label'];
                }
            }
        }
        return false;
    }

    /**
     * Return the matching option value(s) for the passed option label(s)
     *
     * @param int|string $value A single option label or a comma separated list for multiselect
     * @return null|string
     */
    public function getOptionId($value)
    {
        if (
            $this->getAttribute()->getFrontendInput() === 'multiselect' &&
            (is_array($value) || strpos($value, ',') !== false)
        ) {
            if (is_scalar($value)) {
                $value = explode(',', $value);
            }

            $optionIds = array();
            foreach ($value as $optionValue) {
                $optionIds[] = $this->getOptionId($optionValue);
            }
            return implode(',', $optionIds);
        }

        foreach ($this->getAllOptions() as $option) {
            if (strcasecmp($option['label'], $value) == 0 || $option['value'] == $value) {
                return $option['value'];
            }
        }
        return null;
    }
}

This then is displaying using the following code to render a multiselect in the backend:

   public function addGroupsCatalogAttribute($entityType)
    {
        $attributeCode = Netzarbeiter_GroupsCatalog2_Helper_Data::HIDE_GROUPS_ATTRIBUTE;
        $this->addAttribute($entityType, $attributeCode, array(
            'label' => 'Hide/Show from Customer Groups',
            'group' => 'General',
            'type' => 'text',
            'input' => 'multiselect',
            'source' => 'netzarbeiter_groupscatalog2/entity_attribute_source_customergroup_withdefault',
            'backend' => 'netzarbeiter_groupscatalog2/entity_attribute_backend_customergroups',
            'frontend' => 'netzarbeiter_groupscatalog2/entity_attribute_frontend_customergroups',
            'input_renderer' => 'netzarbeiter_groupscatalog2/adminhtml_data_form_customergroup',
            'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
            'required' => 0,
            'default' => Netzarbeiter_GroupsCatalog2_Helper_Data::USE_DEFAULT,
            'user_defined' => 0,
            'filterable_in_search' => 0,
            'is_configurable' => 0,
            'used_in_product_listing' => 1,
        ));
    }

What I need to know is how could this be altered to use several checkboxes instead of a multiselect box?

Нет правильного решения

Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top