Exemple #1
0
 function wplister_prepare_listing($post_id, $profile_id)
 {
     // prepare product
     $listingsModel = new ListingsModel();
     $listingsModel->prepareProductForListing($post_id);
     if (!$profile_id) {
         return;
     }
     // get profile
     $profilesModel = new ProfilesModel();
     $profile = $profilesModel->getItem($profile_id);
     if (!$profile) {
         return;
     }
     $listingsModel->applyProfileToNewListings($profile);
 }
Exemple #2
0
 public function handleActions()
 {
     // handle save listing
     if ($this->requestAction() == 'save_listing') {
         $this->saveListing();
     }
     // set account_id
     $account_id = isset($_REQUEST['auction']) ? WPLE_ListingQueryHelper::getAccountID($_REQUEST['auction']) : false;
     // handle verify action
     if ($this->requestAction() == 'verify') {
         $this->initEC($account_id);
         $this->EC->verifyItems($_REQUEST['auction']);
         $this->EC->closeEbay();
         if ($this->EC->isSuccess) {
             $this->showMessage(__('Selected items were verified with eBay.', 'wplister'));
         } else {
             $this->showMessage(__('There were some problems verifying your items.', 'wplister'), 1);
         }
     }
     // handle revise action
     if ($this->requestAction() == 'revise') {
         $this->initEC($account_id);
         $this->EC->reviseItems($_REQUEST['auction']);
         $this->EC->closeEbay();
         if ($this->EC->isSuccess) {
             $this->showMessage(__('Selected items were revised on eBay.', 'wplister'));
         } else {
             $this->showMessage(__('There were some problems revising your items.', 'wplister'), 1);
         }
     }
     // handle publish to eBay action
     if ($this->requestAction() == 'publish2e') {
         $this->initEC($account_id);
         $this->EC->sendItemsToEbay($_REQUEST['auction']);
         $this->EC->closeEbay();
         if ($this->EC->isSuccess) {
             $this->showMessage(__('Selected items were published on eBay.', 'wplister'));
         } else {
             $this->showMessage(__('Some items could not be published.', 'wplister'), 1);
         }
     }
     // handle relist action
     if ($this->requestAction() == 'relist') {
         $this->initEC($account_id);
         $this->EC->relistItems($_REQUEST['auction']);
         $this->EC->closeEbay();
         if ($this->EC->isSuccess) {
             $this->showMessage(__('Selected items were re-listed on eBay.', 'wplister'));
         } else {
             $this->showMessage(__('There were some problems relisting your items.', 'wplister'), 1);
         }
     }
     // handle end_item action
     if ($this->requestAction() == 'end_item') {
         $this->initEC($account_id);
         $this->EC->endItemsOnEbay($_REQUEST['auction']);
         $this->EC->closeEbay();
         $this->showMessage(__('Selected listings were ended.', 'wplister'));
     }
     // handle update from eBay action
     if ($this->requestAction() == 'update') {
         $this->initEC($account_id);
         $this->EC->updateItemsFromEbay($_REQUEST['auction']);
         $this->EC->closeEbay();
         $this->showMessage(__('Selected items were updated from eBay.', 'wplister'));
     }
     // handle delete action
     if (isset($_REQUEST['auction']) && $this->requestAction() == 'delete_listing') {
         $id = $_REQUEST['auction'];
         if (is_array($id)) {
             foreach ($id as $single_id) {
                 WPLE_ListingQueryHelper::deleteItem($single_id);
             }
         } else {
             WPLE_ListingQueryHelper::deleteItem($id);
         }
         $this->showMessage(__('Selected items were removed.', 'wplister'));
     }
     // handle archive action
     if ($this->requestAction() == 'archive') {
         $id = $_REQUEST['auction'];
         $data = array('status' => 'archived');
         if (is_array($id)) {
             foreach ($id as $single_id) {
                 ListingsModel::updateListing($single_id, $data);
             }
         } else {
             ListingsModel::updateListing($id, $data);
         }
         $this->showMessage(__('Selected items were archived.', 'wplister'));
     }
     // handle wple_reset_status action
     if ($this->requestAction() == 'wple_reset_status') {
         $lm = new ListingsModel();
         $id = $_REQUEST['auction'];
         $data = array('status' => 'prepared', 'ebay_id' => NULL, 'end_date' => NULL, 'date_published' => NULL, 'last_errors' => '');
         if (is_array($id)) {
             foreach ($id as $single_id) {
                 $status = WPLE_ListingQueryHelper::getStatus($single_id);
                 if (!in_array($status, array('ended', 'sold', 'archived'))) {
                     wple_show_message("Item with status <i>{$status}</i> was skipped. Only ended and sold items can have their status reset to <i>prepared</i>.", 'warn');
                     continue;
                 }
                 ListingsModel::updateListing($single_id, $data);
                 $lm->reapplyProfileToItem($single_id);
             }
             wple_show_message(__('Selected items had their status reset to prepared.', 'wplister'));
         }
     }
     // handle wple_clear_eps_data action
     if ($this->requestAction() == 'wple_clear_eps_data') {
         $id = $_REQUEST['auction'];
         if (is_array($id)) {
             foreach ($id as $single_id) {
                 ListingsModel::updateWhere(array('id' => $single_id), array('eps' => ''));
             }
             wple_show_message(__('EPS cache was cleared for selected items.', 'wplister'));
         }
     }
     // handle lock action
     if ($this->requestAction() == 'lock') {
         $id = $_REQUEST['auction'];
         $data = array('locked' => true);
         if (is_array($id)) {
             foreach ($id as $single_id) {
                 ListingsModel::updateListing($single_id, $data);
             }
         } else {
             ListingsModel::updateListing($id, $data);
         }
         $this->showMessage(__('Selected items were locked.', 'wplister'));
     }
     // handle unlock action
     if ($this->requestAction() == 'unlock') {
         $id = $_REQUEST['auction'];
         $data = array('locked' => false);
         if (is_array($id)) {
             foreach ($id as $single_id) {
                 ListingsModel::updateListing($single_id, $data);
             }
         } else {
             ListingsModel::updateListing($id, $data);
         }
         $this->showMessage(__('Selected items were unlocked.', 'wplister'));
     }
     // handle cancel_schedule action
     if ($this->requestAction() == 'cancel_schedule') {
         $id = $_REQUEST['auction'];
         $data = array('relist_date' => null);
         if (is_array($id)) {
             foreach ($id as $single_id) {
                 ListingsModel::updateListing($single_id, $data);
             }
         } else {
             ListingsModel::updateListing($id, $data);
         }
         $this->showMessage(__('Selected items were unscheduled from auto relist.', 'wplister'));
     }
     // clean listing archive
     if ($this->requestAction() == 'wpl_clean_listing_archive') {
         WPLE_ListingQueryHelper::cleanArchive();
         $this->showMessage(__('Archive was cleared.', 'wplister'));
     }
     // handle toolbar action - prepare listing from product
     if ($this->requestAction() == 'wpl_prepare_single_listing') {
         // get profile
         $profilesModel = new ProfilesModel();
         $profile = isset($_REQUEST['profile_id']) ? $profilesModel->getItem($_REQUEST['profile_id']) : false;
         if ($profile) {
             // prepare product
             $listingsModel = new ListingsModel();
             $listing_id = $listingsModel->prepareProductForListing($_REQUEST['product_id'], $profile['profile_id']);
             if ($listing_id) {
                 $listingsModel->applyProfileToNewListings($profile);
                 $this->showMessage(__('New listing was prepared from product.', 'wplister'));
             } else {
                 $msg = __('Could not create a new listing from this product.', 'wplister');
                 if ($listingsModel->errors) {
                     $msg .= '<br>' . join('<br>', $listingsModel->errors);
                 }
                 if ($listingsModel->warnings) {
                     $msg .= '<br>' . join('<br>', $listingsModel->warnings);
                 }
                 $this->showMessage($msg, 2);
             }
         } elseif (isset($_REQUEST['product_id'])) {
             // prepare product
             $listingsModel = new ListingsModel();
             $listingsModel->prepareProductForListing($_REQUEST['product_id']);
         }
     }
     // handle reapply profile action
     if ($this->requestAction() == 'reapply') {
         $listingsModel = new ListingsModel();
         $listingsModel->reapplyProfileToItems($_REQUEST['auction']);
         $this->showMessage(__('Profiles were re-applied to selected items.', 'wplister'));
     }
     // cancel (re-)selecting profile process
     if ($this->requestAction() == 'cancel_profile_selection') {
         ListingsModel::cancelSelectingListings();
     }
 }