Changeset 2115208
- Timestamp:
- 07/01/2019 05:57:04 AM (7 years ago)
- Location:
- ds-titan
- Files:
-
- 6 edited
-
tags/0.2/src/DSTitan.php (modified) (3 diffs)
-
tags/0.2/src/Products.php (modified) (3 diffs)
-
tags/0.2/views/admin.php (modified) (2 diffs)
-
trunk/src/DSTitan.php (modified) (3 diffs)
-
trunk/src/Products.php (modified) (3 diffs)
-
trunk/views/admin.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ds-titan/tags/0.2/src/DSTitan.php
r2112597 r2115208 191 191 public function pushWebhook($req) 192 192 { 193 // Log everything 194 $appLogs = get_option(Products::APP_LOG_KEY, []); 195 $logs = []; 193 196 try { 194 197 $rawBody = $req->get_body(); … … 197 200 // Get the body id 198 201 $productIds = $body['productIds']; 202 203 $logs[] = 'Products pushed from DSTitan:' . implode($productIds); 199 204 } catch(\Exception $e) { 200 205 return new \WP_Error('invalid_post_body', 'Sorry the post body is invalid', [ … … 207 212 $productMapping = get_option(Products::PRODUCT_MAPPING_KEY, []); 208 213 214 // Go through each productIds 215 $newProducts = []; 216 217 // Get new instance of api 218 $accessToken = get_option(self::PLUGIN_ID . '_access_token'); 219 $Api = new API($accessToken); 220 221 foreach ($productIds as $productId) { 222 try { 223 $newProducts[$productId] = $Api->getProduct($productId); 224 } catch (\Exception $e) { 225 $logs[] = "Failed to fetch product detail from DSTitan for: $productId"; 226 } 227 } 228 229 // Save the log 230 $appLogs[time()] = $logs; 231 update_option(Product::APP_LOG_KEY, $appLogs); 232 233 // Try to save the products 209 234 try { 210 // Get new instance of api211 $accessToken = get_option(self::PLUGIN_ID . '_access_token');212 $Api = new API($accessToken);213 214 // Go through each productIds215 $newProducts = [];216 foreach ($productIds as $productId) {217 $newProducts[$productId] = $Api->getProduct($productId);218 }219 220 235 // Save the products 221 236 $Products = new Products(); -
ds-titan/tags/0.2/src/Products.php
r2112597 r2115208 64 64 } 65 65 $productMapping[$rawProduct['id']][] = $productId; 66 } else { 67 $this->logs[] = "Failed create product for " . $rawProduct['id']; 66 68 } 67 69 … … 497 499 498 500 // Log it 501 /* 499 502 if ($newVariation) { 500 503 $this->logs[] = "Created variation: $variationId for parent product: $parentId"; … … 502 505 $this->logs[] = "Updated variation: $variationId for parent product: $parentId"; 503 506 } 507 */ 504 508 } 505 509 } -
ds-titan/tags/0.2/views/admin.php
r2112592 r2115208 48 48 49 49 <br /> 50 <?php /* 50 51 <?php if ($accessToken) { ?> 51 52 <form action="<?= esc_url(admin_url('admin-post.php')) ?>"> … … 55 56 </form> 56 57 <?php } ?> 58 */ ?> 57 59 58 60 <br /> -
ds-titan/trunk/src/DSTitan.php
r2112597 r2115208 191 191 public function pushWebhook($req) 192 192 { 193 // Log everything 194 $appLogs = get_option(Products::APP_LOG_KEY, []); 195 $logs = []; 193 196 try { 194 197 $rawBody = $req->get_body(); … … 197 200 // Get the body id 198 201 $productIds = $body['productIds']; 202 203 $logs[] = 'Products pushed from DSTitan:' . implode($productIds); 199 204 } catch(\Exception $e) { 200 205 return new \WP_Error('invalid_post_body', 'Sorry the post body is invalid', [ … … 207 212 $productMapping = get_option(Products::PRODUCT_MAPPING_KEY, []); 208 213 214 // Go through each productIds 215 $newProducts = []; 216 217 // Get new instance of api 218 $accessToken = get_option(self::PLUGIN_ID . '_access_token'); 219 $Api = new API($accessToken); 220 221 foreach ($productIds as $productId) { 222 try { 223 $newProducts[$productId] = $Api->getProduct($productId); 224 } catch (\Exception $e) { 225 $logs[] = "Failed to fetch product detail from DSTitan for: $productId"; 226 } 227 } 228 229 // Save the log 230 $appLogs[time()] = $logs; 231 update_option(Product::APP_LOG_KEY, $appLogs); 232 233 // Try to save the products 209 234 try { 210 // Get new instance of api211 $accessToken = get_option(self::PLUGIN_ID . '_access_token');212 $Api = new API($accessToken);213 214 // Go through each productIds215 $newProducts = [];216 foreach ($productIds as $productId) {217 $newProducts[$productId] = $Api->getProduct($productId);218 }219 220 235 // Save the products 221 236 $Products = new Products(); -
ds-titan/trunk/src/Products.php
r2112597 r2115208 64 64 } 65 65 $productMapping[$rawProduct['id']][] = $productId; 66 } else { 67 $this->logs[] = "Failed create product for " . $rawProduct['id']; 66 68 } 67 69 … … 497 499 498 500 // Log it 501 /* 499 502 if ($newVariation) { 500 503 $this->logs[] = "Created variation: $variationId for parent product: $parentId"; … … 502 505 $this->logs[] = "Updated variation: $variationId for parent product: $parentId"; 503 506 } 507 */ 504 508 } 505 509 } -
ds-titan/trunk/views/admin.php
r2112580 r2115208 48 48 49 49 <br /> 50 <?php /* 50 51 <?php if ($accessToken) { ?> 51 52 <form action="<?= esc_url(admin_url('admin-post.php')) ?>"> … … 55 56 </form> 56 57 <?php } ?> 58 */ ?> 57 59 58 60 <br />
Note: See TracChangeset
for help on using the changeset viewer.