how can we create search webservice in magento? - php

I am making a web service in magento. I have created many web-service of magento project like login, register, etc in magento project. I am not using third party web-service (default magento webservice).
I am follow the step: just create folder in magento root directory(webservice) then after create file serach.php and write the code for searching:
require("../app/Mage.php");
Mage::app();
if (isset($_REQUEST['search_text']) && ($_REQUEST['search_text'] != "")) {
$text = $_REQUEST['search_text'];
} else {
$text = "";
}
$search = "%" . trim($text) . "%";
$collection->addCategoryFilter()->addAttributeToSelect('name')->addAttributeToFilter('name', array(
'like' => $search
));
echo "";
print_r($collection);
die;
I am getting the error:
Fatal error: Call to a member function getId() on a non-object in /home/demo/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php on line 700

require("../app/Mage.php");
Mage::app();
if (isset($_REQUEST['search_text']) && ($_REQUEST['search_text'] != "")) {
$text = $_REQUEST['search_text'];
}
else{
$text = "";
}
$search = "%".trim($text)."%";
$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('sku');
$collection->addAttributeToSelect('city');
$collection->joinAttribute('city', 'catalog_product/city', 'entity_id', null, 'inner');
$category = Mage::getModel('catalog/category')->load();
$productCollection = $collection->addCategoryFilter($category)
->addAttributeToSelect('name')
->addAttributeToFilter('name',array('like'=>$search));

Magento provides inbuilt easy to use SOAP and REST API..both easily extendable ..you can refer to Vinai Kopps got repo for REST API by session authentication

You haven't initialized and load the collection.
I'm missing such a line as:
$collection = Mage::getModel('catalog/product')->getCollection()...

Related

How would I keep the slash in my $domain when using wpmu_create_blog to create a site

I am currently working on an automated site creation function on my local installation of wordpress. In essence, a form is filled out on an already existing site and that info is pulled to create a new site automatically via an endpoint that activates some queries. So far I have been able to successfully pull the information into an array and then pass that to the wpmu_create_blog function. The issue is that the $domain isn't being called correctly(that is to say, how I intend it to be called), the '/' is lost between 'localhost' and 'wordpress'.
public function create_endpoint($request) {
$key = $request['key'];
if ($this->validate_key($key)) {
$newsite = array (
$title = $request['name'],
$path = $request['slug'],
$admin_user = $request['admin_user'],
);
$domain = 'localhost/wordpress';
$site_id = get_blog_id_from_url($domain, $path);
$user_id = get_user_by('login', $admin_user);
if ( !empty($title) and !empty($domain) and !empty($path) and empty($user_id) ) {
return wpmu_create_blog($domain, $path, $title, $user_id, $site_id);
}
else {
return "Not enough information";
}
}
else {
return $this->invalid_key_message;
}
}
Everything but the domain being called as intended is working as intended. This is also just the static prototype, my end goal is that this is entirely dynamic including the $domain variable.
I'm just totally lost on where to go from here. I've tried some appendage stuff and moving syntax around in all types of ways but keep hitting a wall. Any input or suggestions are happily accepted.
I have a solution implemented. In the array $path has been changed to $slug (use of slug is specific to my code). The $domain now only calls 'localhost' and I create $path using plain text the 'wordpress' and then add the slug via a $request.
$newsite = array (
$title = $request['name'],
$slug = $request['slug'],
$admin_user = $request['admin_user'],
);
$domain = 'localhost';
$path = 'wordpress/'.$request['slug'];

Mediawiki add user from custom registration page

I set up a custom registration page to my http server (apache) which hosts a number of services, including a wiki.
The intended goal is to have the user sign-up at once to all these services including the wiki of course.
For the wiki I'm trying to rearrange the "CreateAndPromote" maintenance script and fit it into my page. By now I came up with this snippet
$path = "/wiki";
putenv("MW_INSTALL_PATH={$path}");
require_once ("/wiki/includes/WebStart.php");
chdir("wiki");
$mediaWiki = new MediaWiki();
$name = $_POST['username'];
$pass = $_POST['password'];
$user = User::newFromName( $name );
if ( !is_object( $user ) ) {
die("Invalid user!\n");
}
$exists = ( 0 !== $user->idForName() );
if ( !$exists ) {
$user->addToDatabase();
}
try {
$user->setPassword( $pass );
} catch ( PasswordError $pwe ) {
die("password error:" . $pwe->getText()."");
}
$user->addGroup("editor");
$user->saveSettings();
$ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
$ssu->doUpdate();
But i get
Error: LightnCandy class not defined
MediaWiki 1.25.2
PHP 5.6.12 (apache2handler)
The problem was simple as that:
declaring the MW_INSTALL_PATH like that apparently did not work
$path = "/wiki";
putenv("MW_INSTALL_PATH={$path}");
require_once ("/wiki/includes/WebStart.php");
so I had to change dir to the wiki BEFORE requiring the webstart.php
chdir("wiki");
require_once ("/includes/WebStart.php");

