/** * Begins an actual export job sequence based on requested data -- the job class itself will validate most of this info before attempting an export * * @param array $data */ protected function _moduleExportCommenceCommon($data) { $keystore = Interspire_KeyStore::instance(); // find a unique export id to use do { $id = md5(uniqid('',true)); } while ($keystore->exists('email:module_export:id:' . $id)); $keystore->set('email:module_export:id:' . $id, $id); $prefix = 'email:module_export:' . $id; if (!isset($data['exportSearch'])) { $data['exportSearch'] = array(); } if (!isset($data['exportMap'])) { $data['exportMap'] = array(); } $keystore->set($prefix . ':started', time()); $keystore->set($prefix . ':abort', 0); $keystore->set($prefix . ':skip', 0); $keystore->set($prefix . ':type', $data['exportType']); $keystore->set($prefix . ':module', $data['exportModule']); $keystore->set($prefix . ':list', $data['exportList']); $keystore->set($prefix . ':search', ISC_JSON::encode($data['exportSearch'])); $keystore->set($prefix . ':map', ISC_JSON::encode($data['exportMap'])); $keystore->set($prefix . ':success_count', 0); $keystore->set($prefix . ':error_count', 0); $keystore->set($prefix . ':doubleoptin', $data['exportDoubleOptin']); $keystore->set($prefix . ':updateexisting', $data['exportUpdateExisting']); // 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('emailintegration', 'Job_EmailIntegration_ModuleExport', $jobData), 'id' => $id, ); if (isset($data['return']) && $data['return']) { return $json; } ISC_JSON::output($json); }
/** * 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(); }
/** * @param array<Interspire_EmailIntegration_Subscription> $batch */ protected function _subscribeBatch($batch) { $results = $this->_module->addSubscribersToList($this->_list['provider_list_id'], $batch, $this->_map); if (!is_array($results)) { $error = GetLang('EmailIntegration_Log_JobCustomerBatchApiError'); $this->_logError($error); $this->_errorExport($error); return false; } $successCount = 0; $errorCount = 0; $errorMessages = ''; foreach ($results as /** @var Interspire_EmailIntegration_AddSubscriberResult */$result) { if ($result->success) { $successCount++; } else { $errorCount++; $message = $result->apiErrorMessage . ' (' . $result->apiErrorCode . ')'; $error = array( 'email' => $result->subscription->getSubscriptionEmail(), 'time' => time(), 'message' => $message, ); $this->_keystore->set($this->_prefix . 'error:' . md5($result->subscription->getSubscriptionEmail() . uniqid('',true)), ISC_JSON::encode($error)); $errorMessages .= GetLang('EmailIntegration_Log_BatchSubscribeError_MessageTemplate', array( 'email' => $result->subscription->getSubscriptionEmail(), 'error' => $message, )) . "\n"; } } if ($errorMessages) { $this->_log->LogSystemError(array('emailintegration', $this->_module->GetName()), GetLang('EmailIntegration_Log_BatchSubscribeError', array( 'errorcount' => $errorCount, )), nl2br($errorMessages)); } $this->_log->LogSystemNotice(array('emailintegration', $this->_module->GetName()), GetLang('EmailIntegration_Log_BatchComplete', array( 'start' => ($this->_skip + 1), 'end' => ($this->_skip + count($batch)), 'success_count' => $successCount, 'error_count' => $errorCount, ))); $this->_keystore->increment($this->_prefix . 'success_count', $successCount); $this->_keystore->increment($this->_prefix . 'error_count', $errorCount); return $results; }
/** * Logs an exception on the entire request * * @param array $products The products in the batch * @param ISC_EBAY_API_EXCEPTION $ex The exception that was caught */ private function logBatchException($products, $ex) { $ids = "Product ID's: " . implode(', ', array_keys($products)); $this->_logDebug('exception processing batch', $ex->getMessage()); // log error $error = array( 'prodname' => $ids, 'time' => time(), 'message' => $ex->getMessage(), ); $this->_keystore->set($this->_prefix . 'error:' . md5($ids . uniqid('', true)), ISC_JSON::encode($error)); }