For main website example: mywebsite.pl
- A short description of the product is displayed from the attribute short_descrption
.
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";
}
}