how to get the product details in amazon mws? - amazon-web-services

Hi here is my code please check it and let me know what im missing.
im using amazon orders API for this.
<?php
require_once('.config.inc.php');
//$serviceUrl = "https://mws.amazonservices.com/Orders/2013-09-01";
// Europe
$serviceUrl = "https://mws-eu.amazonservices.com/Orders/2013-09-01";
// Japan
//$serviceUrl = "https://mws.amazonservices.jp/Orders/2013-09-01";
// China
//$serviceUrl = "https://mws.amazonservices.com.cn/Orders/2013-09-01";
$config = array (
'ServiceURL' => $serviceUrl,
'ProxyHost' => null,
'ProxyPort' => -1,
'ProxyUsername' => null,
'ProxyPassword' => null,
'MaxErrorRetry' => 3,
);
$service = new MarketplaceWebServiceOrders_Client(
AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY,
APPLICATION_NAME,
APPLICATION_VERSION,
$config);
$request = new MarketplaceWebServiceOrders_Model_ListOrdersRequest();
$request->setSellerId(MERCHANT_ID);
// object or array of parameters
echo"<pre>";
print_r($service);
invokeListOrders($service, $request);
function invokeListOrders(MarketplaceWebServiceOrders_Interface $service, $request)
{
try {
$response = $service->ListOrders($request);
echo ("Service Response\n");
echo ("=============================================================================\n");
$dom = new DOMDocument();
$dom->loadXML($response->toXML());
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
echo $dom->saveXML();
echo("ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n");
} catch (MarketplaceWebServiceOrders_Exception $ex) {
echo("Caught Exception: " . $ex->getMessage() . "\n");
echo("Response Status Code: " . $ex->getStatusCode() . "\n");
echo("Error Code: " . $ex->getErrorCode() . "\n");
echo("Error Type: " . $ex->getErrorType() . "\n");
echo("Request ID: " . $ex->getRequestId() . "\n");
echo("XML: " . $ex->getXML() . "\n");
echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n");
}
}
This is the XMl im using for getting the details i request somebody to reply me as soon as possible.

Just add these two lines after the
$request->setSellerId(MERCHANT_ID);
after this line add these two lines.
$request->setMarketplaceId(MARKETPLACE_ID);
$request->setCreatedAfter('2016-04-01');
Hope this helps..

Related

Cannot start phalcon project on browser

