【问题标题】:Magento 2.0 - How to get Customer Multiselect Attribute Options ValueMagento 2.0 - 如何获取客户多选属性选项值
【发布时间】:2016-05-02 19:33:21
【问题描述】:

我正在尝试从 Magento 2.0 EE 上的客户会话中获取当前商店范围内的自定义客户属性选项值。

现在我只得到选项 ID:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
$customerRepository = $objectManager
    ->get('Magento\Customer\Api\CustomerRepositoryInterface');
$customer = $customerRepository->getById($customerSession->getCustomerId());
$attrValue = $customer->getCustomAttribute('attribute_code')->getValue();

var_dump($attrValue) is string(id1,id2,id3)

如何获取这些选项的前端文本值。

【问题讨论】:

    标签: php magento custom-attributes magento-2.0 customer


    【解决方案1】:

    我找到了一个解决方案,我不确定是不是一个好习惯...:

            $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
            $customerSession = $objectManager->get('Magento\Customer\Model\Session');
            $customerRepository = $objectManager
                ->get('Magento\Customer\Api\CustomerRepositoryInterface');
            $customer = $customerRepository->getById($customerSession->getCustomerId());
    
            $model = $objectManager->create('Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection');
            $model->setIdFilter(explode(',',$customer->getCustomAttribute('attribute_code')->getValue()))
                ->setStoreFilter();
    
            var_dump($model->toOptionArray());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-31
      • 2016-03-29
      • 1970-01-01
      • 1970-01-01
      • 2019-11-20
      • 2011-04-28
      • 1970-01-01
      • 2018-04-24
      相关资源
      最近更新 更多