0

Magento version: 2.0.0

In ther Magento\Checkout\Block\Cart, there has a function is:

/**
 * @codeCoverageIgnore
 * @return int
 */
public function getItemsCount()
{
    return $this->getQuote()->getItemsCount();
}

getQuote() is from the Class AbstractCart because Cart is extends \Magento\Checkout\Block\Cart\AbstractCart.

According the Eclipse helping, getItemsCount() should be from Magento\Quote\Model\Quote.

In \Magento\Checkout\Block\Cart\AbstractCart, the Class Quote is just only invoked with use keywords but not initialize or extend.

So, I am confused the relationship of getQuote() with getItemsCount(). getQuote() is not extend from Quote class, why it can use the getItemsCount() of Quote?

0

Here's the code from vendor/magento/module-checkout/Block/Cart/AbstractCart.php:

public function getQuote()
{
    if (null === $this->_quote) {
        $this->_quote = $this->_checkoutSession->getQuote();
    }
    return $this->_quote;
}

$this->_$quote is an object of Magento/Quote/Model/Quote class. Thus, the relationship is quite certain.

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.