VirtueMart Forum

VirtueMart 2 + 3 + 4 => Administration & Configuration => Topic started by: mailblade on December 01, 2018, 15:47:07 PM

Title: Hide product rows in category based on virtuemart_product_id?
Post by: mailblade on December 01, 2018, 15:47:07 PM
Hi!

I have three category layouts for my products.

One menu item (VirtueMart Category Layout via Menu item) is for "Dry", one menu item is for "Frozen" and one is "General", which shows all "Dry" and "Frozen" products combined.

Now, for the "General" menu item, I need to hide certain products depending on "virtuemart_product_id". You see, the problem is that I have some other products that are also displaying here, from a completely different category not related to either "Dry" or "Frozen". The "General" menu item should only list all products for "Dry" and "Frozen".

I added the product_id's which I want excluded from the view into an array and added it at the start of the "foreach" product output.

I have done the following, but it did not work:


<?php
// Start the Output
foreach ( $this->products as $product ) {
 
     
// Show the horizontal seperator
if ($iBrowseCol == && $iBrowseProduct $BrowseProducts_per_row) { ?>

<div class="horizontal-separator"></div>
<?php }

?>

<?php
$arr 
= [483,484,485,486,487,488,489,490,491];
if(!
in_array($virtuemart_product_id$arr)) { ?>

<tr style="border-bottom: 1px solid #ffb3b3; height: 30px;">
<td style="width: 45px;padding-right: 15px;"><?php 
// Get a db connection.
$db JFactory::getDbo();

// Create a new query object.
$query $db->getQuery(true);

// Select all records from the user profile table where key begins with "custom.".
// Order it by the ordering field.

$query->select($db->quoteName(array('customfield_value''virtuemart_product_id')));
$query->from($db->quoteName('jos_virtuemart_product_customfields'));
$query->where($db->quoteName('virtuemart_custom_id') . ' LIKE '$db->quote('6'). ' AND '$db->quoteName('virtuemart_product_id') . 'LIKE ' $db->quote($product->virtuemart_product_id));

// Reset the query using our newly populated query object.
$db->setQuery($query);

// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$results $db->loadResult();
echo (
$results); 
?>

</td>

<td style="padding-left: 10px;width: 300px; color: #ff3333;">
<?php 


 
echo $product->product_name
 
 
 
?>


</td>

<td style="width: 90px; text-align: center;">
<?php

// Get a db connection.
$db JFactory::getDbo();

// Create a new query object.
$query $db->getQuery(true);

// Select all records from the user profile table where key begins with "custom.".
// Order it by the ordering field.

$query->select($db->quoteName(array('customfield_value''virtuemart_product_id')));
$query->from($db->quoteName('jos_virtuemart_product_customfields'));
$query->where($db->quoteName('virtuemart_custom_id') . ' LIKE '$db->quote('3'). ' AND '$db->quoteName('virtuemart_product_id') . 'LIKE ' $db->quote($product->virtuemart_product_id));

// Reset the query using our newly populated query object.
$db->setQuery($query);

// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$results $db->loadResult();
echo (
$results); 
?>

</td>
</tr> <?php ?>


Obviously this is just a piece of the whole table, to show you what it looks like. I only added 3 fields from the table. 2 customfields and the product_name field.

Now, when I do this the rows for the products in the array are still showing. I have added the array at the start of the "foreach" output of the products, right after my table's headers.

Title: Re: Hide product rows in category based on virtuemart_product_id?
Post by: GJC Web Design on December 01, 2018, 22:35:01 PM
Products can be in multiple VM cats  -- why don't u just put what u want in the appropriate cats and display the cat?
Title: Re: Hide product rows in category based on virtuemart_product_id?
Post by: mailblade on December 02, 2018, 06:52:44 AM
But all the items already have a category. Either dry or frozen. I can't combine 2 categories
Title: Re: Hide product rows in category based on virtuemart_product_id?
Post by: mailblade on December 02, 2018, 07:06:25 AM
I just created a parent category and added the other 2 categories as child to it.

Such an easy solution haha.