Bug ? Feature> interesting issue.
I saw a post earlier regarding the same issue and I have tested it to see the same issue.
* If I add a product to more than one category - like Free beer - using the navigation buttons - just above the product it will always take me back to the original category.
* eg If I put Beer in the 'Healthy food' Category and it has 100s of products in that category when I navigate back I see chocolate.
* If I enter the "Unhealthy" Food Category and click on beer it has 100s of different products if I navigate back it will jump to chocolate even though it is not in that category.
Same problem in previous versions.
Hopefully this will be fixed soon.
vm 2.0.8E
hi john,
I saw that post also. I had noticed it before some days.
The thing (not a bug in IMHO) is that gives the first parent category where the product belongs too. For example the product details use $this->product->virtuemart_category_id returns the first parent category. The same thing happen in the category layout that uses $product->link for creating the product_details_button, gives the parent category link (i found it normal, if you have SEF enabled for example you have only ONE path link --> http://livesite/virtuemart/category/product, where category=master parent category).
I think is how VM and joomla working to route things ...
What is needed (if someone else need it) is the ability to give the last session-ed category (from where the user navigates to product), don't forget also if you navigate from a module link or a custom link the same thing will happen, you will go to the first category page.
PS: i think vm keep's session track of the last category, so could be used for the "return to cat" button.
Regards
Ok I'll give an example where I would not want this to happen -
In a bridal ( gift shop where I have placed only items I want people to buy for my wedding)- I would put the products in an extra category - I want people to stay in that category - jumping back and forth and only buy there. This issue would not be helpful.
John,
i had
exactly the same issue with you (for that i noticed) before some days but i didn't seat down to implemented because wasn't to "serious" for me.
The best way,IMHO, to accomplish that is exactly what i write on my previous post
QuoteWhat is needed (if someone else need it) is the ability to give the last session-ed category (from where the user navigates to product)
So, would be better as a feature or as an upgraded template feature the back_to_category_link returns the last_session-ed_category_id.
I total agree with you that the back to category should be fixed as you suggest. If the developers have the same opinion that should be implemented to work like this (gives the link to the category that user navigates from).
Regards
Hi guys,
I just read that post, but now I can't find it? I read so many posts it's all becoming a blur...
Could someone pls point me to it? I have a solution for them
Ta
hi,
i am not remember also that post ... i was thinking to ask john ... by the way i have also a solution using a session for that, like i told in my previous post, but haven't test appropriate ... if someone could.
inside default category template (category\default.php) we add around line 40 before ?> the following code:
//Save Categoryid in Session
$cat_session =& JFactory::getSession();
$cat_session->set( 'cur_browse_cat', $this->category->virtuemart_category_id);
after that inside product details (productdetails\default.php) page we change the back_to_category button code from line 78 to line 86
previous:
<?php // Back To Category Button
if ($this->product->virtuemart_category_id) {
$catURL = JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$this->product->virtuemart_category_id);
$categoryName = $this->product->category_name ;
} else {
$catURL = JRoute::_('index.php?option=com_virtuemart');
$categoryName = jtext::_('COM_VIRTUEMART_SHOP_HOME') ;
}
?>
to this:
<?php // Back To Category Button
$cat_session =& JFactory::getSession();
$last_cat=$cat_session->get( 'cur_browse_cat', 'empty');
if ($this->product->virtuemart_category_id) {
$catURL = JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$this->product->virtuemart_category_id);
$categoryName = $this->product->category_name ;
if ($last_cat != 'empty') {
$catURL = JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='. $last_cat);
$catModel = VmModel::getModel('category');
$category_new_name = $catModel->getCategory($last_cat);
$categoryName=$category_new_name->category_name;
//$cat_session->set( 'cur_browse_cat', 'empty');
}
} else {
$catURL = JRoute::_('index.php?option=com_virtuemart');
$categoryName = jtext::_('COM_VIRTUEMART_SHOP_HOME') ;
}
?>
Hope helps some people out there :)
John you can test it if you like and post back if this is actual working
Best regards
nice work bytelord,
I did mine slightly differently, but then I also noticed that the NEXT/PREVIOUS product navigation was also wrong (I refer to $this->product->neighbours).
The VirtueMartModelProducts function
public function getNeighborProducts ($product, $onlyPublished = TRUE, $max = 1) {}
still grabs the wrong category_id.
I fixed it by duplicating the function to the FE model, but you could also easily create a new function in a helper file, but regardless it seems like such a huge hack. Probably better to get it sorted in the main BE model
:P
silly me... my original hack
/components/com_virtemart/views/category/tmpl/default.php @ line 249
<div class="width70 floatright">
<h2><?php echo JHTML::link($product->link, $product->product_name); ?></h2>
CHANGE TO:
<div class="width70 floatright">
<?php
$inCategory = array_intersect($product->categories, array($this->category->virtuemart_category_id));
if (count($inCategory)>0) :
$product->link = JRoute::_ ( 'index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id='. $product->virtuemart_product_id .'&virtuemart_category_id=' . $this->category->virtuemart_category_id );
endif;
?>
<h2><?php echo JHTML::link($product->link, $product->product_name); ?></h2>
heh,
you can fix and mine also :) i use the model to bring the category name ... :) :)
btw, nice work too, thanks :)
Why you just not use shopFunctionsF::getLastVisitedCategoryId(); ? and hey, why do you not consider to change the core, if you can assume that it will be integrated.
My solution is product model line 1145
$q .= ' WHERE `virtuemart_category_id` = ' . (int)$product->virtuemart_category_id;
change to
if ($app->isSite ()) {
if (!class_exists ('shopFunctionsF')) require(JPATH_VM_SITE . DS . 'helpers' . DS . 'shopFunctionsF.php');
$q .= ' WHERE `virtuemart_category_id` = ' . shopFunctionsF::getLastVisitedCategoryId();
} else {
$q .= ' WHERE `virtuemart_category_id` = ' . (int)$product->virtuemart_category_id;
}
ah yes and what is the FE model? We dont have any models in FE. Except the cart may be considered as a model. Or what do you mean?
Quoteah yes and what is the FE model?
I made one. That's where I put all my modification codes so my site can remain hack-free... sneaky
;)
hey Milbo,
I knew i have seen somewhere that function (getLastVisitedCategoryId)..l
When implement my solution didn't have in mind change the core.
btw, would be great to implemented to the core so get applied on the next release [2.10.11?? maybe :)].
Regards.
Does it work? we made today 2.0.10. Now we start with the next big release.
didn't give a try on your solution. mine is working, is just uses a session to keep track the last category_id if you navigate from the category.
Please do :-P
heh,
may be john test it, i don't have products more than once in parent categories any more ... :)
ok, i will try it, but may be the next 2-3 days because in a few hours I'm travelling (vacation time ... at last) ;)
Hi,
Ok Milbo /team - - I can see the code - point me to exactly where this needs to go - what folder - where?
Hey john,
You can use the code i post http://forum.virtuemart.net/index.php?topic=106713.msg356430#msg356430 that only changes your override vm template, i explain how.
Milbo's suggested to edit a core file (official solution but untested):
Update: the file location: joomla_folder\administrator\components\com_virtuemart\models\product.php (i think the line is different for v209b line
1142)
QuoteWhy you just not use shopFunctionsF::getLastVisitedCategoryId(); ? and hey, why do you not consider to change the core, if you can assume that it will be integrated.
My solution is product model line 1145
$q .= ' WHERE `virtuemart_category_id` = ' . (int)$product->virtuemart_category_id;
change to
if ($app->isSite ()) {
if (!class_exists ('shopFunctionsF')) require(JPATH_VM_SITE . DS . 'helpers' . DS . 'shopFunctionsF.php');
$q .= ' WHERE `virtuemart_category_id` = ' . shopFunctionsF::getLastVisitedCategoryId();
} else {
$q .= ' WHERE `virtuemart_category_id` = ' . (int)$product->virtuemart_category_id;
}
test both if you have time :)
Works with me ....
Stefan
Hi folks, I feel a bit nervous in this gathering of eagles but I'm having trouble with this also at a development site at www.furnitureconnections.com.au With products in a number of categories, the navigation link provided as per the screenshot attached continues to throw errors. I'm confused about whether any of the discussions above are 'core' or 'hack' so I think for the moment it would be simpler to remove the navigation altogether and have users rely on the back button in their browser. I'm not sure which part of the code shows it though.
UPDATE:
In the course of jumping up and down and banging my head against a wall, I noticed that by restoring the template setting to "default joomla" that navigation works as expected. I'm still testing and will update if I find an exception but for the moment, please ignore the request outlined above. For interest's sake, I had the template set to the default template I'm using on my site, which is a Shape5 responsive template.
[attachment cleanup by admin]
Hello all.
I have implemented and tested the code supplied by Milbo and when a product is in multiple categories and you click forward and backward we are now staying within the category of products.
The only thing I can't get to work is the custom ordering.
When product are ordered in a custom order in the admin I can't get them to display in the same order in the neighbours navigation. The ordering is constantly being displayed alphabetically.
Is there some line of code that can be changed so the ordering reflects what is in the admin?
Note: the ordering in the category page is correct as per the custom admin ordering.
regards Karl