eBay Finding API filter by shipToLocations - ebay-api

I'm using eBay Finding API and I want to get results by filtering shipping to my country. I found this shipToLocations, but I can't find the filter.
$apicall .= "&itemFilter(0).name=Condition";
$apicall .= "&itemFilter(0).value=New";
$apicall .= "&itemFilter(1).name=ListingType";
$apicall .= "&itemFilter(1).value=FixedPrice";
$apicall .= "&itemFilter(2).name=HideDuplicateItems";
$apicall .= "&itemFilter(2).value=true";

You can set a new itemFilter with name=AvailableTo and value=<2 Characters code of your country>
For example:
$apicall .= "&itemFilter(1).name=AvailableTo";
$apicall .= "&itemFilter(1).value=DE"; // DE = country code for Germany

Related

How to Direct access through the database query to product name , product price and permalink and product photo columns

How do I get Direct access through the database query to product name , product price ,permalink , and image url of product in WordPress WooCommerce ?!
what's the sql query ?
global $wpdb;
$metas = array(
'_thumbnail_id', '_regular_price'
);
foreach ($metas as $i=>$meta_key) {
$meta_fields[] = 'm' . $i . '.meta_value as ' . $meta_key;
$meta_joins[] = ' left join ' . $wpdb->postmeta . ' as m' . $i . ' on m' . $i . '.post_id=' . $wpdb->posts . '.ID and m' . $i . '.meta_key="' . $meta_key . '"';
}
$request = "SELECT ID, post_title, " . join(',', $meta_fields) . " FROM $wpdb->posts ";
$request .= join(' ', $meta_joins);
$request .= " WHERE post_status='publish' AND post_type='product' AND $wpdb->posts.post_title like '%sample%'";
$product_details = $wpdb->get_row($request, OBJECT);
if(!empty($product_details)){
$qry = "SELECT guid FROM $wpdb->posts WHERE ID=" . $product_details->_thumbnail_id;
$uri_obj = $wpdb->get_row($qry, OBJECT);
$product_details->_thumbnail_id = $uri_obj->guid;
}
echo '<pre>';print_r($product_details);exit;

How can I convert this to use PDO?

I would like to use PDO for selecting (searching) a database.
The search 'form' has MULTIPLE fields that can be used.. 1 or many can be filled in to help refine the search. (or there can be many o them left blank/empty)
here is what I have been using (locally):
//localhost details
$db_username="root"; //database user name
$db_password="";//database password
$db_database="test"; //database name
$db_host="localhost";
mysql_connect($db_host,$db_username,$db_password);
#mysql_select_db($db_database) or die("Unable to connect to database.");
if(isset($_POST['submit'])) {
// define the list of fields
$fields = array('first', 'trialdate', 'wcity', 'wstate', 'plantif');
$conditions = array();
//loop through the defined fields
foreach($fields as $field){
// if the field is set and not empty
if(isset($_POST[$field]) && $_POST[$field] != '') {
// create a new condition while escaping the value inputed by the user (SQL Injection)
$conditions[] = "`$field` LIKE '%" . mysql_real_escape_string($_POST[$field]) . "%'";
}
}
//build the query
$query = "SELECT * FROM myTable ";
// if there are conditions defined
if(count($conditions) > 0) {
// append the conditions
$query .= "WHERE " . implode (' OR ', $conditions); // you can change to 'OR', but I suggest to apply the filters cumulative
}
$result = mysql_query($query);
if(isset($_POST['submit'])) {
while($row = mysql_fetch_array($result)) {
echo $row['first'] . "<br />"; //individual value
//build panels that displays everything from row..etc
}
}
}
this has been working fine... but I'd like convert to using the PDO approach.
I gave it a few tries...but am missing something here..
heres what I've tried so far..
//localhost details
$db_username="root"; //database user name
$db_password="";//database password
$db_database="test"; //database name
$db_host="localhost";
//PDO DB connection
$conn = new PDO('mysql:host='.$db_host.'dbname='.$db_database.'charset=utf8', $db_username, $db_password);
if(isset($_POST['submit'])) {
$stmt = $conn->prepare('SELECT * FROM myTable WHERE first LIKE :first OR trialdate LIKE :trialdate OR wcity LIKE :wcity OR wstate LIKE :wstate OR plantif LIKE :plantif');
//build query placeholders (*note: use bindValue for $_POST values)
$stmt->bindValue(':first', '%' . $_POST['first'] . '%');
$stmt->bindValue(':trialdate', '%' . $_POST['trialdate'] . '%');
$stmt->bindValue(':wcity', '%' . $_POST['wcity'] . '%');
$stmt->bindValue(':wstate', '%' . $_POST['wstate'] . '%');
$stmt->bindValue(':plantif', '%' . $_POST['plantif'] . '%');
$stmt->execute();
foreach ($stmt as $row) {
// do something with $row
echo $row['first'] . "<br />"; //individual value
}
}
I could use help on getting the PDO example working with a displayed result/row/value?

