Example #1
0
 /**
  * Action export template products
  * @return array
  */
 public static function actionEndTemplate()
 {
     $template = Template::getById((int) $_REQUEST['template_id']);
     if (empty($template->id)) {
         return array();
     }
     $product_ids = Product::getTemplateProductIds($template->id);
     static::endProducts($product_ids);
     return static::returnBackRedirect('ebay.manage');
 }
Example #2
0
            }
        }
        fn_set_notification('W', __('notice'), __('ebay_addon_used_trial_license', array('[ebay_license_url]' => fn_ebay_get_license_url(), '[days]' => __('ebay_addon_plural_days', array($days)))));
    }
    Tygh::$app['view']->assign('templates', $templates);
    Tygh::$app['view']->assign('search', $search);
} elseif ($mode == 'add' || $mode == 'update') {
    $template_data = array();
    if ($mode == 'add') {
        $template_data = fn_restore_post_data('template_data');
    } elseif (!empty($_REQUEST['template_id'])) {
        $template_data = fn_get_ebay_template($_REQUEST['template_id']);
        if (empty($template_data)) {
            return array(CONTROLLER_STATUS_REDIRECT, 'ebay.manage');
        }
        $template_data['product_ids'] = \Ebay\Product::getTemplateProductIds($_REQUEST['template_id']);
    }
    if (!isset($template_data['site_id'])) {
        $template_data['site_id'] = Registry::get('addons.ebay.site_id');
    }
    if (isset($_REQUEST['site_id']) && $template_data['site_id'] != $_REQUEST['site_id']) {
        $template_data['site_id'] = $_REQUEST['site_id'];
        if (!defined('AJAX_REQUEST')) {
            fn_set_notification('N', __('information'), __('ebay_changed_region_message'), 'K');
        }
    }
    if (isset($_REQUEST['category_id'])) {
        $template_data['category'] = (int) $_REQUEST['category_id'];
    }
    if (isset($_REQUEST['shipping_type'])) {
        $template_data['shipping_type'] = $_REQUEST['shipping_type'];
Example #3
0
function fn_update_ebay_template($data, $template_id = 0, $lang_code = CART_LANGUAGE)
{
    if (empty($data['name'])) {
        return false;
    }
    unset($data['template_id']);
    if (fn_allowed_for('ULTIMATE')) {
        // check that template owner was not changed by store administrator
        if (Registry::get('runtime.company_id') || empty($data['company_id'])) {
            $template_company_id = db_get_field('SELECT company_id FROM ?:ebay_templates WHERE template_id = ?i', $template_id);
            if (!empty($template_company_id)) {
                $data['company_id'] = $template_company_id;
            } else {
                if (Registry::get('runtime.company_id')) {
                    $template_company_id = $data['company_id'] = Registry::get('runtime.company_id');
                } else {
                    $template_company_id = $data['company_id'] = fn_get_default_company_id();
                }
            }
        } else {
            $template_company_id = $data['company_id'];
        }
    } else {
        if (Registry::get('runtime.company_id')) {
            $template_company_id = Registry::get('runtime.company_id');
        } else {
            $template_company_id = $data['company_id'];
        }
    }
    if (fn_allowed_for('ULTIMATE') && Registry::get('runtime.company_id') && !empty($template_company_id) && Registry::get('runtime.company_id') != $template_company_id) {
        $create = false;
    } else {
        $isUpdate = false;
        if (isset($data['payment_methods']) && is_array($data['payment_methods'])) {
            $data['payment_methods'] = implode(',', $data['payment_methods']);
        }
        if (empty($data['root_sec_category'])) {
            $data['sec_category'] = '';
        }
        if (!empty($template_id)) {
            $isUpdate = true;
            db_query('UPDATE ?:ebay_templates SET ?u WHERE template_id = ?i', $data, $template_id);
            db_query('UPDATE ?:ebay_template_descriptions SET ?u WHERE template_id = ?i AND lang_code = ?s', $data, $template_id, $lang_code);
            if (isset($_REQUEST['share_objects']) && isset($_REQUEST['share_objects']['ebay_templates']) && isset($_REQUEST['share_objects']['ebay_templates'][$template_id])) {
                $_products = db_get_fields("SELECT product_id FROM ?:products WHERE company_id NOT IN (?n) AND ebay_template_id = ?i", $_REQUEST['share_objects']['ebay_templates'][$template_id], $template_id);
                if (!empty($_products)) {
                    db_query("UPDATE ?:products SET ebay_template_id = 0 WHERE product_id IN (?n)", $_products);
                }
            }
        } else {
            $data['template_id'] = $template_id = db_query("INSERT INTO ?:ebay_templates ?e", $data);
            if (isset($data['name']) && empty($data['name'])) {
                unset($data['name']);
            }
            if (!empty($data['name'])) {
                foreach (fn_get_translation_languages() as $data['lang_code'] => $_v) {
                    db_query("INSERT INTO ?:ebay_template_descriptions ?e", $data);
                }
            }
        }
        if ($data['use_as_default'] == 'Y') {
            db_query('UPDATE ?:ebay_templates SET use_as_default = ?s WHERE company_id = ?i AND NOT template_id = ?i', 'N', $template_company_id, $template_id);
        }
        if ($template_id && array_key_exists('product_ids', $data)) {
            if ($isUpdate) {
                $current_product_ids = \Ebay\Product::getTemplateProductIds($template_id);
            } else {
                $current_product_ids = array();
            }
            $data['product_ids'] = (array) $data['product_ids'];
            $add_product_ids = array_diff($data['product_ids'], $current_product_ids);
            $delete_product_ids = array_diff($current_product_ids, $data['product_ids']);
            if (!empty($add_product_ids)) {
                foreach ($add_product_ids as $product_id) {
                    \Ebay\Product::updateProductTemplateId($product_id, $template_id);
                }
            }
            if (!empty($delete_product_ids)) {
                foreach ($delete_product_ids as $product_id) {
                    \Ebay\Product::updateProductTemplateId($product_id, 0);
                }
            }
        }
    }
    return $template_id;
}