cw_header_location("index.php?target={$target}"); } if ($action == 'delete' && $saved_template_id) { cw_web_delete_layout($saved_template_id); $saved_template_id = 0; cw_header_location("index.php?target={$target}"); } if ($action == 'create' && $title) { $saved_template_id = cw_barcode_create_template($title); cw_header_location("index.php?target={$target}"); } if ($action == 'update' && $saved_template_id) { $data = addslashes(serialize($label_data)); cw_array2update('layouts', array('data' => $data), "layout_id='{$saved_template_id}'"); cw_header_location("index.php?target={$target}"); } if ($saved_template_id) { $product = array('eancode' => cw_product_generate_sku($config['barcode']['gen_product_code'], 'eancode'), 'display_price' => '10.00', 'display_discounted_price' => '9.00', 'list_price' => '15.00', 'supplier_code' => cw_product_generate_sku($config['barcode']['gen_product_code'], 'eancode'), 'discount' => '1.00', 'productcode' => 'Product SKU', 'sn' => cw_product_generate_sku($config['barcode']['gen_product_code'], 'eancode'), 'product' => 'Product Title'); $smarty->assign('product', $product); $template = cw_web_get_layout_by_id($saved_template_id); if ($template['layout'] != 'barcode') { $saved_template_id = 0; cw_header_location("index.php?target={$target}"); } $smarty->assign('layout_data', $template); } $smarty->assign('template_id', $saved_template_id); $smarty->assign('home_style', 'popup'); $smarty->assign('current_main_dir', 'addons'); $smarty->assign('current_section_dir', 'barcode'); $smarty->assign('main', 'popup_barcode');
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; }
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; }
$smarty->assign('main', 'product_add'); } if ($REQUEST_METHOD == "POST" && ($action == "product_modify" || $action == 'add') && (AREA_TYPE == 'A' || AREA_TYPE == 'V')) { $is_variant = false; # kornev, TOFIX if ($product_id && $addons['product_options']) { $is_variant = cw_product_has_variants($product_id); } $last_added_product_type = $product_data['product_type']; if (!$product_data['eancode'] && $addons['barcode'] && $config['barcode']['gen_product_code']) { $product_data['eancode'] = cw_product_generate_sku($config['barcode']['gen_product_code'], 'eancode'); } cw_ean_clear($product_data['eancode']); if ($mode == 'add') { if (!$product_data['productcode']) { $product_data['productcode'] = cw_product_generate_sku(); } if (!$product_data['membership_ids']) { $product_data['membership_ids'] = array_keys(unserialize($config['product_settings']['default_product_memberships'])); } } $rules = array('category_id' => '', 'product' => '', 'productcode' => array('func' => 'cw_error_sku_exists'), 'manufacturer_code' => array('func' => 'cw_error_manufacturer_code_exists')); if ($config['General']['product_descr_is_required'] == 'Y') { $rules['fulldescr'] = ''; } $product_data['product_id'] = $product_id; $product_data['attributes'] = $attributes; if ($config['Appearance']['categories_in_products'] == '0') { unset($rules['category_id']); } elseif ($config['Appearance']['categories_in_products'] == '1' && empty($product_data['category_id'])) { $product_data['category_id'] = 1;