_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
With a bit of homework I've managed to sort this myself, there was already some things in this forum that I had overlooked. Here is my full 'copy_to_confirm.php' file that I hope people might find interesting, please note though, there are a lot of extra fields, I have modified www.katiesgiftshop.co.uk quite a lot!
<?php
/**
* @package admin
* @copyright Copyright 2003-2009 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: copy_to_confirm.php 14139 2009-08-10 13:46:02Z wilt $
*/
if (!defined('IS_ADMIN_FLAG')) {
die('Illegal Access');
}
if (isset($_POST['products_id']) && isset($_POST['categories_id'])) {
$products_id = zen_db_prepare_input($_POST['products_id']);
$categories_id = zen_db_prepare_input($_POST['categories_id']);
// Copy attributes to duplicate product
$products_id_from=$products_id;
if ($_POST['copy_as'] == 'link') {
if ($categories_id != $current_category_id) {
$check = $db->Execute("select count(*) as total
from " . TABLE_PRODUCTS_TO_CATEGORIES . "
where products_id = '" . (int)$products_id . "'
and categories_id = '" . (int)$categories_id . "'");
if ($check->fields['total'] < '1') {
$db->Execute("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . "
(products_id, categories_id)
values ('" . (int)$products_id . "', '" . (int)$categories_id . "')");
}
} else {
$messageStack->add_session(ERROR_CANNOT_LINK_TO_SAME_CATEGORY, 'error');
}
/*Removed 27/09/2011 as part of RRP mod
} elseif ($_POST['copy_as'] == 'duplicate') {
$old_products_id = (int)$products_id;
$product = $db->Execute("select products_type, products_quantity, products_model, products_image,
products_price, products_virtual, products_date_available, products_weight,
products_tax_class_id, manufacturers_id,
products_quantity_order_min, products_quantity_order_units, products_priced_by_attribute,
product_is_free, product_is_call, products_quantity_mixed,
product_is_always_free_shipping, products_qty_box_status, products_quantity_order_max, products_sort_order,
products_price_sorter, master_categories_id
from " . TABLE_PRODUCTS . "
where products_id = '" . (int)$products_id . "'");
*/
/* Removed and replaced as part of google category addition
} elseif ($_POST['copy_as'] == 'duplicate') {
$old_products_id = (int)$products_id;
$product = $db->Execute("select products_type, products_quantity, products_model, products_image,
products_price, products_msrp, products_virtual, products_date_available, products_weight,
products_tax_class_id, manufacturers_id,
products_quantity_order_min, products_quantity_order_units, products_priced_by_attribute,
product_is_free, product_is_call, products_quantity_mixed,
product_is_always_free_shipping, products_qty_box_status, products_quantity_order_max, products_sort_order,
products_price_sorter, master_categories_id
from " . TABLE_PRODUCTS . "
where products_id = '" . (int)$products_id . "'");
*/
} elseif ($_POST['copy_as'] == 'duplicate') {
$old_products_id = (int)$products_id;
$product = $db->Execute("select p.products_type, p.products_quantity, p.products_model, p.products_image,
p.products_price, p.products_msrp, p.products_virtual, p.products_date_available, p.products_weight,
p.products_tax_class_id, p.manufacturers_id,
p.products_quantity_order_min, p.products_quantity_order_units, p.products_priced_by_attribute,
p.product_is_free, p.product_is_call, p.products_quantity_mixed,
p.product_is_always_free_shipping, p.products_qty_box_status, p.products_quantity_order_max, p.products_sort_order,
p.products_price_sorter, p.master_categories_id, pdex.google_category
from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_ADDITIONAL_DETAILS . " pdex
where p.products_id = '" . (int)$products_id . "'
and pdex.products_id = '" . (int)$products_id . "'");
$tmp_value = zen_db_input($product->fields['products_quantity']);
$products_quantity = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
$tmp_value = zen_db_input($product->fields['products_price']);
$products_price = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
$tmp_value = zen_db_input($product->fields['products_weight']);
$products_weight = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
$db->Execute("insert into " . TABLE_PRODUCTS . "
(products_type, products_quantity, products_model, products_image, products_price, products_msrp,
products_virtual, products_date_added, products_date_available,
products_weight, products_status, products_tax_class_id,
manufacturers_id,
products_quantity_order_min, products_quantity_order_units, products_priced_by_attribute,
product_is_free, product_is_call, products_quantity_mixed,
product_is_always_free_shipping, products_qty_box_status, products_quantity_order_max, products_sort_order,
products_price_sorter, master_categories_id
)
values ('" . zen_db_input($product->fields['products_type']) . "',
'" . $products_quantity . "',
'" . zen_db_input($product->fields['products_model']) . "',
'" . zen_db_input($product->fields['products_image']) . "',
'" . $products_price . "',
'" . zen_db_input($product->fields['products_msrp']) . "',
'" . zen_db_input($product->fields['products_virtual']) . "',
now(),
'" . (zen_not_null(zen_db_input($product->fields['products_date_available'])) ? zen_db_input($product->fields['products_date_available']) : '0001-01-01 00:00:00') . "',
'" . $products_weight . "', '0',
'" . (int)$product->fields['products_tax_class_id'] . "',
'" . (int)$product->fields['manufacturers_id'] . "',
'" . zen_db_input($product->fields['products_quantity_order_min']) . "',
'" . zen_db_input($product->fields['products_quantity_order_units']) . "',
'" . zen_db_input($product->fields['products_priced_by_attribute']) . "',
'" . (int)$product->fields['product_is_free'] . "',
'" . (int)$product->fields['product_is_call'] . "',
'" . (int)$product->fields['products_quantity_mixed'] . "',
'" . zen_db_input($product->fields['product_is_always_free_shipping']) . "',
'" . zen_db_input($product->fields['products_qty_box_status']) . "',
'" . zen_db_input($product->fields['products_quantity_order_max']) . "',
'" . zen_db_input($product->fields['products_sort_order']) . "',
'" . zen_db_input($product->fields['products_price_sorter']) . "',
'" . zen_db_input($categories_id) .
"')");
$dup_products_id = $db->Insert_ID();
// added fields////////
$db->Execute("insert into " . TABLE_PRODUCTS_ADDITIONAL_DETAILS. "
(products_id, google_category )
values ('" . (int)$dup_products_id ."', '" . zen_db_input($product->fields['google_category']) . "' )");
// added fields////////
$description = $db->Execute("select language_id, products_name, products_description,
products_url
from " . TABLE_PRODUCTS_DESCRIPTION . "
where products_id = '" . (int)$products_id . "'");
while (!$description->EOF) {
$db->Execute("insert into " . TABLE_PRODUCTS_DESCRIPTION . "
(products_id, language_id, products_name, products_description,
products_url, products_viewed)
values ('" . (int)$dup_products_id . "',
'" . (int)$description->fields['language_id'] . "',
'" . zen_db_input($description->fields['products_name']) . "',
'" . zen_db_input($description->fields['products_description']) . "',
'" . zen_db_input($description->fields['products_url']) . "', '0')");
$description->MoveNext();
}
$db->Execute("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . "
(products_id, categories_id)
values ('" . (int)$dup_products_id . "', '" . (int)$categories_id . "')");
$products_id = $dup_products_id;
$description->MoveNext();
// FIX HERE
/////////////////////////////////////////////////////////////////////////////////////////////
// Copy attributes to duplicate product
// moved above $products_id_from=zen_db_input($products_id);
$products_id_to= $dup_products_id;
$products_id = $dup_products_id;
if ( $_POST['copy_attributes']=='copy_attributes_yes' and $_POST['copy_as'] == 'duplicate' ) {
// $products_id_to= $copy_to_products_id;
// $products_id_from = $pID;
// $copy_attributes_delete_first='1';
// $copy_attributes_duplicates_skipped='1';
// $copy_attributes_duplicates_overwrite='0';
if (DOWNLOAD_ENABLED == 'true') {
$copy_attributes_include_downloads='1';
$copy_attributes_include_filename='1';
} else {
$copy_attributes_include_downloads='0';
$copy_attributes_include_filename='0';
}
zen_copy_products_attributes($products_id_from, $products_id_to);
}
// EOF: Attributes Copy on non-linked
/////////////////////////////////////////////////////////////////////
// copy product discounts to duplicate
if ($_POST['copy_discounts'] == 'copy_discounts_yes') {
zen_copy_discounts_to_product($old_products_id, (int)$dup_products_id);
}
// BEGIN CEON URI MAPPING 1 of 1
// Generate new URI mapping for this new product?
$uri_mapping_autogen = (($_POST['uri_mapping'] == 'autogen') ? true : false);
// Copy existing URIs from product being copied?
$uri_mapping_copy = (($_POST['uri_mapping'] == 'copy') ? true : false);
if ($uri_mapping_autogen || $uri_mapping_copy) {
if ($uri_mapping_copy) {
// Lookup and copy any URI mappings for the product be copied from
$existing_product_uri_mappings = array();
$existing_product_uri_mappings_sql = "
SELECT
language_id,
uri
FROM
" . TABLE_CEON_URI_MAPPINGS . "
WHERE
main_page = '" . zen_db_input($zc_products->get_handler($product->fields['products_type'])) . "_info'
AND
associated_db_id = '" . (int) $products_id_from . "'
AND
current_uri = '1';";
$existing_product_uri_mappings_result =
$db->Execute($existing_product_uri_mappings_sql);
while (!$existing_product_uri_mappings_result->EOF) {
$existing_product_uri_mappings[
$existing_product_uri_mappings_result->fields['language_id']] =
$existing_product_uri_mappings_result->fields['uri'];
$existing_product_uri_mappings_result->MoveNext();
}
}
// Now insert the URI mappings for the new product into the database
$languages = zen_get_languages();
for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
$uri_mapping = '';
$unique_id_to_add = '';
// Auto-generate the URI if requested
if ($uri_mapping_autogen) {
$uri_mapping = ceon_uri_mapping_autogen_category_or_product_uri(
$products_id_to, 'product', null, null, $languages[$i]['code'],
$languages[$i]['id']);
} else {
// Copy any URI mappings for the product be copied from, changing them slightly so
// they are unique (in case admin user forgets to change the URI for the "new"
// product)
if (isset($existing_product_uri_mappings[$languages[$i]['id']])) {
$uri_mapping = $existing_product_uri_mappings[$languages[$i]['id']];
if (strlen($uri_mapping) > 1) {
$unique_id_to_add = '/' . $products_id_to;
}
}
}
if (strlen($uri_mapping) > 1) {
// Make sure URI mapping is relative to root of site and does not have more than
// one trailing slash or any illegal characters
$uri_mapping = ceon_uri_mapping_cleanup_uri_mapping($uri_mapping);
}
if ($uri_mapping != '') {
// URI mapping does not yet exist
$sql_data_array = array(
'uri' => zen_db_prepare_input($uri_mapping . $unique_id_to_add),
'date_added' => date('Y-m-d H:i:s')
);
$insert_sql_data = array(
'main_page' => $zc_products->get_handler($product->fields['products_type']) .
'_info',
'associated_db_id' => (int) $products_id_to,
'language_id' => (int) $languages[$i]['id'],
'current_uri' => 1
);
$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
zen_db_perform(TABLE_CEON_URI_MAPPINGS, $sql_data_array);
// Now add the URI mappings for the review pages/tell-a-friend page for this
// product
if (substr($uri_mapping, -1) != '/') {
$uri_mapping .= '/';
}
$sql_data_array['uri'] = zen_db_prepare_input($uri_mapping .
CEON_URI_MAPPING_URI_PART_PRODUCT_REVIEWS . $unique_id_to_add);
$sql_data_array['main_page'] = zen_db_prepare_input(FILENAME_PRODUCT_REVIEWS);
zen_db_perform(TABLE_CEON_URI_MAPPINGS, $sql_data_array);
$sql_data_array['uri'] = zen_db_prepare_input($uri_mapping .
CEON_URI_MAPPING_URI_PART_PRODUCT_REVIEWS_INFO . $unique_id_to_add);
$sql_data_array['main_page'] =
zen_db_prepare_input(FILENAME_PRODUCT_REVIEWS_INFO);
zen_db_perform(TABLE_CEON_URI_MAPPINGS, $sql_data_array);
$sql_data_array['uri'] = zen_db_prepare_input($uri_mapping .
CEON_URI_MAPPING_URI_PART_PRODUCT_REVIEWS_WRITE . $unique_id_to_add);
$sql_data_array['main_page'] =
zen_db_prepare_input(FILENAME_PRODUCT_REVIEWS_WRITE);
zen_db_perform(TABLE_CEON_URI_MAPPINGS, $sql_data_array);
$sql_data_array['uri'] = zen_db_prepare_input($uri_mapping .
CEON_URI_MAPPING_URI_PART_TELL_A_FRIEND . $unique_id_to_add);
$sql_data_array['main_page'] =
zen_db_prepare_input(FILENAME_TELL_A_FRIEND);
zen_db_perform(TABLE_CEON_URI_MAPPINGS, $sql_data_array);
}
}
}
// END CEON URI MAPPING 1 of 1
}
// reset products_price_sorter for searches etc.
zen_update_products_price_sorter($products_id);
}
zen_redirect(zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $categories_id . '&pID=' . $products_id . (isset($_GET['page']) ? '&page=' . $_GET['page'] : '')));



Reply With Quote
