2017-09-24 53 views
0

我可以用下面的代码显示的属性值,但如果该属性为空,它会打印出“否”字样获取的Magento 2自定义属性值

<?php echo $_product->getResource()->getAttribute('c_address')->getFrontend()->getValue($_product); ?> 

回答

0

要获得客户的属性,你可以使用这样的:

$customerRepository = $objectManager->get('Magento\Customer\Api\CustomerRepositoryInterface'); 
$customer = $customerRepository->getById(1); 
$cattrValue = $customer->getCustomAttribute('c_address'); 

要获得的产品属性,你可以使用这样的:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$product = $objectManager->get('Magento\Catalog\Model\Product')->load('YOUR PRODUCT ID'); 
echo $product->getAttributeText('your_attribut'); 
相关问题