I use wamp 2.5
I successfully included the phalcon extension by copying the dll file into the ext folder of the wamp php folder , and editing the php.ini file by including extension=php_phalcon.dll. I created a simple project. But when I wanted to open the project on the browser then it shows the list of folders but not the desired page ! Here is the captured photo of the result :
So how to fix it ?
edit :
here is code of the index.php in the public folder :
<?php
use Phalcon\Loader;
use Phalcon\DI\FactoryDefault;
use Phalcon\Mvc\View;
use Phalcon\Mvc\Application;
use Phalcon\Mvc\Url as UrlProvider;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
use Phalcon\Session\Adapter\Files as SessionFiles;
include("../app/config_const.php");
include("../app/config_inc.php");
include("../app/lib/PSR.php");
require_once RP_BIRT . 'runReport.php';
try {
// Register an autoloader
$loader = new Loader();
$loader->registerDirs(array(
'../app/controllers/',
'../app/models/'
))->register();
// Create a DI
$di = new FactoryDefault();
// Start the session the first time when some component request the session service
$di->setShared('session', function () {
$session = new SessionFiles();
$session->start();
return $session;
});
// Setup the database service
$di->set('db', function(){
$cnx = new DbAdapter(array(
"host" => SERVEUR,
"username" => LOGIN_DB,
"password" => PWS_DB,
"dbname" => BDD
));
return $cnx;
});
// Setup the view component
$di->set('view', function(){
$view = new View();
$view->setViewsDir('../app/views/');
$view->registerEngines(array(
".phtml" => 'Phalcon\Mvc\View\Engine\Volt'
));
return $view;
});
// Setup a base URI so that all generated URIs include the "phalcon" folder
$di->set('url', function(){
$url = new UrlProvider();
$url->setBaseUri('/'.SITE.'/');
return $url;
});
//Register the flash service with custom CSS classes
$di->set('flash', function(){
$flash = new \Phalcon\Flash\Direct(array(
'error' => 'alert alert-error',
'success' => 'alert alert-success',
'notice' => 'alert alert-info',
));
return $flash;
});
//Handle the request
$app = new Application($di);
echo $app->handle()->getContent();
} catch(\Exception $e) {
echo "Exception: ", $e->getMessage();
}
?>
code of ../app/config_const.php :
<?php
define("BDD","resto_vide");
define("SITE", "resto");
define('HTTP_MAIN', 'http://'. $_SERVER["HTTP_HOST"] .'/'.SITE.'/') ;
define('RP_LANG', HTTP_MAIN . 'lang/');
define('RP_SSP', HTTP_MAIN . 'ssp/');
define("SERVEUR",$_SERVER["HTTP_HOST"]);
define("LOGIN_DB","root");
define("PWS_DB","admin");
define("BDD_PORT" ,3306);
define('HTTP_CSS', HTTP_MAIN . "css/");
define('HTTP_JS', HTTP_MAIN . "javascript/");
define('HTTP_IMG', HTTP_MAIN . "images/");
define('HTTP_IMG_LOGO', HTTP_IMG . "logo/");
define('HTTP_IMG_ART', HTTP_IMG . "articles/");
define('HTTP_IMG_TMP', HTTP_IMG . "tmp/");
define('HTTP_IMG_MODE_REGLEMENT', HTTP_IMG . "mode_reglement/");
define('HTTP_IMG_BILLETAGE', HTTP_IMG . "billetage/");
define('HTTP_IMG_CHAMBRE', HTTP_IMG . "chambre/");
define('HTTP_IMG_SALLE', HTTP_IMG . "salle/");
define('HTTP_IMG_TABLE_CLIENT', HTTP_IMG . "table_client/");
define('RP_MAIN', substr($_SERVER["DOCUMENT_ROOT"],-1) == '/' ? $_SERVER["DOCUMENT_ROOT"] . SITE.'/' : $_SERVER["DOCUMENT_ROOT"].'/' . SITE.'/');
define('RP_IMG', RP_MAIN . 'public/images/');
define('RP_IMG_LOGO', RP_IMG . 'logo/');
define('RP_IMG_ART', RP_IMG . 'articles/');
define('RP_IMG_TMP', RP_IMG . 'tmp/');
define('RP_IMG_BILLETAGE', RP_IMG . "billetage/");
define('RP_IMG_CHAMBRE', RP_IMG . "chambre/");
define('RP_IMG_SALLE', RP_IMG . "salle/");
define('RP_IMG_TABLE_CLIENT', RP_IMG . "table_client/");
define('RP_LIB', RP_MAIN . 'app/lib/');
define('CODE_LANG','sess_code_lang');
define('DEFAULT_LANG', '/fr/');
define('RP_RESSOURCES', RP_MAIN . 'app/ressources/');
define('RP_BIRT' , RP_LIB . 'birt/');
define('RP_REPORT' , RP_MAIN . "public/report/");
// SQL server connection information
$sql_details = array(
'user' => LOGIN_DB,
'pass' => PWS_DB,
'db' => BDD,
'host' => SERVEUR
);
?>
code of ../app/config_inc.php :
<?php
require_once RP_LIB . 'ressources.lib.php';
require_once RP_LIB . 'pagination.lib.php';
require_once RP_LIB . 'debug.php';
require_once RP_LIB . 'datetime.lib.php';
require_once RP_LIB . 'mysql.lib.php';
require_once RP_LIB . 'string.lib.php';
require_once RP_LIB . 'numberFormat.lib.php';
require_once RP_LIB . 'file.lib.php';
#ini_alter('error_log', RP_MAIN . 'log/error.log');
#ini_alter('default_charset', 'iso-8859-1');
loadRessource('main') ;
loadRessource('global') ;
?>
code of ../app/lib/PSR.php :
<?php
/*
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to license#phalconphp.com so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Piyush Rajesh <mba.piyushgupta#gmail.com> |
| Serghei Iakovlev <sadhooklay#gmail.com> |
+------------------------------------------------------------------------+
*/
namespace Phalcon\Loader;
use Phalcon\Loader;
/**
* Phalcon\Loader\PSR.
* Implements PSR-0 autoloader for your apps.
*
* #package Phalcon\Loader
*/
class PSR extends Loader
{
/**
* Namespace separator
* #var string
*/
protected $namespaceSeparator = '\\';
/**
* Loads the given class or interface.
*
* #param string $className The name of the class to load.
*
* #return bool
*/
public function autoLoad($className)
{
// Reduce slashes
$className = ltrim($className, $this->namespaceSeparator);
$array = explode($this->namespaceSeparator, $className);
if (array_key_exists($array[0], $this->_namespaces)) {
$array[0] = $this->_namespaces[$array[0]];
$class = array_pop($array);
array_push($array, str_replace("_", DIRECTORY_SEPARATOR, $class));
$file = implode($array, DIRECTORY_SEPARATOR);
foreach ($this->_extensions as $ext) {
if (file_exists($file . ".$ext")) {
require $file . ".$ext";
return true;
}
}
}
// If it did not fit standard PSR-0, pass it on to the original Phalcon autoloader
return parent::autoLoad($className);
}
}
The folder you are pointing to doesn't contain an index.php so apache doesn't know to look in your /public/ folder for your index.php. You'd either need to visit http://localhost/resto/public/ to see your site, add an index.php to the base directory (that maybe just includes the one in public) or what is probably best is to create a virtual host that points to your public folder (this does what it would need to in production and makes your business code not directly accessible).
Info on setting up vhosts in WAMP https://john-dugan.com/wamp-vhost-setup/
Phalcon documention for what a vhost should look like https://docs.phalconphp.com/en/3.3/webserver-setup#apache

