Magento 2: How can display Name of Tax Rule on product page
-
15-04-2021 - |
Keine korrekte Lösung
Andere Tipps
Create Module with the following code, this will give you exactly that you are looking for :D
=> app/code/Vendor/Module/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Vendor_Module',
__DIR__
);
=> app/code/Vendor/Module/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Module" setup_version="0.0.1">
</module>
</config>
=> app/code/Vendor/Module/view/frontend/layout/catalog_product_view.xml
<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<referenceContainer name="product.info.main">
<block class="Vendor\Module\Block\TexRuleNames" name="tex.rule.names" template="Vendor_Module::product/view/text_rule_names.phtml" after="product.info.price" />
</referenceContainer>
</referenceContainer>
</body>
</page>
=> app/code/Vendor/Module/Block/TexRuleNames.php
<?php
namespace Vendor\Module\Block;
class TexRuleNames extends \Magento\Framework\View\Element\Template
{
public function __construct
(
\Magento\Tax\Model\TaxRuleCollection $taxRuleCollection,
\Magento\Framework\View\Element\Template\Context $context
)
{
$this->_taxRuleCollection = $taxRuleCollection;
parent::__construct($context);
}
public function getTextRuleNames()
{
return $this->_taxRuleCollection->getColumnValues('code');
}
}
=> app/code/Vendor/Module/view/frontend/templates/product/view/text_rule_names.phtml
<?php $TextRuleName = $block->getTextRuleNames(); ?>
<div class="text-rules">
<?php foreach ($TextRuleName as $rule): ?>
<h1><?php echo $rule; ?></h1>
<?php endforeach; ?>
</div>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange