예제 #1
0
/**
 * function executed every hour on cron job
 */
function updateItemsDataHourly()
{
    $appid = get_option('dbaa_amazon_appid');
    $coutryCode = get_option('dbaa_amazon_coutnrycode');
    $secretKey = get_option('dbaa_amazon_secretkey');
    $associatetag = get_option('dbaa_amazon_associatetag');
    if ($appid != '' && $coutryCode != '' && $secretKey != '') {
        $amazon = new Zend_clicks_Service_Amazon($appid, $coutryCode, $secretKey);
        $results = AA_Items::get();
        foreach ($results as $result) {
            $amazonresults = $amazon->itemLookup($result->item_asin, array('AssociateTag' => $associatetag, 'ResponseGroup' => 'Small, OfferFull, ItemAttributes'));
            foreach ($amazonresults as $amazonresult) {
                $vk = 'bla';
                if (isset($amazonresult->Offers->Offers)) {
                    $vk = $amazonresult->Offers->Offers[0]->FormattedPrice;
                } elseif (isset($amazonresult->FormattedPrice)) {
                    $vk = $amazonresult->FormattedPrice;
                }
                if ($result->item_price != $vk) {
                    AA_Item::updatePrice($vk, $result->item_id);
                }
            }
        }
    }
}