3

我通过安装程序创建了一个自定义多选产品属性。它有效,如果我只从多选值中选择一个选项,我可以保存产品。但是,如果我选择 2 个值,产品仍然可以保存,但会再次返回 1 个选定值。简而言之,我无法使用 2 个选定值保存属性。

$installer = $this;
$installer->startSetup();

$installer->addAttribute('catalog_product', 'attr_id',array(
         'label'             => 'Frontend Name',
         'type'              => 'int',
         'input'             => 'multiselect',
         'backend'           => 'eav/entity_attribute_backend_array',
         'frontend'          => '',
         'source'            => '',
         'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
         'visible'           => true,
         'required'          => false,
         'user_defined'      => true,
         'searchable'        => false,
         'filterable'        => false,
         'comparable'        => false,
         'option'            => array (
            'value' => array(
                     '0' => array('First Option'),
                     '1' => array('Second Option'),
                     '2' => array('Third Option'),
                     )
                    ),
         'visible_on_front'  => false,
         'visible_in_advanced_search' => false,
         'unique'            => false
));

$installer->endSetup();
4

5 回答 5

7

问题来自您的属性类型。

'type'=> 'int',

多选属性的值以逗号连接保存1,4,6。为此,您需要属性为varcharor textvarchar如果您不打算为该属性提供数百个选项,我建议您这样做。
现在配置的方式,当它被保存时,值1,4,6被转换为 int 并且它最终是1.

于 2013-11-07T09:15:13.257 回答
1

修改你的选项数组

 'option' => array (
  'value' => array(
  '0' => array('First Option'),
  '1' => array('Second Option'),
  '2' => array('Third Option'),
  )
),

'option' => array (
  'value' => array(
  'first_option' => array('First Option'),
  'second_option' => array('Second Option'),
  'third_option' => array('Third Option'),
  )

),

多选将接受关联的数组。

于 2013-11-07T08:02:06.263 回答
0

我的自定义类别属性遇到问题。它不会将多选值保存在数据库中,并且不会在类别后端管理员上显示多选值。

        <?php
        require_once("app/Mage.php");
        Mage::app('default');
        Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

        $installer = new Mage_Eav_Model_Entity_Setup('core_setup');
        $entityTypeId     = $installer->getEntityTypeId('catalog_category');
        $attributeSetId   = $installer->getDefaultAttributeSetId($entityTypeId);
        $attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

        $installer->addAttribute('catalog_category', 'cutomcity',  array(
             'label'            => 'Test Select',
            'type'              => 'varchar',
            'input'             => 'multiselect',
            'visible'           => true,
            'user_defined'      => true,
             'required'         => false,
            'position'          => 80,
            'visible_on_front'  => false,    

            'group'    => 'General Information',   
            'input'    => 'multiselect', 
    'backend_model'=>'eav/entity_attribute_backend_array'   

            'source' => 'GA_Multiattribute_Helper_Testsource'


        // eav/entity_attribute_source_table   Even if i use this untill it does not show selected value on the Multiselect


        ));
        ?>

这是我的帮助文件代码

<?php 

class GA_Multiattribute_Helper_Multiattributesource extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
    protected $_optionsDefault = array();
    public function getAllOptions($withEmpty = true, $defaultValues = false)
    {
        $collection = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*');;
        $customers = array();
        foreach($collection as $cust)
        {
            $fname = $cust->getFirstname();
            $lname = $cust->getLastname();
            $id = $cust->getId();
            $customers[] = array('value'=>"$id$fname", 'label'=>"$fname $lname");
        }
        return $customers;
    }
}  ?>
于 2014-02-06T09:48:59.937 回答
0

我正在使用 SOAP API 在 magento 商店中输入产品。这是完整的代码

在多选自定义属性的情况下。

            $arrProductTime = explode(',', '136,139');

            $result = $client->catalogProductCreate($session, 'simple', $attributeSet->set_id, 'product_sku1234', array(

                'categories' => array(36),
                'websites' => array(1),
                'name' => 'my_pdt1008',
                'description' => 'my_pdt1',
                'short_description' => 'my_pdt1000',
                'weight' => '11',
                'status' => '1',
                'url_key' => 'product-url-key1',
                'url_path' => 'product-url-path1',
                'visibility' => '4',
                'price' => '100',
                'tax_class_id' => 1,
                'meta_title' => 'Product meta title1',
                'meta_keyword' => 'Product meta keyword1',
                'meta_description' => 'Product meta description1',
                'stock_data' => array('qty'=>'100','is_in_stock'=>1,'manage_stock'=>1),
                'additional_attributes' => array('multi_data' => array(array('key' => 'product_time', 'value' => $arrProductTime)))
            ));
于 2014-06-06T07:50:01.123 回答
0
    I have found the solution myself .

    open app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php 
    on save action after this

    $category->setAttributeSetId($category->getDefaultAttributeSetId());

    Please change language is your attribute name . you can change attribute name accordingly

    $ga = "";
    if($data['general']['language']){
    foreach($data['general']['language'] as $a){
    $ga .= $a.",";
    }
    $category->setLanguage(substr_replace($ga, "", -1));

    }
Please replace language to your attribute name and it works...**
于 2014-02-06T11:04:13.240 回答