Authenticating with OpenLDAP from PHP

Using CentOS 7.5, Apache 2.4.6. Running in a VM. No SSL.
I followed https://linuxhostsupport.com/blog/how-to-install-ldap-on-centos-7/ and configured OpenLDAP.
From PHP, when I do an anonymous bind, and issue ldap_search, I see the entry for the user.
When binding with the userid & password, the function fails.
P.S: In case I am typing the wrong password, how do I change a password for a user defined in LDAP using ldif file?
Here is the code:
$ds = ldap_connect("localhost"); // must be a valid LDAP server!
echo "LDAP Server connection result is " . $ds . "<br />";
if ($ds) {
echo "Binding ...";
$r=ldap_bind($ds); // this is an "anonymous" bind, typically
// read-only access
echo "Bind result is " . $r . "<br />";
echo "Searching for (sn=*) ...";
// Search surname entry
$sr=ldap_search($ds, "o=Sapphire, ou=karachi", "sn=*");
echo "Search result is " . $sr . "<br />";
echo "Number of entries returned is " . ldap_count_entries($ds, $sr) . "<br />";
echo "Getting entries ...<p>";
$info = ldap_get_entries($ds, $sr);
echo "Data for " . $info["count"] . " items returned:<p>";
for ($i=0; $i<$info["count"]; $i++) {
echo "dn is: " . $info[$i]["dn"] . "<br />";
echo "first cn entry is: " . $info[$i]["cn"][0] . "<br />";
echo "first email entry is: " . $info[$i]["mail"][0] . "<br /><hr />";
}
echo "Binding as $userid ... ";
if( $r = ldap_bind($ds, "uid=hussain,ou=People,dc=karachi,dc=sapphire", $password) ){
echo "Userid or Password is valid";
}else{
echo "Userid or Password is not valid";
}
echo "Closing connection";
ldap_close($ds);
} else {
echo "<h4>Unable to connect to LDAP server</h4>";
}
Found the answer. I needed to add
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
before issuing the bind.

Opencart "store change" php code

