コード例 #1
0
/**
 * Clone accessories when product cloned
 * POST hook
 * @see include/func/cw.product.php: cw_product_clone()
 * 
 */
function cw_ac_product_clone($product_id)
{
    $new_product_id = cw_get_return();
    if (!empty($new_product_id)) {
        cw_core_copy_tables('linked_products', 'product_id', $product_id, $new_product_id);
    }
    return $new_product_id;
}
コード例 #2
0
/**
 * Clone tabs when product cloned
 * POST hook
 * @see include/func/cw.product.php: cw_product_clone()
 * 
 */
function cw_pt_product_clone($product_id)
{
    global $_pt_addon_tables;
    $new_product_id = cw_get_return();
    if (!empty($new_product_id)) {
        cw_core_copy_tables($_pt_addon_tables['product'], 'product_id', $product_id, $new_product_id);
    }
    return $new_product_id;
}
コード例 #3
0
function cw_product_clone($product_id)
{
    global $addons, $customer_id, $tables;
    $tables_array = array(array('table' => 'products_images_thumb', 'key_field' => 'id'), array('table' => 'products_images_det', 'key_field' => 'id'), array('table' => 'delivery', 'key_field' => 'product_id'), array('table' => 'attributes_values', 'key_field' => 'item_id'), array('table' => 'products_lng', 'key_field' => 'product_id'), array('table' => 'products_categories', 'key_field' => 'product_id'), array('table' => 'products_memberships', 'key_field' => 'product_id'));
    $product_data = cw_query_first("SELECT * FROM {$tables['products']} WHERE product_id='{$product_id}'");
    if (!$product_data) {
        return;
    }
    $product_data['productcode'] = cw_product_generate_sku();
    $new_product_id = cw_array2insert('products', array('productcode' => $product_data['productcode'], 'product_type' => $product_data['product_type']));
    $to_update = array();
    foreach ($product_data as $field => $value) {
        if (!in_array($field, array('product_id', 'productcode', 'product_type', 'views_stats'))) {
            $to_update[] = $field;
        }
    }
    $product_data['product'] = $product_data['product'] . ' (CLONE)';
    cw_array2update('products', cw_addslashes($product_data), "product_id='{$new_product_id}'", $to_update);
    foreach ($tables_array as $k => $v) {
        $error_string .= cw_core_copy_tables($v['table'], $v['key_field'], $product_id, $new_product_id);
    }
    db_query("update {$tables['products_lng']} set product = concat(product, ' (CLONE)') where product_id='{$new_product_id}'");
    // Clone prices
    $prices = cw_query("SELECT * FROM {$tables['products_prices']} WHERE product_id = '{$product_id}' AND variant_id = '0'");
    if (!empty($prices)) {
        foreach ($prices as $v) {
            unset($v['price_id']);
            $v['product_id'] = $new_product_id;
            cw_array2insert('products_prices', $v);
        }
    }
    $prices = cw_query("select pp.* from {$tables['products_prices']} as pp where pp.product_id='{$product_id}'");
    cw_func_call('cw_product_build_flat', array('product_id' => $new_product_id));
    cw_product_update_system_info($new_product_id, $customer_id);
    //    cw_warehouse_recalculate($product_id);
    // Update products counter for categories in which product is placed
    $product_categorie = cw_query_first("SELECT category_id FROM {$tables['products_categories']} WHERE product_id = '{$product_id}'");
    cw_recalc_subcat_count($product_categorie['category_id']);
    return $new_product_id;
}
コード例 #4
0
function cw_product_options_clone($product_id)
{
    global $tables, $addons, $config;
    $new_product_id = cw_get_return();
    cw_core_copy_tables('product_options_js', 'product_id', $product_id, $new_product_id);
    $hash = array();
    $classes = cw_query("SELECT * FROM {$tables['product_options']} WHERE product_id = '{$product_id}'");
    if (!empty($classes)) {
        foreach ($classes as $v) {
            $options = cw_query("SELECT * FROM {$tables['product_options_values']} WHERE product_option_id = '{$v['product_option_id']}'");
            $old_classid = $v['product_option_id'];
            unset($v['product_option_id']);
            $v['product_id'] = $new_product_id;
            $v = cw_addslashes($v);
            $classid = cw_array2insert('product_options', $v);
            if ($options) {
                foreach ($options as $o) {
                    $old_optionid = $o['option_id'];
                    unset($o['option_id']);
                    $o['product_option_id'] = $classid;
                    $o = cw_addslashes($o);
                    $optionid = cw_array2insert('product_options_values', $o);
                    $hash[$old_optionid] = $optionid;
                    cw_core_copy_tables('product_options_values_lng', 'option_id', $old_optionid, $optionid);
                }
            }
            cw_core_copy_tables('product_options_lng', 'product_option_id', $old_classid, $classid);
        }
    }
    // Clone product option exceptions
    if (!empty($hash)) {
        $hash_ex = array();
        $exceptions = cw_query("SELECT * FROM {$tables['products_options_ex']} WHERE option_id IN ('" . implode("','", array_keys($hash)) . "')");
        if (!empty($exceptions)) {
            foreach ($exceptions as $v) {
                if (empty($hash[$v['option_id']])) {
                    continue;
                }
                $v['option_id'] = $hash[$v['option_id']];
                if (empty($hash_ex[$v['exception_id']])) {
                    $hash_ex[$v['exception_id']] = cw_query_first_cell("SELECT MAX(exception_id) FROM {$tables['product_options_ex']}") + 1;
                }
                $v['exception_id'] = $hash_ex[$v['exception_id']];
                cw_array2insert('products_options_ex', $v);
            }
        }
        unset($hash_ex);
    }
    // Clone product option variants
    $variants = db_query("SELECT * FROM {$tables['product_variants']} WHERE product_id = '{$product_id}' ORDER BY variant_id");
    if ($variants) {
        while ($v = db_fetch_array($variants)) {
            $old_variantid = $v['variant_id'];
            $v['product_id'] = $new_product_id;
            unset($v['variant_id']);
            $v['productcode'] = cw_product_generate_sku();
            if ($addons['barcode'] && $config['barcode']['gen_product_code']) {
                $v['eancode'] = cw_product_generate_sku($config['barcode']['gen_product_code'], 'eancode');
            } else {
                $v['eancode'] = cw_product_generate_sku(0, 'eancode');
            }
            //cw_ean_clear($v['eancode']);
            $v = cw_addslashes($v);
            $variantid = cw_array2insert('product_variants', $v);
            // Add Variant items
            $items = cw_query("SELECT option_id FROM {$tables['product_variant_items']} WHERE variant_id = '{$old_variantid}'");
            if (!empty($items)) {
                foreach ($items as $i) {
                    if (isset($hash[$i['option_id']])) {
                        db_query("INSERT INTO {$tables['product_variant_items']} (variant_id, option_id) VALUES ('{$variantid}', '" . $hash[$i['option_id']] . "')");
                    }
                }
            }
            // warehouse
            if ($addons['warehouse']) {
                $items = cw_query("SELECT * FROM {$tables['products_warehouses_amount']} WHERE variant_id = '{$old_variantid}' AND product_id = '{$product_id}'");
                if (!empty($items)) {
                    foreach ($items as $i) {
                        db_query("INSERT INTO {$tables['products_warehouses_amount']} (product_id, warehouse_customer_id, avail, avail_ordered, avail_sold, avail_reserved, variant_id) VALUES ('{$new_product_id}', '" . $i['warehouse_customer_id'] . "', '" . $i['avail'] . "', '" . $i['avail_ordered'] . "', '" . $i['avail_sold'] . "', '" . $i['avail_reserved'] . "', '{$variantid}')");
                    }
                }
            }
            // Add Variant prices
            $prices = cw_query("SELECT * FROM {$tables['products_prices']} WHERE variant_id = '{$old_variantid}' AND product_id = '{$product_id}'");
            if ($prices) {
                foreach ($prices as $p) {
                    unset($p['price_id']);
                    $p['variant_id'] = $variantid;
                    $p['product_id'] = $new_product_id;
                    cw_array2insert('products_prices', $p);
                }
            }
            // Add Variant thumbnails & variant images
            cw_core_copy_tables('products_images_var', 'id', $old_variantid, $variantid);
        }
        db_free_result($variants);
    }
    return $new_product_id;
}