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;
 }
Viral Patel
1,1001 gold badge8 silver badges17 bronze badges
asked Mar 23, 2022 at 20:39

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));
answered Mar 23, 2022 at 22:44

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.