2017-09-24 82 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'); 
相關問題