magento2-docker/app/code/Kai/Product/Block/Custom.php

28 lines
675 B
PHP
Executable File

<?php
namespace Kai\Product\Block;
use Magento\Framework\Registry;
use Magento\Framework\View\Element\Template;
class Custom extends Template
{
protected $registry;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
Registry $registry,
array $data = []
) {
parent::__construct($context, $data);
$this->registry = $registry;
}
public function getCustomAttribute()
{
$product = $this->registry->registry('current_product');
// Replace 'your_custom_attribute_code' with your actual attribute code
return $product->getData('kai_attribute');
}
}