product virtuemart_category_id in VM 3.0.14 is missing !(AND FIX)

Started by Studio 42, April 04, 2016, 19:13:33 PM

Previous topic - Next topic

Studio 42

Hi all Dev,
Do you know why now in product, virtuemart_category_id is set to false ?
Problem is that this is needed for other modules, but now i cannot check anymore for current category because :
   $currentCatId = JFactory::getApplication()->input->getInt('virtuemart_category_id', '');
   $currentCatId = vRequest::getInt('virtuemart_category_id');
return false or 0 !
So only getLastVisitedCategoryId return the ID, but this is bad when you are outside a category !
SO please revert the code to not delete from request the category id, because it's not possible to be sure the ID is current real ID and you cannot anymore use this as condition and you can be sure category id in session is right.

Ghost

Category ID is used in URL unless "Use full category tree for product links" option is disabled.

Studio 42

#2
I don't changed the option and use full URL and not shorten urls
In all case, you need now to overide the VM product url, else you get redirected in bad category since last release.
Eg if i'm in category 2 and have multiple categories, if you don't overide it and get category id, you get redirected to first category(eg categroy 1)
This completly change the logic of a shop in last release.
So you are inside
yoursite.com/category2
In vm 3.0.14
the URL for the product is not  yoursite.com/category2/product but  yoursite.com/category1/product
SO i needed to overide the category template to  have correct linking urls.
But now inside the product the category is empty, but i need this to write product childs, but cannot get this!

This was a working code before :
$request = vRequest::getRequest('virtuemart_category_id');
if($currentCatId) $productChild->virtuemart_category_id = $currentCatId;
$url = JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id='. $productChild->virtuemart_product_id. '&virtuemart_category_id='. $productChild->virtuemart_category_id);


Studio 42

I have found the bug
in YOURISTE/components/com_virtuemart/router.php
line 1019 :
if(empty($categoryName)){
replace with
if(empty($categoryName) && empty($virtuemart_category_id)){

So if your product are directly in a category having a menu, the category ID is set corretly.
Perhaps another code is needed to use new simplified product URLS, but this is another problem

Ghost

Not sure if I understand you. With seo_full enabled I get expected category IDs and URLs.

When in example.com/category3/category11/product-name, vRequest::getInt('virtuemart_category_id') returns 11. When in example.com/category3/product-name, returns 3. What is your menu setup?

For seo_full disabled, perhaps category ID should be explicitly set directly in view.

if(in_array($last_category_id,$product->categories) && !$seo_full)
{
$product->virtuemart_category_id = $last_category_id;
vRequest::setVar('virtuemart_category_id',$last_category_id);
}

Studio 42

Thanks Ghost to try to help me, but i think the problem is the code i send.
I developped the router.php file for VM2 when i was in the core team.

For the new feature "simplified URL" i don't think it's change something, because the category is never set and don't respect any rules for the pathway, but is get from the DB and the menu ID too, but i don't use this part of code, so i dont checked more.

But for "standard" SEF urls, i think it's fixed now with this code. I tested on the website and they have set sometime 4 or 5 categories by prooduct and no longer have any trouble now.