osCmax v2.5 User Manual
Results 1 to 10 of 10

hide new product button in parent category in admin

This is a discussion on hide new product button in parent category in admin within the osCmax v2 Customization/Mods forums, part of the osCmax v2.0 Forums category; does anyone know how to hide the "new product" button in admin/categories.php if you're in a parent category? I don't ...

      
  1. #1
    Member
    Join Date
    Oct 2006
    Location
    Cincinnati, ohio
    Posts
    43
    Rep Power
    0


    Default hide new product button in parent category in admin

    does anyone know how to hide the "new product" button in admin/categories.php if you're in a parent category?

    I don't want to give store admins the ability to add products in parent categories alongside other categories because it's not needed. Currently if there are products in a parent category with other categories, then only the products show up on the frontend not the sub categories as well. So forcing them to add a new category below in order to add new products only in that lowest category is best. I've never seen a shop that has a store page with both category listings and product listings at the same time, so this isn't needed.

    Let me know how I might go about doing this.

    Here's my categories.php code where the new product button is. You can see i'm trying to work it but it's not working right.


    <?php
    }
    $cPath_back = '';
    if (sizeof($cPath_array) > 0) {
    for ($i=0, $n=sizeof($cPath_array)-1; $i<$n; $i++) {
    if (empty($cPath_back)) {
    $cPath_back .= $cPath_array[$i];
    } else {
    $cPath_back .= '_' . $cPath_array[$i];
    }
    }
    }
    $cPath_back = (tep_not_null($cPath_back)) ? 'cPath=' . $cPath_back . '&' : '';

    $categories_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$current_category_id . "'");
    while ($categories = tep_db_fetch_array($categories_query)) {
    if (sizeof($cPath_array) > 0) {
    if (!$categories['parent_id'] > 0) {
    $new_prod_button = '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&action=new_product') . '">' .tep_image_button('button_new_product.gif', IMAGE_NEW_PRODUCT) . '</a>';
    }}}
    ?>
    <tr>
    <td colspan="3"><table border="0" width="100%" cellspacing="0" cellpadding="2">
    <tr>
    <td class="smallText"><?php echo TEXT_CATEGORIES . '&nbsp;' . $categories_count . '<br>' . TEXT_PRODUCTS . '&nbsp;' . $products_count; ?></td>
    <td align="right" class="smallText"><?php if (sizeof($cPath_array) > 0) echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, $cPath_back . 'cID=' . $current_category_id) . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a>&nbsp;'; if (!isset($HTTP_POST_VARS['search'])) echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&action=new_category') . '">' . tep_image_button('button_new_category.gif', IMAGE_NEW_CATEGORY) . '</a>&nbsp;'.$new_prod_button; ?>&nbsp;</td>
    </tr>
    </table></td>
    </tr>
    </table></td>
    Regards,

    Ben Wade
    www.AllWebNow.com - E-commerce Web Hosting

  2. #2
    Senior Member blackhawk's Avatar
    Join Date
    Aug 2009
    Location
    indiana
    Posts
    640
    Blog Entries
    1
    Rep Power
    27


    Default Re: hide new product button in parent category in admin

    Depending on your version of oscmax, it may be as simple as showing and hiding the button with some php code. PG and I talked about it back in the day...

    way to assign administrator?

    give it a look and see it can help

  3. #3
    Member
    Join Date
    Oct 2006
    Location
    Cincinnati, ohio
    Posts
    43
    Rep Power
    0


    Default Re: hide new product button in parent category in admin

    Thanks for the response blackhawk.

    But they need access to add a new product, just not if they are in a parent category. ie.

    - parent category 1
    no products button allowed
    -sub category 1
    product button allowed only
    Regards,

    Ben Wade
    www.AllWebNow.com - E-commerce Web Hosting

  4. #4
    Senior Member blackhawk's Avatar
    Join Date
    Aug 2009
    Location
    indiana
    Posts
    640
    Blog Entries
    1
    Rep Power
    27


    Default Re: hide new product button in parent category in admin

    ah - here is one creative idea...

    Look at your cpath variable being called in your URL. Every time you go into a deeper folder the cpath variable expands. Use that to your advantage as a conditional to determine which parent folders and sub folders your admin have access to, (in addition to the link I sent you).

  5. #5
    osCMax Development Team
    pgmarshall's Avatar
    Join Date
    Feb 2009
    Location
    London
    Posts
    2,678
    Rep Power
    49


    Default Re: hide new product button in parent category in admin

    I would have thought 5 minutes of training your admins would be the way forward. However, if you really want to achieve this then the code in index.php in the catalog folder should point you in the right direction. Basically you need to check if there are any sub folders - if there are then don't show "new product" button.

    Not sure why you would want to restrict the category button? This would only allow you to have a store 1 category deep!

    Anyway, here is the code:

    $category_depth = 'top';
    if (isset($cPath) && tep_not_null($cPath)) {
    $categories_products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'");
    $categories_products = tep_db_fetch_array($categories_products_query);
    if ($categories_products['total'] > 0) {
    $category_depth = 'products'; // display products
    } else {
    $category_parent_query = tep_db_query("select count(*) as total from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$current_category_id . "'");
    $category_parent = tep_db_fetch_array($category_parent_query);
    if ($category_parent['total'] > 0) {
    $category_depth = 'nested'; // navigate through the categories
    } else {
    $category_depth = 'products'; // category has no products, but display the 'no products' message
    }
    }
    }
    You will need to tailor to suit.

    Regards,
    pgmarshall
    _______________________________

  6. #6
    osCMax Development Team met00's Avatar
    Join Date
    Oct 2005
    Location
    wherever I happen to be at the moment
    Posts
    854
    Blog Entries
    2
    Rep Power
    26


    Default Re: hide new product button in parent category in admin

    so, let's see if I understand the logic

    if category is empty - display new product and new category buttons
    if category has a category - display new category button, hide new products button
    if category has a product - display new product button, hide new category button

    Easiest way to do that is:

    assign a class to each button (in php use variable $buttonclass-p or -c)
    Code:
    $new_prod_button = '<span class=".$buttonclass-p."><a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&action=new_product') . '">' .tep_image_button('button_new_product.gif', IMAGE_NEW_PRODUCT) . '</a></span>';
    Now before that code put in the logic (above) to set the $buttonclass-p and $buttonclass-c to new CSS classes called hidebutton and showbutton

    then add a CSS styles that hides/shows the button in admin/categories.php

    CSS. Simple. No?
    so endith the lesson
    <think>sometimes I just sit's and thinks</think>
    "Here you are with a hand full of holes, a thumb up your ass, and a big grin to pass the time of day with." - TWB

  7. #7
    Senior Member blackhawk's Avatar
    Join Date
    Aug 2009
    Location
    indiana
    Posts
    640
    Blog Entries
    1
    Rep Power
    27


    Default Re: hide new product button in parent category in admin

    love the plan met00!

  8. #8
    Member
    Join Date
    Oct 2006
    Location
    Cincinnati, ohio
    Posts
    43
    Rep Power
    0


    Default Re: hide new product button in parent category in admin

    Met00

    Yes, this is exactly what I need. But i don't know how to determine which class to load. i'm not that advanced in php.
    Regards,

    Ben Wade
    www.AllWebNow.com - E-commerce Web Hosting

  9. #9
    Senior Member blackhawk's Avatar
    Join Date
    Aug 2009
    Location
    indiana
    Posts
    640
    Blog Entries
    1
    Rep Power
    27


    Default Re: hide new product button in parent category in admin

    I think you can determine the full scope of the categories right on categories.php. You just have to find the right variables on that page and set up your conditional "around the button" like met said. Am I wrong for saying that?
    Last edited by blackhawk; 02-10-2011 at 05:06 AM.

  10. #10
    osCMax Development Team met00's Avatar
    Join Date
    Oct 2005
    Location
    wherever I happen to be at the moment
    Posts
    854
    Blog Entries
    2
    Rep Power
    26


    Default Re: hide new product button in parent category in admin

    look for

    Code:
        $categories_count = 0;
        $rows = 0;
    Since this comes first, this is where you set it to the unhidden class to both buttons

    Code:
    $buttonclass-c = "showbutton";
    $buttonclass-p = "showbutton";
    find

    Code:
          $categories_count++;
          $rows++;
    This is where you are working with categories so add

    Code:
         $buttonclass-p = "hidebutton";
    This will hide the button for products since we have categories

    find

    Code:
          $products_count++;
          $rows++;
    This means that we have products so add

    Code:
         $buttonclass-c = "hidebutton";
    That will hide the categories button

    now locate

    Code:
     <td align="right" class="smallText"><?php if (sizeof($cPath_array) > 0) echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, $cPath_back . 'cID=' . $current_category_id) . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a>&nbsp;'; if (!isset($_GET['search'])) echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&amp;action=new_category') . '">' . tep_image_button('button_new_category.gif', IMAGE_NEW_CATEGORY) . '</a>&nbsp;<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&amp;action=new_product') . '">' . tep_image_button('button_new_product.gif', IMAGE_NEW_PRODUCT) . '</a>'; ?>&nbsp;</td>
    change that to

    Code:
     <td align="right" class="smallText"><?php if (sizeof($cPath_array) > 0) echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, $cPath_back . 'cID=' . $current_category_id) . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a>&nbsp;'; if (!isset($_GET['search'])) echo '<span class=".$buttonclass-c."><a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&amp;action=new_category') . '">' . tep_image_button('button_new_category.gif', IMAGE_NEW_CATEGORY) . '</a></span>&nbsp;<span class=".$buttonclass-p."><a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&amp;action=new_product') . '">' . tep_image_button('button_new_product.gif', IMAGE_NEW_PRODUCT) . '</a></span>'; ?>&nbsp;</td>
    All that is left is to add the CSS styles to hide/unhide the spans. That can be added in your CSS (recommended) or you can use the style tags and add it in the head of the categories.php file.

    [thank you's can be made at the "Donate" button at the top of the page]
    Last edited by met00; 02-10-2011 at 08:46 AM. Reason: doneta - donate - donate
    so endith the lesson
    <think>sometimes I just sit's and thinks</think>
    "Here you are with a hand full of holes, a thumb up your ass, and a big grin to pass the time of day with." - TWB

Similar Threads

  1. Simple fast easy way to hide category
    By michael_s in forum New osCommerce Contributions
    Replies: 0
    Last Post: 06-19-2010, 11:52 PM
  2. hide the category name under the images
    By guedes in forum osCmax v2 Customization/Mods
    Replies: 3
    Last Post: 06-13-2010, 01:44 AM
  3. Hide No product Category In Category Menu
    By michael_s in forum New osCommerce Contributions
    Replies: 0
    Last Post: 07-31-2009, 12:03 AM
  4. Hide Parent Category and Display only Child or Sub Category in a DHTML menu
    By michael_s in forum New osCommerce Contributions
    Replies: 1
    Last Post: 01-15-2009, 06:45 AM
  5. Temporary hide a category
    By yulises in forum osCmax v2 Customization/Mods
    Replies: 2
    Last Post: 05-15-2008, 03:34 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •