Plugin Directory

Changeset 1360010


Ignore:
Timestamp:
02/28/2016 12:28:08 PM (10 years ago)
Author:
2kblater.com
Message:

v2.1.0

Location:
2kb-amazon-affiliates-store/trunk
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • 2kb-amazon-affiliates-store/trunk/KbAmazonController.php

    r1154110 r1360010  
    298298        $importer = new KbAmazonImporter;
    299299        $data['groups'] = $importer->getAmazonCategoryGroups();
    300         $view = new KbView($data);
     300        $view = new KbView($data, KbAmazonStorePluginPath . 'template/admin/settingsAmazonApi');
    301301        return $view;
    302302    }
  • 2kb-amazon-affiliates-store/trunk/KbAmazonImporter.php

    r1154110 r1360010  
    2121    protected $request      = array();
    2222    protected $requestKey   = '';
    23    
     23    protected $errors       = array();
     24
     25
    2426    protected $importCategories = array();
    2527   
     
    3537        'es'        => 'Spain', // ok
    3638        '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 
    3752    );
    3853   
     
    282297    }
    283298   
     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
    284312    public function saveRequests()
    285313    {
     
    290318            )
    291319        );
     320    }
     321   
     322    public function hasCountry($country)
     323    {
     324        return isset($this->amazonCategories[$country]) ? true : false;
    292325    }
    293326
     
    404437            $responseGroup = is_array($responseGroup) ? $responseGroup : array($responseGroup);
    405438        }
    406 
     439       
     440        $firstAsin = is_array($asin) ? $asin[key($asin)] : $asin;
     441        $country   = getKbAmz()->getProductCountry($firstAsin);
    407442       
    408443        $key = is_array($asin) ? implode(' ', $asin) : $asin . serialize($responseGroup);
    409         //if (!$data = getKbAmz()->getCache($key)) {
     444        if (!$data = getKbAmz()->getCache($key)) {
    410445            $time = microtime(true);
    411446            if ($this->request['lastRun'] + 1 / $this->requestPerSec > $time) {
     
    416451           
    417452            $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();
    422458           
    423459            $this->request['lastRun'] = microtime(true);
     
    436472             */
    437473            if (is_array($asin)) {
    438                 $data = new KbAmazonItems($result);
     474                $data = new KbAmazonItems($result, $country);
    439475            } else {
    440                 $data = new KbAmazonItem($result);
     476                $data = new KbAmazonItem($result, false, $country);
    441477            }
    442478            getKbAmz()->setCache($key, $data);
    443479           
    444        // }
     480        }
     481       
     482        if ($data->getError()) {
     483            $this->errors[] = $data->getError();
     484            getKbAmz()->addException('warning', "$firstAsin: " . $data->getError());
     485        }
    445486       
    446487//        LEGACY
     
    480521        }
    481522       
     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         */
    482550        $groups = array_chunk($importAsins, 10);
    483551
     
    494562                trigger_error('Invalid result for asins: ' . implode(',', $asins));
    495563            }
    496             
     564           
    497565            foreach ($items as $item) {
    498566                if (getKbAmz()->getOption('allowVariants')
     
    513581                    }
    514582                }
     583               
    515584                if ($item->isValid()) {
    516585                    if ($updatePrice) {
     
    527596                }
    528597            }
     598           
     599           
    529600        }
    530601   
     
    547618    }
    548619   
    549     protected function priceToMeta(&$meta)
     620    protected function priceToMeta(&$meta, KbAmazonItem $item)
    550621    {
    551622        $meta['PriceAmount']          = 0;
     
    555626            $meta['PriceQuantity']     = 1;
    556627        }
    557        
    558628        //1. OfferSummary.LowestNewPrice.FormattedPrice
    559629        //2. Offers.Offer.OfferListing.SalePrice.FormattedPrice
     
    598668        $meta['PriceAmount'] = self::paddedNumberToDecial($meta['PriceAmount']);
    599669
    600 //       
     670//      @TODO
    601671//        $meta['PriceAmount']          = rand(1, 999);
    602672//        $meta['PriceAmountFormatted'] = '$' . $meta['PriceAmount'];
     
    656726           
    657727        $meta = $item->getFlattenArray();
    658         $this->priceToMeta($meta);
     728        $this->priceToMeta($meta, $item);
    659729        $this->updateProductPostMeta($meta, $postId);
    660730       
     
    701771        $meta = $item->getFlattenArray();
    702772        $meta['SimilarProducts'] = $item->getSimilarProducts();
    703         $this->priceToMeta($meta);
     773        $this->priceToMeta($meta, $item);
    704774       
    705775        $canImportFreeItems = getKbAmz()->getOption('canImportFreeItems', true);
     
    747817            do_action('wp_insert_post', 'wp_insert_post');
    748818            update_post_meta($postId, 'KbAmzASIN', $item->getAsin());
     819            update_post_meta($postId, 'KbAmzCountry', getKbAmz()->getOption('amazon.country'));
    749820            getKbAmz()->addProductCount(1);
    750821        } else {
     
    758829            );
    759830        }
    760              
    761         update_post_meta($postId, 'KbAmzLastUpdateTime', time());
    762831       
    763832        $metaToInsert = $this->updateProductPostMeta($meta, $postId);
  • 2kb-amazon-affiliates-store/trunk/KbAmazonStore.php

    r1154345 r1360010  
    721721    {
    722722        global $wpdb;
     723        static $cache;
     724        if (is_array($cache) && array_key_exists($asin, $cache)) {
     725            return $cache[$asin];
     726        }
    723727        $sql = "
    724728           SELECT post_id
     
    728732       
    729733        $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           
    733748    function getCurrentCategoryId()
    734749    {
     
    15371552        }
    15381553        if (!$response['success']) {
    1539             $response['msg'] = 'Something went wrong. Please try again.';
     1554            $response['msg'] = __('Something went wrong. Please try again.');
    15401555        }
    15411556       
     
    15621577                    'ASIN' => $meta['KbAmzASIN']
    15631578                );
    1564                 $cart = getKbAmazonApi()->responseGroup('Cart')->cartThem($params);
     1579               
     1580                $cart = getKbAmazonApi(getKbAmz()->getProductCountry($meta['KbAmzASIN']))->responseGroup('Cart')->cartThem($params);
     1581               
    15651582                $cart = isset($cart['Cart']) ? $cart['Cart'] : $cart;
    15661583                if (isset($cart['Request']['Errors'])) {
    15671584                    $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.');
    15701587                    $this->addProductForDownload($meta['KbAmzASIN']);
    15711588                    $response['title'] = __('Info');
     
    15931610        }
    15941611        if (!$response['success'] && !isset($response['msg'])) {
    1595             $response['msg'] = 'Something went wrong. Please try again.';
     1612            $response['msg'] = __('Something went wrong. Please try again.');
    15961613        }
    15971614       
  • 2kb-amazon-affiliates-store/trunk/lib/KbAmazonApi.php

    r1154110 r1360010  
    401401    }
    402402
    403     function aws_signed_request($region, $params, $public_key, $private_key, $associate_tag = NULL, $version = '2011-08-01')
     403    function aws_signed_request($region, $params, $public_key, $private_key, $associate_tag = NULL, $version = '2013-08-01')
    404404    {
    405405        $method = 'GET';
     
    411411        $params['Timestamp'] = gmdate('Y-m-d\TH:i:s\Z');
    412412        $params['Version'] = $version;
     413        $params['MerchantId'] = 'All';
     414        $params['Condition'] = 'New';
    413415        if ($associate_tag !== NULL) {
    414416            $params['AssociateTag'] = $associate_tag;
  • 2kb-amazon-affiliates-store/trunk/lib/KbAmazonItem.php

    r1154110 r1360010  
    1212   
    1313    protected $excudeFlattenKeys = array(
    14         'ItemLinks',
     14        // 'ItemLinks',
    1515        'SmallImage',
    1616        'MediumImage',
     
    2828   
    2929    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)
    3236    {
    3337        if (isset($result['Items']['Item']['AlternateVersions'])) {
     
    4145        $this->result       = $result;
    4246        $this->isSimilar    = $isSimilar;
     47        $this->country      = $country;
    4348    }
    4449   
     
    5055    public function isValid()
    5156    {
    52         if (isset($this->result['src'])) {
     57        if (isset($this->result['src']) && !$this->getError()) {
    5358            return true;
    5459        }
     
    6974        }
    7075    }
     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    }
    71114
    72115    /**
     
    113156        if (null === $this->flatten) {
    114157            $this->flatten = array();
     158            /**
     159             * Moved to saved product
     160             */
     161            //$this->flatten['Country'] = $this->country;
    115162            $this->flatten($this->item, $this->flatten, null);
    116163        }
  • 2kb-amazon-affiliates-store/trunk/lib/KbAmazonItems.php

    r1154110 r1360010  
    88    protected $items = array();
    99   
    10     public function __construct($result)
     10    public function __construct($result, $country = null)
    1111    {
    1212        $this->result = $result;
    1313        if ($this->isValid() && isset($result['Items']['Item'])) {
    1414            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);
    1616            } else {
    1717                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);
    1919                    $this->items[] = $item;
    2020                }
  • 2kb-amazon-affiliates-store/trunk/plugin.php

    r1171123 r1360010  
    1616}
    1717
    18 define('KbAmazonVersion', '2.0.2');
    19 define('KbAmazonVersionNumber', 202);
     18define('KbAmazonVersion', '2.1.0');
     19define('KbAmazonVersionNumber', 210);
    2020define('KbAmazonStoreFolderName',  pathinfo(dirname(__FILE__), PATHINFO_FILENAME));
    2121define('KbAmazonStorePluginPath',  dirname(__FILE__) . '/');
  • 2kb-amazon-affiliates-store/trunk/readme.txt

    r1171123 r1360010  
    464610. /assets/screenshot-10.jpg
    4747== Changelog ==
     48= 2.1.0 =
     49Maintenance release
    4850= 2.0.2 =
    4951Css fixes
  • 2kb-amazon-affiliates-store/trunk/store_functions.php

    r1138499 r1360010  
    33!defined('ABSPATH') and exit;
    44
    5 function getKbAmazonApi() {
     5function getKbAmazonApi($country = null) {
    66    $amz = getKbAmz()->getOption('amazon');
    77    $accessKey    = isset($amz['accessKey']) ? $amz['accessKey'] : null;
    88    $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;
    1010    $associateTag = isset($amz['associateTag']) ? $amz['associateTag'] : null;
    1111
     
    492492        $per = getKbAmz()->getOption('updateProductsPriceCronNumberToProcess');
    493493        $interval = getKbAmz()->getOption('updateProductsPriceCronInterval');
    494         $intervals = $count / $per;
     494        $intervals = $count / (empty($per) ? 50 : $per);
    495495        $intervalHours = 1;
    496496        if ($interval == 'twicedaily') {
  • 2kb-amazon-affiliates-store/trunk/template/admin/index.phtml

    r1138499 r1360010  
    7171                            $per = getKbAmz()->getOption('updateProductsPriceCronNumberToProcess');
    7272                            $interval = getKbAmz()->getOption('updateProductsPriceCronInterval');
    73                             $intervals = $count / $per;
     73                            $intervals = 0;
     74                            if ($per) {
     75                                $intervals = $count / $per;
     76                            }
    7477                            $intervalHours = 1;
    7578                            if ($interval == 'twicedaily') {
  • 2kb-amazon-affiliates-store/trunk/template/admin/version.phtml

    r1154110 r1360010  
    11<div class="row" id="kb-amz-version">
    22    <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>
    315        <h4>2.0.1</h4>
    416        <ul style="list-style-type: disc;">
  • 2kb-amazon-affiliates-store/trunk/template/default/css/style.css

    r1171123 r1360010  
    221221    margin-left: 0.1em;
    222222}
    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{
    224226    width: 100%;
    225227    height: 2.5em;
Note: See TracChangeset for help on using the changeset viewer.