Plugin Directory

Changeset 1145580


Ignore:
Timestamp:
04/25/2015 02:22:12 PM (11 years ago)
Author:
2kblater.com
Message:

DISCONTINUED

Location:
2kb-amazon-dropship-manager/trunk
Files:
4 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • 2kb-amazon-dropship-manager/trunk/plugin.php

    r1112573 r1145580  
    44 * Plugin URI: http://www.2kblater.com/
    55 * Description: Amazon DropShip Manager helps drop ship sellers to manage their products more easily. This plugin will help you keep track of quantity and price. It will send you reports for product changes by email.
    6  * Version: 1.0.0
     6 * Version: DISCONTINUED
    77 * Author: 2kblater.com
    88 * Author URI: http://www.2kblater.com
     
    1111
    1212!defined('ABSPATH') and exit;
    13 
    14 define('KbAmazonDropShipManagerVersion', '1.0.0');
    15 define('KbAmazonDropShipManagerNumber', 100);
    16 define('KbAmazonDropShipManagerFolderName',  pathinfo(dirname(__FILE__), PATHINFO_FILENAME));
    17 define('KbAmazonDropShipManagerPluginPath',  dirname(__FILE__) . '/');
    18 
    19 if (!defined('KbAmazonVersionNumber') || KbAmazonVersionNumber < 120) {
    20     add_action( 'admin_notices', 'kbAmazonDropShipManagerPluginRequired' );
    21     function kbAmazonDropShipManagerPluginRequired()
    22     {
    23         echo sprintf(
    24             '<div class="error"><p>2kb Amazon DropShip Manager requires 2kb Amazon Affiliate Store Plugin v1.2.0 or bigger. <b><a href="%s">Install it</a></b> or <b><a href="%s">open in wordpress.org</a></b></p></div>',
    25             admin_url() . 'plugin-install.php?tab=search&s=2kb+amazon+affiliate+store',
    26             'https://wordpress.org/plugins/2kb-amazon-affiliates-store/'
    27         );
    28     }
    29     return;
    30 }
    31 
    32 if(!class_exists('WP_List_Table')){
    33    require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
    34 }
    35 
    36 require_once KbAmazonDropShipManagerPluginPath . 'KbAmazonDropShipManagerController.php';
    37 require_once KbAmazonDropShipManagerPluginPath . 'KbAmazonDropShipManagerAdmin.php';
    38 require_once KbAmazonDropShipManagerPluginPath . 'functions.php';
    39 
    40 add_filter('getKbAmzDefaultOptions', 'KbAmazonDropShipManagerDefaultOptions');
    41 function KbAmazonDropShipManagerDefaultOptions($options)
    42 {
    43     $options['DropShipManagerLowQuantity'] = 5;
    44     $options['DropShipManagerMediumQuantity'] = 20;
    45     $options['DropShipManagerLargeQuantity'] = 50;
    46     $options['DropShipManagerReminderEmail'] = null;
    47     $options['DropShipManagerReminderLow'] = true;
    48     $options['DropShipManagerReminderMedium'] = false;
    49     $options['DropShipManagerReminderLarge'] = false;
    50     $options['DropShipManagerReminderTryScrap'] = true;
    51     $options['DropShipManagerDontShowDeleteOnNoQuantity'] = false;
    52     $options['DropShipManagerErrors'] = array();
    53    
    54     return $options;
    55 }
    56 
    57 add_action('KbAmazonImporter::saveProduct', 'KbAmazonDropShipManagerProductSave');
    58 function KbAmazonDropShipManagerProductSave($postId)
    59 {
    60     if (!getKbAmz()->isCronRunning()) {
    61         return;
    62     }
    63    
    64     $isDropShipProduct = get_post_meta($postId, 'KbAmzDropShipManager', true);
    65     if (!$isDropShipProduct) {
    66         return;
    67     }
    68    
    69     $quantity = get_post_meta($postId, 'KbAmzOfferSummary.TotalNew', true);
    70     $low = getKbAmz()->getOption('DropShipManagerReminderLow');
    71    
    72     if ($low && $quantity <= getKbAmz()->getOption('DropShipManagerLowQuantity')) {
    73         KbAmazonDropShipManagerNotifyForQuantityChange($postId, $quantity, 'Low');
    74         return;
    75     }
    76    
    77     $medium = getKbAmz()->getOption('DropShipManagerReminderMedium');
    78     if ($medium && $quantity <= getKbAmz()->getOption('DropShipManagerMediumQuantity')) {
    79         KbAmazonDropShipManagerNotifyForQuantityChange($postId, $quantity, 'Medium');
    80         return;
    81     }
    82    
    83     $large = getKbAmz()->getOption('DropShipManagerReminderLarge');
    84     if ($large && $quantity <= getKbAmz()->getOption('DropShipManagerLargeQuantity')) {
    85         KbAmazonDropShipManagerNotifyForQuantityChange($postId, $quantity, 'Large');
    86         return;
    87     }
    88 }
    89 
    90 
    91 function KbAmazonDropShipManagerNotifyForQuantityChange($postId, $quantity, $type)
    92 {
    93     $lastEmailSentTime = getKbAmz()->getOption('DropShipManagerLastEmailSentTime');
    94     if ($lastEmailSentTime && $lastEmailSentTime + 1800 > time()) {
    95         return;
    96     }
    97     getKbAmz()->setOption('DropShipManagerLastEmailSentTime', time());
    98            
    99     $post = get_post($postId);
    100     $asin = get_post_meta($post->ID, 'KbAmzASIN', true);
    101     $postTitle = $post->post_title;
    102    
    103     $emails = explode(',', getKbAmz()->getOption('DropShipManagerReminderEmail'));
    104     foreach ($emails as $email) {
    105         $email = trim($email);
    106 
    107         $title = '2kb Amazon DropShip Manager Reminder';
    108         $headers = array();
    109         $headers[] = 'From: 2kb Amazon DropShip Manager <'.$email.'>';
    110         $message = "Product with ASIN $asin ($postTitle) has reached quantity of $quantity.";
    111         $message .= "\n";
    112         $message .= get_admin_url() . 'admin.php?page=kbAmzDropShipManager&kbAction=manager';
    113         try {
    114             $isSent = wp_mail(
    115                 $email,
    116                 $title,
    117                 $message,
    118                 $headers
    119             );
    120 
    121             if (!$isSent) {
    122                 $errors = getKbAmz()->getOption('DropShipManagerErrors');
    123                 $errors[] = array(
    124                     'date' => date('Y-m-d H:i:s'),
    125                     'msg' => 'Mail Send Error: Unknown'
    126                 );
    127                 getKbAmz()->setOption('DropShipManagerErrors', $errors);
    128             }
    129         } catch (Exception $e) {
    130             $errors = getKbAmz()->getOption('DropShipManagerErrors');
    131             $errors[] = array(
    132                 'date' => date('Y-m-d H:i:s'),
    133                 'msg' => 'Mail Send Error: ' . $e->getMessage()
    134             );
    135             getKbAmz()->setOption('DropShipManagerErrors', $errors);
    136         }
    137     }
    138    
    139 }
    140 
    141 
    142 add_action('KbAmazonImporter::saveProduct', 'KbAmazonDropShipManagerProductSaveForceScrap', 1);
    143 function KbAmazonDropShipManagerProductSaveForceScrap($postId)
    144 {
    145     $isDropShipProduct = get_post_meta($postId, 'KbAmzDropShipManager', true);
    146     if (!$isDropShipProduct) {
    147         return;
    148     }
    149    
    150     $post = get_post($postId);
    151     $meta = getKbAmz()->getProductMeta($post->ID, true);
    152     if (!isset($meta['KbAmzDetailPageURL'])) {
    153         return;
    154     }
    155 
    156     // B00K6DVA8C
    157     $urlParts = parse_url($meta['KbAmzDetailPageURL']);
    158     $url = sprintf(
    159         '%s://%s/dp/%s',
    160         $urlParts['scheme'],
    161         $urlParts['host'],
    162         $meta['KbAmzASIN']
    163     );
    164 
    165     $args = array(
    166         'user-agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1'
    167     );
    168    
    169     $content = wp_remote_get($url, $args);
    170     if (!is_array($content)) {
    171         $content = wp_remote_get($meta['KbAmzDetailPageURL'], $args);
    172     }
    173     if (!isset($content['body'])) {
    174         return;
    175     }
    176     $content = $content['body'];
    177    
    178     $meta = array();
    179     $quantityParts = explode('<select name="quantity"', $content);
    180     if (isset($quantityParts[1])) {
    181         $quantityOptionsParts = explode('</select>', $quantityParts[1]);
    182         if (isset($quantityOptionsParts[0])) {
    183             $options = $quantityOptionsParts[0];
    184             $quantity = substr_count($options, '</option>');
    185             $meta['KbAmzOfferSummary.TotalNew'] = $quantity;
    186         }
    187     }
    188    
    189     if (!isset($meta['KbAmzOfferSummary.TotalNew'])) {
    190         $quantityParts = explode('id="availability"', $content);
    191         if (isset($quantityParts[1])) {
    192             $quantityOptionsParts = explode('</div>', $quantityParts[1]);
    193             if (isset($quantityOptionsParts[0])) {
    194                 $quantity = preg_replace("/[^0-9]/", "", $quantityOptionsParts[0]);
    195                 $meta['KbAmzOfferSummary.TotalNew'] = $quantity;
    196             }
    197         }
    198     }
    199    
    200     if (isset($meta['KbAmzOfferSummary.TotalNew'])
    201     && empty($meta['KbAmzOfferSummary.TotalNew'])) {
    202         unset($meta['KbAmzOfferSummary.TotalNew']);
    203     }
    204    
    205     $priceParts = explode('id="priceblock_ourprice"', $content);
    206    
    207     if (isset($priceParts[1])) {
    208         $priceParts = explode('</span>', $priceParts[1]);
    209         if (isset($priceParts[0])) {
    210             $priceParts = explode('>', $priceParts[0]);
    211             if (isset($priceParts[1]) && !empty($priceParts[1])) {
    212                 $meta['KbAmzPriceAmountFormatted'] = $priceParts[1];
    213                 $meta['KbAmzPriceAmount']          = KbAmazonImporter::paddedNumberToDecial(
    214                     KbAmazonImporter::formattedNumberToDecial($priceParts[1]) . '00'
    215                 );
    216             }
    217         }
    218     }
    219 
    220     foreach ($meta as $name => $val) {
    221         update_post_meta($post->ID, $name, $val);
    222     }
    223 }
    224 
    225 
    226 /**
    227  * Save Price Differences
    228  */
    229 add_action('KbAmazonImporter::preSaveProduct', 'KbAmazonDropShipManagerProductPreSaveQuantityManager');
    230 function KbAmazonDropShipManagerProductPreSaveQuantityManager($params)
    231 {
    232     $postId = $params['postId'];
    233     if ($postId) {
    234         $isDropShipProduct = get_post_meta($postId, 'KbAmzDropShipManager', true);
    235         if (!$isDropShipProduct) {
    236             return;
    237         }
    238        
    239         $meta = getKbAmz()->getProductMeta($postId, true);
    240        
    241         $currentStorage =
    242         get_post_meta(
    243             $postId,
    244             '_KbAmazonDropShipManagerStorageHistory',
    245             true
    246         );
    247 
    248         if (!isset($currentStorage['history'])) {
    249             $currentStorage['history'] = array();
    250         }
    251 
    252         $storageRow = array(
    253             'KbAmzOfferSummary.TotalNew'     => $meta['KbAmzOfferSummary.TotalNew'],
    254             'KbAmzPriceAmountFormatted'      => $meta['KbAmzPriceAmountFormatted'],
    255             'KbAmzPriceAmount'               => $meta['KbAmzPriceAmount'],
    256             'time'                           => time()
    257         );
    258 
    259         $currentStorage['history'][] = $storageRow;
    260         $currentStorage['history'] = array_slice($currentStorage['history'], -100);
    261 
    262         $storageRow['history'] = $currentStorage['history'];
    263 
    264         update_post_meta(
    265             $postId,
    266             '_KbAmazonDropShipManagerStorageHistory',
    267             $storageRow
    268         );
    269     }
    270 }
    271 
    272 /**
    273  * Save original price
    274  */
    275 add_action('KbAmazonImporter::saveProduct', 'KbAmazonDropShipManagerProductSaveOriginalPrice', 10);
    276 function KbAmazonDropShipManagerProductSaveOriginalPrice($postId)
    277 {
    278     if ($postId) {
    279         $isDropShipProduct = get_post_meta($postId, 'KbAmzDropShipManager', true);
    280         if (!$isDropShipProduct) {
    281             return;
    282         }
    283        
    284         $meta = getKbAmz()->getProductMeta($postId, true);
    285         if (isset($meta['KbAmzOfferSummary.TotalNew'])
    286         && isset($meta['KbAmzPriceAmountFormatted'])
    287         && isset($meta['KbAmzPriceAmount'])) {
    288            
    289             $currentStorage =
    290             get_post_meta(
    291                 $postId,
    292                 '_KbAmazonDropShipManagerImportStorage',
    293                 true
    294             );
    295            
    296             if (empty($currentStorage)
    297             || (empty($currentStorage['KbAmzOfferSummary.TotalNew'])
    298             || empty($currentStorage['KbAmzPriceAmountFormatted'])
    299             || empty($currentStorage['KbAmzPriceAmount']))) {
    300                 $storageRow = array(
    301                     'KbAmzOfferSummary.TotalNew'     => $meta['KbAmzOfferSummary.TotalNew'],
    302                     'KbAmzPriceAmountFormatted'      => $meta['KbAmzPriceAmountFormatted'],
    303                     'KbAmzPriceAmount'               => $meta['KbAmzPriceAmount'],
    304                     'time'                           => time()
    305                 );
    306                 update_post_meta(
    307                     $postId,
    308                     '_KbAmazonDropShipManagerImportStorage',
    309                     $storageRow
    310                 );
    311             }
    312         }
    313     }
    314 }
Note: See TracChangeset for help on using the changeset viewer.