Howto disable/hide Navigation-Tab 'Status' in phpMyAdmin4 multi-user environment

I need to disable the Navigation-Tab 'Status' in a phpMyAdmin4 multi-user environment. This post explains how to do it but it seems as it is for previous versions of phpMyAdmin.
As explained in the above link there should be a file named 'server_links.inc.php'. Under 'usr/share/phpmyadmin/libraries/' there does not exist such file... These are my server_* files:
server_bin_log.lib.php
server_collations.lib.php
server_common.inc.php
server_common.lib.php
server_databases.lib.php
server_engines.lib.php
server_plugins.lib.php
server_privileges.lib.php
server_status.lib.php
server_status_advisor.lib.php
server_status_monitor.lib.php
server_status_queries.lib.php
server_status_variables.lib.php
server_user_groups.lib.php
server_users.lib.php
server_variables.lib.php
In which file is the tab-navigation stored?
How can I disable/hide the 'Status'-Tab?
How can I restrict access for SQL Queries like 'SHOW STATUS' after hiding the 'Status'-Tab?
If you want to change the menu tabs without touching the code, the user groups feature will do just that; see http://docs.phpmyadmin.net/en/latest/config.html?highlight=usergroup#cfg_Servers_usergroups.
You can can also change the code, in libraries/Menu.class.php.
This is my working code for hiding the tab 'Status' in /phpmyadmin/libraries/Menu.class.php:
if ($is_superuser) {
$tabs['status']['icon'] = 's_status.png';
$tabs['status']['link'] = 'server_status.php';
$tabs['status']['text'] = __('Status');
$tabs['status']['active'] = in_array(
basename($GLOBALS['PMA_PHP_SELF']),
array(
'server_status.php',
'server_status_advisor.php',
'server_status_monitor.php',
'server_status_queries.php',
'server_status_variables.php'
)
);
}
This is my working code in /phpmyadmin/server_status.php to deny access anyway if not superuser:
if (!$GLOBALS['dbi']->isSuperuser()) {
$msg = PMA_Message::error(__('No Privileges'));
$msg->display();
exit;
}
Note that the other files belonging to server_status.php should also contain the superuser check, so that no one can access these files directly:
'server_status_advisor.php',
'server_status_monitor.php',
'server_status_queries.php',
'server_status_variables.php'.
for newest phpmyadmin, you can edit at
libraries/classes/menu.php
refer to function _getMenu()
if (strlen((string) $this->_table) > 0) {
$tabs = $this->_getTableTabs();
$url_params['db'] = $this->_db;
$url_params['table'] = $this->_table;
$level = 'table';
} elseif (strlen($this->_db) > 0) {
$tabs = $this->_getDbTabs();
$url_params['db'] = $this->_db;
$level = 'db';
} else {
$tabs = $this->_getServerTabs();
$level = 'server';
}
and then you can modify menu you wanted to, let say edit menu table tabs, then edit function _getTableTabs. eg. you wanted to make menu export hide permanently then comment this code bellow
$tabs['export']['icon'] = 'b_tblexport';
$tabs['export']['link'] = 'tbl_export.php';
$tabs['export']['args']['single_table'] = 'true';
$tabs['export']['text'] = __('Export');
PS. this solution only for permanently hide

Yii::app()->lang doesn't work sometimes with LimeSurvey

