I am working on aMagento 1.9
website.
I want to add
an attribute
of the brand
on the product page
under the product name
.
I have highlighted in the following image.
can anyone please guide how can I do the same.
Open ..\..\catalog\product\view.phtml
And Find line,
<span class="h1"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></span>
Put the code below span
<?php
$productId = $_product->getId();
$product= Mage::getModel('catalog/product')->load($productId);
$manufaturer= $product->getAttributeText('manufacturer');
echo $manufaturer;
?>
For example, Your attribute code is "Brand", You need to use this code in following location:
/app/design/frontend/[your package]/[your theme]/template/catalog/product/view.phtml:
<?php
$Brand = $this->htmlEscape($_product->getData('Brand'));
echo $Brand;
?>
Or
echo $this->htmlEscape($_product->getData('Brand'));
If you want to add with saperate file then you can call custom phtml file before after sku,
<referenceContainer name="product.info.stock.sku">
<block class="Magento\Catalog\Block\Product\View" name="product_view_style" template="Magento_Catalog::product/view/custom.phtml" before="-"/>
</referenceContainer>
and create custom.phtml
here ,
YOUR_THEME/Magento_Catalog/templates/product/view/custom.phtml
<?php $_product = $this->getProduct();
$optionId = $_product->getData('color');
/*Swacth Text value*/
$attr = $_product->getResource()->getAttribute('color');
if ($attr->usesSource()) {
$optionText = $attr->getSource()->getOptionText($optionId);
}
echo $optionText;
?>
Hope it's help you !
To edit some extra information you should not modify default Magento file. For this, you can override Magento default file in your theme.
To display brand attribute value after product name follows below steps:
1.Copy view.phtml file from
magento/app/design/frontend/base/default/template/catalog/product
and place in
magento/app/design/frontend/[your_package]/[your_theme]/template/catalog/product/
in this file, you can see
<div class="product-name">
<h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
</div>
Write below code after completion of "product-name" div, for example, your attribute code is "brand" and attribute type is "text" then
<div class="brand-name">
<?php echo $this->->escapeHtml($_product->getData('brand')); ?>
</div>
if the attribute type is dropdown then use
<div class="brand-name">
<?php echo $_product->getAttributeText("brand"); ?>
</div>