Mostaq mahmud
Mostaq mahmud

Reputation: 93

How to call model class method from controller in megento?

I have created a new model class in checkout/type name Cartpage.php and it has a method name addValue($id). Want to call this model class method from saveShippingMethodAction() in OnepageController.php at Checkout/controllers. I have called in several ways but it gives me an error:

Fatal error: Call to a member function addValue() on a non-object in .../app/code/core/Mage/Checkout/controllers/OnepageController.php

I have tried:

$myModel = Mage::getSingleton('checkout/cartpage');
$return = $myModel->addValue($my_value);

Model:

class Mage_Checkout_Model_Type_Cartpage extends  Mage_Sales_Model_Quote_Address_Total_Abstract
{
        public function addValue($value)
    {
    return $value;
    }

}

How can I call my custom model from OnepageController?

Upvotes: 0

Views: 3282

Answers (1)

Justus Krapp
Justus Krapp

Reputation: 1116

If your module is located under Checkout/Model/Type/Cartpage.php the correct classgroupto call is checkout/type_cartpage
so use Mage::getSingleton('checkout/type_cartpage'); instead of Mage::getSingleton('checkout/cartpage');

However it looks like you are adding your model class under the core namespace which is a nogo in magento.

create you own module und the local namespace and create rewrites for the parts you want/need to change

Upvotes: 4

Related Questions