Question

I have tried to add a custom price attribute on the product page near price.

class InstallData implements InstallDataInterface {
private $eavSetupFactory;

public function __construct(EavSetupFactory $eavSetupFactory)
{
    $this->eavSetupFactory = $eavSetupFactory;
}

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
    $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
    $eavSetup->addAttribute(
        \Magento\Catalog\Model\Product::ENTITY,
        'retail_price',
        [
            'type' => 'text',
            'backend' => '',
            'frontend' => '',
            'label' => 'Retail Price',
            'input' => 'text',
            'class' => '',
            'source' => '',
            'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
            'visible' => true,
            'required' => true,
            'user_defined' => false,
            'default' => '',
            'searchable' => false,
            'filterable' => false,
            'comparable' => false,
            'visible_on_front' => false,
            'used_in_product_listing' => true,
            'unique' => false,
            'apply_to' => '',
            'sort_order' => 4,
        ]
    );
}

I manage to see my new attribute in the admin panel on product configuration, but when I try to get it's value in final_price.phtml with:

$_product = $block->getPriceType('final_price')->getProduct();
$attr = $_product->getData();

I don't see my attribute.

I tried with getCustomAttribute it's not working, tried with getData(), and in the debugger, I can see all attributes except mine. Did I miss something, do you have any ideas guys?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top