Author Topic: Disable element based on duplicate customfield values with different ID.  (Read 173 times)

mailblade

  • Jr. Member
  • **
  • Posts: 77
  • A beginner
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:

Code: [Select]
<?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.

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 2741
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 &amp; 3.0.x.y
Re: Disable element based on duplicate customfield values with different ID.
« Reply #1 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
Code: [Select]
  <script>
   jQuery(".addtocart-button").css("display", "none");
  </script>
hide all addtocart-button, not only 1.

mailblade

  • Jr. Member
  • **
  • Posts: 77
  • A beginner
Re: Disable element based on duplicate customfield values with different ID.
« Reply #2 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".

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 2741
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 &amp; 3.0.x.y
Re: Disable element based on duplicate customfield values with different ID.
« Reply #3 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

mailblade

  • Jr. Member
  • **
  • Posts: 77
  • A beginner
Re: Disable element based on duplicate customfield values with different ID.
« Reply #4 on: February 15, 2018, 09:38:18 am »
Thanks for the reply appreciate it.