| @@ 119-187 (lines=69) @@ | ||
| 116 | * |
|
| 117 | * @return DealsResultset |
|
| 118 | */ |
|
| 119 | public function getDeals($merchantID,int $page=0,int $items_per_page=10) : DealsResultset |
|
| 120 | { |
|
| 121 | if (!isIntegerPositive($items_per_page)){ |
|
| 122 | $items_per_page=10; |
|
| 123 | } |
|
| 124 | $result=DealsResultset::createInstance(); |
|
| 125 | if (!$this->checkLogin()) { |
|
| 126 | return $result; |
|
| 127 | } |
|
| 128 | $arrResult = array(); |
|
| 129 | $jsonVouchers = file_get_contents("https://api.tradedoubler.com/1.0/vouchers.json;dateOutputFormat=iso8601?token=".$_ENV['TRADEDOUBLER_TOKEN']); |
|
| 130 | $arrVouchers = json_decode($jsonVouchers, true); |
|
| 131 | ||
| 132 | foreach($arrVouchers as $voucher) { |
|
| 133 | $Deal = Deal::createInstance(); |
|
| 134 | $Deal->setValues($voucher, [ |
|
| 135 | 'id' => 'deal_ID' , |
|
| 136 | 'programId' => 'merchant_ID' , |
|
| 137 | 'code' => 'code' , |
|
| 138 | 'updateDate' => 'update_date' , |
|
| 139 | 'publishStartDate' => 'publish_start_date' , |
|
| 140 | 'publishEndDate' => 'publish_end_date' , |
|
| 141 | 'startDate' => 'start_date' , |
|
| 142 | 'endDate' => 'end_date' , |
|
| 143 | 'title' => 'name' , |
|
| 144 | 'shortDescription' => 'short_description' , |
|
| 145 | 'description' => 'description' , |
|
| 146 | 'voucherTypeId' => 'deal_type' , |
|
| 147 | 'defaultTrackUri' => 'default_track_uri' , |
|
| 148 | 'landingUrl' => 'landing_url' , |
|
| 149 | 'discountAmount' => 'discount_amount' , |
|
| 150 | 'isPercentage' => 'is_percentage' , |
|
| 151 | 'publisherInformation' => 'information' , |
|
| 152 | 'languageId' => 'language' , |
|
| 153 | 'exclusive' => 'is_exclusive' , |
|
| 154 | 'siteSpecific' => 'is_site_specific' , |
|
| 155 | 'currencyId' => 'currency_initial' , |
|
| 156 | 'logoPath' => 'logo_path' , |
|
| 157 | ]); |
|
| 158 | switch ($voucher['voucherTypeId']) { |
|
| 159 | case 1: |
|
| 160 | $Deal->deal_type = \Oara\Utilities::OFFER_TYPE_VOUCHER; |
|
| 161 | break; |
|
| 162 | case 2: |
|
| 163 | $Deal->deal_type = \Oara\Utilities::OFFER_TYPE_DISCOUNT; |
|
| 164 | break; |
|
| 165 | case 3: |
|
| 166 | $Deal->deal_type = \Oara\Utilities::OFFER_TYPE_FREE_ARTICLE; |
|
| 167 | break; |
|
| 168 | case 4: |
|
| 169 | $Deal->deal_type = \Oara\Utilities::OFFER_TYPE_FREE_SHIPPING; |
|
| 170 | break; |
|
| 171 | case 5: |
|
| 172 | $Deal->deal_type = \Oara\Utilities::OFFER_TYPE_LOTTERY; |
|
| 173 | break; |
|
| 174 | } |
|
| 175 | ||
| 176 | if($merchantID > 0) { |
|
| 177 | if($voucher['programId'] == $merchantID) { |
|
| 178 | $arrResult[] = $Deal; |
|
| 179 | } |
|
| 180 | } |
|
| 181 | else { |
|
| 182 | $arrResult[] = $Deal; |
|
| 183 | } |
|
| 184 | } |
|
| 185 | $result->deals[]=$arrResult; |
|
| 186 | return $result; |
|
| 187 | } |
|
| 188 | ||
| 189 | /** |
|
| 190 | * @param \DateTime $dateFrom |
|
| @@ 110-178 (lines=69) @@ | ||
| 107 | * |
|
| 108 | * @return DealsResultset |
|
| 109 | */ |
|
| 110 | public function getDeals($merchantID,int $page=0,int $items_per_page=10) : DealsResultset |
|
| 111 | { |
|
| 112 | if (!isIntegerPositive($items_per_page)){ |
|
| 113 | $items_per_page=10; |
|
| 114 | } |
|
| 115 | $result=DealsResultset::createInstance(); |
|
| 116 | if (!$this->checkLogin()) { |
|
| 117 | return $result; |
|
| 118 | } |
|
| 119 | $arrResult = array(); |
|
| 120 | $jsonVouchers = file_get_contents("https://api.tradedoubler.com/1.0/vouchers.json;dateOutputFormat=iso8601?token=".$_ENV['TRADEDOUBLER_TOKEN']); |
|
| 121 | $arrVouchers = json_decode($jsonVouchers, true); |
|
| 122 | ||
| 123 | foreach($arrVouchers as $voucher) { |
|
| 124 | $Deal = Deal::createInstance(); |
|
| 125 | $Deal->setValues($voucher, [ |
|
| 126 | 'id' => 'deal_ID' , |
|
| 127 | 'programId' => 'merchant_ID' , |
|
| 128 | 'code' => 'code' , |
|
| 129 | 'updateDate' => 'update_date' , |
|
| 130 | 'publishStartDate' => 'publish_start_date' , |
|
| 131 | 'publishEndDate' => 'publish_end_date' , |
|
| 132 | 'startDate' => 'start_date' , |
|
| 133 | 'endDate' => 'end_date' , |
|
| 134 | 'title' => 'name' , |
|
| 135 | 'shortDescription' => 'short_description' , |
|
| 136 | 'description' => 'description' , |
|
| 137 | 'voucherTypeId' => 'deal_type' , |
|
| 138 | 'defaultTrackUri' => 'default_track_uri' , |
|
| 139 | 'landingUrl' => 'landing_url' , |
|
| 140 | 'discountAmount' => 'discount_amount' , |
|
| 141 | 'isPercentage' => 'is_percentage' , |
|
| 142 | 'publisherInformation' => 'information' , |
|
| 143 | 'languageId' => 'language' , |
|
| 144 | 'exclusive' => 'is_exclusive' , |
|
| 145 | 'siteSpecific' => 'is_site_specific' , |
|
| 146 | 'currencyId' => 'currency_initial' , |
|
| 147 | 'logoPath' => 'logo_path' , |
|
| 148 | ]); |
|
| 149 | switch ($voucher['voucherTypeId']) { |
|
| 150 | case 1: |
|
| 151 | $Deal->deal_type = \Oara\Utilities::OFFER_TYPE_VOUCHER; |
|
| 152 | break; |
|
| 153 | case 2: |
|
| 154 | $Deal->deal_type = \Oara\Utilities::OFFER_TYPE_DISCOUNT; |
|
| 155 | break; |
|
| 156 | case 3: |
|
| 157 | $Deal->deal_type = \Oara\Utilities::OFFER_TYPE_FREE_ARTICLE; |
|
| 158 | break; |
|
| 159 | case 4: |
|
| 160 | $Deal->deal_type = \Oara\Utilities::OFFER_TYPE_FREE_SHIPPING; |
|
| 161 | break; |
|
| 162 | case 5: |
|
| 163 | $Deal->deal_type = \Oara\Utilities::OFFER_TYPE_LOTTERY; |
|
| 164 | break; |
|
| 165 | } |
|
| 166 | ||
| 167 | if($merchantID > 0) { |
|
| 168 | if($voucher['programId'] == $merchantID) { |
|
| 169 | $arrResult[] = $Deal; |
|
| 170 | } |
|
| 171 | } |
|
| 172 | else { |
|
| 173 | $arrResult[] = $Deal; |
|
| 174 | } |
|
| 175 | } |
|
| 176 | $result->deals[]=$arrResult; |
|
| 177 | return $result; |
|
| 178 | } |
|
| 179 | ||
| 180 | /** |
|
| 181 | * @param \DateTime $dateFrom |
|