Hello I would like to set the Description for magento products using data collected from Amazon api. I am calling the API and receiving the response however in the logs I get :
Recoverable Error: Object of class stdClass could not be converted to string
The question is how to parse the information into a string so it can be used within magento product details?
<?php
require_once '../abstract.php';
require('AmazonApi.php');
class Mage_Shell_Amazon extends Mage_Shell_Abstract
{
public function run() {
//Create API access object
$public_key = '*********';
$secret_key = '*********+*******';
$associate_tag = '*******-21';
$amazon_api = new AmazonAPI($public_key, $secret_key, $associate_tag);
//load product by categoryId
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('asin')
->addAttributeToSelect('description');
//Array of request parameters
foreach($products as $prod)
{
//load the actual products data
$product = Mage::getModel('catalog/product')->load($prod->getId());
$asin = $product->getAsin();
$params_array = array(
'Operation' => 'ItemLookup',
'IdType' => 'ASIN',
'ItemId' => $asin ,
'ResponseGroup' => 'Tracks');
// returns a list of items for the search query 'Slow Magic'
$response = $amazon_api->sendRequest($params_array);
$product->setDescription($restponse);
$product->getResource()->saveAttribute($product, 'description');
foreach ($response as $restponse)
{
sleep(1);
}
echo '<pre>';
print_r($restponse);
echo '</pre>';
}
// foreach($parsed_xml->OperationRequest->Errors->Error as $error){
// echo "Error code: " . $error->Code . "\r\n";
// echo $error->Message . "\r\n";
// echo "\r\n";
// }
}
}
$amazonConnector = new Mage_Shell_Amazon();
$amazonConnector->run();
Sample from Amazon response for one of the products :
[Items] => stdClass Object
(
[Request] => stdClass Object
(
[IsValid] => True
[ItemLookupRequest] => stdClass Object
(
[IdType] => ASIN
[ItemId] => B000002OGL
[ResponseGroup] => Tracks
[VariationPage] => All
)
)
[Item] => stdClass Object
(
[ASIN] => B000002OGL
[Tracks] => stdClass Object
(
[Disc] => stdClass Object
(
[Track] => Array
(
[0] => stdClass Object
(
[_] => Mustang Sally
[Number] => 1
)
[1] => stdClass Object
(
[_] => Take Me To The River
[Number] => 2
)
[2] => stdClass Object
(
[_] => Chain Of Fools
[Number] => 3
)
[3] => stdClass Object
(
[_] => The Dark End Of The Street
[Number] => 4
)
[4] => stdClass Object
(
[_] => Destination: Anywhere
[Number] => 5
)
[5] => stdClass Object
(
[_] => I Can't Stand The Rain
[Number] => 6
)
[6] => stdClass Object
(
[_] => Try A Little Tenderness
[Number] => 7
)
[7] => stdClass Object
(
[_] => Treat Me Right
[Number] => 8
)
[8] => stdClass Object
(
[_] => Do Right Woman Do Right Man
[Number] => 9
)
[9] => stdClass Object
(
[_] => Mr. Pitiful
[Number] => 10
)
[10] => stdClass Object
(
[_] => I Never Loved A Man
[Number] => 11
)
[11] => stdClass Object
(
[_] => In The Midnight Hour
[Number] => 12
)
[12] => stdClass Object
(
[_] => Bye Bye Baby
[Number] => 13
)
[13] => stdClass Object
(
[_] => Slip Away
[Number] => 14
)
)
[Number] => 1
)
)
)
)
)