When Magento's API doesn't work properly...
Posted on December 22, 2012 by Nimrod Techn There have been 0 comments
Write your own "API":
1. app/code/local/Engineering/Extapi/controllers/ExtapiController.php
<?php class Engineering_Extapi_ExtapiController extends Mage_Core_Controller_Front_Action { protected function _initAction() { return $this; } public function indexAction() { $this->loadLayout(); } public function getnumberofordersAction() { if($this->getRequest()->getParam('pass')=="123") { //check password $query = "SELECT count(*) FROM `sales_flat_order`"; $resource = Mage::getSingleton('core/resource'); $readConnection = $resource->getConnection('core_read'); $result = $readConnection->fetchOne($query); echo $result; } } public function getnumberofcustomersAction() { if($this->getRequest()->getParam('pass')=="123") { //check password $query = "SELECT count(DISTINCT email) FROM customer_entity"; $resource = Mage::getSingleton('core/resource'); $readConnection = $resource->getConnection('core_read'); $result = $readConnection->fetchOne($query); echo $result; } } }
2. app/code/local/Engineering/Extapi/etc/config.xml
<?xml version="1.0"?> <config> <modules> <Engineering_Extapi> <version>0.1.0</version> </Engineering_Extapi> </modules> <frontend> <routers> <extapi_router> <use>standard</use> <args> <module>Engineering_Extapi</module> <frontName>extapi</frontName> <!-- URI --> </args> </extapi_router> </routers> </frontend> </config> Now - Don't forget to create the app/etc/modules/Engineering_Extapi.xml file:
<?xml version="1.0"?> <config> <modules> <Engineering_Extapi> <active>true</active> <codePool>local</codePool> </Engineering_Extapi> </modules> </config>Now you can reach the actions via:
http://yoursite.com/extapi/getnumberoforders/?pass=123
http://yoursite.com/extapi/getnumberofcustomers/?pass=123
This post was posted in Writing a Magento Extension
Magento is a well-engineered eCommerce platform designed to help engineers develop customized eCommerce online stores.
Due to lack of proper coding documentation, Engineer-ing.com was created with the sole purpose of instructing Magento developers to-be with the "how-to-do" know-how.
In the event of unresolved issues, you are more than welcome to contact me for consultation.
However, please do so only if you possess a Software Engineering background and you're able to specify your question.