Is there any php code to change store? So for example if php detects the language is Spanish I would like it to change the whole store to other store.
So it can be used for example anytime when language is changed - then the store is changed also.
So for example if anyone is viewing the store1 in English and change language to Spanish then automatically the store1 is also changed to store2 toghether with the language. Any idea?
If you open file: index.php or startup.php (based on the OpenCart version you use) you will see that there is a code that checks the url of which the user has visited and then searches the database to see if it's default store (store_id = 0) or other store. If it's the default store, then nothing changes. If it's not though, then session variable (store_id) is changed to the specified store_id and the whole opencart will operate based on this store_id.
OpenCart 1.5.x index.php
// Store
if (isset($_SERVER['HTTPS']) && (($_SERVER['HTTPS'] == 'on') || ($_SERVER['HTTPS'] == '1'))) {
$store_query = $db->query("SELECT * FROM " . DB_PREFIX . "store WHERE REPLACE(`ssl`, 'www.', '') = '" . $db->escape('https://' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/') . "'");
} else {
$store_query = $db->query("SELECT * FROM " . DB_PREFIX . "store WHERE REPLACE(`url`, 'www.', '') = '" . $db->escape('http://' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/') . "'");
}
if ($store_query->num_rows) {
$config->set('config_store_id', $store_query->row['store_id']);
} else {
$config->set('config_store_id', 0);
}
OpenCart 2.x / 3.x - catalog/controller/startup/startup.php
// Store
if ($this->request->server['HTTPS']) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "store WHERE REPLACE(`ssl`, 'www.', '') = '" . $this->db->escape('https://' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/') . "'");
} else {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "store WHERE REPLACE(`url`, 'www.', '') = '" . $this->db->escape('http://' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/') . "'");
}
if (isset($this->request->get['store_id'])) {
$this->config->set('config_store_id', (int)$this->request->get['store_id']);
} else if ($query->num_rows) {
$this->config->set('config_store_id', $query->row['store_id']);
} else {
$this->config->set('config_store_id', 0);
}
So, you can extend this code and you will check the browser's language and based on every language you will change the store_id to the one you need.
A sample code is the following, it's not the ideal, but it will give you the idea on how to implement it by yourself.
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
switch ($lang){
case "fr":
$this->config->set('config_store_id', 1);
break;
case "it":
$this->config->set('config_store_id', 2);
break;
case "en":
$this->config->set('config_store_id', 3);
break;
case "el":
$this->config->set('config_store_id', 4);
break;
default:
//else default store
$this->config->set('config_store_id', 0);
break;
}
Hope the above answer will help you. It's easy, but you need to understand how OpenCart works. Also, just my advice..."Don't wait for ready-made extensions, try to make yours." ;)
Cheers!

Doctrine Querybuilder, binding Parameters

My Select function of my QueryManager:
/**
* Führt eine SELECT - Query durch
*
* #param $select = array( array(column, [...]), table, shortcut )
* $orderby = array(column, sorting-type)
* $where = array( array( column, value, type[or, and] ), [...] )
* $innerjoin = array( table, shortcut, condition )
* $pagination = array( page, limit )
*
* #return array $data
*/
public function select($select,$orderby, $where, $innerjoin, $pagination)
{
$qb = $this->conn->createQueryBuilder()
->select($select[0])
->from($select[1], $select[2])
;
if ($orderby) {
$qb->orderBy($orderby);
}
if ($where) {
foreach($where as $cond) {
$x = 0;
if ( key($cond) == 0 ) {
$qb
->where($cond[0] . ' = ?')
->setParameter($x,$cond[1]);
}
elseif ( $cond[2] == 'and' ) {
$qb
->andWhere($cond[0] . ' = ?')
->setParameter($x,$cond[1]);
}
elseif ( $cond[2] == 'and' ) {
$qb
->orWhere($cond[0] . ' = :' . $x)
->setParameter($x,$cond[1]);
}
$x++;
}
}
if ($innerjoin) {
$qb->join($select[2],$innerjoin);
}
$this->sql = $qb->getSQL();
$this->totalRowCount = count( $qb->execute() ) ;
if ($pagination) {
$max = $pagination[0] * $pagination[1];
$first = $max - $limit;
$qb
->setFirstResult($first)
->setMaxResults($max)
;
}
$stmt = $qb->execute();
return $stmt->fetchAll();
}
I don't know why, but in action, this function produces a select query without inserted values for the parameters:
/**
* Lädt einen User nach dessen Username
*
* #param $username
* #return User $user | null
*/
public function getUser($username)
{
if($data = $this->select(array('*','users','u'), null, array( array('username',$username) ), null,null)) {
return $user = $this->hydrate($data);
}
return null;
}
I didn't get a result, and the query is not setup correctly:
array(0) { }
SELECT * FROM users u WHERE username = ?
In my opinion the Builder doesn't supstitute my parameters with the provided values ...
I got the latest version of Doctrine DBAL (2.4) and this version should support this features!
Thanks for Help and Suggestions :)
I also had this Problem. I have readed here doctrine 2 querybuilder with set parameters not working that:
You cant bind parameters to QueryBuilder, only to Query
But im creating SQL conditions as collected AND & OR experssions in deep nested objects, and the toppest object creates the query object. So i cant create the query object before, i always return expression objects.
So i solved the problem with direct including the variable into the prepared variable's position.
$qb->where($cond[0] . '=' . $cond[1]);
And because i expect strings there i added hard coded quotes. This is not the desired way, but at the moment i dont know how to solve that in an other way with binding parameters to the QueryBuilder object.
$expr = $d_qb->expr()->between($t_c, "'" . $date_from . "'", "'" . $date_from . "'");
Other suggestions?
Following codes results:
$expr = $d_qb->expr()->between($t_c, ':from', ':to');
$d_qb->setParameter('from', 1);
$d_qb->setParameter('to', 1);
or
$expr = $d_qb->expr()->between($t_c, ':from', ':to');
$d_qb->setParameter(':from', 1);
$d_qb->setParameter(':to', 1);
Results:
e0_.created BETWEEN ? AND ?

Trying to publish to my wall, getting "Insufficient permission" error

I am using the following code post to my timeline. I am getting an error which is shown at the end of this post. Any ideas?
<?php
......
$request = 'https://graph.facebook.com/oauth/access_token';
$grant_type = 'client_credentials';
$client_id = '1504901xxxxxxxx'; //FaceBook Developer App_id LIVE
$client_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; //Facebook Developer Api_secret LIVE
$postargs = 'grant_type=' . urlencode($grant_type) . '&client_id=' . $client_id . '&client_secret=' . $client_secret;
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, $postargs);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
preg_match('/access_token=(.*)/', $response, $match);
curl_close($session);
$access_token = trim($match[1]);
$Application = 'WTSO';
$User = '1504901xxxxxxxx'; /*this is the user id*/
$target_id = '1647886xxxxxxxx';
$api_url = 'https://api.facebook.com/method/stream.publish?';
$server_loc = 'https://wtso.com';
$logo = new stdClass();
$attachment = new stdClass();
$logo->type = 'image';
$logo->src = 'http://admin.wtso.com' . '/images/' . (($new_products['image_name']) ? $new_products['image_name'] : 'xx1235.jpg');
$logo->href = $facebook_bitly;
$attachment->name = ' '; //'WTSO Product Notification';
$attachment->caption = (!empty($new_products['products_short_description'])) ? substr(strip_tags($new_products['products_short_description']), 0, 900) : $facebookText;
$attachment->description = ' ';
$attachment->href = $facebook_bitly;
$attachment->media = array($logo);
$message = (!empty($facebookText)) ? strip_tags($facebookText) : $new_products['products_name'];
$postargs2 = 'message=' . urlencode($message) . '&attachment=' . urlencode(json_encode($attachment)) . '&target_id=' . urlencode($target_id) . '&access_token=' . urlencode($access_token) . '&method=stream.publish';
$request2 = $api_url . $postargs2;
//Initiating a 2nd Curl instance
$session2 = curl_init($request2);
curl_setopt($session2, CURLOPT_HEADER, false);
curl_setopt($session2, CURLOPT_RETURNTRANSFER, true);
$response2 = curl_exec($session2);
curl_close($session2);
?>
I am getting this error from Facebook in $response2
<error_code>200</error_code>
<error_msg>Insufficient permission to post to target on behalf of the viewer</error_msg>