示例#1
0
 /**
  * Return product ebay template
  * @return Template
  */
 public function getTemplate()
 {
     return Template::getById($this->template_id);
 }
示例#2
0
        $params['product_ids'] = array_filter(explode(',', $params['product_ids']));
    }
    // Init filter
    $params = \Tygh\Navigation\LastView::instance()->update('ebay_product_logs', $params);
    list($logs, $search) = \Ebay\ProductLogger::getList($params, Registry::get('settings.Appearance.admin_elements_per_page'));
    $types = \Ebay\ProductLogger::getTypes();
    $actions = \Ebay\ProductLogger::getActions();
    $templates = fn_get_ebay_templates(array(), 0, DESCR_SL, true);
    Tygh::$app['view']->assign('logs', $logs);
    Tygh::$app['view']->assign('ebay_types', $types);
    Tygh::$app['view']->assign('ebay_actions', $actions);
    Tygh::$app['view']->assign('ebay_templates', $templates);
    Tygh::$app['view']->assign('search', $search);
} elseif ($mode == 'categories_picker') {
    $company_id = !empty($_REQUEST['company_id']) ? $_REQUEST['company_id'] : null;
    $used_site_ids = \Ebay\Template::getUsedSiteIds($company_id);
    if (isset($_REQUEST['site_id']) && in_array($_REQUEST['site_id'], $used_site_ids)) {
        $current_site_id = $_REQUEST['site_id'];
    } else {
        $current_site_id = reset($used_site_ids);
    }
    $category_id = empty($_REQUEST['category_id']) ? 0 : $_REQUEST['category_id'];
    $category_count = db_get_field("SELECT COUNT(*) FROM ?:ebay_categories WHERE site_id = ?i", $current_site_id);
    $except_id = 0;
    if (!empty($_REQUEST['except_id'])) {
        $except_id = $_REQUEST['except_id'];
        Tygh::$app['view']->assign('except_id', $_REQUEST['except_id']);
    }
    if ($category_count < CATEGORY_THRESHOLD) {
        $params = array('simple' => false, 'b_id' => !empty($_REQUEST['b_id']) ? $_REQUEST['b_id'] : '', 'except_id' => $except_id);
        list($categories_tree, ) = fn_ebay_get_categories($params, $current_site_id, DESCR_SL);
示例#3
0
 /**
  * @param array $product_ids
  */
 protected static function exportProducts(array $product_ids)
 {
     static::$count_success = 0;
     static::$count_fail = 0;
     static::$count_skip = 0;
     static::$errors = array();
     static::$error_counter = array();
     $product_ids = array_filter($product_ids);
     $templates = $groups = array();
     fn_set_progress('parts', count($product_ids) * 2);
     foreach ($product_ids as $product_id) {
         $product = new Product($product_id);
         if (empty($product->id)) {
             fn_set_progress('echo', '.');
             static::$count_skip++;
             continue;
         }
         if (empty($product->template_id)) {
             $template = Template::getDefaultByCompanyId($product->company_id);
             if ($template) {
                 $product->setTemplateId($template->id);
                 $product->saveTemplateId();
             } else {
                 $company_name = fn_get_company_name($product->company_id);
                 fn_set_notification('E', __('error'), __('ebay_default_template_not_found', array('[company_name]' => $company_name)));
             }
         }
         if (!empty($product->external_id)) {
             $api = Client::instance($product->getTemplate());
             static::uploadProductImages($product);
             fn_set_progress('echo', __('ebay_export_product', array('[product]' => htmlspecialchars($product->original_title))), false);
             $combinations = $product->getCombinations();
             $external_combinations = $product->getExternalCombinations();
             if (!empty($combinations) && empty($external_combinations)) {
                 $result = $api->getItem($product);
                 if ($result && $result->isSuccess()) {
                     $product->setExternalCombinations($result->getProductVariations());
                 }
             }
             $result = $api->reviseItem($product);
             if ($result) {
                 if ($result->isSuccess()) {
                     $product->setStatusActive();
                     $product->saveExternalData();
                 } elseif ($result->issetErrorAuctionEnded()) {
                     $result = $api->relistItem($product);
                     if ($result && $result->isSuccess()) {
                         Product::deleteExternalData($product->external_id);
                         $product->external_id = $result->getExternalId();
                         $product->saveExternalData();
                         $product->setStatusActive();
                     }
                 }
             }
             if ($result) {
                 if ($result->isSuccess()) {
                     static::$count_success++;
                     ProductLogger::info(ProductLogger::ACTION_UPDATE_PRODUCT, $product, __('ebay_success_exported_product_notice'));
                 } else {
                     static::$count_fail++;
                 }
                 static::checkResponse($product, $result, ProductLogger::ACTION_UPDATE_PRODUCT);
             } else {
                 static::checkInternalErrors($product, $api, ProductLogger::ACTION_UPDATE_PRODUCT);
             }
             fn_set_progress('echo', '.');
         } else {
             $groups[$product->template_id][] = $product;
             $templates[$product->template_id] = $product->getTemplate();
             if (count($groups[$product->template_id]) >= static::MAX_COUNT_EXPORT_NEW_PRODUCTS) {
                 static::exportGroupProducts($product->getTemplate(), $groups[$product->template_id]);
                 unset($groups[$product->template_id]);
             }
         }
     }
     if (!empty($groups)) {
         foreach ($groups as $template_id => $products) {
             static::exportGroupProducts($templates[$template_id], $products);
         }
     }
     /** @var \Smarty $smarty */
     $smarty = Tygh::$app['view'];
     $smarty->assign('export_result', array('count_success' => static::$count_success, 'count_fail' => static::$count_fail, 'count_skip' => static::$count_skip, 'errors' => static::$errors, 'error_counter' => static::$error_counter, 'count_external_error' => static::$count_external_error));
     fn_set_notification('I', static::$count_fail == 0 ? __('ebay_export_success') : __('ebay_export_failed'), $smarty->fetch('addons/ebay/views/ebay/components/export_summary.tpl'));
 }