Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Recommended Posts

Hi,  I was trying to create the module for Categories on Index based on the Subcategory box module..

Being very new to creating the code for the new edge version modules please can someone help me recode the subcategory fetch to the category fetch on index page.

I created below page but need to edit the subcategory code area to fetch main categories...

<?php
/*
  $Id$

  generated by: 
  https://oscompose.com (c)2018

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2018 osCommerce

  Released under the GNU General Public License
*/


class cm_catindex { 
  var $code;
  var $group;
  var $title;
  var $description;
  var $sort_order;
  var $enabled = false;

  function __construct() {
    $this->code = get_class($this);
    $this->group = basename(dirname(__FILE__));

    $this->title = MODULE_CONTENT_CATINDEX_TITLE;

    $this->description = MODULE_CONTENT_CATINDEX_DESCRIPTION;
    $this->description .= '<div class="secWarning">' . MODULE_CONTENT_BOOTSTRAP_ROW_DESCRIPTION . '</div>';

    if ( defined('MODULE_CONTENT_CATINDEX_STATUS') ) {
      $this->sort_order = MODULE_CONTENT_CATINDEX_SORT_ORDER;
      $this->enabled = (MODULE_CONTENT_CATINDEX_STATUS == 'True');
    }
  }

	  function execute() {
      global $oscTemplate, $current_category_id, $OSCOM_category;
      
      $content_width  = MODULE_CONTENT_CATINDEX_CONTENT_WIDTH;
      $category_width = MODULE_CONTENT_CATINDEX_CONTENT_WIDTH_EACH;
      
      $category_name  = $OSCOM_category->getData($OSCOM_category, 'name');
      $category_level = $OSCOM_category->setMaximumLevel(1);
      $category_array = $OSCOM_category->buildBranchArray($current_category_id, $category_level);

    ob_start();
    include('includes/modules/content/' . $this->group . '/templates/tpl_' . basename(__FILE__));
    $template = ob_get_clean();

    $oscTemplate->addContent($template, $this->group);
  }

  function isEnabled() {
    return $this->enabled;
  }

  function check() {
    return defined('MODULE_CONTENT_CATINDEX_STATUS');
  }

