News:

Looking for documentation? Take a look on our wiki

Main Menu

VM3 Navigation among products belonging to multiple categories

Started by capricorn, August 07, 2015, 19:11:58 PM

Previous topic - Next topic

capricorn

Hello,

I'm running VM 3.0.9 with J 3.4.3.

I've got some products which belong to several categories.

To output all "Back to: Category" links on a product details page I've done an override in:

(solution is based on http://forum.virtuemart.net/index.php?topic=105810.0)

~/templates/my_template/html/com_virtuemart/productdetails/default.php.

I removed the original code:

   <?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_idFALSE);
$categoryName vmText::_($this->product->category_name) ;
} else {
$catURL =  JRoute::_('index.php?option=com_virtuemart');
$categoryName vmText::_('COM_VIRTUEMART_SHOP_HOME') ;
}
?>

<div class="back-to-category">
    <a href="<?php echo $catURL ?>" class="product-details" title="<?php echo $categoryName ?>"><?php echo vmText::sprintf('COM_VIRTUEMART_CATEGORY_BACK_TO',$categoryName?></a>
</div>

   
And put there instead above the following code:

   <?php
$categoryModel VmModel::getModel ('category');
$categoryArray = array();
foreach ($this->product->categories as $catid) :
$categoryArray[] = $categoryModel->getCategory ($catidtrue);
endforeach;
?>


<?php
foreach ($categoryArray as $category) :
// Category Link
$caturl JRoute::'index.php?option=com_virtuemart&view=category&virtuemart_category_id=' $category->virtuemart_category_id );
echo '<div class="back-to-category"><a href="'.$caturl .'" class="product-details">'vmText::sprintf('COM_VIRTUEMART_CATEGORY_BACK_TO',$categoryName).  $category->category_name '</a>&nbsp</div>';
endforeach;
?>

   
Sorry if it looks not so good. Anyway, as a result, I have now all "back to:" categories links the product belongs to on a product details page.

But I have a navigation problem.

For example, I'm on a product details page:

/index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=31&virtuemart_category_id=68&Itemid=167

There are output 3 "Back to: category" links:

/index.php?option=com_virtuemart&view=category&virtuemart_category_id=71&Itemid=167
/index.php?option=com_virtuemart&view=category&virtuemart_category_id=69&Itemid=167
/index.php?option=com_virtuemart&view=category&virtuemart_category_id=68&Itemid=167

If I go to category ID=69 view using a link below:

/index.php?option=com_virtuemart&view=category&virtuemart_category_id=69&Itemid=167

I see, that the product link becomes:
/index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=31&virtuemart_category_id=68&Itemid=167

I.e. following the link above I come back to category ID=68, not to category ID=69, where I came from.

In the mean time I have a Notice in a log file:
"(Notice) Undefined variable: categoryName"

To cut the story short:

My navigation sequence is Category1 -> Product -> Category2, instead of Category1 -> Product -> Category1

What is strange - with some products and categories the navigation forward-back is correct.

Any ideas?

I tried also this code but with the same result.
http://forum.virtuemart.net/index.php?topic=105810.msg451312#msg451312

Thanks

Studio 42


capricorn

Hi,

I think there is a problem with the product link. I found a similar topic.https://forum.virtuemart.net/index.php?topic=125134.0

What happens - if you are on a category page, for example with ID=69, product links may give you URL like:

index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=7&virtuemart_category_id=68.

So, the question is how to obtain correct product links in sublayouts/products.php around line 112 to make them match a category ID.

Any ideas?
BRG