I was working on the shipping part, but I found that some functions' declaration can not be found in the code repository. For example, in the 1000th line of


$shippingRates = $result->getAllRates();


I searched the whole mangento 2 repository, but I could not find something like

public function getAllRates(){ //....}

Is there any mechanism in Magento 2 that will auto generate functions?

2 Answers 2


The getAllRates method is not a direct method as you assumed, understand that it does not process anything it is a simple getter.

What happens in the app/code/Magento/Quote/Model/Quote/Address.php is that first, this line is called:

$result = $this->_rateCollector->create()->collectRates($request)->getResult();

The collectRates method is called, this method is implemented by every carrier model that implements the RateCollectorInterface interface.

This collectRates method returns a Magento\Shipping\Model\Rate\Result object which is retrieved by the getResult() method.

Then the getAllRates() method is called from Magento\Shipping\Model\Rate\Result:

public function getAllRates()
    return $this->_rates;

The _rates variable is set via the Magento\Quote\Model\Quote\Address\RateResult\MethodFactory directly in the carrier model, most of the time with code that looks like this:

$rate = $this->_rateMethodFactory->create();
$rate->setMethodTitle($this->getCode('method', $method));

Check in Magento\Shipping\Model\Rate\Result around line 90:

     * Return all quotes in the result
     * @return array
    public function getAllRates()
        return $this->_rates;

This is what you are looking for.

Anyway, in Magento2 there are some automatically created classes and methods, but not for this kind of functions. Mainly for plugins and factories.

Hope it helps.

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.