keat Posted March 11, 2015 Share Posted March 11, 2015 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 Quote Link to comment Share on other sites More sharing options...
Al Brookbanks Posted March 11, 2015 Share Posted March 11, 2015 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. ;) Quote Link to comment Share on other sites More sharing options...
bsmither Posted March 12, 2015 Share Posted March 12, 2015 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(). Quote Link to comment Share on other sites More sharing options...
Al Brookbanks Posted March 12, 2015 Share Posted March 12, 2015 Excellent! Quote Link to comment Share on other sites More sharing options...
keat Posted March 12, 2015 Author Share Posted March 12, 2015 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. Quote Link to comment Share on other sites More sharing options...
bsmither Posted March 12, 2015 Share Posted March 12, 2015 Folder permissions: CubeCart will want to save a copy of the PHP code as a file named snippet.hash.php in the /includes/extra/ folder. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.