2

In Magento 2.1.x Lets say I want to show the minimum order amount for free shipping in a block somewhere in my website, how can I retrieve this value?

The setting has been configured in Stores > Configuration > Sales > Shipping Methods > Free Shipping > **Minimum Order Amount**

Dynomite
  • 632
  • 1
  • 6
  • 19

1 Answers1

4

You have to retrieve the good config path and use this method : https://magento.stackexchange.com/a/78473/33619

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

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

/**
 * @return float
 */
public function getFreeShippingSubtotal()
{
    return $this->scopeConfig->getValue('carriers/freeshipping/free_shipping_subtotal', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}

We need to call the default method available.

Just Use \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, In your constructor argument and set the class property: $this->scopeConfig = $scopeConfig;

Now to Get the configuration value just use
$this->scopeConfig->getValue('dev/debug/template_hints', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

Matthéo Geoffray
  • 2,684
  • 2
  • 20
  • 45