1

I added a custom field to product in admin panel named vendor_name So I wanna get value of this field by do something like

$_product->getVendorName()

Like what I can do with non eav attribute (i.e $product->getSku()) But $_product->getVendorName() give me null value , What is the best solution to get attribute ? I wanna same syntax for both eav and None eav attribute.

2
  • is your catalog flat table enabled for the application ? Commented May 28, 2016 at 21:42
  • No it is not and i am in developer mode.
    – ali gh
    Commented May 29, 2016 at 5:48

1 Answer 1

1

In Store > Attributes > Product > YOUR ATTRIBUTE > Storefront Properties set Visible on Catalog Pages on Storefront and Used in Product Listing to TRUE.

In your code you can use:

<?php echo $this->helper('Magento\Catalog\Helper\Output')->productAttribute($_product, $_product->getYourAttribute(), 'your_attribute') ?>

or

<?php echo $_product->getYourAttribute() ?>
1
  • I wanna use this code <?php echo $_product->getYourAttribute() ?> In this class magento/catalog/helper/image , in this class $product will loaded and given by the argument of the init function here is a code: {public function init($product, $imageId, $attributes = [])} so when I debug the code the $_data of $product has only original attribute of a product model not custom (EAV) attribute .
    – ali gh
    Commented Jun 4, 2016 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.