Good day
I need some help with the following issue. I'll give the whole scenario. It shouldn't be too much work, but I just can not get it to work 100%.
All my products are loaded in the category page. Now, I have a customfield "Sequence No."(virtuemart__custom_id = 2). Let's say the other customfield is "Score" (virtuemart_custom_id = 3), and the value can be any integer value.
Different products can have the same sequence number.
So let's assume we have this scenario:
Seq # | Product | Score | Cart Button |
123456 | Shoes | 50 | "Addtocart-button" |
123456 | Shirt | 55 | "Addtocart-button" |
So, I need to disable the "Addtocart-button" for the product
with the higher score; in this case, the "Shirt" product.
Here is the code I wrote. It is inside the
"foreach ($this->product as $products) { }" element:
<?php
$db = JFactory::getDbo();
$sequence = "SELECT customfield_value FROM `jos_virtuemart_product_customfields` WHERE virtuemart_custom_id=2";
$score = "SELECT customfield_value FROM `jos_virtuemart_product_customfields` WHERE virtuemart_custom_id=3";
$producttest = "SELECT virtuemart_product_id FROM `jos_virtuemart_product_customfields`";
if($sequence==$sequence && $score>=$score){ ?>
<script>
jQuery(".addtocart-button").css("display", "none");
</script>
<?php } ?>
Is there any way to check for duplicates in a column in the database? I'd need to check customfield_value of "Sequence Number" for every "Product ID". I then need to determine which of the duplicate values has the highest "Score".
This sounds impossible, as I can't find anything on the web related to it.
Your code do nothing, or is not complet.
But each product have already customfield in the $product object, so you should simply get the customfields and compare.
Because you dont wrote all details, it's hard to give a solution.
And the code
<script>
jQuery(".addtocart-button").css("display", "none");
</script>
hide all addtocart-button, not only 1.
Thanks for the reply Studio 42.
How do I get the customfield value using $product? I can't figure that out.
Is it: $product->virtuemart_custom_id->customfield_value?
Yes, I need to hide the button ONLY where the sequence number is duplicated. It needs to hide the addtocart button of the product with the higher "Score".
$product->customfields should have all customfields
If you look for a specific template position
$product->customfieldSorted['yourposition'];
Have all custom fields in this position
Thanks for the reply appreciate it.