2.0.9 b Product Navigation problem when adding One product to many Categories

Started by John2400, August 22, 2012, 11:35:30 AM

Previous topic - Next topic

John2400

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.

ronald@aava.nl

Same problem in previous versions.
Hopefully this will be fixed soon.

vm 2.0.8E

bytelord

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
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

John2400

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.


bytelord

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
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

ivus

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

bytelord

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

Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

ivus

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

ivus

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>


bytelord

heh,

you can fix and mine also :) i use the model to bring the category name ... :) :)

btw, nice work too, thanks :)
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

Milbo

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;
}
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Milbo

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?
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

ivus

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

;)

bytelord

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.
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

Milbo

Does it work? we made today 2.0.10. Now we start with the next big release.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/