Magento API SOAP filter website_ids error - api

I'm using api soap v1 and calling catalog_product.list everytime I add the website_ids in filter It cause an error.
$filter = array(
'status' => array( '=' => 1 ),
'type_id' => array( '=' => 'simple' ),
'website_ids' => array('6'),
);
2nd question, the args of catalog_product.list is filter and storeView, if I add the store view id or code I display all the product I guess It ignores what I add on it.
$proxy->call($sessionId, 'catalog_product.list', $filter = null, '6');
Thanks

I found this solution.
//you're website's id
$result = $client->call($session, 'store.info', '6');
$code = $result['code'];
//here all filters, in 'filters' you can add others filters (like price for example)
$filters = array(
'filters' => array(
'status' => 1,
'type_id' => 'simple',
),
'storeView' => "$code"
);
try{
$result = $client->call($session, 'catalog_product.list',$filters);
} catch (Exception $e){
print_r($e);
}
print_r($result);
now it works? :)

Related

Prestashop filter date_add in webservice

i'm new, and i've a problem with webservice.
when i try to retrieve customers filtering by date_add i get this error:
<message><![CDATA[This filter does not exist. Did you mean: "deleted"? The full list is: "id", "id_default_group", "id_lang", "newsletter_date_add", "ip_registration_newsletter", "last_passwd_gen", "secure_key", "deleted", "passwd", "lastname", "firstname", "email", "id_gender", "birthday", "newsletter", "optin", "website", "company", "siret", "ape", "outstanding_allow_amount", "show_public_prices", "id_risk", "max_payment_days", "active", "note", "is_guest", "id_shop", "id_shop_group"]]></message>
this is my code:
$yesterday = date("Y-m-d H:i:s", time() - 60 * 60 * 24);
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
// Qui imposto le opzion dell'array per il Webservice: in questo caso i clienti e setto che il formato รจ json
$opt = array( 'resource' => 'customers',
'filter[date_add]' => '['.$yesterday.']&date=1',
'display' => 'full',
'output_format' => 'JSON'
);
// faccio la chiamata
$xml = $webService->get($opt);
I'm stuck, I do not know what to do !!! any help is appreciated
Looking at the Customer class webservice parameters, there is no date_add:
protected $webserviceParameters = array(
'fields' => array(
'id_default_group' => array('xlink_resource' => 'groups'),
'id_lang' => array('xlink_resource' => 'languages'),
'newsletter_date_add' => array(),
'ip_registration_newsletter' => array(),
'last_passwd_gen' => array('setter' => null),
'secure_key' => array('setter' => null),
'deleted' => array(),
'passwd' => array('setter' => 'setWsPasswd'),
),
'associations' => array(
'groups' => array('resource' => 'group'),
)
);
If you have access to the server installation, you could add the date_add field to the webserviceParameters.
Or the function getWebserviceObjectList to change the behavour.
If you don't have access to the server installation, you can use the sort to get the latest customers until you reach the one you already have. You can use with limit to use in a foreach or while loop.
EDIT After some testing and inspecting what was going on:
First, it's we don't need to add the field date_add to the $webserviceParameters.
The request should be:
$opt = array( 'resource' => 'customers',
'filter[date_add]' => '['.$begin.','.$finish.']',
'date' => 1,
'display' => 'full',
'output_format' => 'JSON'
);
If you only add one date to the filter it will try to match only that date.
Then you need to change the PSWebServiceLibrary.php in line 284 and add the field 'date':
$params = array('filter', 'display', 'sort', 'limit', 'id_shop', 'id_group_shop', 'date');
Now it should work. I tested myself.
EDIT 2:
This is my full test, after changing the the line i mentioned in PSWebserviceLibrary.php, this retrieves my customers with date_add in the interval date.
<?php
require_once( 'PSWebServiceLibrary.php' );
echo 'starting<br />'.PHP_EOL;
try {
// creating web service access
$webService = new PrestaShopWebservice(MY_BASE_URL, WS_KEY, true);
$yesterday = date("Y-m-d", time() - 60 * 60 * 24);
$begin = date("Y-m-d", time() - 60 * 60 * 24 * 30);
$opt = array( 'resource' => 'customers',
'filter[date_add]' => '['.$begin.','.$yesterday.']',
'date' => 1,
'display' => 'full',
'output_format' => 'JSON'
);
//Retrieving the XML data
$xml = $webService->get($opt);
}
catch (PrestaShopWebserviceException $ex) {
// Shows a message related to the error
echo 'Other error: <br />' . $ex->getMessage();
}
?>
first of all: thanks
I modified as your indication, but the result does not change, still gives me the same error.
protected $webserviceParameters = array(
'fields' => array(
'id_default_group' => array('xlink_resource' => 'groups'),
'id_lang' => array('xlink_resource' => 'languages'),
'newsletter_date_add' => array(),
'ip_registration_newsletter' => array(),
'last_passwd_gen' => array('setter' => null),
'secure_key' => array('setter' => null),
'deleted' => array(),
'passwd' => array('setter' => 'setWsPasswd'),
/** inizio modifica aggiunta per il webservice */
'date_add' => array(),
/** fine della modifica */
),
'associations' => array(
'groups' => array('resource' => 'group'),
)
);
I can not understand

