Jump to content

Additional Feature Request


keat

Recommended Posts

I'm toying with a test V6 site, still has a lot of work to do before it has all the features we had written for our V3 site.

One feature we had was regarding thumbnails for sub categories.

 

Images for sub categories were taken from the first product in that sub category.

It saved us a heck of a lot of work, and was only a few lines in one of the php.ini files

 

 

Link to comment
Share on other sites

Nice idea. It should hopefully be possible with a code snippet. Locate the hook location if there is one and add the PHP code in the admin control panel under "Manage Hooks" >> "Code Snippet"

Maybe the class.cubecart.display_category hook would be suitable. You can then add this code without changing the core files making upgrading a breeze as you won't need to add it back each time. ;)

Link to comment
Share on other sites

In admin, Manage Hooks, Code Snippets tab, click Add Snippet.

Enabled: Check
Unique_ID: subcat_1st_prod_img      (<<== 32 Characters max)
Execution Order: 1
Description: If subcat is to show 'noimage', then use image of subcat's first product.
Trigger: class.cubecart.display_category
Version: 1.0
Author: https://forums.cubecart.com/topic/49406-additional-feature-request/
PHP Code:
<?php
  $subcats = $GLOBALS['smarty']->getTemplateVars('SUBCATS');
  if($subcats !== false) {
    foreach($subcats as &$subcat){
      if(strpos($subcat['cat_image'],'noimage') !== false) { // using 'noimage' for this subcat, get the subcat's first product's image
        $subcat_products = $this->getCategoryProducts($subcat['cat_id'], 1, 1);
        $subcat_products_keys = array_keys($subcat_products);
        $subcat_product_image_url = $GLOBALS['gui']->getProductImage($subcat_products_keys[0], 'subcategory');
        $subcat['cat_image'] = $subcat_product_image_url;
      }
   }
}
$GLOBALS['smarty']->assign('SUBCATS', $subcats);

There may still be the case where the first product returned for the respective sub-category also uses the noimage file.

 

And if you do not make the setting, "Display empty categories", as No, empty categories won't have a list of products to get an image from.

 

Therefore, the above code could be enhanced to check for a false from getCategoryProducts().

Link to comment
Share on other sites

I added the following to the PHP box

<?php
  $subcats = $GLOBALS['smarty']->getTemplateVars('SUBCATS');
  if($subcats !== false) {
    foreach($subcats as &$subcat){
      if(strpos($subcat['cat_image'],'noimage') !== false) { // using 'noimage' for this subcat, get the subcat's first product's image
        $subcat_products = $this->getCategoryProducts($subcat['cat_id'], 1, 1);
        $subcat_products_keys = array_keys($subcat_products);
        $subcat_product_image_url = $GLOBALS['gui']->getProductImage($subcat_products_keys[0], 'subcategory');
        $subcat['cat_image'] = $subcat_product_image_url;
      }
   }
}
$GLOBALS['smarty']->assign('SUBCATS', $subcats);

and at first it didn't work, but i think that's because i edited the folder permissions after install (see my other thread)

Changing folder permissions back and it works wonderfully.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...