2

I suppose I need to find Helper/Data method to get Magento Shipping->Ship To Specific Countries selected countries list. Where do I find it?

  • For which shipping method? – Sukumar Gorai Oct 3 '18 at 8:44
  • Default Magento shipping – Trenox Oct 3 '18 at 8:47
  • There are more than one shipping method then for which method you want this? For different method code will be different. – Sukumar Gorai Oct 3 '18 at 9:07
  • When going to admin panel Stores->Configuration->Sales->Shipping Methods->Magento Shipping->Ship to applicable countries->Specific countries. Then theres drop down menu of all countries from which you can choose. And I need to get a list of those selected countries for my custom module. – Trenox Oct 3 '18 at 9:12
1

Create a helper under your module like below:

app/code/Vendor/Module/Helper/Data.php

with below code:

<?php
namespace Vendor\Module\Helper;
use \Magento\Framework\App\Helper\AbstractHelper;

class Data extends AbstractHelper
{
    protected $scopeConfig;

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

    public function getSpecificCountries()
    {
        return $this->scopeConfig->getValue('carriers/temando/specificcountry', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
    }
}

To retrieve the value in block class, use the below code:

protected $helperData;

public function __construct(
    ....
    \Vendor\Module\Helper\Data $helperData,
    ....
) {
    ....
    $this->helperData = $helperData;
    ....
}

public function getSpecificCountries()
{
    return $this->helperData->getSpecificCountries();
}

Now you can call the block function getSpecificCountries() in your phtml file like below:

print_r($block->getSpecificCountries());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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