Podio Api - Create item error - "Invalid value null (null): must be Range"

I am trying to create an item with relationship field with multiple references like this.
$collection = new PodioCollection(array(
new PodioItem(array('item_id' => 425989858)),
new PodioItem(array('item_id' => 425987845))
));
$response = PodioItem::create("16748745", array('fields' => array(
"130415123" => "+13334445552",
"130415337" => $collection
)));
While creating item it shows error PodioBadRequestError: "Invalid value null (null): must be Range". I have only these two fields in this app.
I get the same error with single reference also.
$response = PodioItem::create("16748745", array('fields' => array(
"130415123" => "+13334445552",
"130415337" => array('item_id' => 425989858)
)));
Any help?
This one should work
$response = PodioItem::create("16748745", array('fields' => array(
"130415123" => "+13334445552",
"130415337" => array(425989858, 425987845)
)));
I've tested this for Ruby code and that works well :)
created_item = Podio::Item.create(app_id,
'fields' =>
{'title' => 'just for test',
'relationship' => [item_1_id, item_2_id] })

why am i receiving this error for a simple compare? Invalid parameter number- Yii

I am not sure why am I receiving this error. I've been doing this, doesn't seem to have an error elsewhere. Why is this showing an error?
Invalid parameter number: number of bound variables does not match number of tokens.
in model:
public function read()
{
$criteria = new CDbCriteria;
$criteria->compare('status_receiver',"N",true);
$data = new CActiveDataProvider($this, array('criteria'=>$criteria,));
return $data->getData();
}
public function defaultScope()
{
$id = Yii::app()->user->user_id;
return array(
'condition'=>"id ='".$id ."'",
'params' => array(':id' => $id ),
);
}
return array(
'condition'=>"id =:id",
'params' => array('id' => $id ),
);
return array(
'condition'=>"id = :id",
'params' => array(':id' => $id ),
);

How create condition to relations Yii

I have relations in Yii:
public function relations() {
return array(
'applicant' => array(
self::BELONGS_TO,
'ApplicantProfile',
array('applicant_id' => 'id'),
),
'filePair' => array(
self::BELONGS_TO,
'DocumentCategoryFile',
array('file_pair_id' => 'id'),
'joinType' => 'inner join'
)
);
}
How i can create addCondition in CDbCriteria() for aplicant, for example i want do is_deleted = 0. I am tried it $criteria->with = array('applicant' => array('join'=>'left join','condition'=>'aplicant.is_deleted = 0')); but i have sql syntax error
Thanks
Try this -
$criteria = new CDbCriteria();
$criteria->with = array('applicant');
$criteria->together = true;
$criteria->addCondition('applicant.is_deleted=0');
You should refer the link here to learn how to use it.

Drupal 7 Form Invalid foreach with tableselect EDIT - How to delete selected rows from tableselect

