0

I would like to create a custom module, I want to get used to the vendor/magento/module-ups/ module, and use the same config in my custom module, such as userID, password, access key.

how can I include it in my custom module?

I want to get used to the below function in my custom module.

Please advise.

    protected function setXMLAccessRequest()
    {
        $userId = $this->getConfigData('username');
        $userIdPass = $this->getConfigData('password');
        $accessKey = $this->getConfigData('access_license_number');

        $this->_xmlAccessRequest = <<<XMLAuth
<?xml version="1.0" ?>
<AccessRequest xml:lang="en-US">
  <AccessLicenseNumber>$accessKey</AccessLicenseNumber>
  <UserId>$userId</UserId>
  <Password>$userIdPass</Password>
</AccessRequest>
XMLAuth;
    }

1 Answer 1

0

You could have your class extend Magento\Shipping\Model\Carrier\AbstractCarrierOnline which should allow you to call the public getConfigData() function. That function is defined in Magento\Shipping\Model\Carrier\AbstractCarrier, however AbstractCarrierOnline extends that on, so for the sake of having that function available either of those two abstract classes should to the trick.

A more general answer - often, but not exclusively, seen in Magento\SomeModule\Helper\Data classes - is to create a helper class for your module as well, extend Magento\Framework\App\Helper\AbstractHelper and do something similar to

$storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
$sys_conf_val = $this->scopeConfig->getValue('sys/conf/valpath', $storeScope));

Your Answer

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

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