weirks2000 Posted August 7, 2014 Share Posted August 7, 2014 I'm just want to switch roles with this option on the homepage.. I'm using crosshatch. Can ayone point me in the right direction? I want our popular products to be in the mid section just like latest products is by default layout. And I want the latest products to show in the left column as text links just like popular products by are by default layout . Quote Link to comment Share on other sites More sharing options...
bsmither Posted August 7, 2014 Share Posted August 7, 2014 The initial idea was to simply exchange the product arrays of LP and PP. Easy Peasy. However, this turned out to be way more difficult than I had anticipated. The difficulty lay in the fact that the code that assembles the array of products for the Latest Products is not at all similar enough to the code that assembles the array of products for the Popular Products. The LP code is locked into the function that will display the Homepage, and the PP code fetches only what is strictly necessary for the PP box. Thus, the code in the following Code Snippet copies somewhat from the other's respective function, meaning, if CubeCart changes the way certain things are done, this Snippet will need to be updated to match. In admin, Manage Hooks, Code Snippets, click Add Snippet. In the form, enter: Enabled: Green Check Unique ID: LPxPP@CubeCart Execution Order: 50 Description: Swaps Latest Products and Popular Products Trigger: class.gui.display Version: 1.0 Author: weirks2000 PHP Code:{php} // class.gui.display $tmpSN = $GLOBALS['smarty']->getTemplateVars('SECTION_NAME'); $tmpPP = $GLOBALS['smarty']->getTemplateVars('LATEST_PRODUCTS'); $tmpLP = $GLOBALS['smarty']->getTemplateVars('POPULAR'); if( $tmpSN != 'home' ) { // If not at the Homepage, need to fetch the actual Latest Products // Cannot use the actual Cubecart->displayHomePage because of template creation $where = $GLOBALS['catalogue']->outOfStockWhere(array('status' => '1', 'featured' => '1')); $latestProducts = $GLOBALS['db']->select('CubeCart_inventory', 'product_id', $where, array('date_added' => 'DESC', 'product_id' => 'DESC'), (int)$GLOBALS['config']->get('config', 'catalogue_latest_products_count')); if ($latestProducts) { foreach( $latestProducts as $product ) { $category_data = $GLOBALS['catalogue']->getCategoryStatusByProductID($product['product_id']); $category_status = false; if( is_array($category_data) ) { foreach( $category_data as $trash => $data ) { if( $data['status'] == 1 ) $category_status = true; } } if( $category_status ) $LP2PP[] = $product['product_id']; } } if( $LP2PP ) { $tmpPP = $GLOBALS['catalogue']->getProductData($LP2PP); } } else { // At the Homepage, need to fetch the complete product data for Popular Products if( !empty($tmpLP) ) { foreach( $tmpLP as $product ) { $PP2LP[] = $product['product_id']; } $tmpLP = $GLOBALS['catalogue']->getProductData($PP2LP); foreach( $tmpLP as &$product ) { $GLOBALS['catalogue']->productAssign($product); $product['image'] = $GLOBALS['gui']->getProductImage($product['product_id'], 'small'); $product['ctrl_stock'] = (!$product['use_stock_level'] || $GLOBALS['config']->get('config', 'basket_out_of_stock_purchase') || ($product['use_stock_level'] && $GLOBALS['catalogue']->getProductStock($product['product_id'], null, true))) ? true : false; $product['url'] = $GLOBALS['seo']->buildURL('prod', $product['product_id']); } } } if( !empty($tmpPP) ) { $GLOBALS['smarty']->assign('POPULAR', $tmpPP); $content = $GLOBALS['smarty']->fetch('templates/box.popular.php'); $GLOBALS['smarty']->assign('POPULAR_PRODUCTS', $content); } if( !empty($tmpLP) && $tmpSN == 'home' ) { $GLOBALS['smarty']->assign('LATEST_PRODUCTS', $tmpLP); $content = $GLOBALS['smarty']->fetch('templates/content.homepage.php'); $GLOBALS['smarty']->assign('PAGE_CONTENT', $content); } {/php} Quote Link to comment Share on other sites More sharing options...
weirks2000 Posted August 8, 2014 Author Share Posted August 8, 2014 Wow you are good. I think it did swap it but NOW I need to swap the pp & lp text here is the website.. www.absupplies.com BTW THANKS for your help... I'm so happy.. I have spent 3 days pouring over code to try and figure out how to do this.. Quote Link to comment Share on other sites More sharing options...
bsmither Posted August 8, 2014 Share Posted August 8, 2014 "NOW I need to swap the pp & lp text!" Ah! Of course! I was going to suggest that the admin Language editor be used, but then, what happens when the Snippet is disabled??? We will need to affect the change to the template variable $LANG in the Snippet code. So, make the edit in the Snippet code as follows:At the top, add: $tmpPP_LANG = $GLOBALS['smarty']->getTemplateVars('LANG.catalogue.latest_products'); $tmpLP_LANG = $GLOBALS['smarty']->getTemplateVars('LANG.catalogue.title_popular'); Was: if( !empty($tmpPP) ) { $GLOBALS['smarty']->assign('POPULAR', $tmpPP); $content = $GLOBALS['smarty']->fetch('templates/box.popular.php'); $GLOBALS['smarty']->assign('POPULAR_PRODUCTS', $content); } if( !empty($tmpLP) && $tmpSN == 'home' ) { $GLOBALS['smarty']->assign('LATEST_PRODUCTS', $tmpLP); $content = $GLOBALS['smarty']->fetch('templates/content.homepage.php'); $GLOBALS['smarty']->assign('PAGE_CONTENT', $content); } Now: if( !empty($tmpPP) ) { $GLOBALS['smarty']->assign('LANG.catalogue.title_popular', $tmpPP_LANG); $GLOBALS['smarty']->assign('POPULAR', $tmpPP); $content = $GLOBALS['smarty']->fetch('templates/box.popular.php'); $GLOBALS['smarty']->assign('POPULAR_PRODUCTS', $content); } if( !empty($tmpLP) && $tmpSN == 'home' ) { $GLOBALS['smarty']->assign('LANG.catalogue.latest_products', $tmpLP_LANG); $GLOBALS['smarty']->assign('LATEST_PRODUCTS', $tmpLP); $content = $GLOBALS['smarty']->fetch('templates/content.homepage.php'); $GLOBALS['smarty']->assign('PAGE_CONTENT', $content); } I haven't checked these edits, so let us know if the phrases get switched around properly. Quote Link to comment Share on other sites More sharing options...
weirks2000 Posted August 8, 2014 Author Share Posted August 8, 2014 Ok I made the changes but no effect on the text.. here is the code as I edited it: {php} $tmpPP_LANG = $GLOBALS['smarty']->getTemplateVars('LANG.catalogue.latest_products'); $tmpLP_LANG = $GLOBALS['smarty']->getTemplateVars('LANG.catalogue.title_popular'); // class.gui.display $tmpSN = $GLOBALS['smarty']->getTemplateVars('SECTION_NAME'); $tmpPP = $GLOBALS['smarty']->getTemplateVars('LATEST_PRODUCTS'); $tmpLP = $GLOBALS['smarty']->getTemplateVars('POPULAR'); if( $tmpSN != 'home' ) { // If not at the Homepage, need to fetch the actual Latest Products // Cannot use the actual Cubecart->displayHomePage because of template creation $where = $GLOBALS['catalogue']->outOfStockWhere(array('status' => '1', 'featured' => '1')); $latestProducts = $GLOBALS['db']->select('CubeCart_inventory', 'product_id', $where, array('date_added' => 'DESC', 'product_id' => 'DESC'), (int)$GLOBALS['config']->get('config', 'catalogue_latest_products_count')); if ($latestProducts) { foreach( $latestProducts as $product ) { $category_data = $GLOBALS['catalogue']->getCategoryStatusByProductID($product['product_id']); $category_status = false; if( is_array($category_data) ) { foreach( $category_data as $trash => $data ) { if( $data['status'] == 1 ) $category_status = true; } } if( $category_status ) $LP2PP[] = $product['product_id']; } } if( $LP2PP ) { $tmpPP = $GLOBALS['catalogue']->getProductData($LP2PP); } } else { // At the Homepage, need to fetch the complete product data for Popular Products if( !empty($tmpLP) ) { foreach( $tmpLP as $product ) { $PP2LP[] = $product['product_id']; } $tmpLP = $GLOBALS['catalogue']->getProductData($PP2LP); foreach( $tmpLP as &$product ) { $GLOBALS['catalogue']->productAssign($product); $product['image'] = $GLOBALS['gui']->getProductImage($product['product_id'], 'small'); $product['ctrl_stock'] = (!$product['use_stock_level'] || $GLOBALS['config']->get('config', 'basket_out_of_stock_purchase') || ($product['use_stock_level'] && $GLOBALS['catalogue']->getProductStock($product['product_id'], null, true))) ? true : false; $product['url'] = $GLOBALS['seo']->buildURL('prod', $product['product_id']); } } } if( !empty($tmpPP) ) { $GLOBALS['smarty']->assign('LANG.catalogue.title_popular', $tmpPP_LANG); $GLOBALS['smarty']->assign('POPULAR', $tmpPP); $content = $GLOBALS['smarty']->fetch('templates/box.popular.php'); $GLOBALS['smarty']->assign('POPULAR_PRODUCTS', $content); } if( !empty($tmpLP) && $tmpSN == 'home' ) { $GLOBALS['smarty']->assign('LANG.catalogue.latest_products', $tmpLP_LANG); $GLOBALS['smarty']->assign('LATEST_PRODUCTS', $tmpLP); $content = $GLOBALS['smarty']->fetch('templates/content.homepage.php'); $GLOBALS['smarty']->assign('PAGE_CONTENT', $content); } Quote Link to comment Share on other sites More sharing options...
bsmither Posted August 8, 2014 Share Posted August 8, 2014 I was concerned about using the template style of array notation. Apparently, that style is only interpreted in templates, and not in PHP function arguments. So, undo the edits in post #4. Do these edits instead:Was: // class.gui.display $tmpSN = $GLOBALS['smarty']->getTemplateVars('SECTION_NAME'); $tmpPP = $GLOBALS['smarty']->getTemplateVars('LATEST_PRODUCTS'); $tmpLP = $GLOBALS['smarty']->getTemplateVars('POPULAR'); Now: // class.gui.display $tmpSN = $GLOBALS['smarty']->getTemplateVars('SECTION_NAME'); $tmpPP = $GLOBALS['smarty']->getTemplateVars('LATEST_PRODUCTS'); $tmpLP = $GLOBALS['smarty']->getTemplateVars('POPULAR'); $tmpLANG = $GLOBALS['smarty']->getTemplateVars('LANG'); $tmpPP_LANG = $tmpLANG['catalogue']['latest_products']; $tmpLP_LANG = $tmpLANG['catalogue']['title_popular']; $tmpLANG['catalogue']['title_popular'] = $tmpPP_LANG; $tmpLANG['catalogue']['latest_products'] = $tmpLP_LANG; $GLOBALS['smarty']->assign('LANG', $tmpLANG); Quote Link to comment Share on other sites More sharing options...
weirks2000 Posted August 8, 2014 Author Share Posted August 8, 2014 Awesome! Looks like that worked perfectly. Thank you so much. 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.