What I am trying to do is create a selectlist using the form API, where a user can select rows and press a delete button that deletes the selected rows from the database and reloads the table with a conformation that those selected had been deleted. With my current code, when I hit the delete button I get this error:
Warning: Invalid argument supplied for foreach() in form_execute_handlers() (line 1431 of C:\xampp\htdocs\amaware\includes\form.inc).
Here is the code:
/**
* Implements hook_menu().
*/
function smsfeed_menu() {
$items = array();
$items['admin/config/content/smsfeed'] = array(
'title' => 'SMS Messages and Newsletters',
'description' => 'Edit the Setting for the SMS Feed and Newsletter',
'page callback' => 'drupal_get_form',
'page arguments' => array('smsfeed_form'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/config/content/smsfeed/settings'] = array(
'title' => 'Settings',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 1,
);
$items['admin/config/content/smsfeed/newsletter'] = array(
'title' => 'Newsletter',
'page callback' => 'drupal_get_form',
'page arguments' => array('newsletter_table_form'),
'access arguments' => array('access administration pages'),
'type' => MENU_LOCAL_TASK,
'weigth' => 2,
);
$items['admin/config/content/smsfeed/feed'] = array(
'title' => 'SMS Feed',
'page callback' => 'drupal_get_form',
'page arguments' => array('feed_form'),
'access arguments' => array('access administration pages'),
'type' => MENU_LOCAL_TASK,
'weight' => 3,
);
$items['admin/config/content/smsfeed/questions'] = array(
'title' => 'Questions',
'page callback' => 'drupal_get_form',
'page arguments' => array('questions_form'),
'access arguments' => array('access administration pages'),
'type' => MENU_LOCAL_TASK,
'weigth' => 4,
);
return $items;
}
/**
* Page callback: SMS Settings
*
* #see smsfeed_menu()
*/
function smsfeed_form($form, &$form_state) {
$form['response_time'] = array(
'#type' => 'textfield',
'#title' => t('Response Time (In Days)'),
'#default_value' => variable_get('response_time', 3),
'#size' => 2,
'#maxlength' => 2,
'#description' => t('The response time, in days, that users should expect.'),
);
$form['feed_keyword'] = array(
'#type' => 'textfield',
'#title' => t('Feed Keyword'),
'#default_value' => variable_get('feed_keyword', 'FEED'),
'#size' => 10,
'#maxlength' => 10,
'#description' => t('The keyword users should text to have their message moderated and added to the website feed.'),
);
$form['join_keyword'] = array(
'#type' => 'textfield',
'#title' => t('Join Keyword'),
'#default_value' => variable_get('join_keyword', 'JOIN'),
'#size' => 10,
'#maxlength' => 10,
'#description' => t('The keyword users should text to be added to the newsletter list.'),
);
$form['quit_keyword'] = array(
'#type' => 'textfield',
'#title' => t('Quite Keyword'),
'#default_value' => variable_get('quit_keyword', 'QUIT'),
'#size' => 10,
'#maxlength' => 10,
'#description' => t('The keyword users should text to be removed from the newsletter list.'),
);
return system_settings_form($form);
}
/**
* Page Callback Newsletter
*/
function newsletter_table_form($form, $form_state) {
$rows = array();
$header = array(t('User Name'), t('User Number'), t('User E-mail'),);
$query = db_select('sms_newsletter');
$query->fields('sms_newsletter', array('name', 'number', 'email',))
->orderBy('name', 'ASC');
$results = $query->execute();
foreach ($results as $line) {
$rows[] = array(
$line->name,
$line->number,
$line->email,
);
}
$form['table'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $rows,
'#empty' => t('No users found'),
);
$form['delete'] = array(
'#type' => 'submit',
'#value' => t('Delect Selected'),
'#submit' => 'newsletter_table_form_delete'
);
return $form;
}
function newsletter_table_form_delete ($form, &$form_state) {
foreach ($form_state['values']['collections'] as $key => $value) {
if ($value) {
$delete = db_delete('sms_newsletter')
-> execute();
}
}
}
Any help is deeply appreciated.
EDIT:
I've edited my news_letter_table_form to read:
function newsletter_table_form_delete ($form, $form_state) {
foreach (($form_state['values']['table']) as $rows) {
//$delete = db_delete('sms_newsletter')
//-> execute();
drupal_set_message ('' . $rows . '');
//drupal_set_message ('' . $form_state['values']['table'] . '');
}
}
And the new output leaves me puzzled as to how I'd identify selected rows, and delete them from the database. Using the above newsletter_table_form_delete I get the following output:
If I select the top row nothing happens
If I select the second row the output is 1
If I select the third row the output is 2 and so on
If I select multiple rows the output is an unordered html list of the selected rows.
I'm curious now how I could take what I have now and change it so I can delete selected rows from the database.
Thanks again!
Try changing
$form['delete'] = array(
'#type' => 'submit',
'#value' => t('Delect Selected'),
'#submit' => 'newsletter_table_form_delete'
);
to
$form['delete'] = array(
'#type' => 'submit',
'#value' => t('Delect Selected'),
'#submit' => array('newsletter_table_form_delete') // <-- make this an array
);
Based on the additional info added in your question edit, I noticed that your tableselect is built without specifying array keys like:
foreach ($results as $line) {
$rows[] = array( // <-- No array keys specified here
$line->name,
$line->number,
$line->email,
);
}
Since there were no keys specified, the default by PHP is a 0-based index. That is why you are getting no results for the top row, 1 for the second row, and so on.
See the documentation for the tableselect element for an example.
I don't know what your database table structure looks like but you will probably need to query the Primary Key for the table and include it as array keys to your $rows array. That way, when you process the data in your delete function, you have the Primary Key of the row you want to delete and delete it.
For me this wasn't clear straight away so.
I would just like to add that in the end what nmc was saying is you should construct your rows like this, where you add a key to row.
foreach ($results as $line) {
$rows[$line->name] = array(
$line->name,
$line->number,
$line->email,
);