I am working on a custom script to automatically send out invites and reminders. I have everything working fine up until a point. My function to send invites looks like this:
function sendInvites($iSurveyID) {
$oSurvey = Survey::model()->findByPk($iSurveyID);
if (!isset($oSurvey)) {
die("could not load survey");
}
if(!tableExists("{{tokens_$iSurveyID}}")) {
die("survey has no tokens or something");
}
$SQLemailstatuscondition = "emailstatus = 'OK'";
$SQLremindercountcondition = '';
$SQLreminderdelaycondition = '';
$iMaxEmails = (int)Yii::app()->getConfig("maxemails");
$iMaxReminders = 1;
if(!is_null($iMaxReminders)) {
$SQLremindercountcondition = "remindercount < " . $iMaxReminders;
}
$oTokens = Tokens_dynamic::model($iSurveyID);
$aResultTokens = $oTokens->findUninvited(false, $iMaxEmails, true, $SQLemailstatuscondition, $SQLremindercountcondition, $SQLreminderdelaycondition);
if (empty($aResultTokens)) {
die("No tokens to send invites to");
}
$aResult = emailTokens($iSurveyID, $aResultTokens, 'invite');
}
I also have a simple little file that starts up Yii:
Yii::createApplication('LSYii_Application', APPPATH . 'config/config' . EXT);
Yii::app()->loadHelper('admin/token');
Yii::app()->loadHelper('common');
Everything works as expected up until I actually try to send emails to the tokens. I've tracked the problem down to the following, on of the functions called by emailTokens has this in it:
$clang = Yii::app()->lang;
$aBasicTokenFields=array('firstname'=>array(
'description'=>$clang->gT('First name'),
'mandatory'=>'N',
'showregister'=>'Y'
),
The Yii::app()->lang part seems to be causing issues because then php is unable to call the gT method. However, when LimeSurvey is running "properly" this never happens. I can't even seem to find where "lang" is in the LimeSurvey source.
What can I do to make it work?
Why do you make it so hard on yourself and not use the RemoteControl2 API ?
See http://manual.limesurvey.org/wiki/RemoteControl_2_API#invite_participants
On that page you will also find a PHP example script.
maybe
Yii::import('application.libraries.Limesurvey_lang');
$clang = new Limesurvey_lang($oTokens->language);

url cutoff by link module or pagepeeker formatter issue in drupal 7

I have drupal 7 question that may involve some php help. I have created an rss feed from google alerts that I am mapping into fields. I have had success mapping into all the fields except the link module field where I have put a field formatter that creates a pagepeeker screenshot by attaching the appropriate url server query to the feeds url. Feeds is doing its job by taking the Item URL (link) and putting it into the field correctly. I am having an issue with with either pagepeeker or link module because below keeps happening.
To recap-
Google Alert feed -> Link module field -> pagepeeker screenshot formatter
here's the error
The url that google alerts provides is
http://www.google.com/url?sa=X&q=http://www.beautyjunkiesunite.com/WP/2012/05/30/whats-new-anastasia-beverly-hills-lash-genius/&ct=ga&cad=CAcQARgAIAEoATAAOABA3t-Y_gRIAlgBYgVlbi1VUw&cd=F7w9TwL-6ao&usg=AFQjCNG2rbJCENvRR2_k6pL9RntjP66Rvg
When the link is displayed I get :
http://pagepeeker.com/thumbs.php?size=m&url=www.google.com/url
Its cutting the url at url and not getting the rest of the url.
Here's the code that pagepeeker uses to parse the url ?
<?php
function _pagepeeker_format_url($url, $domain_only = FALSE) {
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
return FALSE;
}
// try to parse the url
$parsed_url = parse_url($url);
if (!empty($parsed_url)) {
$host = (!empty($parsed_url['host'])) ? $parsed_url['host'] : '';
$port = (!empty($parsed_url['port'])) ? ':' . $parsed_url['port'] : '';
$path = (!empty($parsed_url['path'])) ? $parsed_url['path'] : '';
$query = (!empty($parsed_url['query'])) ? '?' . $parsed_url['query'] : '';
$fragment = (!empty($parsed_url['fragment'])) ? '#' . $parsed_url['fragment'] : '';
if ($domain_only) {
return $host . $port;
}
else {
return $host . $port . $path . $query . $fragment;
}
}
return FALSE;
}
Could this be the problem?
Please let me know I can clarify in any way.
What I need is for the entire url to get processed and not just the truncated one
Thanks !
I have seen a very similar question here at SO or drupal SO page but couldn't find it so I'm writing "my way" answer again here.
<?php
function _pagepeeker_format_url($url, $domain_only = FALSE) {
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
return FALSE;
}
//$url = 'http://www.google.com/url?sa=X&q=http://www.beautyjunkiesunite.com/WP/2012/05/30/whats-new-anastasia-beverly-hills-lash-genius/&ct=ga&cad=CAcQARgAIAEoATAAOABA3t-Y_gRIAlgBYgVlbi1VUw&cd=F7w9TwL-6ao&usg=AFQjCNG2rbJCENvRR2_k6pL9RntjP66Rvg';
// Now we use parse_url to split the url to an array with url parts.
$parsed_url = parse_url($url);
// $parsed_url['query'] is 'sa=X&q=http://www.beautyjunkiesunite.com/WP/2012/05/30/whats-new-anastasia-beverly-hills-lash-genius/&ct=ga&cad=CAcQARgAIAEoATAAOABA3t-Y_gRIAlgBYgVlbi1VUw&cd=F7w9TwL-6ao&usg=AFQjCNG2rbJCENvRR2_k6pL9RntjP66Rvg'
// ";" can also be used to separate params. But & is the usual one so using it.
$queryParts = explode('&', $parsed_url['query']);
$params = array();
foreach ($queryParts as $param) {
$item = explode('=', $param);
// sa = X, etc.
$params[$item[0]] = $item[1];
}
//$params is now an array with query parts.
// $params['sa'] = 'X' , q = 'http://www.beautyjunkiesunite.com/WP/2012/05/30/whats-new-anastasia-beverly-hills-lash-genius', etc.
if ($domain_only){
$new_url_parsts = parse_url($params['q']);
return $new_url_parts['host'];
}
else{
return $params['q'];
}

Categories