News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Category of featured, latest, random, topten, recent and discounted Products

Started by anisimow, October 06, 2013, 17:20:57 PM

Previous topic - Next topic

anisimow

In my work I've met some problem to display instead of just category, to show category  of featured, latest, random, topten, recent or even discounted Products. So
I've created some simple and free hack to display it.
1. in components/com_virtuemart/views/category/tmpl/default.xml line17
after
<fields name="request">
<fieldset name="request"
addfieldpath="/administrator/components/com_virtuemart/models/fields">
<field name="virtuemart_category_id" type="category"
label="COM_VIRTUEMART_CATEGORY_FIELD_SELECT_TITLE" required="true"
description="COM_VIRTUEMART_CATEGORY_FIELD_SELECT_TITLE_DESC" />   
                </fieldset>             
</fields>

add

        <fields name="params">
                <fieldset name="basic">

                        <field name="product_group" type="list" default=""
                                label="product_type"
                                description="product type">
                        <option value="none">COM_VIRTUEMART_NO</option>
                        <option value="featured">COM_VIRTUEMART_FEATURED_PRODUCT</option>
                        <option value="latest">latest</option>
                        <option value="random">random</option>
                        <option value="topten">topten</option>
                        <option value="discounted">discounted</option>
                        </field> 
                </fieldset>
         
</fields>

and now in your menu you can chose filter method to category. You can leave  it uncategorized to show from all categories.
2. in components/com_virtuemart/views/category/view.html.php line
instead of

// Load the products in the given category
$ids = $productModel->sortSearchListQuery (TRUE, $categoryId);

replace width

                    jimport( 'joomla.html.parameter' );
                    $application = JFactory::getApplication();
                    $menu = $application->getMenu();
                    $activeMenuItem = $menu->getActive();
                    $activeMenuParams = new JParameter($activeMenuItem->params);
                    $group = $activeMenuParams->get('product_group');
                    if ($group == 'none') $group = false;
                    if ($group!=='none' && !empty($group)) $category->category_name = $title;
                    $ids = $productModel->sortSearchListQuery (TRUE, $categoryId,$group);


3. This step you must do if you want that works discounted Products. It will work if discount assigned only to product. Not for global such like category, user, manufacturer. There must bee additional conditionals. In common cases its enough.
in administrator/components/com_virtuemart/models/product.php
instead of

switch ($group) {
case 'featured':
$where[] = 'p.`product_special`="1" ';
$orderBy = 'ORDER BY RAND()';
break;
case 'latest':
$date = JFactory::getDate (time () - (60 * 60 * 24 * $latest_products_days));
$dateSql = $date->toMySQL ();
$where[] = 'p.`' . $latest_products_orderBy . '` > "' . $dateSql . '" ';
$orderBy = 'ORDER BY p.`' . $latest_products_orderBy . '`';
$this->filter_order_Dir = 'DESC';
break;
case 'random':
$orderBy = ' ORDER BY RAND() '; //LIMIT 0, '.(int)$nbrReturnProducts ; //TODO set limit LIMIT 0, '.(int)$nbrReturnProducts;
break;
case 'topten';
$orderBy = ' ORDER BY p.`product_sales` '; //LIMIT 0, '.(int)$nbrReturnProducts;  //TODO set limitLIMIT 0, '.(int)$nbrReturnProducts;
$where[] = 'pp.`product_price`>"0.0" ';
$this->filter_order_Dir = 'DESC';
break;
case 'recent';
$rSession = JFactory::getSession();
$rIds = $rSession->get('vmlastvisitedproductids', array(), 'vm'); // get recent viewed from browser session
return $rIds;
}

replace width,

switch ($group) {
case 'featured':
$where[] = 'p.`product_special`="1" ';
$orderBy = 'ORDER BY RAND()';
break;
case 'latest':
$date = JFactory::getDate (time () - (60 * 60 * 24 * $latest_products_days));
$dateSql = $date->toMySQL ();
$where[] = 'p.`' . $latest_products_orderBy . '` > "' . $dateSql . '" ';
$orderBy = 'ORDER BY p.`' . $latest_products_orderBy . '`';
$this->filter_order_Dir = 'DESC';
break;
case 'random':
$orderBy = ' ORDER BY RAND() '; //LIMIT 0, '.(int)$nbrReturnProducts ; //TODO set limit LIMIT 0, '.(int)$nbrReturnProducts;
break;
case 'topten';
$orderBy = ' ORDER BY p.`product_sales` '; //LIMIT 0, '.(int)$nbrReturnProducts;  //TODO set limitLIMIT 0, '.(int)$nbrReturnProducts;
$where[] = 'pp.`product_price`>"0.0" ';
$this->filter_order_Dir = 'DESC';
break;
                                        case 'discounted':
$where[] = 'pp.`override`!="0" OR pp.`product_discount_id` != "0"';
$orderBy = 'ORDER BY RAND()';
break;
case 'recent';
$rSession = JFactory::getSession();
$rIds = $rSession->get('vmlastvisitedproductids', array(), 'vm'); // get recent viewed from browser session
return $rIds;
}
, or just in case add our custom case discounted
break;
                                        case 'discounted':
$where[] = 'pp.`override`!="0" OR pp.`product_discount_id` != "0"';
$orderBy = 'ORDER BY RAND()';

Good luck in use it. Virtuemart is the best.

dav3sh

Thank for sharing. I 'd like to have the ability to set a 'random' order in the products category display page. I tried your hack but it seems to be useless..I don't get any new feature.. maybe i used it in the wrong way or i didn't get the exact meaning of that. So if anybody knows how to get a random order products inside the category page please share it..thank you anyway

I'am using joomla 3.4.5 and VM 3.0.10

Spirz

Thank for share. But I have some problems. My param - VM 2.6.0, Joomla 2.5.28
So, when I create in menu manager category like this, I have problem with a link product. For example, I create 2 menu category to same category in virtuemart with alias1 and alias2:
1. http://site.com/shop/cat/alias1/ - main category
2. http://site.com/shop/cat/alias2/
But after that link of product in category alias1 have a link of alias2. But I need links to products by 1 main category - that alias1. So whats is wrong? please help(( and sorry for my English))


Milbo

Spirz, the whole post got useless, because vm3.0.18 has this onboard and the whole thing atm in heavy development for vm3.0.18.1 (the idea is that we dont need any frontpage, and work only with category views, which gives a lot more flexibility).
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/