| 1 | # | ||
| 2 | # Copyright (c) 2005, Presicient Corp., USA | ||
| 3 | # | ||
| 4 | # Permission is granted to use this software according to the terms of the | ||
| 5 | # Artistic License, as specified in the Perl README file, | ||
| 6 | # with the exception that commercial redistribution, either | ||
| 7 | # electronic or via physical media, as either a standalone package, | ||
| 8 | # or incorporated into a third party product, requires prior | ||
| 9 | # written approval of the author. | ||
| 10 | # | ||
| 11 | # This software is distributed in the hope that it will be useful, | ||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
| 14 | # | ||
| 15 | # Presicient Corp. reserves the right to provide support for this software | ||
| 16 | # to individual sites under a separate (possibly fee-based) | ||
| 17 | # agreement. | ||
| 18 | # | ||
| 19 | # History: | ||
| 20 | # | ||
| 21 | # 2005-Jan-27 D. Arnold | ||
| 22 | # Coded. | ||
| 23 | # | ||
| 24 | =pod | ||
| 25 | |||
| 26 | =head4 Offers (table, readonly) | ||
| 27 | |||
| 28 | Product offer information including non-Amazon sources | ||
| 29 | |||
| 30 | =over 4 | ||
| 31 | |||
| 32 | =item ASIN - Amazon ID; primary key | ||
| 33 | |||
| 34 | =item MerchantID - ID of Offer merchant/seller | ||
| 35 | |||
| 36 | =item Condition - new/used/refurb/etc. | ||
| 37 | |||
| 38 | =item SubCondition - detailed condition info | ||
| 39 | |||
| 40 | =item ConditionNote - more detail | ||
| 41 | |||
| 42 | =back | ||
| 43 | |||
| 44 | =cut | ||
| 45 | |||
| 46 | package SQL::Amazon::Tables::Offers; | ||
| 47 | |||
| 48 | use DBI qw(:sql_types); | ||
| 49 | use base qw(SQL::Amazon::Tables::Table); | ||
| 50 | use strict; | ||
| 51 | |||
| 52 | our %metadata = ( | ||
| 53 | NAME => [ | ||
| 54 | qw/ASIN | ||
| 55 | MerchantId | ||
| 56 | GlancePage | ||
| 57 | OfferListingId | ||
| 58 | PriceAmt | ||
| 59 | PriceCurrency | ||
| 60 | PriceFormatted | ||
| 61 | SalePriceAmt | ||
| 62 | SalePriceCurrency | ||
| 63 | SalePriceFormatted | ||
| 64 | Availability | ||
| 65 | ISPUStoreAddress | ||
| 66 | ISPUStoreHours | ||
| 67 | Condition | ||
| 68 | SubCondition | ||
| 69 | ConditionNote/ | ||
| 70 | ], | ||
| 71 | TYPE => [ | ||
| 72 | SQL_VARCHAR, | ||
| 73 | SQL_VARCHAR, | ||
| 74 | SQL_VARCHAR, | ||
| 75 | SQL_VARCHAR, | ||
| 76 | SQL_DECIMAL, | ||
| 77 | SQL_VARCHAR, | ||
| 78 | SQL_VARCHAR, | ||
| 79 | SQL_DECIMAL, | ||
| 80 | SQL_VARCHAR, | ||
| 81 | SQL_VARCHAR, | ||
| 82 | SQL_VARCHAR, | ||
| 83 | SQL_VARCHAR, | ||
| 84 | SQL_VARCHAR, | ||
| 85 | SQL_VARCHAR, | ||
| 86 | SQL_VARCHAR, | ||
| 87 | SQL_VARCHAR, | ||
| 88 | ], | ||
| 89 | PRECISION => [ | ||
| 90 | 32, | ||
| 91 | 32, | ||
| 92 | 256, | ||
| 93 | 32, | ||
| 94 | 15, | ||
| 95 | 10, | ||
| 96 | 32, | ||
| 97 | 15, | ||
| 98 | 10, | ||
| 99 | 32, | ||
| 100 | 256, | ||
| 101 | 256, | ||
| 102 | 256, | ||
| 103 | 32, | ||
| 104 | 256, | ||
| 105 | 1024, | ||
| 106 | ], | ||
| 107 | SCALE => [ | ||
| 108 | undef, | ||
| 109 | undef, | ||
| 110 | undef, | ||
| 111 | undef, | ||
| 112 | 2, | ||
| 113 | undef, | ||
| 114 | undef, | ||
| 115 | 2, | ||
| 116 | undef, | ||
| 117 | undef, | ||
| 118 | undef, | ||
| 119 | undef, | ||
| 120 | undef, | ||
| 121 | undef, | ||
| 122 | undef, | ||
| 123 | undef, | ||
| 124 | ], | ||
| 125 | NULLABLE => [ | ||
| 126 | undef, | ||
| 127 | undef, | ||
| 128 | 1, | ||
| 129 | undef, | ||
| 130 | 1, | ||
| 131 | 1, | ||
| 132 | 1, | ||
| 133 | 1, | ||
| 134 | 1, | ||
| 135 | 1, | ||
| 136 | 1, | ||
| 137 | 1, | ||
| 138 | 1, | ||
| 139 | 1, | ||
| 140 | 1, | ||
| 141 | 1, | ||
| 142 | ] | ||
| 143 | ); | ||
| 144 | |||
| 145 | sub new { | ||
| 146 | my $class = shift; | ||
| 147 | my $obj = $class->SUPER::new(\%metadata); | ||
| 148 | $obj->{_key_cols} = [ 0, 1, 3 ]; | ||
| 149 | return $obj; | ||
| 150 | } | ||
| 151 | |||
| 152 | sub insert { | ||
| 153 | my ($obj, $offer, $asin, $reqid) = @_; | ||
| 154 | my $names = $obj->{NAME}; | ||
| 155 | my $types = $obj->{TYPE}; | ||
| 156 | my @row = (); | ||
| 157 | my $colnums = $obj->{col_nums}; | ||
| 158 | $row[$colnums->{ASIN}] = $asin; | ||
| 159 | $row[$colnums->{MerchantId}] = | ||
| 160 | $offer->{Merchant}{MerchantId}, | ||
| 161 | $row[$colnums->{GlancePage}] = | ||
| 162 | $offer->{Merchant}{GlancePage} | ||
| 163 | if $offer->{Merchant}; | ||
| 164 | |||
| 165 | $row[$colnums->{Condition}] = | ||
| 166 | $offer->{OfferAttributes}{Condition} | ||
| 167 | if $offer->{OfferAttributes}; | ||
| 168 | |||
| 169 | if ($offer->{OfferListing}) { | ||
| 170 | $offer = $offer->{OfferListing}; | ||
| 171 | $row[$colnums->{Availability}] = | ||
| 172 | $offer->{Availability}; | ||
| 173 | $row[$colnums->{OfferListingId}] = | ||
| 174 | $offer->{OfferListingId}; | ||
| 175 | |||
| 176 | $row[$colnums->{PriceAmt}] = | ||
| 177 | $obj->format_money($offer->{Price}{Amount}), | ||
| 178 | $row[$colnums->{PriceCurrency}] = | ||
| 179 | $offer->{Price}{CurrencyCode}, | ||
| 180 | $row[$colnums->{PriceFormatted}] = | ||
| 181 | $offer->{Price}{FormattedPrice} | ||
| 182 | if $offer->{Price}; | ||
| 183 | } | ||
| 184 | |||
| 185 | return $obj->SUPER::save_row(\@row, $offer, $reqid); | ||
| 186 | } | ||
| 187 | |||
| 188 | 1; | ||
| 189 |