I have a a module that makes a soap call to a service to retrieve live shipping quotes, and it returns a bunch of data, an import fee being one of those things it returns.

I have created a new AbstractTotal class called ImportFee and I need a way to set the amount of this fee to be the amount of the user's selected shipping rate's import fee. I have already stored the import fee on my shipping rates in an extension_attribute, I just do not know how I am supposed to obtain the object from the AbstractTotal class.

If some code is needed, please ask which code would be specific. I do not want to spam this with a bunch of code. The concept is the same.

I have an extension_attribute on my shipping rate, and I need to set an AbstractTotal class value to that extension_attribute. Thanks!

3 Answers 3


Declare \Magento\Checkout\Model\Cart in construct of your class.

Try following snippet:

protected $_cart;

public function __construct (
    \Magento\Framework\App\Helper\Context $context,
    \Magento\Checkout\Model\Cart $_cart
) {
    $this->_cart = $_cart;

Then you can do following:

$shippingAmount = $this->_cart->getQuote()->getShippingAddress()->getShippingAmount();

In Magento 2 YOu can use this Code:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$cart = $objectManager->get('\Magento\Checkout\Model\Cart');


To get selected shipping rate from current quote please use below code:

quote = Mage::getModel("checkout/session")->getQuote();
$amount = $quote->getShippingAddress()->getShippingAmount();
  • I should have clarified I am on magento 2. I will update my question, and I am not looking for the shipping amount, I am looking for an attribute_extension i put on the shipping rate Mar 23, 2017 at 16:35

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.