コード例 #1
0
/**
 * set product tags
 *
 * @param $tags
 * @param $product_id
 */
function cw_tags_set_product_tags($tags, $product_id)
{
    global $tables;
    if (empty($tags) || !is_numeric($product_id)) {
        return;
    }
    $old_tags = array();
    $_tags = cw_tags_get_product_tags($product_id);
    if (!empty($_tags)) {
        foreach ($_tags as $tag) {
            $old_tags[] = $tag['name'];
        }
    }
    $new_tags = cw_tags_get_diff_tags($old_tags, $tags);
    $del_tags = cw_tags_get_diff_tags($tags, $old_tags);
    if (count($new_tags)) {
        foreach ($new_tags as $tag) {
            if (!($tag_id = cw_query_first_cell("SELECT tag_id FROM {$tables['tags']} WHERE name = '{$tag}'"))) {
                $tag_id = cw_array2insert('tags', array('name' => $tag, 'product_count' => 1));
            } else {
                db_query("UPDATE {$tables['tags']} SET product_count = product_count + 1 WHERE tag_id = '{$tag_id}'");
            }
            cw_array2insert('tags_products', array('tag_id' => $tag_id, 'product_id' => $product_id));
        }
    }
    if (count($del_tags)) {
        foreach ($del_tags as $tag) {
            $tag_id = cw_query_first_cell("SELECT tag_id FROM {$tables['tags']} WHERE name = '{$tag}'");
            db_query("DELETE FROM {$tables['tags_products']} WHERE tag_id = '{$tag_id}' AND product_id = '{$product_id}'");
            db_query("UPDATE {$tables['tags']} SET product_count = product_count - 1 WHERE tag_id = '{$tag_id}'");
        }
    }
    cw_tags_clear_empty_tags();
}
コード例 #2
0
function cw_product_get($params, $return = null)
{
    extract($params);
    global $customer_id, $customer_id_type, $current_area, $cart, $current_location;
    global $current_language, $tables, $config, $addons;
    cw_load('files', 'taxes', 'tags');
    $lang = $lang ? $lang : $current_language;
    $variant_id = $variant_id ? $variant_id : 0;
    $amount = intval($amount > 0 ? $amount : 1);
    $fields = $from_tbls = $query_joins = $where = array();
    # kornev, merge standart and additional variables
    if ($return) {
        foreach ($return as $saname => $sadata) {
            if (isset(${$saname}) && is_array(${$saname}) && empty(${$saname})) {
                ${$saname} = $sadata;
            }
        }
    }
    $from_tbls[] = 'products';
    $where[] = "{$tables['products']}.product_id='{$id}'";
    # kornev
    # customer area - all of the checkings
    # pos area - not check for membership, just available for sale property
    if (in_array($current_area, array('C'))) {
        $memberships = array(0);
        if ($user_account['membership_id'] > 0) {
            $memberships[] = intval($user_account['membership_id']);
        }
        $where[] = "{$tables['products_memberships']}.membership_id IN (" . join(',', $memberships) . ")";
        $where[] = "{$tables['products_prices']}.quantity <= {$amount} and {$tables['products_prices']}.membership_id in (" . join(',', $memberships) . ")";
        if ($config['Appearance']['categories_in_products'] == '1') {
            $where[] = "{$tables['categories_memberships']}.membership_id IN (" . join(',', $memberships) . ")";
            $query_joins['products_categories'] = array('on' => "{$tables['products_categories']}.product_id = {$tables['products']}.product_id", 'pos' => '0', 'is_straight' => 1);
            $query_joins['categories'] = array('on' => "{$tables['products_categories']}.category_id = {$tables['categories']}.category_id", 'parent' => 'products_categories');
            $query_joins['categories_memberships'] = array('on' => "{$tables['categories_memberships']}.category_id = {$tables['categories']}.category_id", 'parent' => 'categories', 'is_straight' => 1);
        }
        $where[] = "{$tables['products']}.status in ('" . implode("', '", cw_core_get_required_status($current_area)) . "')";
    } elseif (in_array($current_area, array('G'))) {
        $where[] = "{$tables['products']}.product_id = {$tables['products_prices']}.product_id AND {$tables['products_prices']}.quantity <= {$amount} and {$tables['products_prices']}.membership_id in (" . join(',', $memberships) . ")";
    }
    $fields[] = "{$tables['products']}.*";
    $query_joins['products_warehouses_amount'] = array('on' => "{$tables['products']}.product_id = {$tables['products_warehouses_amount']}.product_id and {$tables['products_warehouses_amount']}.warehouse_customer_id=0 and {$tables['products_warehouses_amount']}.variant_id='{$variant_id}'");
    $in_cart = 0;
    if ($current_area == 'C' && !empty($cart) && !empty($cart['products'])) {
        foreach ($cart['products'] as $cart_item) {
            if ($cart_item['product_id'] == $id) {
                $in_cart += $cart_item['amount'];
            }
        }
    }
    $fields[] = "{$tables['products_warehouses_amount']}.avail-{$in_cart} AS avail";
    # kornev, TOFIX
    if ($addons['product_options'] && in_array($current_area, array('A', 'P'))) {
        $query_joins['product_variants'] = array('on' => "{$tables['products']}.product_id = {$tables['product_variants']}.product_id");
        $fields[] = "IF({$tables['product_variants']}.product_id IS NULL, '', 'Y') as is_variants";
    }
    /*
        if ($addons['manufacturers']) {
            $query_joins['manufacturers'] = array(
                'on' => "$tables[manufacturers].manufacturer_id = $tables[products].manufacturer_id",
            );
            $fields[] = "$tables[manufacturers].manufacturer";
        }
    */
    // statistic
    $fields[] = "{$tables['products_stats']}.views_stats";
    $fields[] = "{$tables['products_stats']}.sales_stats";
    $fields[] = "{$tables['products_stats']}.del_stats";
    $fields[] = "{$tables['products_stats']}.add_to_cart";
    $query_joins['products_stats'] = array('on' => "{$tables['products_stats']}.product_id = {$tables['products']}.product_id");
    if ($current_area == 'A' || $current_area == 'P') {
        $fields[] = "{$tables['products_prices']}.price";
        $fields[] = "{$tables['products_prices']}.list_price";
        $query_joins['products_prices'] = array('on' => "{$tables['products_prices']}.product_id={$tables['products']}.product_id AND {$tables['products_prices']}.variant_id = '{$variant_id}' and {$tables['products_prices']}.quantity <= {$amount}");
    } else {
        $query_joins['products_prices'] = array('on' => "{$tables['products_prices']}.product_id={$tables['products']}.product_id", 'is_inner' => 1);
        # kornev, find the min price and select only this record.
        $fields[] = "min({$tables['products_prices']}.price) as price";
        $fields[] = "{$tables['products_prices']}.variant_id";
        $fields[] = "min({$tables['products_prices']}.list_price) as list_price";
    }
    $fields[] = "IF({$tables['products_lng']}.product_id != '', {$tables['products_lng']}.product, {$tables['products']}.product) as product";
    $fields[] = "IF({$tables['products_lng']}.product_id != '', {$tables['products_lng']}.descr, {$tables['products']}.descr) as descr";
    $fields[] = "IF({$tables['products_lng']}.product_id != '', {$tables['products_lng']}.fulldescr, {$tables['products']}.fulldescr) as fulldescr";
    $fields[] = "IF({$tables['products_lng']}.product_id != '', {$tables['products_lng']}.features_text, {$tables['products']}.features_text) as features_text";
    $fields[] = "IF({$tables['products_lng']}.product_id != '', {$tables['products_lng']}.specifications, {$tables['products']}.specifications) as specifications";
    $query_joins['products_lng'] = array('on' => "{$tables['products_lng']}.code='{$lang}' AND {$tables['products_lng']}.product_id = {$tables['products']}.product_id");
    if (in_array($current_area, array('C', 'G', 'S'))) {
        $fields[] = "{$tables['products_flat']}.*";
        $query_joins['products_flat'] = array('on' => "{$tables['products']}.product_id = {$tables['products_flat']}.product_id");
        if ($current_area == 'C') {
            $query_joins['products_memberships'] = array('on' => "{$tables['products_memberships']}.product_id = {$tables['products']}.product_id", 'is_inner' => 1);
        }
    }
    if ($config['Appearance']['categories_in_products'] == '1') {
        $fields[] = "{$tables['products_categories']}.category_id";
        $query_joins['categories'] = array('parent' => 'products_categories', 'on' => "{$tables['categories']}.category_id = {$tables['products_categories']}.category_id");
        $query_joins['products_categories'] = array('on' => "{$tables['products_categories']}.product_id = {$tables['products']}.product_id and {$tables['products_categories']}.main=1", 'pos' => '0', 'is_straight' => 1);
    }
    $fields[] = "{$tables['products']}.product_id";
    $query = cw_db_generate_query($fields, $from_tbls, $query_joins, $where, array("{$tables['products']}.product_id"), array(), array());
    $product = cw_query_first($query);
    # Error handling
    if (!$product || $current_area == 'C' && !$product['category_id'] && $config['Appearance']['categories_in_products'] == '1') {
        return false;
    }
    $product['system'] = cw_call('cw_product_get_system_info', array($product['product_id']));
    $product['attribute_class_ids'] = cw_func_call('cw_items_attribute_classes_get', array('item_id' => $product['product_id'], 'item_type' => 'P', 'for_product_modify' => $for_product_modify));
    if ($info_type & 1) {
        $product['membership_ids'] = cw_query_key("select membership_id from {$tables['products_memberships']} where product_id = '{$product['product_id']}'");
    }
    # kornev, TOFIX
    if ($info_type & 64 && $product['variant_id'] && $addons['product_options']) {
        $tmp = cw_query_first("SELECT * FROM {$tables['product_variants']} WHERE variant_id = '{$product['variant_id']}'");
        if (!empty($tmp)) {
            cw_unset($tmp, "def");
            $product = cw_array_merge($product, $tmp);
        } else {
            cw_unset($product, 'variant_id');
        }
    }
    if ($info_type & 128) {
        cw_load('image');
        $product['image_thumb'] = cw_image_get('products_images_thumb', $id);
    }
    if ($info_type & 512) {
        $product['image_det'] = cw_image_get('products_images_det', $id);
        # kornev, TOFIX
        if (in_array($current_area, array('C', 'B')) && $product['variant_id'] && $addons['product_options']) {
            $var_image = cw_image_get('products_images_var', $id);
            if (!$var_image['is_default']) {
                $product['image_det'] = $var_image;
            }
        }
    }
    # TOFIX
    if (in_array($current_area, array('C', 'B', 'G'))) {
        if (!$addons['egoods']) {
            $product['distribution'] = '';
        }
        $product['display_price'] = $product['price'];
        if ($current_area == 'C' && $info_type & 8) {
            $_tmp_price = $product['price'];
            $product['price'] = $product['list_price'];
            cw_get_products_taxes($product, $user_account);
            $product['list_price_net'] = $product['list_price'];
            $product['list_price'] = $product['taxed_price'];
            $product['price'] = $_tmp_price;
        }
        $product['taxes'] = cw_get_products_taxes($product, $user_account, false, '', $current_area == 'G' && $user_account['usertype'] != 'R');
    }
    if (in_array($current_area, array('C', 'B'))) {
        $product['descr'] = cw_eol2br($product['descr']);
        $product['fulldescr'] = cw_eol2br($product['fulldescr']);
    }
    $product['uns_shippings'] = unserialize($product['shippings']);
    $product['tags'] = cw_tags_get_product_tags($id);
    if ($info_type & 4096 && $product['warranty_id']) {
        $wr = cw_get_warranty($product['warranty_id'], $lang);
        $product['warranties'] = $wr['body'];
    }
    // TODO: move to addon as on_product_get handler
    if ($info_type & 8192) {
        cw_load('warehouse');
        if ($addons['warehouse']) {
            if (AREA_TYPE == 'A') {
                $product['avail_ordered'] = cw_warehouse_get_avail($id, 0, 'avail_ordered');
                $product['avail_sold'] = cw_warehouse_get_avail($id, 0, 'avail_sold');
                $product['avail_reserved'] = cw_warehouse_get_avail($id, 0, 'avail_reserved');
            } elseif (AREA_TYPE == 'P') {
                $product['avail'] = cw_warehouse_get_warehouse_avail($customer_id, $id);
                $product['avail_ordered'] = cw_warehouse_get_warehouse_avail($customer_id, $id, 'avail_ordered');
            } else {
                // TOFIX:  $product['avail'] becomes different meanings when info_type & 8192 flag is raised or not
                // without flag - avail of all variants without products already in cart
                // with flag - total avail as set in admin per variant
                //                $product['avail'] = cw_warehouse_get_avail_for_customer($id, $product['variant_id']);
                //                $product['avails']= cw_warehouse_get_avails_customer($id);
                $product['avail'] = cw_warehouse_get_avail_for_customer($id, $product['variant_id']);
            }
        } else {
            $product['avails'] = cw_warehouse_get_avails_customer($id, $product['avail'] + $product['avail_ordered']);
        }
    }
    return $product;
}
コード例 #3
0
    }
}
if ($addons['wholesale_trading'] && empty($product_info['variant_id'])) {
    cw_include('addons/wholesale_trading/product.php');
}
if ($addons['recommended_products']) {
    cw_include('addons/recommended_products/recommends.php');
}
$location = array_merge($location, cw_category_get_location($cat, '', 0, 1));
if ($product_info) {
    $location[] = array($product_info['product'], '');
}
if ($config['Appearance']['categories_in_products']) {
    $product_info['category_category_url'] = cw_category_category_url($product_info['category_id']);
}
$product_info['tags'] = cw_tags_get_product_tags($product_id);
// Supplier delivery time
if ($product_info['system']['supplier_customer_id']) {
    $supplier_fields = cw_user_get_custom_fields($product_info['system']['supplier_customer_id'], 0, '', 'field');
    if ($supplier_fields['min_delivery_time'] == $supplier_fields['max_delivery_time']) {
        $product_info['supplier']['delivery_time'] = $supplier_fields['min_delivery_time'];
    } else {
        $product_info['supplier']['delivery_time'] = $supplier_fields['min_delivery_time'] . '-' . $supplier_fields['max_delivery_time'];
    }
    unset($supplier_fields);
}
$smarty->assign('product', $product_info);
// TODO: move to addon
if ($addons['faq']) {
    cw_load('faq');
    $smarty->assign('faq', cw_faq_get_product_faq($product_id));