/** * Initiliazes a job to list products on eBay * */ private function initProductListingAction() { $productOptions = $_POST['productOptions']; $productCount = (int)$_POST['productCount']; $templateId = (int)$_POST['templateId']; try { $template = new ISC_ADMIN_EBAY_TEMPLATE($templateId); } catch (Exception $ex) { ISC_JSON::output($ex->getMessage(), false); } $estimatedTotal = $productCount * $template->getQuantityToSell(); $where = ISC_ADMIN_EBAY_LIST_PRODUCTS::getWhereFromOptions($productOptions); // list 'now' or 'schedule' $listingDate = $_POST['listingDate']; $isoScheduleDate = ''; if ($listingDate == 'schedule') { // user's timestamp date in GMT $scheduleDate = $_POST['scheduleDate']; // convert to ISO 8601 $isoScheduleDate = date('c', $scheduleDate); } $keystore = Interspire_KeyStore::instance(); // find a unique export id to use do { $id = md5(uniqid('',true)); } while ($keystore->exists('ebay:list_products:id:' . $id)); $keystore->set('ebay:list_products:id:' . $id, $id); $prefix = 'ebay:list_products:' . $id; $keystore->set($prefix . ':started', time()); $keystore->set($prefix . ':abort', 0); $keystore->set($prefix . ':offset', 0); $keystore->set($prefix . ':actual_processed', 0); $keystore->set($prefix . ':actual_listed', 0); $keystore->set($prefix . ':estimated_total', $estimatedTotal); $keystore->set($prefix . ':templateid', $templateId); $keystore->set($prefix . ':template_name', $template->getTemplateName()); $keystore->set($prefix . ':listing_date', $listingDate); $keystore->set($prefix . ':schedule_date', $isoScheduleDate); $keystore->set($prefix . ':where', $where); $keystore->set($prefix . ':options', ISC_JSON::encode($productOptions)); $keystore->set($prefix . ':success_count', 0); $keystore->set($prefix . ':warning_count', 0); $keystore->set($prefix . ':error_count', 0); // so we can send an email later, or diagnose troublesome users $user = $GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetUser(); $keystore->set($prefix . ':owner:id', $user['pk_userid']); $keystore->set($prefix . ':owner:username', $user['username']); $keystore->set($prefix . ':owner:email', $user['useremail']); $jobData = array( 'id' => $id, ); $json = array( 'success' => (bool)Interspire_TaskManager::createTask('ebay', 'Job_Ebay_ListProducts', $jobData), 'id' => $id, ); ISC_JSON::output($json); }
/** * Displays the edit template form * */ public function editEbayTemplate() { GetLib('class.json'); $templateId = (int)$_GET['templateId']; try { $template = new ISC_ADMIN_EBAY_TEMPLATE($templateId); $this->template->assign('templateId', $templateId); $this->template->assign('formTitle', GetLang('EditEbayTemplate')); $this->template->assign('hasStore', (bool)GetConfig('EbayStore')); $this->template->assign('ebaySites', $this->getSupportedSites()); $this->template->assign('siteId', $template->getSiteId()); $this->template->assign('templateName', $template->getTemplateName()); $this->template->assign('templateIsDefault', $template->isDefaultTemplate()); $this->template->assign('isPrivateListing', $template->isPrivateListing()); // setup category details $primaryCategoryOptions = $template->getPrimaryCategoryOptions(); $secondaryCategoryOptions = $template->getSecondaryCategoryOptions(); $this->template->assign('primaryCategory', $primaryCategoryOptions['path']); $this->template->assign('primaryCategoryOptions', ISC_JSON::encode($primaryCategoryOptions)); $this->template->assign('categoryOptions', $primaryCategoryOptions); $this->template->assign('sellingMethod', $template->getSellingMethod()); try { if (empty ($secondaryCategoryOptions)) { $secondaryCategoryId = $template->getSecondaryCategoryId(); if (!empty ($secondaryCategoryId)) { $secondaryCategoryOptions = ''; $secondaryCategoryOptions = ISC_ADMIN_EBAY_CATEGORIES::getCategoryFeatures($secondaryCategoryId, $template->getSiteId()); $categoryPath = ISC_ADMIN_EBAY_CATEGORIES::getFormattedCategoryPath($secondaryCategoryId, $template->getSiteId()); $secondaryCategoryOptions['path'] = $categoryPath; } else { $secondaryCategoryOptions = ISC_ADMIN_EBAY_CATEGORIES::getCategoryOptionsFromId($template->getSecondaryCategoryId(), $template->getSiteId()); } } } catch (Exception $ex) { $secondaryCategoryOptions = array( 'category_id' => $template->getSecondaryCategoryId(), 'name' => $template->getSecondaryCategoryName(), 'path' => $template->getSecondaryCategoryName(), ); } if ($secondaryCategoryOptions) { $this->template->assign('secondaryCategoryOptionsData', $secondaryCategoryOptions); $this->template->assign('secondaryCategory', $secondaryCategoryOptions['path']); } $secCatNotSupportVariations = (isset ($secondaryCategoryOptions['variations_supported']) && $secondaryCategoryOptions['variations_supported'] == 0); $this->template->assign('secCatSelectedNotSupportVariations', ($secCatNotSupportVariations)); $this->template->assign('secondaryCategoryOptions', ISC_JSON::encode($secondaryCategoryOptions)); $this->template->assign('categoryFeaturesList', $this->template->render('ebay.template.featureslist.tpl')); $primaryStoreCategoryOptions = array(); if ($template->getPrimaryStoreCategoryId()) { $primaryStoreCategoryOptions = array( 'category_id' => $template->getPrimaryStoreCategoryId(), 'name' => $template->getPrimaryStoreCategoryName(), 'path' => $template->getPrimaryStoreCategoryName(), ); $this->template->assign('primaryStoreCategory', $primaryStoreCategoryOptions['path']); } $this->template->assign('primaryStoreCategoryOptions', ISC_JSON::encode($primaryStoreCategoryOptions)); $secondaryStoreCategoryOptions = array(); if ($template->getSecondaryStoreCategoryId()) { $secondaryStoreCategoryOptions = array( 'category_id' => $template->getSecondaryStoreCategoryId(), 'name' => $template->getSecondaryStoreCategoryName(), 'path' => $template->getSecondaryStoreCategoryName(), ); $this->template->assign('secondaryStoreCategory', $secondaryStoreCategoryOptions['path']); } $this->template->assign('secondaryStoreCategoryOptions', ISC_JSON::encode($secondaryStoreCategoryOptions)); $this->template->assign('sellingMethod', $template->getSellingMethod()); } catch (Exception $ex) { FlashMessage($ex->getMessage(), MSG_ERROR, 'index.php?ToDo=viewEbay'); } $GLOBALS['BreadcrumEntries'][GetLang('EditEbayTemplate')] = 'index.php?ToDo=editEbayTemplate'; $this->engine->PrintHeader(); $this->template->display('ebay.template.form.tpl'); $this->engine->PrintFooter(); }