コード例 #1
0
ファイル: ListingsModel.php プロジェクト: booklein/wpbookle
 public function applyProfileToItem($profile, $item, $update_title = true)
 {
     global $wpdb;
     // get item data
     $id = $item['id'];
     $post_id = $item['post_id'];
     $status = WPLE_ListingQueryHelper::getStatus($id);
     $ebay_id = self::getEbayIDFromID($id);
     $post_title = get_the_title($item['post_id']);
     WPLE()->logger->info("applyProfileToItem() - listing_id: {$id} / post_id: {$post_id}");
     // WPLE()->logger->callStack( debug_backtrace() );
     // skip ended auctions - or not, if you want to relist them...
     // if ( $status == 'ended' ) return;
     // use parent title for single (split) variation
     if (ProductWrapper::isSingleVariation($post_id)) {
         $parent_id = ProductWrapper::getVariationParent($post_id);
         $post_title = get_the_title($parent_id);
         // check if parent product has a custom eBay title set
         if (get_post_meta($parent_id, '_ebay_title', true)) {
             $post_title = trim(get_post_meta($parent_id, '_ebay_title', true));
         }
         // get variations
         $variations = ProductWrapper::getVariations($parent_id);
         // find this variation in all variations of this parent
         foreach ($variations as $var) {
             if ($var['post_id'] == $post_id) {
                 // append attribute values to title
                 $post_title = self::processSingleVariationTitle($post_title, $var['variation_attributes']);
             }
         }
     }
     // gather profile data
     $data = array();
     $data['profile_id'] = $profile['profile_id'];
     $data['account_id'] = $profile['account_id'];
     $data['site_id'] = $profile['site_id'];
     $data['auction_type'] = $profile['type'];
     $data['listing_duration'] = $profile['listing_duration'];
     $data['template'] = $profile['details']['template'];
     $data['quantity'] = $profile['details']['quantity'];
     $data['date_created'] = date('Y-m-d H:i:s');
     $data['profile_data'] = self::encodeObject($profile);
     // echo "<pre>";print_r($data);echo"</pre>";die();
     // add prefix and suffix to product title
     if ($update_title) {
         // append space to prefix, prepend space to suffix
         // TODO: make this an option
         $title_prefix = trim($profile['details']['title_prefix']) . ' ';
         $title_suffix = ' ' . trim($profile['details']['title_suffix']);
         // custom post meta fields override profile values
         if (get_post_meta($post_id, 'ebay_title_prefix', true)) {
             $title_prefix = trim(get_post_meta($post_id, 'ebay_title_prefix', true)) . ' ';
         }
         if (get_post_meta($post_id, 'ebay_title_suffix', true)) {
             $title_prefix = trim(get_post_meta($post_id, 'ebay_title_suffix', true)) . ' ';
         }
         $data['auction_title'] = trim($title_prefix . $post_title . $title_suffix);
         // custom post meta title override
         if (get_post_meta($post_id, '_ebay_title', true)) {
             $data['auction_title'] = trim(get_post_meta($post_id, '_ebay_title', true));
         } elseif (get_post_meta($post_id, 'ebay_title', true)) {
             $data['auction_title'] = trim(get_post_meta($post_id, 'ebay_title', true));
         }
         // process attribute shortcodes in title - like [[attribute_Brand]]
         if (strpos($data['auction_title'], ']]') > 0) {
             $templatesModel = new TemplatesModel();
             WPLE()->logger->info('auction_title before processing: ' . $data['auction_title'] . '');
             $data['auction_title'] = $templatesModel->processAllTextShortcodes($item['post_id'], $data['auction_title'], 80);
         }
         WPLE()->logger->info('auction_title after processing : ' . $data['auction_title'] . '');
         // trim title to 255 characters - longer titles will break $wpdb->update()
         if (strlen($data['auction_title']) > 255) {
             $data['auction_title'] = self::mb_substr($data['auction_title'], 0, 80);
             // eBay titles can not be longer than 80 characters
         }
     }
     // apply profile price
     $data['price'] = ProductWrapper::getPrice($post_id);
     $data['price'] = self::applyProfilePrice($data['price'], $profile['details']['start_price']);
     // fetch product stock if no quantity set in profile - and apply max_quantity limit
     if (intval($data['quantity']) == 0) {
         $max = isset($profile['details']['max_quantity']) && intval($profile['details']['max_quantity']) > 0 ? $profile['details']['max_quantity'] : PHP_INT_MAX;
         $data['quantity'] = min($max, intval(ProductWrapper::getStock($post_id)));
         // update listing quantity properly - using setListingQuantity() which regards current quantity_sold
         self::setListingQuantity($post_id, $data['quantity']);
         unset($data['quantity']);
     }
     // default new status is 'prepared'
     $data['status'] = 'prepared';
     // except for already published items where it is 'changed'
     if (intval($ebay_id) > 0) {
         $data['status'] = 'changed';
     }
     // ended items stay 'ended' and sold items stay sold
     if ($status == 'ended') {
         $data['status'] = 'ended';
     }
     if ($status == 'sold') {
         $data['status'] = 'sold';
     }
     if ($status == 'archived') {
         $data['status'] = 'archived';
     }
     // locked items simply keep their status
     if (@$item['locked']) {
         $data['status'] = $status;
     }
     // but if apply_changes_to_all_locked checkbox is ticked, even locked published items will be marked as 'changed'
     if (@$item['locked'] && $status == 'published' && isset($_POST['wpl_e2e_apply_changes_to_all_locked'])) {
         $data['status'] = 'changed';
     }
     // except for selected items which shouldn't be locked in the first place
     if ($status == 'selected') {
         $data['status'] = 'prepared';
     }
     // and reselected items which have already been 'ended'
     if ($status == 'reselected') {
         $data['status'] = 'ended';
     }
     // and items which have already been 'changed' and now had a new profile applied
     if ($status == 'changed_profile') {
         $data['status'] = 'changed';
     }
     // debug
     if ($status != $data['status']) {
         WPLE()->logger->info('applyProfileToItem(' . $id . ') old status: ' . $status);
         WPLE()->logger->info('applyProfileToItem(' . $id . ') new status: ' . $data['status']);
     }
     // update auctions table
     $wpdb->update($this->tablename, $data, array('id' => $id));
     // WPLE()->logger->info('updating listing ID '.$id);
     // WPLE()->logger->info('data: '.print_r($data,1));
     // WPLE()->logger->info('sql: '.$wpdb->last_query);
     // WPLE()->logger->info('error: '.$wpdb->last_error);
 }