Doctrine inheritance mapping multiple entities on single table

I am doing a translate system (not based on the existing ones because of some constraints).
I've got one class/table Product with default language (french) the others are in another table.
A super class named TranslateProduct, it will be abstract, it depends on the solution I'll find.
There is a class EnProduct for english product, DeProduct for german etc.
These classes are mapped on a single table named translate_product.
In the translateProduct.orm.xml I have this for the inheritance :
<discriminator-column name="translate_type" type="string" />
<discriminator-map>
<discriminator-mapping value="en" class="EnProduct" />
<discriminator-mapping value="de" class="DeProduct" />
<discriminator-mapping value="nl" class="NlProduct" />
<discriminator-mapping value="it" class="ItProduct" />
<discriminator-mapping value="es" class="EsProduct" />
</discriminator-map>
So far it's ok but, the thing I want to do is that each translate of product is in a single row. for example :
I create an object :
$enProduct = new EnProduct();
$emProduct->setProductCode("123456");
$enProduct->setName("Door");
$em->persist($enProduct);
$em->flush();
In the database I'll have :
id | product_code | en_name
1 | 123456 | Door
I have mapped the variables name to column en_name and de_name
through the xml file
So now I want to get an object TranslateProduct with the Id = 1 and cast it to a DeProduct object the problem is the discriminator-column (translate_type) it is already set to enProduct and it's normally but how can I transform a single row in multiple objects of different types ?
I dont know if it was clear...
I found a solution. I don't know if my question was really clear...
So I wanted to get from for example this row :
You can see that this row is an EnProduct object, but I want also get a DeProduct from this same row.
I did the inheritance like in the Doctrine documentation said (still single_table)
And in every repository class I put this code :
public function findOneByPk($id){
$className = $this->getClassMetadata()->name;
$fields = $this->getClassMetadata()->fieldNames;
$rsm = new ResultSetMapping();
$rsm->addEntityResult($className, 'p');
$sql = "Select ";
foreach($fields as $column => $field){
$rsm->addFieldResult('p', $column, $field);
$sql .= "p.".$column. " as ".$field.", ";
}
$sql = trim($sql);
$sql = trim($sql,",");
$sql .= " FROM translate_product p";
$sql .= " WHERE p.id=".$id;
$query = $this->getEntityManager()->createNativeQuery($sql, $rsm);
return $query->getOneOrNullResult();
}
This will hydrate the right object.
Edit:
If using PostgreSQL database and using camelcase fields, you have to put double-quotes on the alias :
public function findOneByPk($id){
$className = $this->getClassMetadata()->name;
$fields = $this->getClassMetadata()->fieldNames;
$rsm = new ResultSetMapping();
$rsm->addEntityResult($className, 'p');
$sql = "Select ";
foreach($fields as $column => $field){
$rsm->addFieldResult('p', $column, $field);
$sql .= 'p.'.$column. ' as "'.$field.'", ';
}
$sql = trim($sql);
$sql = trim($sql,",");
$sql .= " FROM translate_product p";
$sql .= " WHERE p.id=".$id;
$query = $this->getEntityManager()->createNativeQuery($sql, $rsm);
return $query->getOneOrNullResult();
}

Create an video gallery with UStream API

I'm trying to create a simple video gallery that pulls the videos from the recorded shows of a specific Ustream user. I've been doing some research and looking at the API Documentation but can't seem to figure it out.
This is what I have so far.
$request = 'http://api.ustream.tv';
$format = 'php'; // this can be xml, json, html, or php
$args .= 'subject=[channel]';
$args .= '&uid= [the-crossfader-show]';
$args .= '&command=[getCusomEmbedTag]';
$args .= '&params=[autoplay:false; mute:false; height:100; width:100;]';
$args .= '&page=[1]';
$args .= '&limit=[20]';
$args .= '&key=[4872929558631FEB4E9AEE8DDF080F28]';
// Get and config the curl session object
$session = curl_init($request.'/'.$format.'?'.$args);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
//execute the request and close
$response = curl_exec($session);
curl_close($session);
// this line works because we requested $format='php' and not some other output format
$resultsArray = unserialize($response);
// this is your data returned; you could do something more useful here than just echo it
print_r $resultsArray['result'];
I'm not really sure what to do after this to turn it into a simple gallery. Anyone have any experience with the UStream API or have suggestions on what to do next?
I know this is an old post, but I have been looking into the API myself for the first time today and came across this. Try using arguments without the square brackets around your values? example:
$args .= 'subject=channel';
$args .= '&uid=the-crossfader-show';
$args .= '&command=getCusomEmbedTag';
$args .= '&params=autoplay:false; mute:false; height:100; width:100;';
$args .= '&page=1';
$args .= '&limit=20';
$args .= '&key=4872929558631FEB4E9AEE8DDF080F28';
You also had an extra space before the-crossfader-show. I haven't tried this code, but perhaps this will help. Also, setting subject=user would get you all the videos for a user, vs subject=channel which i believe to only be a single video stream?

