2

For main website example: mywebsite.pl - A short description of the product is displayed from the attribute short_descrption.

enter image description here

For other websites stores I want to change display short description from other attributes.

Example:

for website mywebsite.com I want to display product short description from attribute: english_short_description

for website mywebsite.cz I want to display product short description from attribute: czech_short_description

Any solution on how to do in product layout?

New update:

Please check, our code now get duplicate short description: (because we didn't overwrite the code - we just added it above. And now two codes are responsible for downloading the descriptions.)

<?php
/**
 * Copyright © 2016 Magento. 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();
if($_code == "short_description") {
    $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();        
    $storeManager  = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
    $storeCode     = $storeManager->getStore()->getCode();

    if($storeCode == "english") {
        $_call = 'getEnglishShortDescription';
        $_code == "english_short_description";
    }

    if($storeCode == "czech") {
        $_call = 'getCzechShortDescription';
        $_code == "czech_short_description";
    }
}
$_className = $block->getCssClass();
$_attributeLabel = $block->getAtLabel();
$_attributeType = $block->getAtType();
$_attributeAddAttribute = $block->getAddAttribute();

$renderLabel = true;
if ($_attributeLabel == 'none') {
    $renderLabel = false;
}

if ($_attributeLabel && $_attributeLabel == 'default') {
    $_attributeLabel = $_product->getResource()->getAttribute($_code)->getStoreLabel();
}
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 <?= /* @escapeNotVerified */ $_className ?>">
    <?php if ($renderLabel): ?><strong class="type"><?= /* @escapeNotVerified */ $_attributeLabel ?></strong><?php endif; ?>
    <div class="value" <?= /* @escapeNotVerified */ $_attributeAddAttribute ?>><?= /* @escapeNotVerified */ $_attributeValue ?></div>
</div>
<?php endif; ?>
<?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();
$themeHelper = $this->helper('MGS\Mpanel\Helper\Data');

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): ?>
    <?php if($_className == 'overview'): ?>
        <?php if($themeHelper->getStoreConfig('mpanel/product_details/short_description')): ?>
            <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 std" <?php /* @escapeNotVerified */ echo $_attributeAddAttribute;?>><?php /* @escapeNotVerified */ echo $_attributeValue; ?></div>
            </div>
        <?php endif; ?>
    <?php elseif($_className == 'sku'): ?>
        <?php if($themeHelper->getStoreConfig('mpanel/product_details/sku')): ?>
            <div class="product attribute <?php /* @escapeNotVerified */ echo $_className?>">
                <?php if ($_attributeLabel != 'none'): ?><strong class="type"><?php /* @escapeNotVerified */ echo $_attributeLabel?></strong><?php endif; ?>
                <span class="value" <?php /* @escapeNotVerified */ echo $_attributeAddAttribute;?>><?php /* @escapeNotVerified */ echo $_attributeValue; ?></span>
            </div>
        <?php endif; ?>
    <?php else: ?>
        <div class="product attribute <?php /* @escapeNotVerified */ echo $_className?>">
            <?php if ($_attributeLabel != 'none' || $_attributeLabel != __('none')): ?><strong class="type"><?php /* @escapeNotVerified */ echo $_attributeLabel?></strong><?php endif; ?>
            <span class="value" <?php /* @escapeNotVerified */ echo $_attributeAddAttribute;?>><?php /* @escapeNotVerified */ echo $_attributeValue; ?></span>
        </div>
    <?php endif ?>
<?php endif ?>

