コード例 #1
0
ファイル: TemplatesModel.php プロジェクト: booklein/wpbookle
 function getVariationsHTML($item)
 {
     $profile_data = ListingsModel::decodeObject($item['profile_data'], true);
     $variations = ProductWrapper::getVariations($item['post_id']);
     $variations_html = '<div class="variations_list" style="margin:10px 0;">';
     $variations_html .= '<table style="margin-bottom: 8px;">';
     //table header
     if (true) {
         // first column: quantity
         $variations_html .= '<tr>';
         $first_variation = reset($variations);
         if (is_array($first_variation['variation_attributes'])) {
             foreach ($first_variation['variation_attributes'] as $name => $value) {
                 $variations_html .= '<th>';
                 $variations_html .= $name;
                 $variations_html .= '</th>';
             }
         }
         // last column: price
         $variations_html .= '<th align="right">';
         $variations_html .= __('Price', 'wplister');
         $variations_html .= '</th></tr>';
     }
     //table body
     foreach ($variations as $var) {
         // first column: quantity
         // $variations_html .= '<tr><td align="right">';
         // $variations_html .= intval( $var['stock'] ) . '&nbsp;x';
         // $variations_html .= '</td><td>';
         $variations_html .= '<tr>';
         foreach ($var['variation_attributes'] as $name => $value) {
             // $variations_html .= $name.': '.$value ;
             $variations_html .= '<td>';
             $variations_html .= $value;
             $variations_html .= '</td>';
         }
         // $variations_html .= '('.$var['sku'].') ';
         // $variations_html .= '('.$var['image'].') ';
         // last column: price
         $variations_html .= '<td align="right">';
         $price = ListingsModel::applyProfilePrice($var['price'], $profile_data['details']['start_price']);
         $variations_html .= number_format_i18n(floatval($price), 2);
         $variations_html .= '</td></tr>';
     }
     $variations_html .= '</table>';
     $variations_html .= '</div>';
     // return html
     return $variations_html;
 }
コード例 #2
0
ファイル: ListingsTable.php プロジェクト: booklein/wpbookle
 function getProfileData($item)
 {
     $profile_data = ListingsModel::decodeObject($item['profile_data'], true);
     return $profile_data;
 }
