News:

Looking for documentation? Take a look on our wiki

Main Menu

Virtuemart Product detail navigation looping

Started by andrai2, July 14, 2024, 20:21:55 PM

Previous topic - Next topic

andrai2

Hello!

Joomla 4.2.7
Virtuemart 4.0.12 10777
PHP 8.0.27
Show the product navigation: is on

The problem is that "Product detail navigation" display next /prev products on lopp, when is switch template to Cassiopea it has the same behaviour as virtuemart demo site
https://demo.virtuemart.net/advanced-pattern-detail product details navigation dispear when is next / prev is clicked

It shoud displayed all previous and next products within the same category

How to set up / fix product detail navigation so it shows previous and next products within the same category...?

Thans for any ideas.


andrai2

#1
/html/com_virtuemart/productdetails/default.php line 147 (template override code)
// Product Navigation
            if (VmConfig::get('product_navigation', 1)) { ?>
           
            <hr style="width:100%;" />
           
                <div class="product-neighbours">
                    <?php if (!empty($this->product->neighbours ['previous'][0])) {
                    
$prev_link = Route::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $this->product->neighbours ['previous'][0] ['virtuemart_product_id'] . '&virtuemart_category_id=' . $this->product->virtuemart_category_id, FALSE);
                    echo 
HTMLHelper::_('link', $prev_link, $this->product->neighbours ['previous'][0] ['product_name'], array('rel'=>'prev', 'class' => 'previous-page', 'data-toggle' => 'tooltip', 'title' => $this->product->neighbours ['previous'][0] ['product_name'], 'data-dynamic-update' => '1'));
                    } else {
                        echo 
'<span class="empty-previous-page fas fa-ban"></span> ';
                    }
                    if (!empty(
$this->product->neighbours ['next'][0])) {
                    
$next_link = Route::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $this->product->neighbours ['next'][0] ['virtuemart_product_id'] . '&virtuemart_category_id=' . $this->product->virtuemart_category_id, FALSE);
                    echo 
HTMLHelper::_('link', $next_link, $this->product->neighbours ['next'][0] ['product_name'], array('rel'=>'next','class' => 'next-page','data-toggle' => 'tooltip', 'title' => $this->product->neighbours ['next'][0] ['product_name'],'data-dynamic-update' => '1'));
                    } else {
                        echo 
'<span class="empty-next-page fas fa-ban"></span>';
                    } 
?>

                   
                   
                </div>
                <?php } // Product Navigation END

i went to chat gtp and said "Make code work, it loops only three products, not showing all category products"

// Ensure the configuration for product navigation is enabled
if (VmConfig::get('product_navigation', 1)) { ?>

<hr style="width:100%;" />

<div class="product-neighbours">
    <?php
    
// Get the category ID
    
$category_id = $this->product->virtuemart_category_id;

    
// Load the product model
    
$model = VmModel::getModel('product');

    
// Get all products in the current category
    
$products_in_category = $model->getProductsInCategory($category_id);

    
// Find the current product index
    
$current_product_id = $this->product->virtuemart_product_id;
    
$current_index = array_search($current_product_id, array_column($products_in_category, 'virtuemart_product_id'));

    
// Determine previous and next product indices
    
$prev_index = ($current_index > 0) ? $current_index - 1 : count($products_in_category) - 1;
    
$next_index = ($current_index < count($products_in_category) - 1) ? $current_index + 1 : 0;

    
// Previous product link
    
if (isset($products_in_category[$prev_index])) {
        
$prev_product = $products_in_category[$prev_index];
        
$prev_link = Route::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $prev_product->virtuemart_product_id . '&virtuemart_category_id=' . $category_id, false);
        echo 
HTMLHelper::_('link', $prev_link, $prev_product->product_name, array('rel' => 'prev', 'class' => 'previous-page', 'data-toggle' => 'tooltip', 'title' => $prev_product->product_name, 'data-dynamic-update' => '1'));
    } else {
        echo 
'<span class="empty-previous-page fas fa-ban"></span> ';
    }

    
// Next product link
    
if (isset($products_in_category[$next_index])) {
        
$next_product = $products_in_category[$next_index];
        
$next_link = Route::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $next_product->virtuemart_product_id . '&virtuemart_category_id=' . $category_id, false);
        echo 
HTMLHelper::_('link', $next_link, $next_product->product_name, array('rel' => 'next', 'class' => 'next-page', 'data-toggle' => 'tooltip', 'title' => $next_product->product_name, 'data-dynamic-update' => '1'));
    } else {
        echo 
'<span class="empty-next-page fas fa-ban"></span>';
    }
    
?>

</div>
<?php } // Product Navigation END ?>

that my progress "somehow this new product detail navigation code" works for me and product go next / prev as they should, i am still testing thoo

Roderic

I would first start with bringing Virtuemart up to date. And also update Joomla/PHP while you're at it. Good chance that your issue is no longer an issue anymore.