Ejemplo n.º 1
0
function fn_se_prepare_product_data($product_data, $usergroups, $company_id, $lang_code)
{
    $types_map = array('D' => 'int', 'M' => 'text', 'S' => 'text', 'N' => 'float', 'E' => 'text', 'C' => 'text', 'T' => 'text', 'O' => 'float');
    $entry = array('id' => array('value' => $product_data['product_id'], 'title' => __('se_product_id')), 'title' => array('value' => $product_data['product'], 'title' => __('se_title')), 'summary' => array('value' => !empty($product_data['short_description']) ? $product_data['short_description'] : $product_data['full_description'], 'title' => __('se_summary')), 'link' => array('value' => fn_url('products.view?product_id=' . $product_data['product_id'], 'C', 'http', $lang_code), 'title' => __('se_link')), 'price' => array('value' => fn_format_price($product_data['price']), 'title' => __('se_price')), 'quantity' => array('value' => $product_data['amount'], 'title' => __('se_quantity')), 'product_code' => array('value' => $product_data['product_code'], 'title' => __('se_product_code')), 'image_link' => array('title' => __('se_image_link')));
    if (!empty($product_data['main_pair'])) {
        $thumbnail = fn_image_to_display($product_data['main_pair'], SE_IMAGE_SIZE, SE_IMAGE_SIZE);
    }
    if (!empty($thumbnail['image_path'])) {
        $image_link = $thumbnail['image_path'];
    } elseif (!empty($product_data['main_pair']['detailed']['http_image_path'])) {
        $image_link = $product_data['main_pair']['detailed']['http_image_path'];
    } else {
        $image_link = '';
    }
    $entry['image_link']['value'] = htmlspecialchars($image_link);
    if (!empty($product_data['search_words'])) {
        $entry['search_words'] = array('name' => 'search_words', 'title' => __('search_words'), 'text_search' => 'Y', 'weight' => 100, 'value' => $product_data['search_words']);
    }
    if (!empty($product_data['product_features'])) {
        foreach ($product_data['product_features'] as $f) {
            $name = "f_{$f['feature_id']}";
            $entry[$name] = array('name' => $name, 'title' => $f['feature'], 'text_search' => 'Y', 'weight' => 60);
            if ($f['feature_type'] == ProductFeatures::TEXT_SELECTBOX || $f['feature_type'] == ProductFeatures::EXTENDED) {
                $entry[$name]['value'] = $f['variant'];
            } else {
                $entry[$name]['value'] = $f['value'];
            }
        }
    }
    if (!empty($product_data['short_description']) && !empty($product_data['se_full_description'])) {
        $entry['full_description'] = array('name' => 'full_description', 'title' => __('full_description'), 'text_search' => 'Y', 'weight' => 40);
        $entry['full_description']['value'] = $product_data['se_full_description'];
    }
    if (!empty($product_data['product_features']) && fn_se_get_setting('use_navigation', $company_id, DEFAULT_LANGUAGE) == 'Y') {
        foreach ($product_data['product_features'] as $f) {
            if ($f['feature_type'] == ProductFeatures::GROUP) {
                continue;
            }
            $name = "feature_{$f['feature_id']}";
            $entry[$name] = array('name' => $name, 'type' => $types_map[$f['feature_type']], 'title' => str_replace('[id]', $f['feature'], __("se_for_feature_id")));
            if ($f['feature_type'] == ProductFeatures::MULTIPLE_CHECKBOX) {
                if (!empty($f['variants']) && is_array($f['variants'])) {
                    foreach ($f['variants'] as $fv) {
                        $entry[$name]['value'][] = $fv['variant_id'];
                    }
                }
            } else {
                if ($f['feature_type'] == ProductFeatures::TEXT_SELECTBOX || $f['feature_type'] == ProductFeatures::EXTENDED) {
                    $entry[$name]['value'] = $f['variant_id'];
                } elseif ($f['feature_type'] == ProductFeatures::NUMBER_SELECTBOX) {
                    $entry[$name]['value'] = $f['variant'];
                } elseif ($f['feature_type'] == ProductFeatures::NUMBER_FIELD || $f['feature_type'] == ProductFeatures::DATE) {
                    $entry[$name]['value'] = $f['value_int'];
                } elseif ($f['feature_type'] == ProductFeatures::SINGLE_CHECKBOX) {
                    $entry[$name]['value'] = $f['value'] == 'Y' ? 'Y' : 'N';
                } else {
                    // ProductFeatures::TEXT_FIELD
                    $entry[$name]['value'] = $f['value'];
                }
            }
        }
    }
    //
    //
    //
    $entry['category_id'] = array('name' => 'category_id', 'title' => __('se_category_Id'), 'value' => array());
    foreach ($product_data['category_ids'] as $category_id) {
        $entry['category_id']['value'][] = $category_id;
    }
    //
    //
    //
    $entry['category_usergroup_ids'] = array('name' => 'category_usergroup_ids', 'title' => __('se_category_usergroup_ids'), 'value' => array());
    foreach ($product_data['category_usergroup_ids'] as $usergroup_id) {
        $entry['category_usergroup_ids']['value'][] = $usergroup_id;
    }
    //
    //
    //
    $entry['usergroup_ids'] = array('name' => 'usergroup_ids', 'title' => __('se_usergroup_ids'), 'value' => array());
    $product_data['usergroup_ids'] = empty($product_data['usergroup_ids']) ? array(0) : explode(',', $product_data['usergroup_ids']);
    foreach ($product_data['usergroup_ids'] as $usergroup_id) {
        $entry['usergroup_ids']['value'][] = $usergroup_id;
    }
    //
    //
    //
    foreach ($usergroups as $usergroup) {
        $usergroup_id = $usergroup['usergroup_id'];
        $price = !empty($product_data['se_prices'][$usergroup_id]['price']) ? $product_data['se_prices'][$usergroup_id]['price'] : $product_data['se_prices'][0]['price'];
        $name = 'price_' . intval($usergroup_id);
        $entry[$name] = array('name' => $name, 'title' => str_replace('[id]', $usergroup_id, __("se_price_for_usergroup_id")), 'type' => 'float', 'value' => $price);
    }
    //
    //
    //
    $additional_attrs = array('company_id' => 'text', 'weight' => 'float', 'popularity' => 'float', 'amount' => 'int', 'timestamp' => 'int', 'position' => 'int', 'free_shipping' => 'text', 'empty_categories' => 'text', 'status' => 'text');
    if (!empty($product_data['sales_amount'])) {
        $additional_attrs['sales_amount'] = 'int';
    }
    foreach ($additional_attrs as $name => $type) {
        if ($name == 'company_id') {
            $title = __('se_company_id');
        } elseif ($name == 'empty_categories') {
            $title = __('se_empty_categories');
        } else {
            $title = __($name);
        }
        $entry[$name] = array('name' => $name, 'title' => $title, 'type' => $type, 'value' => isset($product_data[$name]) ? $product_data[$name] : '');
    }
    return $entry;
}
Ejemplo n.º 2
0
function fn_se_add_action($action, $data = NULL, $company_id = NULL, $lang_code = NULL)
{
    if (fn_se_is_registered() == false) {
        return;
    }
    $data = array(serialize((array) $data));
    $company_id = fn_se_check_company_id($company_id);
    if ($action == 'prepare_full_import' && empty($company_id) && empty($lang_code)) {
        //Trucate queue for all
        db_query("TRUNCATE ?:se_queue");
    } elseif ($action == 'prepare_full_import' && !empty($company_id)) {
        db_query("DELETE FROM ?:se_queue WHERE company_id = ?i", $company_id);
    }
    $engines_data = fn_se_get_engines_data($company_id, $lang_code);
    foreach ($data as $d) {
        foreach ($engines_data as $engine_data) {
            if (($action == 'facet_update' || $action == 'facet_delete' || $action == 'facet_delete_all') && fn_se_get_setting('use_navigation', $engine_data['company_id'], DEFAULT_LANGUAGE) !== 'Y') {
                continue;
            }
            if ($action != 'phrase') {
                //Remove duplicate actions
                db_query("DELETE FROM ?:se_queue WHERE status = 'pending' AND action = ?s AND data = ?s AND company_id = ?i AND lang_code = ?s", $action, $d, $engine_data['company_id'], $engine_data['lang_code']);
            }
            db_query("INSERT INTO ?:se_queue ?e", array('action' => $action, 'data' => $d, 'company_id' => $engine_data['company_id'], 'lang_code' => $engine_data['lang_code']));
        }
    }
}