here is our original file from template vendor (our file looks little different from the original magento file attribute.phtml. So I think to our original code:

<?php
/**
 * Copyright © 2016 Magento. 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();
$themeHelper = $this->helper('MGS\Mpanel\Helper\Data');

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): ?>
    <?php if($_className == 'overview'): ?>
        <?php if($themeHelper->getStoreConfig('mpanel/product_details/short_description')): ?>
            <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 std" <?php /* @escapeNotVerified */ echo $_attributeAddAttribute;?>><?php /* @escapeNotVerified */ echo $_attributeValue; ?></div>
            </div>
        <?php endif; ?>
    <?php elseif($_className == 'sku'): ?>
        <?php if($themeHelper->getStoreConfig('mpanel/product_details/sku')): ?>
            <div class="product attribute <?php /* @escapeNotVerified */ echo $_className?>">
                <?php if ($_attributeLabel != 'none'): ?><strong class="type"><?php /* @escapeNotVerified */ echo $_attributeLabel?></strong><?php endif; ?>
                <span class="value" <?php /* @escapeNotVerified */ echo $_attributeAddAttribute;?>><?php /* @escapeNotVerified */ echo $_attributeValue; ?></span>
            </div>
        <?php endif; ?>
    <?php else: ?>
        <div class="product attribute <?php /* @escapeNotVerified */ echo $_className?>">
            <?php if ($_attributeLabel != 'none' || $_attributeLabel != __('none')): ?><strong class="type"><?php /* @escapeNotVerified */ echo $_attributeLabel?></strong><?php endif; ?>
            <span class="value" <?php /* @escapeNotVerified */ echo $_attributeAddAttribute;?>><?php /* @escapeNotVerified */ echo $_attributeValue; ?></span>
        </div>
    <?php endif ?>
<?php endif ?>

we need only implement this rule:

$_code = $block->getAtCode();
if($_code == "short_description") {
    $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();        
    $storeManager  = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
    $storeCode     = $storeManager->getStore()->getCode();

    if($storeCode == "english") {
        $_call = 'getEnglishShortDescription';
        $_code == "english_short_description";
    }

    if($storeCode == "czech") {
        $_call = 'getCzechShortDescription';
        $_code == "czech_short_description";
    }
}

1 Answer 1

2

First you need to create english_short_description and czech_short_description attribute for product and assign in particular attribute set

And you need to override the attribute.phtml file under

app/design/frontend/Vendor/Theme/Magento_Catalog/templates/product/view/attribute.phtml

and use the code below:

<?php
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_product = $block->getProduct();
$_call = $block->getAtCall();
$_code = $block->getAtCode();
if($_code == "short_description") {
    $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();        
    $storeManager  = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
    $storeCode     = $storeManager->getStore()->getCode();

    if($storeCode == "english") {
        $_call = 'getEnglishShortDescription';
        $_code == "english_short_description";
    }

    if($storeCode == "czech") {
        $_call = 'getCzechShortDescription';
        $_code == "czech_short_description";
    }
}
$_className = $block->getCssClass();
$_attributeLabel = $block->getAtLabel();
$_attributeType = $block->getAtType();
$_attributeAddAttribute = $block->getAddAttribute();

$renderLabel = true;
if ($_attributeLabel == 'none') {
    $renderLabel = false;
}

if ($_attributeLabel && $_attributeLabel == 'default') {
    $_attributeLabel = $_product->getResource()->getAttribute($_code)->getStoreLabel();
}
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 <?= /* @escapeNotVerified */ $_className ?>">
    <?php if ($renderLabel): ?><strong class="type"><?= /* @escapeNotVerified */ $_attributeLabel ?></strong><?php endif; ?>
    <div class="value" <?= /* @escapeNotVerified */ $_attributeAddAttribute ?>><?= /* @escapeNotVerified */ $_attributeValue ?></div>
</div>
<?php endif; ?>

Flush magento cache and check

Hope this will help you!

9
  • Our file looks little diffrent. Can you please check our update?
    – Sylvester
    Nov 25, 2019 at 7:03
  • You don't need any change in html structure. just put condition above your code and change storeCode as per your store Nov 25, 2019 at 8:10
  • Ok, I add above, but now I see the same double short description. So I think we need implement this rule to our file code we add in topic. Can you please check again? Thank you. e-gerris.co.uk/catalog/product/view/id/90145/s/m83n00-f7v3
    – Sylvester
    Nov 25, 2019 at 8:18
  • Sorry i have checked code. but i m not able to check condition as per your code. bcoz i don't have configuration and all. You have to check your conditions why it happened Nov 25, 2019 at 8:35
  • Let me know have u changed anything in layout file for short description? Nov 25, 2019 at 8:37

Your Answer

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

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