Changeset 4919

Show
Ignore:
Timestamp:
01/12/08 01:54:06 (2 years ago)
Author:
ebihara
Message:

#1747:AmazonECS4.phpを使用するようにした

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • OpenPNE/trunk/webapp/lib/db/review.php

    r4856 r4919  
    9595    } 
    9696 
    97     include_once 'Services/Amazon.php'; 
    98     $amazon =& new Services_Amazon(AMAZON_TOKEN, AMAZON_AFFID, AMAZON_LOCALE, AMAZON_BASEURL); 
     97    // 暫定的に、旧カテゴリとSearchIndexの対応テーブルを用いる 
     98    $category2index = array( 
     99        'books-jp' => 'Books', 
     100        'books-us' => 'ForeignBooks', 
     101        'music-jp' => 'Music', 
     102        'classical-jp' => 'Classical', 
     103        'dvd-jp' => 'Music', 
     104        'videogames-jp' => 'Music', 
     105        'software-jp' => 'Software', 
     106        'electronics-jp' => 'Electronics', 
     107        'kitchen-jp' => 'Kitchen', 
     108        'toys-jp' => 'Toys', 
     109        'sporting-goods-jp' => 'SportingGoods', 
     110        'hpc-jp' => 'HealthPersonalCare', 
     111    ); 
     112     
     113    include_once 'Services/AmazonECS4.php'; 
     114    $amazon =& new Services_AmazonECS4(AMAZON_TOKEN, AMAZON_AFFID); 
     115    $amazon->setLocale(AMAZON_LOCALE); 
     116//    $amazon->setBaseUrl(AMAZON_BASEURL); 
    99117    if (OPENPNE_USE_HTTP_PROXY) { 
    100118        $amazon->setProxy(OPENPNE_HTTP_PROXY_HOST, OPENPNE_HTTP_PROXY_PORT); 
    101119    } 
    102     $products = $amazon->searchKeyword($keyword, $category, $page); 
     120 
     121    $options = array( 
     122        'Keywords' => $keyword, 
     123        'ItemPage' => $page, 
     124        'ResponseGroup' => 'Large', 
     125    ); 
     126    $products = $amazon->ItemSearch($category2index[$category], $options); 
     127 
    103128    if (PEAR::isError($products)) { 
    104129        return null; 
    105130    } 
    106     if (empty($products['totalresults'])) { 
     131    if (empty($products['Request']['IsValid']) || $products['Request']['IsValid'] !== 'True') { 
    107132        return null; 
    108133    } 
    109134 
    110     foreach ($products as $key => $value) { 
    111         if (is_array($value['authors'])) { 
    112             $authors = array_unique($value['authors']); 
    113             $products[$key]['author'] = implode(', ', $authors); 
    114         } 
    115         if (is_array($value['artists'])) { 
    116             $artists = array_unique($value['artists']); 
    117             $products[$key]['artist'] = implode(', ', $artists); 
    118         } 
    119     } 
    120  
    121     $product_page = $products['page']; 
    122     $product_pages = $products['pages']; 
    123     $total_num = $products['totalresults']; 
    124     unset($products[0]); 
    125     unset($products['page']); 
    126     unset($products['pages']); 
    127     unset($products['totalresults']); 
    128  
    129     return array($products, $product_page, $product_pages, $total_num); 
     135    foreach ($products['Item'] as $key => $value) { 
     136        if (is_array($value['ItemAttributes']['Author'])) { 
     137            $authors = array_unique($value['ItemAttributes']['Author']); 
     138            $products['Item'][$key]['author'] = implode(', ', $authors); 
     139        } 
     140        if (is_array($value['ItemAttributes']['Aritst'])) { 
     141            $artists = array_unique($value['ItemAttributes']['Artist']); 
     142            $products['Item'][$key]['artist'] = implode(', ', $artists); 
     143        } 
     144    } 
     145 
     146    $product_page = $products['Request']['ItemSearchRequest']['ItemPage']; 
     147    $product_pages = $products['TotalPages']; 
     148    $total_num = $products['TotalResults']; 
     149 
     150    return array($products['Item'], $product_page, $product_pages, $total_num); 
    130151} 
    131152 
    132153function db_review_write_product4asin($asin) 
    133154{ 
    134     include_once 'Services/Amazon.php'; 
    135     $amazon =& new Services_Amazon(AMAZON_TOKEN, AMAZON_AFFID, AMAZON_LOCALE, AMAZON_BASEURL); 
     155    include_once 'Services/AmazonECS4.php'; 
     156    $amazon =& new Services_AmazonECS4(AMAZON_TOKEN, AMAZON_AFFID); 
     157    $amazon->setLocale(AMAZON_LOCALE); 
     158//    $amazon->setBaseUrl(AMAZON_BASEURL); 
    136159    if (OPENPNE_USE_HTTP_PROXY) { 
    137160        $amazon->setProxy(OPENPNE_HTTP_PROXY_HOST, OPENPNE_HTTP_PROXY_PORT); 
     
    139162    $keyword = mb_convert_encoding($keyword, "UTF-8", "auto"); 
    140163 
    141     $result = $amazon->searchAsin($asin); 
     164    $options = array(); 
     165    $options['ResponseGroup'] = 'Large'; 
     166    $result = $amazon->ItemLookup($asin, $options); 
    142167    if (PEAR::isError($result)) { 
    143168        return false; 
    144169    } 
    145  
    146     $product  =$result[1]; 
    147     if ($result[1]['authors']) { 
    148         $product['author'] = implode(',', $result[1]['authors']); 
    149     } 
    150      
    151     if (!is_array($product)) { 
    152         return false; 
    153     } 
    154     foreach ($product as $key => $value) { 
    155         $product[$key] = mb_convert_encoding($value, 'UTF-8', 'auto'); 
     170    if (empty($result['Request']['IsValid']) || $result['Request']['IsValid'] !== 'True') { 
     171        return null; 
     172    } 
     173 
     174    $product  = $result['Item'][0]; 
     175    if (is_array($product['ItemAttributes']['Author'])) { 
     176        $authors = array_unique($product['ItemAttributes']['Author']); 
     177        $product['author'] = implode(', ', $authors); 
     178    } 
     179    if (is_array($product['ItemAttributes']['Aritst'])) { 
     180        $artists = array_unique($product['ItemAttributes']['Artist']); 
     181        $product['artist'] = implode(', ', $artists); 
    156182    } 
    157183 
     
    509535{ 
    510536    $sql = 'SELECT c_review_id FROM c_review WHERE asin = ?'; 
    511     $params = array($product['asin']); 
     537    $params = array($product['ASIN']); 
    512538    if ($c_review_id = db_get_one($sql, $params)) { 
    513539        return $c_review_id; 
     
    515541 
    516542    $data = array( 
    517         'title'        => $product['name'], 
    518         'release_date' => $product['release'], 
    519         'manufacturer' => $product['manufacturer'], 
     543        'title'        => $product['ItemAttributes']['Title'], 
     544        'release_date' => $product['ItemAttributes']['PublicationDate'], 
     545        'manufacturer' => $product['ItemAttributes']['Manufacturer'], 
    520546        'author'       => $product['author'], 
    521547        'c_review_category_id' => intval($c_review_category_id), 
    522         'image_small'  => $product['imagesmall'], 
    523         'image_medium' => $product['imagemedium'], 
    524         'image_large'  => $product['imagelarge'], 
    525         'url'          => $product['url'], 
    526         'asin'         => $product['asin'], 
    527         'list_price'   => $product['listprice'], 
    528         'retail_price' => $product['ourprice'], 
     548        'image_small'  => $product['MediumImage']['URL'], 
     549        'image_medium' => $product['MediumImage']['URL'], 
     550        'image_large'  => $product['MediumImage']['URL'], 
     551        'url'          => $product['DetailPageURL'], 
     552        'asin'         => $product['ASIN'], 
     553        'list_price'   => $product['ListPrice']['FormattedPrice'], 
     554        'retail_price' => $product['OfferSummary']['LowestUsedPrice']['FormattedPrice'], 
    529555        'r_datetime'   => db_now(), 
    530556    ); 
  • OpenPNE/trunk/webapp/modules/pc/templates/h_review_add.tpl

    r4274 r4919  
    180180<div class="padding_s"> 
    181181 
    182 <a href="({$product.url})" target="_blank"><img src="({if $product.imagemedium})({$product.imagemedium})({else})./skin/dummy.gif({/if})"><br>詳細を見る</a> 
     182<a href="({$product.DetailPageURL})" target="_blank"><img src="({if $product.MediumImage})({$product.MediumImage.URL})({else})./skin/dummy.gif({/if})"><br>詳細を見る</a> 
    183183 
    184184</div> 
     
    208208<div class="padding_s"> 
    209209 
    210 <span class="b_b">({$product.name})</span> 
     210<span class="b_b">({$product.ItemAttributes.Title})</span> 
    211211 
    212212</div> 
     
    240240<div class="padding_s"> 
    241241 
    242 ({$product.release})<br> 
    243 ({$product.manufacturer})<br> 
     242({$product.ItemAttributes.PublicationDate})<br> 
     243({$product.ItemAttributes.Manufacturer})<br> 
    244244({$product.artist})({$product.author}) 
    245245 
     
    262262<div class="padding_s"> 
    263263 
    264 <a href="({t_url m=pc a=page_h_review_add_write})&amp;category_id=({$category_id})&amp;asin=({$product.asin})">レビューを書く</a> 
     264<a href="({t_url m=pc a=page_h_review_add_write})&amp;category_id=({$category_id})&amp;asin=({$product.ASIN})">レビューを書く</a> 
    265265 
    266266</div> 
  • OpenPNE/trunk/webapp/modules/pc/templates/h_review_add_write.tpl

    r4274 r4919  
    4646<td class="bg_02" style="width:180px;" align="center" rowspan="7"> 
    4747 
    48 <a href="({$product.url})" target="_blank"><img src="({$product.imagemedium})"><br>詳細を見る</a> 
     48<a href="({$product.DetailPageURL})" target="_blank"><img src="({if $product.MediumImage})({$product.MediumImage.URL})({else})./skin/dummy.gif({/if})"><br>詳細を見る</a> 
    4949 
    5050</td> 
     
    6464<div class="padding_s"> 
    6565 
    66 ({$product.name}) 
     66({$product.ItemAttributes.Title}) 
    6767 
    6868</div> 
     
    9393<div class="padding_s"> 
    9494 
    95 ({$product.release})<br> 
    96 ({$product.manufacturer})<br> 
    97 ({$product.artist})({$product.author})<br> 
     95({$product.ItemAttributes.PublicationDate})<br> 
     96({$product.ItemAttributes.Manufacturer})<br> 
     97({$product.artist})({$product.author}) 
    9898 
    9999</div>