VirtueMart Forum

VirtueMart 2 + 3 + 4 => Administration & Configuration => Topic started by: mailblade on February 12, 2018, 15:43:17 PM

Title: Disable element based on duplicate customfield values with different ID.
Post by: mailblade on February 12, 2018, 15:43:17 PM
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  #ProductScoreCart Button

123456Shoes50"Addtocart-button"
123456Shirt55"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.
Title: Re: Disable element based on duplicate customfield values with different ID.
Post by: Studio 42 on February 13, 2018, 00:13:19 AM
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.
Title: Re: Disable element based on duplicate customfield values with different ID.
Post by: mailblade on February 13, 2018, 11:15:06 AM
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".
Title: Re: Disable element based on duplicate customfield values with different ID.
Post by: Studio 42 on February 13, 2018, 12:58:07 PM
$product->customfields should have all customfields
If you look for a specific template position
$product->customfieldSorted['yourposition'];
Have all custom fields in this position
Title: Re: Disable element based on duplicate customfield values with different ID.
Post by: mailblade on February 15, 2018, 09:38:18 AM
Thanks for the reply appreciate it.