I modified the attributes functionality to include a status flag on each attribute: with a store that has over 400 options, 3000 option values and 20,000 product attributes it was essential to be able to simply turn off some product attributes rather than delete them only to add them back later.
To achieve this, you'll need to:
1. add a status field to the products_attributes table:
Code:
ALTER TABLE `products_attributes` ADD `attributes_status` TINYINT( 1 ) NOT NULL DEFAULT '1'
2. Make an override copy of includes/modules/attributes.php by copying it to includes/modules/YOUR_TEMPLATE/attributes.php, then edit that new file. (Note: all file edits proposed here are based on clean copies of v1.5.3 files)
At about line 25, edit
Code:
and patrib.options_id = popt.products_options_id
to be
Code:
and patrib.options_id = popt.products_options_id and patrib.attributes_status = '1'
At about line 47, edit
Code:
and patrib.options_id = popt.products_options_id
to be
Code:
and patrib.options_id = popt.products_options_id and patrib.attributes_status = '1'
At about line 82, edit
Code:
and pa.options_values_id = pov.products_options_values_id
to be
Code:
and pa.options_values_id = pov.products_options_values_id and pa.attributes_status = '1'
That's it for the catalog side, now you need to change the admin side to make it work.
3. You need to edit the file YOUR_ADMIN_FOLDER/attributes_controller.php (this is a core file and doesn't have an override capability, so be careful with upgrades in the future)
At about line 207, immediately before
add this code:
Code:
case 'set_flag_attributes_status':
if (isset($_POST['divertClickProto'])) {
$action='';
$new_flag= $db->Execute("select products_attributes_id, products_id, attributes_status from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . $_GET['products_filter'] . "' and products_attributes_id='" . $_GET['attributes_id'] . "'");
if ($new_flag->fields['attributes_status'] == '0') {
$db->Execute("update " . TABLE_PRODUCTS_ATTRIBUTES . " set attributes_status='1' where products_id='" . $_GET['products_filter'] . "' and products_attributes_id='" . $_GET['attributes_id'] . "'");
} else {
$db->Execute("update " . TABLE_PRODUCTS_ATTRIBUTES . " set attributes_status='0' where products_id='" . $_GET['products_filter'] . "' and products_attributes_id='" . $_GET['attributes_id'] . "'");
}
zen_redirect(zen_href_link(FILENAME_ATTRIBUTES_CONTROLLER, $_SESSION['page_info'] . '&products_filter=' . $_GET['products_filter'] . '¤t_category_id=' . $_GET['current_category_id']));
}
break;
At about line 1106, immediately after
Code:
<td class="smallText" align="center"><?php echo LEGEND_ATTRIBUTES_DOWNLOAD ?></td>
add a new line
Code:
<td class="smallText" align="center"><?php echo LEGEND_ATTRIBUTES_ACTIVE ?></td>
At about line 1118, immediately after
Code:
<td class="smallText" align="center"><?php echo zen_image(DIR_WS_IMAGES . 'icon_status_green.gif') . ' ' . zen_image(DIR_WS_IMAGES . 'icon_status_red.gif'); ?></td>
add a new line
{code]<td class="smallText" align="center"><?php echo zen_image(DIR_WS_IMAGES . 'icon_green_off.gif') . ' ' . zen_image(DIR_WS_IMAGES . 'icon_green_on.gif'); ?></td>[/CODE]
At about line 1634, immediately after
Code:
<td class="smallText" align="center"><?php echo ($options_set->fields["attributes_required"] == '0' ? '<a href="' . zen_href_link(FILENAME_ATTRIBUTES_CONTROLLER, 'action=set_flag_attributes_required' . '&attributes_id=' . $options_set->fields["products_attributes_id"] . (isset($_GET['option_page']) ? '&option_page=' . $_GET['option_page'] . '&' : '') . (isset($_GET['value_page']) ? '&value_page=' . $_GET['value_page'] . '&' : '') . (isset($_GET['attribute_page']) ? '&attribute_page=' . $_GET['attribute_page'] : '') . '&products_filter=' . $products_filter . '¤t_category_id=' . $current_category_id) . '" onClick="divertClick(this.href);return false;">' . zen_image(DIR_WS_IMAGES . 'icon_red_off.gif', LEGEND_ATTRIBUTES_REQUIRED) . '</a>' : '<a href="' . zen_href_link(FILENAME_ATTRIBUTES_CONTROLLER, 'action=set_flag_attributes_required' . '&attributes_id=' . $options_set->fields["products_attributes_id"] . (isset($_GET['option_page']) ? '&option_page=' . $_GET['option_page'] . '&' : '') . (isset($_GET['value_page']) ? '&value_page=' . $_GET['value_page'] . '&' : '') . (isset($_GET['attribute_page']) ? '&attribute_page=' . $_GET['attribute_page'] : '') . '&products_filter=' . $products_filter . '¤t_category_id=' . $current_category_id) . '" onClick="divertClick(this.href);return false;">' . zen_image(DIR_WS_IMAGES . 'icon_red_on.gif', LEGEND_ATTRIBUTES_REQUIRED)) . '</a>'; ?></td>
Add
Code:
<td class="smallText" align="center"><?php echo ($options_set->fields["attributes_status"] == '0' ? '<a href="' . zen_href_link(FILENAME_ATTRIBUTES_CONTROLLER, 'action=set_flag_attributes_status' . '&attributes_id=' . $options_set->fields["products_attributes_id"] . (isset($_GET['option_page']) ? '&option_page=' . $_GET['option_page'] . '&' : '') . (isset($_GET['value_page']) ? '&value_page=' . $_GET['value_page'] . '&' : '') . (isset($_GET['attribute_page']) ? '&attribute_page=' . $_GET['attribute_page'] : '') . '&products_filter=' . $products_filter . '¤t_category_id=' . $current_category_id) . '" onClick="divertClick(this.href);return false;">' . zen_image(DIR_WS_IMAGES . 'icon_green_off.gif', LEGEND_ATTRIBUTES_STATUS) . '</a>' : '<a href="' . zen_href_link(FILENAME_ATTRIBUTES_CONTROLLER, 'action=set_flag_attributes_status' . '&attributes_id=' . $options_set->fields["products_attributes_id"] . (isset($_GET['option_page']) ? '&option_page=' . $_GET['option_page'] . '&' : '') . (isset($_GET['value_page']) ? '&value_page=' . $_GET['value_page'] . '&' : '') . (isset($_GET['attribute_page']) ? '&attribute_page=' . $_GET['attribute_page'] : '') . '&products_filter=' . $products_filter . '¤t_category_id=' . $current_category_id) . '" onClick="divertClick(this.href);return false;">' . zen_image(DIR_WS_IMAGES . 'icon_green_on.gif', LEGEND_ATTRIBUTES_STATUS)) . '</a>'; ?></td>
4. If you ever use the attributes copy functions on the attributes controller page, you'll need to make sure that the new attributes_status value is also copied. To do this, you'll need to edit the function zen_copy_products_attributes in YOUR_ADMIN_FOLDER/includes/functions/general.php (again, this is a core file with no override capability)
At about line 2113, in the sql query, find
Code:
attributes_required) values (0,
and change that to
Code:
attributes_required, attributes_status) values (0,
At about line 2192, find
Code:
'" . $products_copy_from->fields['attributes_required'] . "')");
and change that to
Code:
'" . $products_copy_from->fields['attributes_required'] . "',
'" . $products_copy_from->fields['attributes_status'] . "')");
At about line 2221, find
Code:
attributes_required='" . $products_copy_from->fields['attributes_required'] . "'"
and change that to
Code:
attributes_required='" . $products_copy_from->fields['attributes_required'] . "',
attributes_status='" . $products_copy_from->fields['attributes_status'] . "'"
5. You'll need to add new language definitions for the attributes controller page: make a new file YOUR_ADMIN_FOLDER/includes/languages/english/extra_definitions/attributes_status_definitions.php
Include in that new file:
Code:
define('LEGEND_ATTRIBUTES_ACTIVE', 'Active');
define('LEGEND_ATTRIBUTES_STATUS','Status');
That should be it... but as with all custom coding, please make sure that you do this on a TEST Site first before making the changes to a live site.
Bookmarks