This Post show eKomi Fronted Integration with zend application.
In this example i have create ItemreviewServise file for connect eKomi API get reviews and store those reviews on local database. For performance reasons eKomi recommend to store the reviews in local database.
class Itemreview_Service_ItemreviewService extends Base_Model_Service {
public function ekomiItemreview($language)
{
$ekomicertificate = '';
$errorlang = "";
if($language == "english"){
$interfaceid = $configItem->ekomiInterfaceId;
$ekomipassword = $configItem->ekomiPassword;
$errorlang = "English";
}
try
{
$Url = $config->ekomiProFeedbakUrl;
$Service = new Itemreview_Service_ClassAPIwebService($Url, "GET", "ISO-8859-1");
$Params["interface_id"] = $interfaceid;
$Params["interface_pw"] = $ekomipassword;
$Params["type"] = "csv";
$Params["range"] = $config->ekomiRange;
flush();
$Response = $Service->SendRequest($Params);
$CSVBODY = $Response["Body"];
$ItemreviewServicearray = new Itemreview_Service_ItemreviewService();
$retunval = $ItemreviewServicearray->csv_to_array($CSVBODY);
foreach ($retunval as $key => $arrParam) {
try
{
$ItemreviewService = new Itemreview_Service_ItemreviewService();
$Itemreviwentity = new Itemreview_Entity_Itemreview();
$Itemreviwentity->setItm_id($arrParam['product_id']);
$Itemreviwentity->setLang_id(66);
$Itemreviwentity->set_auther("eKomi");
$Itemreviwentity->setRe_text($arrParam['feedback']);
$Itemreviwentity->setRe_text($replasequote);
$Itemreviwentity->set_rating($arrParam['star_rating']);
$Itemreviwentity->set_reviewlink("$ekomicertificate");
$Itemreviwentity->setRe_isenable(1);
$Itemreviwentity->set_unixtime($arrParam['UNIXTIME']);
$Itemreviwentity->set_orderid($arrParam['order_id']);
$ItemreviewDAO = new Itemreview_Dao_ItemreviewDao();
$ItemreviewDAO->addEkomireview($Itemreviwentity);
}
catch ( Exception $e)
{
print_r("error ...!!");
}
}
}
catch ( Exception $e)
{
print_r("record fail-$errorlang ---!!!");
}
}
public static function csv_to_array($csv, $delimiter = ',', $enclosure = '"', $escape = '\\', $terminator = "\n") {
$r = array();
$filecsv = APPLICATION_PATH."/xml/eKomiresponce.csv";
if(file_exists($filecsv)){
unlink($filecsv);
}
$fp = fopen($filecsv, 'w');
fwrite($fp, $csv);
fclose($fp);
$name_columns = array("UNIXTIME", "order_id", "product_id", "star_rating", "feedback");
$handle = fopen ($filecsv, 'r');
while (($data = fgetcsv($handle, 1000, ',', '"')) !== FALSE)
{
$r[] = array_combine($name_columns,$data);
}
return $r;
}
Following Class , i use to connect eKomi web service and get reviews
class Itemreview_Service_ClassApiwebService
{
const TIME_OUT = 10;
private $UserAgent;
private $Method;
private $CharSet;
private $Url;
public function __construct($ServerUrl, $Method, $CharSet, $UserAgent="")
{
error_reporting(E_ERROR | E_WARNING | E_PARSE);
if (function_exists(domxml_open_mem))
throw new Exception("Please comment out the line 'extension=php_domxml.dll' in Apache/bin/php.ini and restart the server!");
if (empty($UserAgent)) $UserAgent = "PHP WebService Client";
$this->Url = parse_url($ServerUrl);
$this->UserAgent = $UserAgent;
$this->Method = strtoupper($Method);
$this->CharSet = $CharSet;
if (empty($this->Url["path"])) $this->Url["path"] = "/";
}
public function SendRequest($Data, $SoapAction="")
{
if (is_array($Data))
{
$Params = array();
foreach ($Data as $Key => $Value)
{
$Encode = str_replace('%7E', '~', rawurlencode($Value));
$Params[] = "$Key=$Encode";
}
$Query = implode('&', $Params);
}
else $DispParams = $Data;
switch ($this->Method)
{
case "GET":
$SendData = "GET ".$this->Url["path"]."?$Query HTTP/1.0\r\n";
$SendData .= "Host: " . $this->Url['host'] . "\r\n";
$SendData .= "User-Agent: " . $this->UserAgent . "\r\n";
$SendData .= "\r\n";
break;
case "POST":
$SendData = "POST ".$this->Url["path"]." HTTP/1.0\r\n";
$SendData .= "Host: " . $this->Url['host'] . "\r\n";
$SendData .= "Content-Type: application/x-www-form-urlencoded; charset=".$this->CharSet."\r\n";
$SendData .= "Content-Length: " . strlen($Query) . "\r\n";
$SendData .= "User-Agent: " . $this->UserAgent . "\r\n";
$SendData .= "\r\n";
$SendData .= $Query;
break;
default:
throw new Exception("Invalid Method: ".$this->Method);
}
$Port = array_key_exists('port',$this->Url) ? $this->Url['port'] : null;
switch ($this->Url['scheme'])
{
case 'https':
if (!function_exists(openssl_verify))
throw new Exception("Please remove the comment in the line ';extension=php_openssl.dll' in Apache/bin/php.ini and restart the server!");
$Scheme = 'ssl://';
$Port = ($Port === null) ? 443 : $Port;
break;
case 'http':
$Scheme = '';
$Port = ($Port === null) ? 80 : $Port;
break;
default:
throw new Exception("Invalid protocol in: ".$this->ServerUrl);
}
$Socket = @fsockopen($Scheme . $this->Url['host'], $Port, $ErrNo, $ErrStr, 10);
if (!$Socket)
throw new Exception ("Unable to establish connection to host " . $this->Url['host'] . " $ErrStr");
fwrite($Socket, $SendData);
$Response = "";
while (!feof($Socket))
{
$Response .= fgets($Socket, 1000);
}
fclose($Socket);
// Between Header and ResponseBody there are two empty lines
list($Header, $ResponseBody) = explode("\r\n\r\n", $Response, 2);
$Split = preg_split("/\r\n|\n|\r/", $Header);
list($Protocol, $StatusCode, $StatusText) = explode(' ', trim(array_shift($Split)), 3);
$RetArray["Status"] = $StatusCode;
$RetArray["Body"] = $ResponseBody;
return $RetArray;
}
}
Hope this will help :)
In this example i have create ItemreviewServise file for connect eKomi API get reviews and store those reviews on local database. For performance reasons eKomi recommend to store the reviews in local database.
class Itemreview_Service_ItemreviewService extends Base_Model_Service {
public function ekomiItemreview($language)
{
$ekomicertificate = '';
$errorlang = "";
if($language == "english"){
$interfaceid = $configItem->ekomiInterfaceId;
$ekomipassword = $configItem->ekomiPassword;
$errorlang = "English";
}
try
{
$Url = $config->ekomiProFeedbakUrl;
$Service = new Itemreview_Service_ClassAPIwebService($Url, "GET", "ISO-8859-1");
$Params["interface_id"] = $interfaceid;
$Params["interface_pw"] = $ekomipassword;
$Params["type"] = "csv";
$Params["range"] = $config->ekomiRange;
flush();
$Response = $Service->SendRequest($Params);
$CSVBODY = $Response["Body"];
$ItemreviewServicearray = new Itemreview_Service_ItemreviewService();
$retunval = $ItemreviewServicearray->csv_to_array($CSVBODY);
foreach ($retunval as $key => $arrParam) {
try
{
$ItemreviewService = new Itemreview_Service_ItemreviewService();
$Itemreviwentity = new Itemreview_Entity_Itemreview();
$Itemreviwentity->setItm_id($arrParam['product_id']);
$Itemreviwentity->setLang_id(66);
$Itemreviwentity->set_auther("eKomi");
$Itemreviwentity->setRe_text($arrParam['feedback']);
$Itemreviwentity->setRe_text($replasequote);
$Itemreviwentity->set_rating($arrParam['star_rating']);
$Itemreviwentity->set_reviewlink("$ekomicertificate");
$Itemreviwentity->setRe_isenable(1);
$Itemreviwentity->set_unixtime($arrParam['UNIXTIME']);
$Itemreviwentity->set_orderid($arrParam['order_id']);
$ItemreviewDAO = new Itemreview_Dao_ItemreviewDao();
$ItemreviewDAO->addEkomireview($Itemreviwentity);
}
catch ( Exception $e)
{
print_r("error ...!!");
}
}
}
catch ( Exception $e)
{
print_r("record fail-$errorlang ---!!!");
}
}
public static function csv_to_array($csv, $delimiter = ',', $enclosure = '"', $escape = '\\', $terminator = "\n") {
$r = array();
$filecsv = APPLICATION_PATH."/xml/eKomiresponce.csv";
if(file_exists($filecsv)){
unlink($filecsv);
}
$fp = fopen($filecsv, 'w');
fwrite($fp, $csv);
fclose($fp);
$name_columns = array("UNIXTIME", "order_id", "product_id", "star_rating", "feedback");
$handle = fopen ($filecsv, 'r');
while (($data = fgetcsv($handle, 1000, ',', '"')) !== FALSE)
{
$r[] = array_combine($name_columns,$data);
}
return $r;
}
Following Class , i use to connect eKomi web service and get reviews
class Itemreview_Service_ClassApiwebService
{
const TIME_OUT = 10;
private $UserAgent;
private $Method;
private $CharSet;
private $Url;
public function __construct($ServerUrl, $Method, $CharSet, $UserAgent="")
{
error_reporting(E_ERROR | E_WARNING | E_PARSE);
if (function_exists(domxml_open_mem))
throw new Exception("Please comment out the line 'extension=php_domxml.dll' in Apache/bin/php.ini and restart the server!");
if (empty($UserAgent)) $UserAgent = "PHP WebService Client";
$this->Url = parse_url($ServerUrl);
$this->UserAgent = $UserAgent;
$this->Method = strtoupper($Method);
$this->CharSet = $CharSet;
if (empty($this->Url["path"])) $this->Url["path"] = "/";
}
public function SendRequest($Data, $SoapAction="")
{
if (is_array($Data))
{
$Params = array();
foreach ($Data as $Key => $Value)
{
$Encode = str_replace('%7E', '~', rawurlencode($Value));
$Params[] = "$Key=$Encode";
}
$Query = implode('&', $Params);
}
else $DispParams = $Data;
switch ($this->Method)
{
case "GET":
$SendData = "GET ".$this->Url["path"]."?$Query HTTP/1.0\r\n";
$SendData .= "Host: " . $this->Url['host'] . "\r\n";
$SendData .= "User-Agent: " . $this->UserAgent . "\r\n";
$SendData .= "\r\n";
break;
case "POST":
$SendData = "POST ".$this->Url["path"]." HTTP/1.0\r\n";
$SendData .= "Host: " . $this->Url['host'] . "\r\n";
$SendData .= "Content-Type: application/x-www-form-urlencoded; charset=".$this->CharSet."\r\n";
$SendData .= "Content-Length: " . strlen($Query) . "\r\n";
$SendData .= "User-Agent: " . $this->UserAgent . "\r\n";
$SendData .= "\r\n";
$SendData .= $Query;
break;
default:
throw new Exception("Invalid Method: ".$this->Method);
}
$Port = array_key_exists('port',$this->Url) ? $this->Url['port'] : null;
switch ($this->Url['scheme'])
{
case 'https':
if (!function_exists(openssl_verify))
throw new Exception("Please remove the comment in the line ';extension=php_openssl.dll' in Apache/bin/php.ini and restart the server!");
$Scheme = 'ssl://';
$Port = ($Port === null) ? 443 : $Port;
break;
case 'http':
$Scheme = '';
$Port = ($Port === null) ? 80 : $Port;
break;
default:
throw new Exception("Invalid protocol in: ".$this->ServerUrl);
}
$Socket = @fsockopen($Scheme . $this->Url['host'], $Port, $ErrNo, $ErrStr, 10);
if (!$Socket)
throw new Exception ("Unable to establish connection to host " . $this->Url['host'] . " $ErrStr");
fwrite($Socket, $SendData);
$Response = "";
while (!feof($Socket))
{
$Response .= fgets($Socket, 1000);
}
fclose($Socket);
// Between Header and ResponseBody there are two empty lines
list($Header, $ResponseBody) = explode("\r\n\r\n", $Response, 2);
$Split = preg_split("/\r\n|\n|\r/", $Header);
list($Protocol, $StatusCode, $StatusText) = explode(' ', trim(array_shift($Split)), 3);
$RetArray["Status"] = $StatusCode;
$RetArray["Body"] = $ResponseBody;
return $RetArray;
}
}
Hope this will help :)
Is there any way to get product name along with product id.
ReplyDeleteeKomi use product id(or SKU) for maintain reviews
DeleteWould you be able to give me any help in integrating the ekomi reviews left for my store, in to the front end of my Magento store via retrieving them and storing them in my db
ReplyDeleteyes sure :), what is the magento version that you use
DeleteThank you. I am using Magento 1.7.0.2.
DeleteIt is the product reviews I need to place on the corresponding product page. There is a widget for the service reviews provided by ekomi so I ma ok for the service reviews, its just the product reviews.
Deletei think you can use " Itemreview_Service_ClassApiwebService" class(that mention in above post) for connect ekomi server and get product reviews. i have done eKomi integration few months ago, i think now eKomi provide select date range(daily, montly, etc..) for get reviews.
DeleteFor add reviews into magento product page, i think this post will help you get idea - http://www.letsmakeitgo.com/blog/2011/06/magento-add-product-ratings-programmatically-or-migrating-reviews-and-ratings-to-magento/
just change
"
foreach ($retunval as $key => $arrParam) {
try
{
"
part into magento migration code, and then set cron for execute above script for daily. hope this will help you, do need more explanation(example code) ? ;)
Thank you for your reply..... an example of the code would be great if you dont mind. Where do I set my ekomi api details to connect to ekomi database?
Deleteaccording to post that i previously, just change following values
Delete$Params["interface_id"] = $your_interface_id;
$Params["interface_pw"] = $your_ekomi_password;
$Params["type"] = "csv";
In your original post of the code does it strip out some of the syntax for the php file for instance <?php at the beginning. I am struggling to get this to work
ReplyDeletemmmm.... if you can send your source code, i think i can help you
Deletewhats the best way to send you the source code?
DeleteHello Kavindu , please tell me how can i get ekomi reviews for my oscommerce store form http://api.ekomi.de/get_productfeedback.php url ?
ReplyDelete