Copy Categories 1.6 Support Thread. For Zencart 1.5.x
What is "Copy Categories"?
Copy Categories is exactly what its name says, Zen Cart's default category management does not have a "Category Copy Option". Now there is.
This allows the store owner or managers to copy categories to where needed. If a store owner has thousands of categories or sub categories then it can be very time consuming to move or type in new ones one by one. With "Copy Categories" this terminates the the manual moving or creating new categories.
File Edits Required: BACKUP FIRST
YOUR_ADMIN/categories.php
YOUR_ADMIN/includes/modules/category_product_listing.php
YOUR_ADMIN_includes/languages/english.php (Forgot To Add language Instructions in contribution. Once approved I will update the contribution and instructions)
Down Load Link:
Currently Under Review
In the mean time:
Edit /YOUR_ADMIN/categories.php (Fresh Unedited Copy)
Find:
Add Directly Before With:Code:case 'move_category_confirm':
At the end of the categories.php file add the following right afterCode:case 'copy_category_confirm':
if (isset($_POST['categories_id']) && ($_POST['categories_id'] != $_POST['copy_to_category_id'])) {
$categories_id = zen_db_prepare_input($_POST['categories_id']);
$new_parent_id = zen_db_prepare_input($_POST['copy_to_category_id']);
_copy_categories_tree($categories_id, $new_parent_id);
zen_redirect(zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $new_parent_id));
} else {
$messageStack->add_session(ERROR_CANNOT_COPY_CATEGORY_TO_CATEGORY_SELF . $cPath, 'error');
zen_redirect(zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath));
}
break;
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
Then edit YOUR_ADMIN/includes/modules/category_product_listing.phpCode:<?php
/**
* The function recursively copies the given category and its descriptions in all languages
* @param $categories_id category to copy
* @param $new_parent_id destination category (it will be parent category)
*
*/
function _copy_categories_tree($categories_id, $new_parent_id){
global $db;
$db->Execute(" INSERT INTO ".TABLE_CATEGORIES." (categories_image, parent_id, sort_order, date_added, last_modified, categories_status)
SELECT categories_image, '{$new_parent_id}' AS parent_id, sort_order, NOW() AS date_added, NOW() AS last_modified, categories_status FROM ".TABLE_CATEGORIES." WHERE categories_id = '{$categories_id}'
");
$copy_id = zen_db_insert_id();
$db->Execute(" INSERT INTO ".TABLE_CATEGORIES_DESCRIPTION." (categories_id, language_id, categories_name, categories_description)
SELECT '{$copy_id}' AS categories_id, language_id, categories_name, categories_description FROM ".TABLE_CATEGORIES_DESCRIPTION." WHERE categories_id = '{$categories_id}'
");
$childs = $db->Execute("SELECT categories_id FROM ".TABLE_CATEGORIES." WHERE parent_id = '{$categories_id}'");
$childids = array();
while(!$childs->EOF){
$childids[] = $childs->fields['categories_id'];
$childs->MoveNext();
}
foreach($childids as $child){
_copy_categories_tree($child, $copy_id);
}
}
?>
Find:
Directly Below Add:Code:<?php echo '<a href="' . zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $categories->fields['categories_id'] . '&action=move_category') . '">' . zen_image(DIR_WS_IMAGES . 'icon_move.gif', ICON_MOVE) . '</a>'; ?>
Language Files: (Forgot To Add langauge Instructions in contribution. Once approved I will update the contribution and instructions)Code:<?php echo '<a href="' . zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $categories->fields['categories_id'] . '&action=copy_category') . '">' . zen_image(DIR_WS_IMAGES . 'icon_copy_to.gif', ICON_COPY_TO) . '</a>'; ?>
Edit YOUR_ADMIN/includes/languages/english.php
Find:
Directly Below Add:Code:define('TEXT_NOEMAIL', 'No Email');
Once completed log into your Shop Admin go to Catalog => Categories / Products, to your right beside the "Move" icon there should be a copy icon beside it.Code:define('TEXT_COPY', 'Copy Category To:');
Enjoy!!
Like to donate to this do so by going here http://www.zen-cart.com/content.php?6-donate