I try create custom module config in magento2. This code add field productzoom

Source file: Xyaddons\Productzoom\etc\adminhtml\system.xml.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd">
         <tab id="catalog" translate="label" sortOrder="200">
        <section id="catalog" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
            <group id="productzoom" translate="label" type="text" sortOrder="200" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Xyaddons Productzoom(Product views page)</label>
                <field id="flat_xyaddons_productzoom" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
                   <!-- <backend_model>Magento\Catalog\Model\Indexer\Category\Flat\System\Config\Mode</backend_model> -->
                <field id="list_zoom_style" translate="label" type="select" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Set style zoom</label>

source File Productzoom.php : Xyaddons\Productzoom\Model\Config\Source\Productzoom

 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
namespace Xyaddons\Productzoom\Model\Config\Source;

class Productzoom implements \Magento\Framework\Option\ArrayInterface
     * {@inheritdoc}
     * @codeCoverageIgnore
    public function toOptionArray()
        return [
            ['value' => 'tints', 'label' => __('Tints')],
            ['value' => 'easing', 'label' => __('Easing')]

how do get value in frontend?

  • is there any error you are facing? Code seems fine
    – Keyur Shah
    Nov 2, 2015 at 5:23
  • plese clean cache after update/add config file
    – KAndy
    Nov 2, 2015 at 6:01

1 Answer 1

/** @var \Magento\Framework\App\Config\ScopeConfigInterface */
protected $scopeConfig;

 * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig    
public function __construct(
    \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
) {
    $this->scopeConfig = $scopeConfig;

 * Fetch config value for above case
 * @return string
public function getCustomConfigValue()
    return $this->scopeConfig->getValue('catalog/productzoom/flat_xyaddons_productzoom');

In your .phtml file, call:

echo $block->getCustomConfigValue();

Your Answer

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

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