  function install() {
    tep_db_query("insert into configuration(configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable catindex Module', 'MODULE_CONTENT_CATINDEX_STATUS', 'True', 'Do you want to add catindex to your shop?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
    tep_db_query("insert into configuration(configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Content Width', 'MODULE_CONTENT_CATINDEX_CONTENT_WIDTH', '6', 'What width container should the content be shown in?', '6', '1', 'tep_cfg_select_option(array(\'12\', \'11\', \'10\', \'9\', \'8\', \'7\', \'6\', \'5\', \'4\', \'3\', \'2\', \'1\'), ', now())");
   tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Category Width', 'MODULE_CONTENT_CATINDEX_CONTENT_WIDTH_EACH', '4', 'What width container should each Category be shown in?', '6', '3', 'tep_cfg_select_option(array(\'12\', \'11\', \'10\', \'9\', \'8\', \'7\', \'6\', \'5\', \'4\', \'3\', \'2\', \'1\'), ', now())");
    tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_CONTENT_CATINDEX_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
  }

  function remove() {
    tep_db_query("delete from configuration where configuration_key in ('" . implode("', '", $this->keys()) . "')");
  }

  function keys() {
    return array('MODULE_CONTENT_CATINDEX_STATUS', 'MODULE_CONTENT_CATINDEX_CONTENT_WIDTH', 'MODULE_CONTENT_CATINDEX_SORT_ORDER');
  }

}
?>

This area needs to be edited to fetch category I really request help on getting this done please...

$category_name  = $OSCOM_category->getData($OSCOM_category, 'name');
      $category_level = $OSCOM_category->setMaximumLevel(1);
      $category_array = $OSCOM_category->buildBranchArray($current_category_id, $category_level);

 

Link to comment
Share on other sites

If I use the other route I try reformatting a old category on index with images addon for NEW FROZEN CE VERSION..

Using The module maker by Sir @wHiTeHaT

In tpl_cat_index.php  file I attach below code:-

<?php

  $info_box_contents = array();
  $info_box_contents[] = array('align' => 'left',
                               'text'  => BOX_HEADING_CATEGORIES
                              );
  new contentBoxHeading($info_box_contents);

  $row = 0;
  $col = 0;
  $width = (int)(100 / MAX_DISPLAY_CATEGORIES_PER_ROW) . '%';
  $info_box_contents = array();
 	$result = tep_db_query("SELECT * FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd WHERE c.parent_id = '0' AND c.categories_id = cd.categories_id AND cd.language_id = '" . (int)$languages_id . "' ORDER BY sort_order ");
	while($data = tep_db_fetch_array($result)){
    $info_box_contents[$row][$col] = array('align' => 'center',
                                           'params' => 'class="smallText" width="' . $width . '" valign="top"',
                                           'text' => '<a href="' . tep_href_link(FILENAME_DEFAULT, tep_get_path($data['categories_id'])) . '">' . tep_image(DIR_WS_IMAGES . $data['categories_image'], $data['categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) . '<br>' . $data['categories_name']);

    $col ++;
    if ($col == MAX_DISPLAY_CATEGORIES_PER_ROW) {
      $col = 0;
      $row ++;
    }
	}
  new contentBox($info_box_contents);
?>
<!-- main_categories_eof //-->

But then the class issue error---- arises that content Box and content BoxHeading class do not exist..

Please can someone help me in direction to what these should be changed too in new version;

THank you in advance;

Warm Regds,.

radhavallabh

 

Link to comment
Share on other sites

On 2018/7/28 at 7:56 PM, Jack_mcs said:

I am not familiar with the addon you mention but my Category Images addon may already do that.

Hi Jack,

In your add-on package includes\modules\content\index\templates\category_images.php, line 17:

<meta itemprop="numberOfItems" content="<?php echo (int)$num_category_images; ?>" />

I did not see any value assigned to $num_category_images and I looked at the HTML source "content" was always set to zero (<meta itemprop="numberOfItems" content="0" />).

Did I miss something?

Thanks, Eddy

Link to comment
Share on other sites

No, you didn't miss anything. The line should be changed to the following. Thanks for mentioning it.

<meta itemprop="numberOfItems" content="<?php echo tep_db_num_rows($categories_query); ?>" />

 

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

I’m using jack cats addon and you can control which cats are displayed if you are willing to sort them using sort order! Say you want to display only 6 cats, set them from 1-6 in category sort and then set Jacks addon to display only 6 category’s. Voila job done.

Its not perfect but does work.

 

Link to comment
Share on other sites

Thank you very much Zahid @JcMagpie for your help

I'm going to try it.
By now seen all my categories are with order 0.

If I want to put only 3 categories, would I have to order the 3 categories 1, 2 and 3 and all the others with the order 4?

Best regards

Valqui

:heart: Community Oscommerce fan :heart: You'll find the latest osC community version here.

 

Link to comment
Share on other sites

Yes set the ones you need 1-3 and set Jacks addon to show only 3.  As for the rest you should really sort them also, put your best selling product category's first! Also use the product sort addon. I never under stood why this is not part of core! Why would you let your best selling product appear at the end of a list!

I use product sort to make sure my best selling products are always at the front of each page. So sort product and sort category's. Its just like a real bricks and mortar shop you put your best product right in front of the customer. 😊  

 

Link to comment
Share on other sites

When you have few categories and products it is easy to make these changes. But if you have many it becomes more complicated since the ones with the lowest order = 0 are the ones that appear first.

So if I have 500 products, do I have to change the priority to all (for example, to 1) and leave the 10 best sellers in order 0?

BR

Valqui

:heart: Community Oscommerce fan :heart: You'll find the latest osC community version here.

 

Link to comment
Share on other sites

😁 500, try over 2000! No the hack is to keep them as they are but change the ones which are your best sellers to negative numbers so I use -20 for the best and then work down to zero. So if in a subcategory say I have 50 products but only 10 are main selling or popular I will use -20 for best down to -10 and that gives me room to add more if required. The rest that are slow can all stay at zero. Also you can group them so if two product sell the same make them both -20 etc. 

Hope that's clear.

For category's its just 0- another number.

 

Link to comment
Share on other sites

Please try the following:

- Uninstall this module.

- Open the includes/modules/content/index/cm_i_category_images.php file.

- Replace this

      $categories_query = tep_db_query ("select c.categories_id, 
                                                c.categories_image, 
                                                cd.categories_name,
                                                SUBSTRING(" . MODULE_CONTENT_CATEGORY_IMAGES_CAT_DESC_SOURCE . ", 1, " . $desc_lgth . ") as categories_description
                                         from categories_description cd left join categories c on c.categories_id = cd.categories_id 
                                         where c.parent_id = '0'                                          
                                           and cd.language_id = '" . (int)$languages_id . "' 
                                         order by " . $sort_order . "
                                         limit " . MODULE_CONTENT_CATEGORY_IMAGES_MAX_DISPLAY                                       
                                       );

with this

      $cat_str = "c.parent_id = '0'";
      if (tep_not_null(MODULE_CONTENT_CATEGORY_IMAGES_CATEGORY_IDS)) {
          $cat_str =  MODULE_CONTENT_CATEGORY_IMAGES_CATEGORY_IDS;
          $cat_str = ' c.categories_id IN (' . $cat_str . ')';
      }

     $categories_query = tep_db_query ("select c.categories_id, 
                                                c.categories_image, 
                                                cd.categories_name,
                                                SUBSTRING(" . MODULE_CONTENT_CATEGORY_IMAGES_CAT_DESC_SOURCE . ", 1, " . $desc_lgth . ") as categories_description
                                         from categories_description cd left join categories c on c.categories_id = cd.categories_id 
                                         where " . $cat_str . "                                          
                                           and cd.language_id = '" . (int)$languages_id . "' 
                                         order by " . $sort_order . "
                                         limit " . MODULE_CONTENT_CATEGORY_IMAGES_MAX_DISPLAY                                       
                                       );

- Find

tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Maximum Display', 'MODULE_CONTENT_CATEGORY_IMAGES_MAX_DISPLAY', '6', 'Maximum Number of categories that should show in this module?', '6', '3', now())");

  

add this beneath it

tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Categories To Display', 'MODULE_CONTENT_CATEGORY_IMAGES_CATEGORY_IDS', '', 'Enter a comma-separated list of the category ID\'s to be displayed. Leave blank to load by name.', '6', '3', now())");

- Replace this line

return array('MODULE_CONTENT_CATEGORY_IMAGES_STATUS', 'MODULE_CONTENT_CATEGORY_IMAGES_CONTENT_WIDTH', 'MODULE_CONTENT_CATEGORY_IMAGES_MAX_DISPLAY', 'MODULE_CONTENT_CATEGORY_IMAGES_DISPLAY_EACH', 'MODULE_CONTENT_CATEGORY_IMAGES_DISPLAY_DESCRIPTION', 'MODULE_CONTENT_CATEGORY_IMAGES_CAT_DESC_SOURCE', 'MODULE_CONTENT_CATEGORY_IMAGES_SORT_ON', 'MODULE_CONTENT_CATEGORY_IMAGES_SORT_ORDER');

with this

return array('MODULE_CONTENT_CATEGORY_IMAGES_STATUS', 'MODULE_CONTENT_CATEGORY_IMAGES_CONTENT_WIDTH', 'MODULE_CONTENT_CATEGORY_IMAGES_MAX_DISPLAY', 'MODULE_CONTENT_CATEGORY_IMAGES_CATEGORY_IDS', 'MODULE_CONTENT_CATEGORY_IMAGES_DISPLAY_EACH', 'MODULE_CONTENT_CATEGORY_IMAGES_DISPLAY_DESCRIPTION', 'MODULE_CONTENT_CATEGORY_IMAGES_CAT_DESC_SOURCE', 'MODULE_CONTENT_CATEGORY_IMAGES_SORT_ON', 'MODULE_CONTENT_CATEGORY_IMAGES_SORT_ORDER');

- Re-install the module and enter the IR's of the categories you want to display.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

14 hours ago, Jack_mcs said:

Please try the following:

- Uninstall this module.

- Open the includes/modules/content/index/cm_i_category_images.php file.

- Replace this


      $categories_query = tep_db_query ("select c.categories_id, 
                                                c.categories_image, 
                                                cd.categories_name,
                                                SUBSTRING(" . MODULE_CONTENT_CATEGORY_IMAGES_CAT_DESC_SOURCE . ", 1, " . $desc_lgth . ") as categories_description
                                         from categories_description cd left join categories c on c.categories_id = cd.categories_id 
                                         where c.parent_id = '0'                                          
                                           and cd.language_id = '" . (int)$languages_id . "' 
                                         order by " . $sort_order . "
                                         limit " . MODULE_CONTENT_CATEGORY_IMAGES_MAX_DISPLAY                                       
                                       );

with this


      $cat_str = "c.parent_id = '0'";
      if (tep_not_null(MODULE_CONTENT_CATEGORY_IMAGES_CATEGORY_IDS)) {
          $cat_str =  MODULE_CONTENT_CATEGORY_IMAGES_CATEGORY_IDS;
          $cat_str = ' c.categories_id IN (' . $cat_str . ')';
      }

     $categories_query = tep_db_query ("select c.categories_id, 
                                                c.categories_image, 
                                                cd.categories_name,
                                                SUBSTRING(" . MODULE_CONTENT_CATEGORY_IMAGES_CAT_DESC_SOURCE . ", 1, " . $desc_lgth . ") as categories_description
                                         from categories_description cd left join categories c on c.categories_id = cd.categories_id 
                                         where " . $cat_str . "                                          
                                           and cd.language_id = '" . (int)$languages_id . "' 
                                         order by " . $sort_order . "
                                         limit " . MODULE_CONTENT_CATEGORY_IMAGES_MAX_DISPLAY                                       
                                       );

- Find


tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Maximum Display', 'MODULE_CONTENT_CATEGORY_IMAGES_MAX_DISPLAY', '6', 'Maximum Number of categories that should show in this module?', '6', '3', now())");

  

add this beneath it


tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Categories To Display', 'MODULE_CONTENT_CATEGORY_IMAGES_CATEGORY_IDS', '', 'Enter a comma-separated list of the category ID\'s to be displayed. Leave blank to load by name.', '6', '3', now())");

- Replace this line


return array('MODULE_CONTENT_CATEGORY_IMAGES_STATUS', 'MODULE_CONTENT_CATEGORY_IMAGES_CONTENT_WIDTH', 'MODULE_CONTENT_CATEGORY_IMAGES_MAX_DISPLAY', 'MODULE_CONTENT_CATEGORY_IMAGES_DISPLAY_EACH', 'MODULE_CONTENT_CATEGORY_IMAGES_DISPLAY_DESCRIPTION', 'MODULE_CONTENT_CATEGORY_IMAGES_CAT_DESC_SOURCE', 'MODULE_CONTENT_CATEGORY_IMAGES_SORT_ON', 'MODULE_CONTENT_CATEGORY_IMAGES_SORT_ORDER');

with this


return array('MODULE_CONTENT_CATEGORY_IMAGES_STATUS', 'MODULE_CONTENT_CATEGORY_IMAGES_CONTENT_WIDTH', 'MODULE_CONTENT_CATEGORY_IMAGES_MAX_DISPLAY', 'MODULE_CONTENT_CATEGORY_IMAGES_CATEGORY_IDS', 'MODULE_CONTENT_CATEGORY_IMAGES_DISPLAY_EACH', 'MODULE_CONTENT_CATEGORY_IMAGES_DISPLAY_DESCRIPTION', 'MODULE_CONTENT_CATEGORY_IMAGES_CAT_DESC_SOURCE', 'MODULE_CONTENT_CATEGORY_IMAGES_SORT_ON', 'MODULE_CONTENT_CATEGORY_IMAGES_SORT_ORDER');

- Re-install the module and enter the IR's of the categories you want to display.

Hi..Awesome update.. I did this but gives below error-

1054 - Unknown column 'MODULE_CONTENT_CATEGORY_IMAGES_CATEGORY_IDS' in 'where clause'
select c.categories_id, c.categories_image, cd.categories_name, SUBSTRING(categories_description, 1, 100) as categories_description from categories_description cd left join categories c on c.categories_id = cd.categories_id where c.categories_id IN (MODULE_CONTENT_CATEGORY_IMAGES_CATEGORY_IDS)  and cd.language_id = '1' order by c.sort_order limit 6
 
Please help!!
Regds.
radhavallabh
Link to comment
Share on other sites

2 minutes ago, JcMagpie said:

You must first uninstall the addon, then make changes and then reinstall. If you make changes with out uninstalling it will not work.

I did that already.. I again reinstalled it thrice.. Yet same error :(

Link to comment
Share on other sites

8 minutes ago, JcMagpie said:

Check your editing as its working fine on my test site. https://www.justfastfood.com/

Well when I say working its install with no errors! however you will need to make all your category's and subcategory's something other than zero or they will show up on the front page. 

Yes.. The copy paste from the code here.. had input hidden extra characters, Throwing errors when I checked in phplint;

Thank you works like a charm now!!!

Many thanks to @Jack_mcs for this wonderful update to the addon.. :)

Warm Regds./

radhavallabh

Link to comment
Share on other sites

? @Stephan Gebbers  Try copying into notepad++ first as that will show any issues, then copy from notepad++ into file. Its worked fine for me, just the issue of it not showing just top level cats to sort out.

Or use the file attached its been edited and worked on my test site. Remember you must uninstall the addon first not just turn it off.

cm_i_category_images.php

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...