I am trying to get backend model class name from system.xml
Right now i am using this code.
magento/app/code/Company/Sso/etc/adminhtml/system.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="admin">
<group id="sso_saml" translate="label" sortOrder="100" showInDefault="1" showInWebsite="0" showInStore="0" >
<label>Single Sign on(SAML)</label>
<field id="is_enabled" translate="label comment" type="select" sortOrder="0" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Is Enabled SAML</label>
<comment>Enable Single Sign On</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</section>
</system>
Magento Code
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$structure = $objectManager->create('Magento\Config\Model\Config\StructureFactory');
$field = $objectManager->create('Magento\Config\Model\Config\Structure')->getElementByConfigPath('admin/sso_saml/is_enabled');
print json_encode($field->getData());
Output:
{"id":"is_enabled","path":"admin/sso_saml","_elementType":"field"}
But i need source_model, can anyone help?
You need to be in the adminhtml area in order to load the rest of the data:
e.g
<?php
require __DIR__ . '/app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$appState = $objectManager->get('Magento\Framework\App\State');
$appState->setAreaCode('adminhtml');
$field = $objectManager->create('Magento\Config\Model\Config\Structure')->getElementByConfigPath('customer/create_account/auto_group_assign');
echo $field->getData()['source_model'];
> Magento\Config\Model\Config\Source\Yesno
You could potentially use \Magento\Framework\App\State::emulateAreaCode to fetch the data from within a non-admin context if necessary.
Here is full solution after implementing Matt's solution.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$appState = $objectManager->get('Magento\Framework\App\State');
$field = $appState->emulateAreaCode('adminhtml', function($path){
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$appState = $objectManager->get('Magento\Framework\App\State');
$appState->setAreaCode('adminhtml');
$field = $objectManager->create('Magento\Config\Model\Config\Structure')
->getElementByConfigPath($path->getPath());
return $field;
}, [$path]);
$value = $path->getData()['backend_model'];
Related
Been spending the last 1 day to find a fix for this.
Basically everything works normal if I delete all the contents of generated folder and then generate the files dynamically by accessing the pages rather than doing setup:di:compile.
On the production though, I'm forced to do setup:di:compile and I end up with this certain admin module page being empty.
This is the controller of the page:
namespace Eadesigndev\AWB\Controller\Adminhtml\Index;
use Eadesigndev\Awb\Api\AwbRepositoryInterface;
use Eadesigndev\Awb\Model\Awb;
use Eadesigndev\Awb\Model\AwbFactory;
use Eadesigndev\Awb\Helper\Data as DataHelper;
use Magento\Framework\Registry;
use Magento\Backend\App\Action\Context;
use Magento\Backend\Model\Session;
use Magento\Framework\View\Result\PageFactory;
use Magento\Backend\App\Action;
class Edit extends Action
{
/**
* Authorization level of a basic admin session
*
*
*/
const ADMIN_RESOURCE = 'Eadesigndev_Awb::awb';
protected $resultPageFactory;
private $awbRepository;
private $awbFactory;
private $registry;
private $session;
private $dataHelper;
private $awbModel;
public function __construct(
Context $context,
PageFactory $resultPageFactory,
AwbRepositoryInterface $awbRepository,
AwbFactory $awbFactory,
Awb $awbModel,
Registry $registry,
DataHelper $dataHelper
) {
$this->resultPageFactory = $resultPageFactory;
$this->awbRepository = $awbRepository;
$this->awbFactory = $awbFactory;
$this->registry = $registry;
$this->awbModel = $awbModel;
$this->session = $context->getSession();
$this->dataHelper = $dataHelper;
parent::__construct($context);
}
/**
* Edit action new awb.
*
* #return \Magento\Backend\Model\View\Result\Page
*/
public function execute()
{
$id = $this->getRequest()->getParam('entity_id');
if ($id) {
$model = $this->awbRepository->getById($id);
if (!$model->getEntityId()) {
$this->messageManager->addErrorMessage(__('This field no longer exists.'));
/** \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create();
return $resultRedirect->setPath('*/*/');
}
} else {
echo '3';
$model = $this->awbFactory->create();
}
/** #var Session $data */
$data = $this->session->getFormData(true);
if (!empty($data)) {
$model->setData($data);
}
$this->registry->register('awb_data', $model);
echo 'wat';
/** #var \Magento\Backend\Model\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$resultPage->addBreadcrumb(__('Edit new Awb'), __('Edit new Awb'));
$resultPage->getConfig()->getTitle()->prepend(__('Edit new Awb'));
echo 'pac';
return $resultPage;
}
the controller currently returns a blank page with my debug strings:
3watpac
in /vendor/eadesignro/awb/Block/Adminhtml/Xtea I have the next files:
Edit (folder)
Edit.php
EditAwb.php
in /vendor/eadesignro/awb/view/adminhtml/layout I have the next files:
shipping_awb_index_edit.xml
shipping_awb_index_editawb.xml
shipping_awb_index_index.xml
Content of shipping_awb_index_edit.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="editor"/>
<head></head>
<body>
<referenceContainer name="content">
<block class="Eadesigndev\Awb\Block\Adminhtml\Xtea\Edit" name="awb_edit"/>
</referenceContainer>
<referenceContainer name="left">
<block class="Eadesigndev\Awb\Block\Adminhtml\Xtea\Edit\Tabs" name="awb_edit_tabs">
<block class="Eadesigndev\Awb\Block\Adminhtml\Xtea\Edit\Tab\General" name="awb_edit_tab_general"/>
<action method="addTab">
<argument name="name" xsi:type="string">general_section</argument>
<argument name="block" xsi:type="string">awb_edit_tab_general</argument>
</action>
<block class="Eadesigndev\Awb\Block\Adminhtml\Xtea\Edit\Tab\Curier" name="awb_edit_tab_curier"/>
<action method="addTab">
<argument name="name" xsi:type="string">curier_section</argument>
<argument name="block" xsi:type="string">awb_edit_tab_curier</argument>
</action>
</block>
</referenceContainer>
</body>
</page>
This is the page:
magento_admin_secreturl/shipping_awb/index/edit/key/xxxxxx
these are the routers:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
<route id="shipping_awb" frontName="shipping_awb">
<module name="Eadesigndev_Awb" before="Magento_Backend"/>
</route>
<route id="edit_awb" frontName="edit_awb">
<module name="Eadesigndev_Awb" before="Magento_Backend"/>
</route>
</router>
</config>
Any possible idea on why $this->resultPageFactory->create(); is simply returning nothing on production but working on development?
The index page works both on production and dev without any problem.
I can provide more info if needed, thank you!
The problem was a CAPSLOCK mistake in the namespace.
namespace Eadesigndev\AWB\Controller\Adminhtml\Index;
should have been
namespace Eadesigndev\Awb\Controller\Adminhtml\Index;
notice the 'AWB' becoming 'Awb'.
Apparently in development mode, the namespaces are not case-sensitive? or perhaps they are all transformed to capslock. If anyone has a clue, leave a comment, thanks!
For anyone who is still getting a blank page in Admin Controller, but the alternative solutions (case-sensitive) doesn't work for you, you may try running php bin/magento setup:di:compile.
This helped me.
I'm new to Joomla, especially to component development. Anyway, here's my question:
site\views\plaingallery\tmpl\default.xml
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<layout title="COM_PLAINGALLERY_PLAINGALLERY_VIEW_DEFAULT_TITLE">
<message>
<![CDATA[COM_PLAINGALLERY_PLAINGALLERY_VIEW_DEFAULT_DESC]]>
</message>
</layout>
<fields name="request"
addfieldpath="/administrator/components/com_plaingallery/models/fields">
<fieldset name="request">
<field name="galleryFolder" type="folderlist" default="" recursive="true"
label="Select a folder" directory="images" filter="" exclude="" width="300"
hide_none="true" hide_default="true" stripext="" />
</fieldset>
</fields>
</metadata>
site\views\plaingallery\view.html.php
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla view library
jimport('joomla.application.component.view');
/**
* HTML View class for the PlainGallery Component
*/
class PlainGalleryViewPlainGallery extends JViewLegacy
{
// Overwriting JView display method
function display($tpl = null)
{
// Assign data to the view
$this->msg = 'I am new to Joomla';
// Display the view
parent::display($tpl);
}
}
My question is: How do I access the value from the field[name="galleryFolder"] the user provided in the menu configuration?
Thanks for your help! I really do appreciate it.
This parameter is located in the query variable of the menu item.
You can try this for example:
$app = JFactory::getApplication();
/* Default Page fallback*/
$active = $app->getMenu()->getActive();
if (NULL == $active) {
$active = $app->getMenu()->getDefault();
}
if ( isset($active->query['galleryFolder']) ) {
$galleryFolder = $active->query['galleryFolder'];
}
I try to create a plugin which will display some text after creation of article in the editor.
/editors/materialwords/materialwords.xml:
<?xml version="1.0" encoding="utf-8"?>
<extension version="3.1" type="plugin" group="editors">
<name>Editor Material Words Count Plugin</name>
<creationDate>December 2016</creationDate>
<author>Aleksandr Lapenko</author>
<authorEmail>lapenkoak#gmail.com</authorEmail>
<authorUrl>vk.com/web_rider</authorUrl>
<copyright>Copyright</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<version>1.0.0</version>
<description>Calculate articles words count</description>
<files>
<filename plugin="materialwords">materialwords.php</filename>
</files>
<config>
<fields name="params">
<fieldset name="basic">
<field name="displayCount" type="text"
label="Display Count"
description="Words display count"
required="true"
size="10"
class="inputbox" />
</fieldset>
</fields>
</config>
</extension>
/editors/materialwords/materialwords.php:
<?php
defined('_JEXEC') or die;
class PlgEditorMaterialwords extends JPlugin
{
public function onSave($id)
{
return 'alert("' . $id . '");';
}
}
I install plugin and enable it. But something wrong (nothing when I save article in editor).
Please, help.
Best regards, Aleksandr.
if you want a plugin before save or after save event
onExtensionBeforeSave
onExtensionAfterSave
Actually editors plugins are type of editors that you can use in joomla back office, if you go in system - configuration in back office, for default editor you'll can choose your plugin because it is an editors plugin.
If you want to perform some action after save an article you'll have to write a content plugin with method onContentAfterSave(). This method takes 3 arguments :
$context, in your case it should be com_content.article, so test it before soing anything else
$article, the instance of the article you are saving
$isNew, a boolean, true if it is a new article, false if it is an udpate
Plugin code
class PlgContentMaterialwords extends JPlugin {
public function onContentAfterSave($context, $article, $isNew){
if ($context != 'com_content.content'){
return true;
}
// do stuff
}
}
Plugin declaration
<?xml version="1.0" encoding="utf-8"?>
<extension version="3.1" type="plugin" group="content">
<name>Editor Material Words Count Plugin</name>
<creationDate>December 2016</creationDate>
<author>Aleksandr Lapenko</author>
<authorEmail>lapenkoak#gmail.com</authorEmail>
<authorUrl>vk.com/web_rider</authorUrl>
<copyright>Copyright</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<version>1.0.0</version>
<description>Calculate articles words count</description>
<files>
<filename plugin="materialwords">materialwords.php</filename>
</files>
<config>
<fields name="params">
<fieldset name="basic">
<field name="displayCount" type="text"
label="Display Count"
description="Words display count"
required="true"
size="10"
class="inputbox" />
</fieldset>
</fields>
</config>
</extension>
Plugin to override save in javascript
With previous method you can not add javascript in this page. If you want to do such you have to add a onBeforeRender method. When clicking on an admin button, javascript method Joomla.submitbutton is called, so you can override it (take care of saving it before so you can call it after your process).
class PlgContentMaterialwords extends JPlugin
{
public function onBeforeRender()
{
if ( JFactory::getApplication()->isAdmin() ){
$document = JFactory::getDocument();
$document->addScriptDeclaration('
var Myvar = {};
Myvar.submitbutton = Joomla.submitbutton;
Joomla.submitbutton = function(task) {
if ( task == "article.save" || task == "article.apply" || task == "article.save2new" ){
alert("foo");
}
Myvar.submitbutton(task);
}
');
}
}
}
I am playing around with a custom build module in Joomla 3.x that uses Ajax to display some real-time data. Within the function executed by the Ajax call I need to access the module parameters and I'm not sure how to do this. Normally, I could just put $var = $params('paramName', 'default') in the module PHP file to get the param but this is not available when the call is made by Ajax. This is my template code that executes the Ajax call:
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery.get('index.php?option=com_ajax&module=whatsinport&method=getWhatsInPort&format=json', function(data) {
console.log(data);
var response = jQuery.parseJSON(data);
This is the code in my helper.php class:
class modWhatsInPortHelper {
public static function getWhatsInPortAjax()
{
$results = array();
$results['status'] = 'ok';
$app = JFactory::getApplication();
$serverName = $app->getCfg('mod_whatsinport_serverName');
$dbName = $app->getCfg('mod_whatsinport_dbName');
$dbUser = $app->getCfg('mod_whatsinport_dbUser');
$dbPwd = $app->getCfg('mod_whatsinport_dbPwd');
$connectionInfo = array( "Database"=>$dbName, "UID"=>$dbUser, "PWD"=>$dbPwd, "ReturnDatesAsStrings"=>true);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
The $app->getCfg does not appear to do what I want - I am guessing it is only used for Joomla config settings. I also tried:
$app = JFactory::getApplication();
$params = $app->getParams();
$serverName = $params->get('mod_whatsinport_serverName');
$dbName = $params->get('mod_whatsinport_dbName');
$dbUser = $params->get('mod_whatsinport_dbUser');
$dbPwd = $params->get('mod_whatsinport_dbPwd');
But this didn't work either. I forgot to include my module config file:
<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="3.1.0" client="site" method="upgrade">
<name>WhatsInPort</name>
<author>Chris Krohn</author>
<version>1.0.0</version>
<description>Displays a list of current vessels in port.</description>
<files>
<filename>mod_whatsinport.xml</filename>
<filename module="mod_whatsinport">mod_whatsinport.php</filename>
<filename>index.html</filename>
<filename>helper.php</filename>
<filename>tmpl/default.php</filename>
<filename>tmpl/index.html</filename>
</files>
<config>
<fields name="params">
<fieldset name="basic">
<field name="mod_whatsinport_serverName" type="text" default="" label="Server Name" description="NETBIOS name of the database server to connect to." />
<field name="mod_whatsinport_dbName" type="text" default="" label="Database Name" description="Name of the database with the HMLOG table." />
<field name="mod_whatsinport_dbUser" type="text" default="" label="Database User" description="User name to login to the server with." />
<field name="mod_whatsinport_dbPwd" type="password" default="" label="Database Password" description="Password to login to the server with." />
</fieldset>
</fields>
</config>
</extension>
Figured it out. Should be:
$app = JFactory::getApplication();
$module = JModuleHelper::getModule('mod_whatsinport','WhatsInPort');
$params = new JRegistry($module->params);
$serverName = $params->get('mod_whatsinport_serverName');
$dbName = $params->get('mod_whatsinport_dbName');
$dbUser = $params->get('mod_whatsinport_dbUser');
$dbPwd = $params->get('mod_whatsinport_dbPwd');
Retrieve data of a parameter within the getjax() method.
public static function getAjax(){
$app = JFactory::getApplication();
$module = JModuleHelper::getModule('my_module');
$params = new JRegistry($module->params);
return $params ->get('myparams');
}
I have been trying to extend the REST API of magento to add configurable product, but I run into the error 405 - Resource Method Not Implemented.
This is my api.xml:
<?xml version="1.0"?>
<config>
<api>
<resources>
<extapi_catalog translate="title" module="extapi">
<model>extapi/catalog_api2</model>
<title>Extapi Catalog API</title>
<acl>extapi/product</acl>
<methods>
<list translate="title" module="extapi">
<title>Retrieve Product Count</title>
<method>count</method>
<acl>extapi/product/info</acl>
</list>
<create translate="title" module="extapi">
<title>Create products</title>
<acl>extapi/product/create</acl>
</create>
<update translate="title" module="extapi">
<title>Update products</title>
<method>update</method>
<acl>extapi/product/update</acl>
</update>
<delete translate="title" module="extapi">
<title>Delete products</title>
<method>delete</method>
<acl>extapi/product/delete</acl>
</delete>
</methods>
<faults module="extapi">
<data_invalid>
<code>100</code>
<message>Invalid Request. Details in error message.</message>
</data_invalid>
<filters_invalid>
<code>101</code>
<message>Invalid filters specified. Details in error message.</message>
</filters_invalid>
<not_exists>
<code>102</code>
<message>No products.</message>
</not_exists>
<not_deleted>
<code>103</code>
<message>Product not deleted. Details in error message.</message>
</not_deleted>
</faults>
</extapi_catalog>
</resources>
<v2>
<resources_function_prefix>
<extapi_catalog>extapi_catalog</extapi_catalog>
</resources_function_prefix>
</v2>
<acl>
<resources>
<extapi_catalog translate="title" module="extapi">
<title>Catalog</title>
<sort_order>3</sort_order>
<info translate="title" module="extapi">
<title>Retrieve product count</title>
</info>
<create translate="title" module="extapi">
<title>Create product count</title>
</create>
<update translate="title" module="extapi">
<title>Update product count</title>
</update>
<delete translate="title" module="extapi">
<title>Delete product count</title>
</delete>
</extapi_catalog>
</resources>
</acl>
</api>
</config>
this is my api2.xml:
<?xml version="1.0"?>
<config>
<api2>
<resource_groups>
<extapi translate="title" module="api2">
<title>Magepim API calls</title>
<sort_order>30</sort_order>
<children>
<extapi_product translate="title" module="api2">
<title>Product</title>
<sort_order>50</sort_order>
</extapi_product>
</children>
</extapi>
</resource_groups>
<resources>
<extapiproducts translate="title" module="api2">
<group>extapi_product</group>
<model>extapi/catalog_api2_product</model>
<working_model>extapi/catalog_api2_product</working_model>
<title>Catalog Product</title>
<sort_order>10</sort_order>
<privileges>
<admin>
<create>1</create>
<retrieve>1</retrieve>
<update>1</update>
<delete>1</delete>
</admin>
</privileges>
<attributes translate="product_count" module="api2">
<product_count>Product Count</product_count>
<catalog_size>Product Count</catalog_size>
</attributes>
<entity_only_attributes>
<catalog>
<read>
<has_custom_options>1</has_custom_options>
<tier_price>1</tier_price>
<total_reviews_count>1</total_reviews_count>
<url>1</url>
<buy_now_url>1</buy_now_url>
<has_custom_options>1</has_custom_options>
<is_in_stock>1</is_in_stock>
</read>
</catalog>
</entity_only_attributes>
<exclude_attributes>
<catalog>
<read>
<attribute_set_id>1</attribute_set_id>
<stock_data>1/</stock_data>
<use_config_gift_message_available>1</use_config_gift_message_available>
<use_config_gift_wrapping_available>1</use_config_gift_wrapping_available>
<url_key_create_redirect>1</url_key_create_redirect>
</read>
</catalog>
<admin>
<read>
<product_count>1</product_count>
</read>
</admin>
</exclude_attributes>
<routes>
<route_entity_count>
<route>/magepim/products</route>
<action_type>entity</action_type>
</route_entity_count>
</routes>
<versions>1</versions>
</extapiproducts>
</resources>
</api2>
</config>
and this is my V1.php:
<?php
/**
* Override for Magento's Catalog REST API
*/
class Magepim_Extapi_Model_Catalog_Api2_Product_Rest_Admin_V1 extends Mage_Catalog_Model_Api2_Product_Rest {
/**
* Retrieves the catalog collection and returns it's size
*
* #return int
*/
protected function _retrieve()
{
/** #var $collection Mage_Catalog_Model_Resource_Product_Collection */
$collection = Mage::getResourceModel('catalog/product_collection');
$store = $this->_getStore();
$collection->setStoreId($store->getId());
$collection->addAttributeToSelect(array_keys(
$this->getAvailableAttributes($this->getUserType(), Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ)
));
$this->_applyCategoryFilter($collection);
$this->_applyCollectionModifiers($collection);
$products = $collection->load()->toArray();
$size = $collection->getSize();
$productCount = new stdClass();
$productCount->catalog_size=$size;
//return $size;
return json_encode($productCount);
}
protected function _create($data)
{
/* #var $validator Mage_Catalog_Model_Api2_Product_Validator_Product */
$validator = Mage::getModel('catalog/api2_product_validator_product', array(
'operation' => self::OPERATION_CREATE
));
if (!$validator->isValidData($data)) {
foreach ($validator->getErrors() as $error) {
$this->_error($error, Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
}
$this->_critical(self::RESOURCE_DATA_PRE_VALIDATION_ERROR);
}
$type = $data['type_id'];
if ($type !== 'simple') {
$this->_critical("Creation of products with type '$type' is not implemented",
Mage_Api2_Model_Server::HTTP_METHOD_NOT_ALLOWED);
}
$set = $data['attribute_set_id'];
$sku = $data['sku'];
/** #var $product Mage_Catalog_Model_Product */
$product = Mage::getModel('catalog/product')
->setStoreId(Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID)
->setAttributeSetId($set)
->setTypeId($type)
->setSku($sku);
foreach ($product->getMediaAttributes() as $mediaAttribute) {
$mediaAttrCode = $mediaAttribute->getAttributeCode();
$product->setData($mediaAttrCode, 'no_selection');
}
$this->_prepareDataForSave($product, $data);
try {
$product->validate();
$product->save();
$this->_multicall($product->getId());
} catch (Mage_Eav_Model_Entity_Attribute_Exception $e) {
$this->_critical(sprintf('Invalid attribute "%s": %s', $e->getAttributeCode(), $e->getMessage()),
Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
} catch (Mage_Core_Exception $e) {
$this->_critical($e->getMessage(), Mage_Api2_Model_Server::HTTP_INTERNAL_ERROR);
} catch (Exception $e) {
$this->_critical(self::RESOURCE_UNKNOWN_ERROR);
}
return $this->_getLocation($product);
}
protected function _multicreate($data)
{
$this->getResponse ()->addMessage ( "", 0, array (
'result' => "created"
), Mage_Api2_Model_Response::MESSAGE_TYPE_SUCCESS );
$this->getResponse ()->setRawHeader ( '"Content-Type" = "application/json"' );
$base_url = Mage::getBaseUrl ( Mage_Core_Model_Store::URL_TYPE_WEB );
$base_url = substr ( $base_url, 0, strlen ( $base_url ) - 1 );
return $base_url . $this->_getLocation ( $order );
}
protected function _update(array $data)
{
return json_encode($productCount);
}
protected function _delete()
{
$this->getResponse ()->addMessage ( "", 0, array (
'result' => "deleted"
), Mage_Api2_Model_Response::MESSAGE_TYPE_SUCCESS );
return json_encode(array("result","_delete"));
}
}
At this stage, _retrieve() is the only method that is working properly. The _delete() seems to be able to receive method call and return code 200. _update() also seems to receive method call properly even though it returns an encoding error.
My main problem is the _create(), which doesn't get called at all. Even I remove all the statements inside the method (which is copied from /app/Mage/Model/Api2/Product/Rest/AdminV1.php), the same problem persists.
Can anyone please give me some advice? Also, is that any documentation available for extending the REST api (not Core API)? I have found a few tutorials on the web (my code is extended to one of the tutorials), but none of them specify the details of what a particular tag in the api.xml/api2.xml means and how the method mapping should be done.
Thanks in advance.
I haven't worked much with Magento's RESTish API, but the
Resource method not implemented yet.
error string is defined in the following constant
#File: app/code/core/Mage/Api2/Model/Resource.php
const RESOURCE_METHOD_NOT_IMPLEMENTED = 'Resource method not implemented yet.';
This constant is used to raise a critical API error in the following locations
#File: app/code/core/Mage/Api2/Model/Resource.php
public function dispatch()
{
switch ($this->getActionType() . $this->getOperation()) {
case self::ACTION_TYPE_ENTITY . self::OPERATION_CREATE:
// Creation of objects is possible only when working with collection
$this->_critical(self::RESOURCE_METHOD_NOT_IMPLEMENTED);
break;
case self::ACTION_TYPE_COLLECTION . self::OPERATION_CREATE:
// If no of the methods(multi or single) is implemented, request body is not checked
if (!$this->_checkMethodExist('_create') && !$this->_checkMethodExist('_multiCreate')) {
$this->_critical(self::RESOURCE_METHOD_NOT_IMPLEMENTED);
}
...
default:
$this->_critical(self::RESOURCE_METHOD_NOT_IMPLEMENTED);
}
}
...
protected function _errorIfMethodNotExist($methodName)
{
if (!$this->_checkMethodExist($methodName)) {
$this->_critical(self::RESOURCE_METHOD_NOT_IMPLEMENTED);
}
}
So, taking some education guesses here, it looks like this error is thrown when
You attempt to call create on a single entity
You attempt to call create on a collection, and the _create or _multiCreate methods haven't been implemented on your PHP class
You attempt to call a method that's not one of the canonical CRUD methods (the default case)
Or if the Magento system code calls the protected _errorIfMethodNotExist error.
The _errorIfMethodNotExist is used a lot, but in relation to _create calls, it's used here
#File: app/code/core/Mage/Api2/Model/Resource.php
// The create action has the dynamic type which depends on data in the request body
if ($this->getRequest()->isAssocArrayInRequestBody()) {
$this->_errorIfMethodNotExist('_create');
$filteredData = $this->getFilter()->in($requestData);
if (empty($filteredData)) {
$this->_critical(self::RESOURCE_REQUEST_DATA_INVALID);
}
$newItemLocation = $this->_create($filteredData);
$this->getResponse()->setHeader('Location', $newItemLocation);
I'm not quite sure what this one's for. Maybe the comments above make sense to you (if you're used the REST API).
Regardless, I'd figure out which one of these calls to _critical is trigger your specific error (use some logging), and that might help you unravel what's wrong with your code.
Also, I wrote an article series on the implementation of the SOAP/XML-RPC API. Although the REST API uses new code not related to SOAP/XML-RPC, that series still may provide you with some insight on how the REST API is implemented.