コード例 #2
0
 public function buildProductOptions($id, $item, $post_id, $profile_details, $listing, $hasVariations, $isVariation)
 {
     // get product SKU
     $product_sku = ProductWrapper::getSKU($post_id);
     // if this is a single split variation, use variation SKU instead of parent SKU
     if ($isVariation) {
         $product_sku = ProductWrapper::getSKU($listing['post_id']);
     }
     // set SKU - if not empty
     if (trim($product_sku) == '') {
         $product_sku = false;
     }
     if ($product_sku) {
         $item->SKU = $product_sku;
     }
     // build buildProductListingDetails (UPC, EAN, MPN, etc.)
     $item = $this->buildProductListingDetails($id, $item, $post_id, $profile_details, $listing, $hasVariations, $isVariation, $product_sku);
     // add subtitle if enabled
     if (@$profile_details['subtitle_enabled'] == 1) {
         // check if custom post meta field '_ebay_subtitle' exists
         if (get_post_meta($post_id, '_ebay_subtitle', true)) {
             $subtitle = get_post_meta($post_id, '_ebay_subtitle', true);
         } elseif (get_post_meta($post_id, 'ebay_subtitle', true)) {
             $subtitle = get_post_meta($post_id, 'ebay_subtitle', true);
         } else {
             // check for custom subtitle from profile
             $subtitle = @$profile_details['custom_subtitle'];
         }
         // if empty use product excerpt
         if ($subtitle == '') {
             $the_post = get_post($post_id);
             $subtitle = strip_tags($the_post->post_excerpt);
         }
         // limit to 55 chars to avoid error
         $subtitle = substr($subtitle, 0, 55);
         $item->setSubTitle($subtitle);
         WPLE()->logger->debug('setSubTitle: ' . $subtitle);
     }
     // item condition description
     $condition_description = false;
     if (@$profile_details['condition_description'] != '') {
         $condition_description = $profile_details['condition_description'];
         $templatesModel = new TemplatesModel();
         $condition_description = $templatesModel->processAllTextShortcodes($post_id, $condition_description);
         $item->setConditionDescription($condition_description);
     }
     return $item;
 }