Customer Portal

Get Involved. Join the Conversation.

Topic

    Richard Keevil
    "Fatal error" with custom widget & modelAnswered
    Topic posted November 12, 2015 by Richard KeevilGold Trophy: 10,000+ Points 
    621 Views, 7 Comments
    Title:
    "Fatal error" with custom widget & model
    Content:

    I have extended a widget and model which works perfectly on the home page, when I use it on the product/detail page I get:

    Fatal error: Call to undefined method RightNow\Models\Prodcat::getExtendedDirectDescendants() in /cgi-bin/**site**.cfg/scripts/cp/customer/development/widgets/custom/navigation/ExtendedVPCS/1.0/controller.php on line 13

    Line 13:

    if (!$items = $this->CI->model('Prodcat')->getExtendedDirectDescendants($hierarchyType, $itemID)->result) return false;
    

    Prodcat has been extended into CustomProdcat which contains getExtendedDirectDescendants(). The Prodcat is overridden with an appropriate entry in config/extensions.yml.

    The widget extends VisualProductCategorySelector which provides a visual way to navigate through your product structure but adds a count of questions, comments and views per visible product.  When you click a product icon it navigates you down the product hierarchy via product/detail/p/*ProductID* page.  Widget works as intended on app/home but I get this error when I click through to a product detail page such as app/products/detail/p/123 or when I manually navigate to an equivalent page.

    If I also change the function back to the original in the widget controller, it works.

    When I add the widget to app/questions/detail/ or app/social/ask it works fine, albeit as it would appear on the home page.

    app/home - Works

    app/questions/detail - Works

    app/questions/detail/qid/44 - Works

    app/products/detail/ - Works

    app/products/detail/p/712 - Breaks :(

    Version:
    Aug2015 3.3.1
    Code Snippet:

    Best Comment

    Jeremy Watson

    Richard,

    I think you've unfortunately run into a subtle bug with the Prodcat model where the framework references it as 'ProdCat' instead of 'Prodcat'.  We will try and get a fix in for this soon.

    As a work-around, try adding this before the class declaration in your custom model:

    require_once CPCORE . 'Models/Prodcat.php';

    That should get your home page working without trying to use extensions.yml.

    Let me know if this works or not and I can try and investigate further.

    Thanks.

    James

    Comment

     

    • Richard Keevil

      Interestingly, if I comment out my extensions.yml override, I get the same error on every page I have the widget.  Almost as if the app/products/detail page isn't honouring the extensions.yml file.

      ModelExtensions:
      #Prodcat: CustomProdcat

    • Richard Keevil

      Other custom widgets and models I have written in the same way work on this page.  If I reference the custom model as below it also works.  I think there is a Framework bug here somewhere.

      Broken

      if (!$items = $this->CI->model('Prodcat')->getExtendedDirectDescendants($hierarchyType, $itemID)->result) return false;
      

      Works

      if (!$items = $this->CI->model('custom/CustomProdcat')->getExtendedDirectDescendants($hierarchyType, $itemID)->result) return false;
      

       

    • Barrilito van Dijk

      Hi Richard,

      I have not read this post completely, but in the beginning you state:

      Prodcat has been extended into CustomProdcat...

      Then you state that this does not work:

      if (!$items = $this->CI->model('Prodcat')->getExtendedDirectDescendants($hierarchyType, $itemID)->result) return false;
      

      Seems logical, as $this->CI->model('Prodcat') refers to the standard model which has no getExtendedDirectDescendants method.

      You should do it like you stated:

      if (!$items = $this->CI->model('custom/CustomProdcat')->getExtendedDirectDescendants($hierarchyType, $itemID)->result) return false;
      

      I think this is how it should be, or am I missing something?

    • Richard Keevil

      I use the widget on 2 pages: model app/home and products/detail.

      When my widget controller uses ('Prodcat'), it works fine on app/home, but on products/detail I get the error

      Fatal error: Call to undefined method RightNow\Models\Prodcat::getExtendedDirectDescendants() in /cgi-bin/**site**/scripts/cp/customer/development/widgets/custom/navigation/ExtendedVPCS/1.0/controller.php on line 13

      When my widget controller uses ('custom/CustomProdcat'), it works fine on products/detail but on app/home I get the error:

      Fatal error: Class 'RightNow\Models\Prodcat' not found in /cgi-bin/**site**/scripts/cp/customer/development/models/custom/CustomProdcat.php on line 8

      If I add a widget call to the widget I have extended from, immediately before it, it works fine everywhere when I use ('custom/CustomProdcat') in the controller.

      Here are the key bits from the headers of the model and controller.

      namespace Custom\Models;
      use RightNow\Connect\v1_2 as Connect;
      
      class CustomProdcat extends \RightNow\Models\Prodcat {
          function __construct() {
              parent::__construct('Prodcat');
          }
      
          public function getExtendedDirectDescendants($filterType, $id = null)
      
      
      namespace Custom\Widgets\navigation;
      use RightNow\Utils\Url;
      class ExtendedVPCS extends \RightNow\Widgets\VisualProductCategorySelector {
          function __construct($attrs) {
              parent::__construct($attrs);
          }
          
          function getData() {
              $hierarchyType = $this->data['attrs']['type'];
              $itemID = $this->data['attrs']['show_sub_items_for'] ?: null;
      
              if (!$items = $this->CI->model('custom/CustomProdcat')->getExtendedDirectDescendants($hierarchyType, $itemID)->result) return false;
      
      
    • Jeremy Watson

      Richard,

      I think you've unfortunately run into a subtle bug with the Prodcat model where the framework references it as 'ProdCat' instead of 'Prodcat'.  We will try and get a fix in for this soon.

      As a work-around, try adding this before the class declaration in your custom model:

      require_once CPCORE . 'Models/Prodcat.php';

      That should get your home page working without trying to use extensions.yml.

      Let me know if this works or not and I can try and investigate further.

      Thanks.

      James

    • Barrilito van Dijk

      Nice update/explanation James, appreciated!

    • Richard Keevil

      Thanks James, your temporary work around worked a treat.