1

I created this custom variable

Path: Stores -> Attributes (Product)

Code Variable: time_di_consegna_modulo

Now I want to print the variable inside the product page.

Path: public_html / vendor / magento / module-catalog / view / frontend / templates / product / view / attribute.phtml

I tried in every way but I can not print the value of the variable. I managed to print only the label.

How can I do?

This is code page with me code for print label variables

    <?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/**
 * Product view template
 *
 * @see \Magento\Catalog\Block\Product\View\Description
 */
?>
<?php
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_product = $block->getProduct();
$_call = $block->getAtCall();
$_code = $block->getAtCode();
$_className = $block->getCssClass();
$_attributeLabel = $block->getAtLabel();
$_attributeType = $block->getAtType();
$_attributeAddAttribute = $block->getAddAttribute();

if ($_attributeLabel && $_attributeLabel == 'default') {
    $_attributeLabel = $_product->getResource()->getAttribute($_code)->getFrontendLabel();
}
if ($_attributeType && $_attributeType == 'text') {
    $_attributeValue = ($_helper->productAttribute($_product, $_product->$_call(), $_code)) ? $_product->getAttributeText($_code) : '';
} else {
    $_attributeValue = $_helper->productAttribute($_product, $_product->$_call(), $_code);
}
?>

<?php if ($_attributeValue): ?>
<div class="product attribute <?php /* @escapeNotVerified */ echo $_className?>">
    <?php if ($_attributeLabel != 'none'): ?><strong class="type"><?php /* @escapeNotVerified */ echo $_attributeLabel?></strong><?php endif; ?>
    <div class="value" <?php /* @escapeNotVerified */ echo $_attributeAddAttribute;?>><?php /* @escapeNotVerified */ echo $_attributeValue; ?></div>
</div>
<?php endif; ?>

<?php
// Stampa varibile giorni per la spedizione 
// tempi_di_consegna_modulo
$tempiconsegnamod ="tempi_di_consegna_modulo";
$_test = $_product->getResource()->getAttribute($tempiconsegnamod)->getFrontendLabel();
echo $_test;
?>

Please help me

  • Hi, Have you created the product attribute with the value set to “YES” in “Visible on Catalog Pages on Storefront” under storefront Properties from the backend? – Haritha Mar 22 '18 at 4:25
  • It is visible, but the problem is the code to retrieve the value. – Alessandro Mar 22 '18 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.