Warning: Cannot modify header information - headers already sent by (output started at /www/wwwroot/sbboke.com/wp-content/plugins/wordpress-seo/src/integrations/front-end-integration.php:409) in /www/wwwroot/sbboke.com/wp-content/themes/pacify/content-single.php on line 5

Magento 2中获取客户组

如何在Magento 2中获得客户群?我将为您提供最简单的方式来做到这一点。该主题将显示以下代码,请将其添加到您的块类中。

/**
 * Customer Group
 *
 * @var \Magento\Customer\Model\ResourceModel\Group\Collection
 */
protected $_customerGroup;
    
/**
 * @param \Magento\Backend\Block\Template\Context $context
 * @param \Magento\Customer\Model\ResourceModel\Group\Collection $customerGroup
 * @param array $data
 */
public function __construct(
    \Magento\Backend\Block\Template\Context $context,
    \Magento\Customer\Model\ResourceModel\Group\Collection $customerGroup,        
    array $data = []
) {
    $this->_customerGroup = $customerGroup;        
    parent::__construct($context, $data);
}
/**
 * Get customer groups
 * 
 * @return array
 */ 
public function getCustomerGroups() {
    $customerGroups = $this->_customerGroup->toOptionArray();
    array_unshift($customerGroups, array('value'=>'', 'label'=>'Any'));
    return $customerGroups;
}

这就是您将用于检索Magento 2中的客户组的所有内容。感谢您的阅读,如果有任何问题,请在下面评论。

相关文章

0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论