コード例 #3
0
 public function checkProductInventory($mode = 'published', $compare_prices = false, $step = 0)
 {
     $batch_size = get_option('wplister_inventory_check_batch_size', 200);
     $limit = $batch_size;
     $offset = $batch_size * $step;
     // get listings - or return false
     $lm = new ListingsModel();
     $listings = $mode == 'published' ? WPLE_ListingQueryHelper::getAllPublished($limit, $offset) : WPLE_ListingQueryHelper::getAllEnded($limit, $offset);
     if (empty($listings)) {
         return false;
     }
     // restore previous data
     $tmp_result = get_option('wple_inventory_check_queue_data', false);
     if ($tmp_result) {
         $out_of_sync_products = $tmp_result['out_of_sync_products'];
         $published_count = $tmp_result['published_count'];
     } else {
         $out_of_sync_products = array();
         $published_count = 0;
     }
     // process published listings
     foreach ($listings as $item) {
         // check wc product
         $post_id = $item['post_id'];
         $_product = ProductWrapper::getProduct($post_id);
         // echo "<pre>";print_r($_product);echo"</pre>";die();
         // get stock level and price
         $stock = ProductWrapper::getStock($item['post_id']);
         $price = ProductWrapper::getPrice($item['post_id']);
         // $item['price_max'] = $price;
         // echo "<pre>";print_r($price);echo"</pre>";#die();
         // echo "<pre>";print_r($item);echo"</pre>";die();
         // apply profile settings to stock level
         $profile_data = ListingsModel::decodeObject($item['profile_data'], true);
         $profile_details = $profile_data['details'];
         $item['qty'] = $item['quantity'] - $item['quantity_sold'];
         // echo "<pre>";print_r($profile_details);echo"</pre>";#die();
         // apply max_quantity from profile
         $max_quantity = isset($profile_details['max_quantity']) && intval($profile_details['max_quantity']) > 0 ? $profile_details['max_quantity'] : false;
         if ($max_quantity) {
             $stock = min($max_quantity, intval($stock));
         }
         // apply price modified from profile
         $profile_start_price = isset($profile_details['start_price']) && !empty($profile_details['start_price']) ? $profile_details['start_price'] : false;
         if ($profile_start_price) {
             // echo "<pre>price: ";print_r($profile_start_price);echo"</pre>";#die();
         }
         // check if product has variations
         if ($_product) {
             $variations = $_product->product_type == 'variable' ? ProductWrapper::getVariations($item['post_id']) : array();
         } else {
             $variations = array();
         }
         // get total stock for all variations
         if (!empty($variations)) {
             // reset prices and stock
             $stock = 0;
             $price_min = PHP_INT_MAX;
             $price_max = 0;
             $ebay_stock = 0;
             $ebay_price_min = PHP_INT_MAX;
             $ebay_price_max = 0;
             // check WooCommerce variations
             foreach ($variations as $var) {
                 // total stock
                 if ($max_quantity) {
                     $stock += min($max_quantity, intval($var['stock']));
                 } else {
                     $stock += $var['stock'];
                 }
                 // min / max prices
                 $price_min = min($price_min, $var['price']);
                 $price_max = max($price_max, $var['price']);
             }
             // check eBay variations
             $cached_variations = maybe_unserialize($item['variations']);
             if (is_array($cached_variations)) {
                 foreach ($cached_variations as $var) {
                     $ebay_stock += $var['stock'];
                     $ebay_price_min = min($ebay_price_min, $var['price']);
                     $ebay_price_max = max($ebay_price_max, $var['price']);
                 }
             }
             // set default values
             $item['qty'] = $ebay_stock;
             $item['price'] = $ebay_price_min != PHP_INT_MAX ? $ebay_price_min : 0;
             $item['price_max'] = $ebay_price_max;
             // echo "<pre>";print_r($cached_variations);echo"</pre>";die();
         } else {
             $price_min = false;
             $price_max = false;
             $ebay_price_min = false;
             $ebay_price_max = false;
         }
         // check if product and ebay listing are in sync
         $in_sync = true;
         // check stock level
         if ($stock != $item['qty']) {
             $in_sync = false;
         }
         // check price
         if ($compare_prices) {
             $price_to_compare = $price;
             if ($profile_start_price) {
                 $price_to_compare = ListingsModel::applyProfilePrice($price, $profile_start_price);
             }
             if (round($price_to_compare, 2) != round($item['price'], 2)) {
                 $in_sync = false;
             }
             // check max price
             if (isset($price_max) && isset($item['price_max']) && round($price_max, 2) != round($item['price_max'], 2)) {
                 $in_sync = false;
             }
         }
         // if in sync, continue with next item
         if ($in_sync) {
             continue;
         }
         // mark listing as changed
         if (isset($_REQUEST['mark_as_changed']) && $_REQUEST['mark_as_changed'] == 'yes') {
             if ($_product) {
                 // only existing products can have a profile re-applied
                 $lm->markItemAsModified($item['post_id']);
             }
             // in case the product is locked or missing, force the listing to be changed
             ListingsModel::updateListing($item['id'], array('status' => 'changed'));
             $item['status'] = 'changed';
         }
         // remove unneccessary data to consume less memory - doesn't seem to work...
         // unset( $item['profile_data'] );
         // unset( $item['post_content'] );
         // unset( $item['details'] );
         // unset( $item['variations'] );
         // unset( $item['last_errors'] );
         // unset( $item['history'] );
         // unset( $item['eps'] );
         // unset( $item['template'] );
         // add to list of out of sync products
         $item['price_woo'] = $price;
         $item['price_woo_max'] = isset($price_max) ? $price_max : false;
         $item['stock'] = $stock;
         $item['exists'] = $_product ? true : false;
         $item['type'] = $_product ? $_product->product_type : 'missing';
         $item['profile_start_price'] = $profile_start_price;
         $out_of_sync_products[] = $item;
         // count products which have not yet been marked as changed
         if ($item['status'] == 'published') {
             $published_count += 1;
         }
     }
     // store result so far
     $tmp_result = array('mode' => $mode, 'compare_prices' => $compare_prices, 'out_of_sync_products' => $out_of_sync_products, 'published_count' => $published_count);
     update_option('wple_inventory_check_queue_data', $tmp_result, 'no');
     // true means we processed more items
     return true;
 }