News:

Support the VirtueMart project and become a member

Main Menu

Add categories to sublayout product,php

Started by encreplus, February 09, 2021, 16:21:58 PM

Previous topic - Next topic

encreplus

Good day

I already add this code to productdetails/default.php and it works perfect,

<h1 class="product-title" id="compatible-products">
    <?php echo JText::('COM_VIRTUEMART_ALSO_IN_CATEGORY'?></h1>
   
   
       


<?php
 
function sortByOption($a$b) {
   return 
strcmp($a['category_name'], $b['category_name']);
 }
 
usort($this->product->categoryItem"sortByOption");
?>

       
        <?php $categories=$this->product->categoryItem;
 foreach (
$categories as $category){
 
$caturl JRoute::'index.php?option=com_virtuemart&view=category&virtuemart_category_id=' $category['virtuemart_category_id'] );
 
$catname=$category['category_name'];
 echo 
'<a href="'.$caturl.'" title="'.$catname.'">'.$catname.'</a> , ';
 }
 
?>


But when i try to add it to product.php in sublayout it destroy my page, it dosent work, any clue what is wrong ?

Stefan

GJC Web Design

use   $product->  instead of

$this->product->
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

encreplus

#2
Quote from: GJC Web Design on February 09, 2021, 18:04:06 PM
use   $product->  instead of

$this->product->


Thanks GJC

now it work in some part,  the layout of the page is destroy , and it shows all categories the product belong to only for the first product not all products that are on page  ;(

Any clue ?

encreplus

#3
I have remove my sorting code and now works ok, any clue why this code destroy that page ?

<?php
function sortByOption($a, $b) {
   return strcmp($a['category_name'], $b['category_name']);
}
usort($product->categoryItem, "sortByOption");
?>