Changeset 1360010
- Timestamp:
- 02/28/2016 12:28:08 PM (10 years ago)
- Location:
- 2kb-amazon-affiliates-store/trunk
- Files:
-
- 1 added
- 12 edited
-
KbAmazonController.php (modified) (1 diff)
-
KbAmazonImporter.php (modified) (18 diffs)
-
KbAmazonStore.php (modified) (5 diffs)
-
lib/KbAmazonApi.php (modified) (2 diffs)
-
lib/KbAmazonItem.php (modified) (6 diffs)
-
lib/KbAmazonItems.php (modified) (1 diff)
-
nbproject (added)
-
plugin.php (modified) (1 diff)
-
readme.txt (modified) (1 diff)
-
store_functions.php (modified) (2 diffs)
-
template/admin/index.phtml (modified) (1 diff)
-
template/admin/version.phtml (modified) (1 diff)
-
template/default/css/style.css (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
2kb-amazon-affiliates-store/trunk/KbAmazonController.php
r1154110 r1360010 298 298 $importer = new KbAmazonImporter; 299 299 $data['groups'] = $importer->getAmazonCategoryGroups(); 300 $view = new KbView($data );300 $view = new KbView($data, KbAmazonStorePluginPath . 'template/admin/settingsAmazonApi'); 301 301 return $view; 302 302 } -
2kb-amazon-affiliates-store/trunk/KbAmazonImporter.php
r1154110 r1360010 21 21 protected $request = array(); 22 22 protected $requestKey = ''; 23 23 protected $errors = array(); 24 25 24 26 protected $importCategories = array(); 25 27 … … 35 37 'es' => 'Spain', // ok 36 38 'in' => 'India', // ok 39 ); 40 41 static protected $amazonStoreCurrency = array( 42 'com' => '%s$', // ok 43 'de' => '€%s', // ok 44 'co.uk' => '£%s', // ok 45 'ca' => 'CDN$%s', // ok 46 'co.jp' => '¥%s', // ok 47 'it' => '€%s', // ok 48 'cn' => '¥%s', 49 'fr' => '€%s', //ok 50 'es' => '€%s', // ok 51 'in' => '%s', // ok 37 52 ); 38 53 … … 282 297 } 283 298 299 public function getErrors() 300 { 301 return $this->errors; 302 } 303 304 public static function getCurrencyPrice($price, $store) 305 { 306 return sprintf( 307 self::$amazonStoreCurrency[$store], 308 $price 309 ); 310 } 311 284 312 public function saveRequests() 285 313 { … … 290 318 ) 291 319 ); 320 } 321 322 public function hasCountry($country) 323 { 324 return isset($this->amazonCategories[$country]) ? true : false; 292 325 } 293 326 … … 404 437 $responseGroup = is_array($responseGroup) ? $responseGroup : array($responseGroup); 405 438 } 406 439 440 $firstAsin = is_array($asin) ? $asin[key($asin)] : $asin; 441 $country = getKbAmz()->getProductCountry($firstAsin); 407 442 408 443 $key = is_array($asin) ? implode(' ', $asin) : $asin . serialize($responseGroup); 409 //if (!$data = getKbAmz()->getCache($key)) {444 if (!$data = getKbAmz()->getCache($key)) { 410 445 $time = microtime(true); 411 446 if ($this->request['lastRun'] + 1 / $this->requestPerSec > $time) { … … 416 451 417 452 $this->countAmazonRequest(); 418 419 $result = getKbAmazonApi() 420 ->responseGroup(implode(',', $responseGroup)) 421 ->lookup($asin, array('Condition' => 'New', 'Availability' => 'Available')); 453 454 $amazonApi = getKbAmazonApi($country); 455 $result = $amazonApi->responseGroup(implode(',', $responseGroup)) 456 ->lookup($asin, array('Condition' => 'New', 'Availability' => 'Available')); 457 $country = $amazonApi->country(); 422 458 423 459 $this->request['lastRun'] = microtime(true); … … 436 472 */ 437 473 if (is_array($asin)) { 438 $data = new KbAmazonItems($result );474 $data = new KbAmazonItems($result, $country); 439 475 } else { 440 $data = new KbAmazonItem($result );476 $data = new KbAmazonItem($result, false, $country); 441 477 } 442 478 getKbAmz()->setCache($key, $data); 443 479 444 // } 480 } 481 482 if ($data->getError()) { 483 $this->errors[] = $data->getError(); 484 getKbAmz()->addException('warning', "$firstAsin: " . $data->getError()); 485 } 445 486 446 487 // LEGACY … … 480 521 } 481 522 523 /** 524 * Check for different stores 525 */ 526 $countryAsins = array(); 527 foreach ($importAsins as $asin) { 528 $country = getKbAmz()->getProductCountry($asin); 529 if (!isset($countryAsins[$country])) { 530 $countryAsins[$country] = array(); 531 } 532 $countryAsins[$country][] = $asin; 533 } 534 535 /** 536 * Match the import by country 537 */ 538 if (count($countryAsins) > 1) { 539 $ids = array(); 540 foreach ($countryAsins as $asins) { 541 $result = $this->import($asins); 542 $ids = array_merge($ids, $result); 543 } 544 return $ids; 545 } 546 547 /** 548 * Else just continue 549 */ 482 550 $groups = array_chunk($importAsins, 10); 483 551 … … 494 562 trigger_error('Invalid result for asins: ' . implode(',', $asins)); 495 563 } 496 564 497 565 foreach ($items as $item) { 498 566 if (getKbAmz()->getOption('allowVariants') … … 513 581 } 514 582 } 583 515 584 if ($item->isValid()) { 516 585 if ($updatePrice) { … … 527 596 } 528 597 } 598 599 529 600 } 530 601 … … 547 618 } 548 619 549 protected function priceToMeta(&$meta )620 protected function priceToMeta(&$meta, KbAmazonItem $item) 550 621 { 551 622 $meta['PriceAmount'] = 0; … … 555 626 $meta['PriceQuantity'] = 1; 556 627 } 557 558 628 //1. OfferSummary.LowestNewPrice.FormattedPrice 559 629 //2. Offers.Offer.OfferListing.SalePrice.FormattedPrice … … 598 668 $meta['PriceAmount'] = self::paddedNumberToDecial($meta['PriceAmount']); 599 669 600 // 670 // @TODO 601 671 // $meta['PriceAmount'] = rand(1, 999); 602 672 // $meta['PriceAmountFormatted'] = '$' . $meta['PriceAmount']; … … 656 726 657 727 $meta = $item->getFlattenArray(); 658 $this->priceToMeta($meta );728 $this->priceToMeta($meta, $item); 659 729 $this->updateProductPostMeta($meta, $postId); 660 730 … … 701 771 $meta = $item->getFlattenArray(); 702 772 $meta['SimilarProducts'] = $item->getSimilarProducts(); 703 $this->priceToMeta($meta );773 $this->priceToMeta($meta, $item); 704 774 705 775 $canImportFreeItems = getKbAmz()->getOption('canImportFreeItems', true); … … 747 817 do_action('wp_insert_post', 'wp_insert_post'); 748 818 update_post_meta($postId, 'KbAmzASIN', $item->getAsin()); 819 update_post_meta($postId, 'KbAmzCountry', getKbAmz()->getOption('amazon.country')); 749 820 getKbAmz()->addProductCount(1); 750 821 } else { … … 758 829 ); 759 830 } 760 761 update_post_meta($postId, 'KbAmzLastUpdateTime', time());762 831 763 832 $metaToInsert = $this->updateProductPostMeta($meta, $postId); -
2kb-amazon-affiliates-store/trunk/KbAmazonStore.php
r1154345 r1360010 721 721 { 722 722 global $wpdb; 723 static $cache; 724 if (is_array($cache) && array_key_exists($asin, $cache)) { 725 return $cache[$asin]; 726 } 723 727 $sql = " 724 728 SELECT post_id … … 728 732 729 733 $result = $this->getSqlResult($sql); 730 return isset($result[0]) ? get_post($result[0]->post_id) : null; 731 } 732 734 $cache[$asin] = isset($result[0]) ? get_post($result[0]->post_id) : null; 735 return $cache[$asin]; 736 } 737 738 public function getProductCountry($asin) 739 { 740 $post = $this->getProductByAsin($asin); 741 $country = ''; 742 if ($post) { 743 $country = get_post_meta($post->ID, 'KbAmzCountry', true); 744 } 745 return !empty($country) ? $country : getKbAmz()->getOption('amazon.country'); 746 } 747 733 748 function getCurrentCategoryId() 734 749 { … … 1537 1552 } 1538 1553 if (!$response['success']) { 1539 $response['msg'] = 'Something went wrong. Please try again.';1554 $response['msg'] = __('Something went wrong. Please try again.'); 1540 1555 } 1541 1556 … … 1562 1577 'ASIN' => $meta['KbAmzASIN'] 1563 1578 ); 1564 $cart = getKbAmazonApi()->responseGroup('Cart')->cartThem($params); 1579 1580 $cart = getKbAmazonApi(getKbAmz()->getProductCountry($meta['KbAmzASIN']))->responseGroup('Cart')->cartThem($params); 1581 1565 1582 $cart = isset($cart['Cart']) ? $cart['Cart'] : $cart; 1566 1583 if (isset($cart['Request']['Errors'])) { 1567 1584 $response['msg'] = isset($cart['Request']['Errors']['Error']['Message']) 1568 ? $cart['Request']['Errors']['Error']['Message']1569 : 'Unable to add this product to the cart. Please contact the shop administrator.';1585 ? __($cart['Request']['Errors']['Error']['Message']) 1586 : __('Unable to add this product to the cart. Please contact the shop administrator.'); 1570 1587 $this->addProductForDownload($meta['KbAmzASIN']); 1571 1588 $response['title'] = __('Info'); … … 1593 1610 } 1594 1611 if (!$response['success'] && !isset($response['msg'])) { 1595 $response['msg'] = 'Something went wrong. Please try again.';1612 $response['msg'] = __('Something went wrong. Please try again.'); 1596 1613 } 1597 1614 -
2kb-amazon-affiliates-store/trunk/lib/KbAmazonApi.php
r1154110 r1360010 401 401 } 402 402 403 function aws_signed_request($region, $params, $public_key, $private_key, $associate_tag = NULL, $version = '201 1-08-01')403 function aws_signed_request($region, $params, $public_key, $private_key, $associate_tag = NULL, $version = '2013-08-01') 404 404 { 405 405 $method = 'GET'; … … 411 411 $params['Timestamp'] = gmdate('Y-m-d\TH:i:s\Z'); 412 412 $params['Version'] = $version; 413 $params['MerchantId'] = 'All'; 414 $params['Condition'] = 'New'; 413 415 if ($associate_tag !== NULL) { 414 416 $params['AssociateTag'] = $associate_tag; -
2kb-amazon-affiliates-store/trunk/lib/KbAmazonItem.php
r1154110 r1360010 12 12 13 13 protected $excudeFlattenKeys = array( 14 'ItemLinks',14 // 'ItemLinks', 15 15 'SmallImage', 16 16 'MediumImage', … … 28 28 29 29 protected $postParent = 0; 30 31 public function __construct($result, $isSimilar = false) 30 31 protected $country; 32 33 protected $moreOffersUrl; 34 35 public function __construct($result, $isSimilar = false, $country = null) 32 36 { 33 37 if (isset($result['Items']['Item']['AlternateVersions'])) { … … 41 45 $this->result = $result; 42 46 $this->isSimilar = $isSimilar; 47 $this->country = $country; 43 48 } 44 49 … … 50 55 public function isValid() 51 56 { 52 if (isset($this->result['src']) ) {57 if (isset($this->result['src']) && !$this->getError()) { 53 58 return true; 54 59 } … … 69 74 } 70 75 } 76 77 public function getOffers() 78 { 79 $item = $this->getItem(); 80 $offers = array(); 81 if (isset($item['Offers']['Offer'])) { 82 $offers = isset($item['Offers']['Offer'][0]) ? $item['Offers']['Offer'] : array($item['Offers']['Offer']); 83 } 84 return $offers; 85 } 86 87 public function hasOffers() 88 { 89 $offers = $this->getOffers(); 90 return !empty($offers); 91 } 92 93 public function getMoreOffersUrl() 94 { 95 if ($this->moreOffersUrl !== null) { 96 return $this->moreOffersUrl; 97 } 98 $this->moreOffersUrl = false; 99 $flatten = $this->getFlattenArray(); 100 if (isset($flatten['Offers.MoreOffersUrl']) 101 && !empty($flatten['Offers.MoreOffersUrl'])) { 102 $this->moreOffersUrl = $flatten['Offers.MoreOffersUrl']; 103 } 104 105 foreach ($flatten as $name => $val) { 106 if (strpos($name, 'ItemLink') !== false 107 && strpos($val, '/offer-listing/') !== false) { 108 $this->moreOffersUrl = $val; 109 break; 110 } 111 } 112 return $this->moreOffersUrl; 113 } 71 114 72 115 /** … … 113 156 if (null === $this->flatten) { 114 157 $this->flatten = array(); 158 /** 159 * Moved to saved product 160 */ 161 //$this->flatten['Country'] = $this->country; 115 162 $this->flatten($this->item, $this->flatten, null); 116 163 } -
2kb-amazon-affiliates-store/trunk/lib/KbAmazonItems.php
r1154110 r1360010 8 8 protected $items = array(); 9 9 10 public function __construct($result )10 public function __construct($result, $country = null) 11 11 { 12 12 $this->result = $result; 13 13 if ($this->isValid() && isset($result['Items']['Item'])) { 14 14 if (isset($result['Items']['Item']['ASIN'])) { 15 $this->items[] = new KbAmazonItem(array('Items' => array('Item' => $result['Items']['Item'])) );15 $this->items[] = new KbAmazonItem(array('Items' => array('Item' => $result['Items']['Item'])), false, $country); 16 16 } else { 17 17 foreach ($result['Items']['Item'] as $item) { 18 $item = new KbAmazonItem(array('Items' => array('Item' => $item)) );18 $item = new KbAmazonItem(array('Items' => array('Item' => $item)), false, $country); 19 19 $this->items[] = $item; 20 20 } -
2kb-amazon-affiliates-store/trunk/plugin.php
r1171123 r1360010 16 16 } 17 17 18 define('KbAmazonVersion', '2. 0.2');19 define('KbAmazonVersionNumber', 2 02);18 define('KbAmazonVersion', '2.1.0'); 19 define('KbAmazonVersionNumber', 210); 20 20 define('KbAmazonStoreFolderName', pathinfo(dirname(__FILE__), PATHINFO_FILENAME)); 21 21 define('KbAmazonStorePluginPath', dirname(__FILE__) . '/'); -
2kb-amazon-affiliates-store/trunk/readme.txt
r1171123 r1360010 46 46 10. /assets/screenshot-10.jpg 47 47 == Changelog == 48 = 2.1.0 = 49 Maintenance release 48 50 = 2.0.2 = 49 51 Css fixes -
2kb-amazon-affiliates-store/trunk/store_functions.php
r1138499 r1360010 3 3 !defined('ABSPATH') and exit; 4 4 5 function getKbAmazonApi( ) {5 function getKbAmazonApi($country = null) { 6 6 $amz = getKbAmz()->getOption('amazon'); 7 7 $accessKey = isset($amz['accessKey']) ? $amz['accessKey'] : null; 8 8 $secretKey = isset($amz['secretKey']) ? $amz['secretKey'] : null; 9 $country = isset($amz['country']) ? $amz['country'] : null;9 $country = $country ? $country : isset($amz['country']) ? $amz['country'] : null; 10 10 $associateTag = isset($amz['associateTag']) ? $amz['associateTag'] : null; 11 11 … … 492 492 $per = getKbAmz()->getOption('updateProductsPriceCronNumberToProcess'); 493 493 $interval = getKbAmz()->getOption('updateProductsPriceCronInterval'); 494 $intervals = $count / $per;494 $intervals = $count / (empty($per) ? 50 : $per); 495 495 $intervalHours = 1; 496 496 if ($interval == 'twicedaily') { -
2kb-amazon-affiliates-store/trunk/template/admin/index.phtml
r1138499 r1360010 71 71 $per = getKbAmz()->getOption('updateProductsPriceCronNumberToProcess'); 72 72 $interval = getKbAmz()->getOption('updateProductsPriceCronInterval'); 73 $intervals = $count / $per; 73 $intervals = 0; 74 if ($per) { 75 $intervals = $count / $per; 76 } 74 77 $intervalHours = 1; 75 78 if ($interval == 'twicedaily') { -
2kb-amazon-affiliates-store/trunk/template/admin/version.phtml
r1154110 r1360010 1 1 <div class="row" id="kb-amz-version"> 2 2 <div class="col-sm-12"> 3 <h4>2.1.0</h4> 4 <ul style="list-style-type: disc;"> 5 <li> 6 Maintenance release 7 </li> 8 </ul> 9 <h4>2.0.2</h4> 10 <ul style="list-style-type: disc;"> 11 <li> 12 Css fixes 13 </li> 14 </ul> 3 15 <h4>2.0.1</h4> 4 16 <ul style="list-style-type: disc;"> -
2kb-amazon-affiliates-store/trunk/template/default/css/style.css
r1171123 r1360010 221 221 margin-left: 0.1em; 222 222 } 223 .kb-amz-item-actions .kb-add-to-cart, .kb-amz-item-actions .kb-checkout{ 223 .kb-amz-item-actions .kb-add-to-cart, 224 .kb-amz-item-actions .kb-checkout 225 { 224 226 width: 100%; 225 227 height: 2.5em;
Note: See TracChangeset
for help on using the changeset viewer.