php/Drupal - list all nodes that a given user to permission to edit

I have a function that lists all nodes on the system. I would like to refine this to show only nodes that current user is able to edit - either with API or SQL statement. (Drupal 6)
function fnGetNodeTypes($typeOfNodes) {
$string = "";
$types_of_nodes = array_keys(node_get_types());
$string .= "<select name='typeOfNodes'>";
$string .= "<option value=''>Please select</option> ";
$string .= "<option value='all'>All</option> ";
foreach($types_of_nodes as $node){
if($typeOfNodes == $node ){
$selected = "selected";
}
else{
$selected = "";
}
$string .= "<option $selected value=\"" . $node . "\">" . $node ;
$string .= "</option>\n";
}
$string .= "</select\n>";
return $string;
}
Update:
Following #chx suggestion I tried messing around with users, users_roles and permissions. Let me know if there is a more Drupal way of doing this.
//----------------------------------------------
// Contruct select/option box of node types
//----------------------------------------------
function fnGetNodeTypes($typeOfNodes) {
$string = "";
$types_of_nodes = array_keys(node_get_types());
$string .= "<select name='typeOfNodes'>";
$string .= "<option value=''>Please select</option> ";
//$string .= "<option value='all'>All</option> ";
foreach($types_of_nodes as $node_type){
if (fnInArray($node_type))
{
if($typeOfNodes == $node_type ){
$selected = "selected";
}
else{
$selected = "";
}
$string .= "<option $selected value=\"" . $node_type . "\">" . $node_type ;
$string .= "</option>\n";
}
}
$string .= "</select\n>";
return $string;
}
//---------------------------------------------------------------------
// function fnInArray - see if user is allowed to edit this node type
//---------------------------------------------------------------------
function fnInArray($node_type)
{
global $user;
if ($user->name == 'admin') { return TRUE; }
// get list of all nodes that user is allowed to access
//
$string = " SELECT permission.perm as permission_perm " .
" from users " .
" join users_roles on ( users_roles.uid = users.uid ) " .
" join permission on (permission.rid = users_roles.rid) " .
" where users.name = '" . $user->name . "'";
$result = db_query($string);
while ($row = db_fetch_object($result)) {
$pieces = explode(", " , $row->permission_perm);
$node_name = "edit any " . trim($node_type) . " content";
if (in_array($node_name, $pieces ))
{
return TRUE;
}
return FALSE;
}
}
This is fairly impossible to do. Node access can be specified by a hook so the only generic way to do that would be to retrieve every. single. node. and run node_access($node, 'update') on them. That's not too fast. You can mess around with node types, permissions, the node access table etc depending on how your site is set up and modules are used. If we presume that the only thing controlling your nodes are the permissions and understand please this presumption is not always true by far, then in Drupal 6 and below (I suspect from node_get_types() you are not using D7) you would indeed iterate over node_get_types()and check user_access("edit own $type content") || user access("edit any $type content") but this won't go too far.
Not quite sure of the proper method for Drupal 6 (check db_rewrite_sql) but for Drupal 7, while you are building your query add addTag('node_access') to the query and that will limit it to only nodes that the user has permission to edit. If you go to the link for db_rewrite_sql above make sure to take a look at the comments.
db_query + db_rewrite_sql: Returns only the rows the logged-in user is allowed to view.
$results = db_query(db_rewrite_sql($query), $args);
This is what the Module Grants Monitor module is for http://drupal.org/project/module_grants. From the project page: "Clicking on it reveals a summary of all the content the logged-in user has access to (i.e. view, edit) after access controls have been applied by the content access modules installed on your site". I installed and tested this today and it seems to work. Does anyone have comments or experience with this module?
It seems like this should also be possible with Views or Rules... but maybe that's just because everything seems possible with them...