If this is your first visit, check our documentation. To post, register or login.
Forums / General Questions / General Questions / Master Category displays as already Ticked in the Delete Product/Links window:

Master Category displays as already Ticked in the Delete Product/Links window:

Started by rlexyd on 18 Sep 2021, 3:32 AM · Views: 481

Results 1 to 4 of 4
18 Sep 2021, 3:32 AM
#1
rlexyd avatar

rlexyd

Zen Follower

Join Date:
Nov 2006
Location:
Sydney, Australia
Posts:
507
Plugin Contributions:
0

Post #1 by rlexyd

Running a fresh install of 1.5.7c, on PHP 7.4 with Responsive Classic Template.
Just went to delete a linked product and when I click on the delete icon, the Delete Product/Links window opens up and displays the usual, however, it shows BOTH boxes as already ticked/pre-selected (The Linked categories and the Master Category).
Even though it says next to the master category..*(The** Master Category** (highlighted) is de-selected to prevent accidental deletion.) - *https://i.imgur.com/JvAzSYX.png
Any reason why the master is pre-selected where it shouldn't be and how to fix it?
I almost deleted a couple of master products as I didn't pay attention.

*Zen Cart eCommerce Solution - Putting the Dream of Owning an Online Business within reach of anyone!

18 Sep 2021, 1:53 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,152
Plugin Contributions:
56

Post #2 by lat9

rlexyd:

Running a fresh install of 1.5.7c, on PHP 7.4 with Responsive Classic Template.
Just went to delete a linked product and when I click on the delete icon, the Delete Product/Links window opens up and displays the usual, however, it shows BOTH boxes as already ticked/pre-selected (The Linked categories and the Master Category).
Even though it says next to the master category..*(The** Master Category** (highlighted) is de-selected to prevent accidental deletion.) - *https://i.imgur.com/JvAzSYX.png
Any reason why the master is pre-selected where it shouldn't be and how to fix it?
I almost deleted a couple of master products as I didn't pay attention.
I can confirm this unwanted behavior on zc157c.

18 Sep 2021, 2:01 PM
#3
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,152
Plugin Contributions:
56

Post #3 by lat9

lat9:

I can confirm this unwanted behavior on zc157c.
Present in /admin/includes/modules/delete_product.php:

<?php

/**
 * @copyright Copyright 2003-2020 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: Steve 2020 Apr 20 Modified in v1.5.7 $
 */
if (!defined('IS_ADMIN_FLAG')) {
    die('Illegal Access');
}

$product_categories_string = '';
$product_categories = zen_generate_category_path($pInfo->products_id, 'product');
if (!isset($category_path)) {
    $category_path = '';
}
[B]$preselect_master_category = true; // set to false to prevent accidental deletion[/B]
for ($i = 0, $n = count($product_categories); $i < $n; $i++) {
    $category_path = '';
    for ($j = 0, $k = count($product_categories[$i]); $j < $k; $j++) {
        $category_path .= $product_categories[$i][$j]['text'];
        if ($j + 1 < $k) {
            $category_path .= ' > ';
        }
    }
    if (count($product_categories) >= 1 && (int)zen_get_parent_category_id($pInfo->products_id) === (int)$product_categories[$i][count($product_categories[$i]) - 1]['id']) {
        $product_categories_string .= '<div class="checkbox text-danger"><label><strong>' . zen_draw_checkbox_field('product_categories[]', $product_categories[$i][count($product_categories[$i]) - 1]['id'], $preselect_master_category) . $category_path . '</strong></label></div>';
        $product_master_category_string = $category_path;
    } else {
        $product_categories_string .= '<div class="checkbox"><label>' . zen_draw_checkbox_field('product_categories[]', $product_categories[$i][count($product_categories[$i]) - 1]['id'], true) . $category_path . '</label></div>';
    }
}

I'll open a GitHub issue to suggest that the highlighted line be changed to a value of false.

GitHub issue: https://github.com/zencart/zencart/issues/4465

18 Sep 2021, 8:48 PM
#4
rlexyd avatar

rlexyd

Zen Follower

Join Date:
Nov 2006
Location:
Sydney, Australia
Posts:
507
Plugin Contributions:
0

Post #4 by rlexyd

Thank you Cindy, problem solved :D

*Zen Cart eCommerce Solution - Putting the Dream of Owning an Online Business within reach of anyone!