1

The custom api function call fails with error message "Resource path not callable" after compilation is enabled. The custom api works as expected when compilation is not enabled.

Question

Is it possible to configure a custom Magento api so that it can be called when both compilation is disabled AND enabled in versions 1.5 and above?

2 workarounds will succeed with compilation enabled :

Workaround #1:

Rename the compiled file from (lowercase the v in V2):

/includes/src/MyApi_Test_Model_Objectmodel_Api_V2.php

to

/includes/src/MyApi_Test_Model_Objectmodel_Api_v2.php

Note: this must be executed after compilation is enabled, and done each time compilation occurs

Workaround #2:

Rename the original V2.php file to v2.php in :

/app/code/local/MyApi/Test/Model/Objectmodel/Api/V2.php

Note: this will fix the api function to succeed 100% of the time when compilation is enabled, but removing the V2.php will break the v2 usage when compilation is disabled. Having BOTH a V2.php and a v2.php will fix both scenarios, but it appears that the 2 files cannot be bundled together for deployment (in addition to not being DRY).

EDIT Adding more details.


I've traced the execution and issue using this very helpful answer, and have come to the following conclusions (all code is taken from version 1.9.1.0 CE):

The V2.php is searched for in the includes/src directory as /includes/src/MyApi_Test_Model_Objectmodel_Api_v2.php.

The "call" function in /var/www/html/includes/src/Mage_Api_Model_Server_Handler_Abstract.php contains the following line :

$modelName = $this->_prepareResourceModelName((string) $resources->$resourceName->model);

and _prepareResourceModelName will append the _resourceSuffix, if it exists, which in this case is '_v2' because it is called in :

/app/code/core/Mage/Api/Model/Server/V2/Handler.php 
protected $_resourceSuffix = '_v2';

The output becomes :

$resources->$resourceName->model=MyApi_Test_Model_Objectmodel_Api

modelName : MyApi_Test_Model_Objectmodel_Api_v2

Community
  • 1
  • 1
Joe Carr
  • 313
  • 1
  • 9

1 Answers1

1

but removing the V2.php will break the v2 usage when compilation is disabled

The right thing to do here is to fix your extension so it works with the class file named V2.php. Uppercased word segments (i.e. Uppercase_Word_Segments are Magento's standard for class names, and using a different convention will likely cause other problems.

Alana Storm
  • 164,128
  • 91
  • 395
  • 599
  • Absolutely! I'm trying to understand if that is possible. Is it a problem with my extension's configuration, or will a V2.php file name ever be searched for in a compiled state as _V2.php? – Joe Carr Dec 21 '15 at 20:40