Jump to content

Recommended Posts

I'm updating a very customized and old oscommerce to gburton/Responsive-osCommerce. My intention is to be as non-intrusive as possible.
My client has certain categories that must not appear in category tree on navigation (the reason is difficult to summarize). Looking for the query that originate the category tree, I find this:

 

The categories tree is built from bm_categories-> execute():

$OSCOM_CategoryTree = new category_tree(); // Query to DB
[...]      
$category_tree = $OSCOM_CategoryTree->getTree(); // Build HTML

the first line execute this:

 public function __construct() {
      global $languages_id;

      static $_category_tree_data;

      if ( isset($_category_tree_data) ) {
        $this->_data = $_category_tree_data;
      } else {

        $categories_query = tep_db_query("select c.categories_id, c.parent_id, c.categories_image, cd.categories_name from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id. "' order by c.parent_id, c.sort_order, cd.categories_name");

        while ( $categories = tep_db_fetch_array($categories_query) ) {
          $this->_data[$categories['parent_id']][$categories['categories_id']] = array('name' => $categories['categories_name'],
                                                                                       'image' => $categories['categories_image']);
        }

        $_category_tree_data = $this->_data;
      }
    }

With this code, I think on different strategies, and I consult you what is better for you, or if you know anyone that I have not imagined.

 

1º) Options "a priori": Preloading the variable, overwrite de query.

[A] I can modify the core static $_category_tree_data on category_tree class, changing it to global variable. That way, I can preload it on a previous module, and take advantage of

 

if ( isset($_category_tree_data) ) {
        $this->_data = $_category_tree_data;
}

con: I modified the core.

 

I can extend the class category_tree overwriting its execute() function, and modify bm_categories to invoke mi_clase_category_tree.

con: I modified the core.

 

[C] I can make the choice and also overwrite bm_categories in order to avoid touching the core.
con: I would have to modify cache.php, because it invokes bm_categories, and maybe something else. Too moch core modifications.

 

2º) Options "a posteriori"

 

[D] I can modify the array category tree->_data once data is loaded ...

con: ...but I don't know how to avoid same cons as the previous options "a priori".

 

[E] I can modify the HTML block in $oscTemplate. This option is, to my knowledge, the least intrusive. It's my option by now, but I want to learn and best designing code techniques on oscommerce

 

 

Ok: What do you think would be best? Although you can say that "a controlled modification of the core is not a big problem," I try to avoid it whenever I can.

 

Thanks a lot for your time :)

Edited by katapofatico

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×