Beispiel #1
0
 public function handleSubmitOnInit()
 {
     WPLE()->logger->debug("handleSubmit()");
     if ($this->requestAction() == 'prepare_auction') {
         $listingsModel = new ListingsModel();
         $listings = $listingsModel->prepareListings($_REQUEST['post']);
         // redirect to listings page
         wp_redirect(get_admin_url() . 'admin.php?page=wplister');
         exit;
     }
     if ($this->requestAction() == 'reselect') {
         ListingsModel::reSelectListings($_REQUEST['auction']);
         // redirect to listings page
         wp_redirect(get_admin_url() . 'admin.php?page=wplister');
         exit;
     }
     if ($this->requestAction() == 'apply_listing_profile') {
         WPLE()->logger->info('apply_listing_profile');
         #WPLE()->logger->info( print_r( $_REQUEST, 1 ) );
         $profilesModel = new ProfilesModel();
         $profile = $profilesModel->getItem($_REQUEST['wpl_e2e_profile_to_apply']);
         $listingsModel = new ListingsModel();
         $items = $listingsModel->applyProfileToNewListings($profile);
         // remember selected profile
         self::updateOption('last_selected_profile', intval($_REQUEST['wpl_e2e_profile_to_apply']));
         // redirect to listings page
         if (@$_REQUEST['wpl_e2e_verify_after_profile'] == '1') {
             // verify new listings if asked to
             wp_redirect(get_admin_url() . 'admin.php?page=wplister&action=verifyPreparedItemsNow');
         } else {
             wp_redirect(get_admin_url() . 'admin.php?page=wplister');
         }
         exit;
     }
     // handle preview action
     if ($this->requestAction() == 'preview_auction') {
         $this->previewListing($_REQUEST['auction']);
         exit;
     }
 }
Beispiel #2
0
 public function ajax_wple_select_profile()
 {
     // TODO: check nonce
     if (isset($_REQUEST['profile_id']) && isset($_REQUEST['product_ids'])) {
         $profile_id = $_REQUEST['profile_id'];
         $product_ids = $_REQUEST['product_ids'];
         $select_mode = $_REQUEST['select_mode'];
         $default_account_id = get_option('wplister_default_account_id', 1);
         $lm = new ListingsModel();
         if ('products' == $select_mode) {
             // get profile
             $pm = new ProfilesModel();
             $profile = $pm->getItem($profile_id);
             // prepare new listings from products
             // $response = $lm->prepareListings( $product_ids, $profile_id );
             $response = $lm->prepareListings($product_ids, $profile_id);
             $lm->applyProfileToNewListings($profile);
         } elseif ('listings' == $select_mode) {
             // change profile for existing listings
             // $profile = WPLE_AmazonProfile::getProfile( $profile_id ); // doesn't work
             $pm = new ProfilesModel();
             $profile = $pm->getItem($profile_id);
             // $items = $lm->applyProfileToListings( $profile, $product_ids );
             foreach ($product_ids as $listing_id) {
                 $item = ListingsModel::getItem($listing_id);
                 $lm->applyProfileToItem($profile, $item);
             }
             // build response
             $response = new stdClass();
             // $response->success     = $prepared_count ? true : false;
             $response->success = true;
             $response->msg = sprintf(__('Profile "%s" was applied to %s items.', 'wplister'), $profile['profile_name'], count($product_ids));
             $this->returnJSON($response);
             exit;
         } else {
             die('invalid select mode: ' . $select_mode);
         }
         if ($response->success) {
             // store ASIN as product meta
             // update_post_meta( $post_id, '_wple_asin', $asin );
             // show message
             if ($response->skipped_count) {
                 $response->msg = sprintf(__('%s product(s) have been prepared and %s products were skipped.', 'wplister'), $response->prepared_count, $response->skipped_count);
             } else {
                 $response->msg = sprintf(__('%s product(s) have been prepared.', 'wplister'), $response->prepared_count);
             }
             // include link to prepared listings
             $response->msg .= '&nbsp; <a href="admin.php?page=wplister&listing_status=prepared" class="button button-small">' . __('View prepared listings', 'wplister') . '</a>';
             // show shorter message if no listings were prepared
             if (!$response->prepared_count) {
                 $response->msg = sprintf(__('%s products have been skipped.', 'wplister'), $response->skipped_count);
             }
             if ($response->errors) {
                 $response->msg .= '<br>' . join('<br>', $response->errors);
             }
             if ($response->warnings) {
                 $response->msg .= '<br>' . join('<br>', $response->warnings);
             }
             $this->returnJSON($response);
             exit;
         } else {
             if (isset($lm->lastError)) {
                 echo $lm->lastError . "\n";
             }
             echo "Failed to prepare product!";
             exit;
         }
     }
 }