*

pitbull

  • **
  • 98 posts
Show single attribute outside of hook position - PROBLEM
« on: August 14, 2019, 10:19:12 AM »
Hi Frosticek, i created an attribute with id "18" for "CARS" category and i m using the function

Code: [Select]
<?php if(function_exists('atr_show_attribute')) { echo atr_show_attribute(18); } ?>
so i can display that attribute in a specific position at item page.

However if you use that function there are 2 problems.

1ST problem: The attribute label is visible on all categories (it must be visible only in CARS category)

2ND problem: The attribute label is still been visible no matter if the attribute value is empty or not.

FOR EXAMPLE I CREATED THE FOLLOWING ATTRIBUTE ONLY FOR THE CARS CATEGORY:

ATTRIBUTE ID= 18
ATTRIBUTE LABEL= TOP SPEED
ATTRIBUTE VALUE= 250mph   

when i add this code in item page file
Code: [Select]
<?php if(function_exists('atr_show_attribute')) { echo atr_show_attribute(18); } ?>

On CARS category it works OK and display: TOP SPEED - 250mph
On PHONES category it display only the label: TOP SPEED (It should hide not only the value of the attribute but also the label!)
On CARS category again if i leave empty the value of the attribute it still display only the label: TOP SPEED (It should hide not only the value of the attribute but also the label when the value is empty!)

Could you please provide a quick fix for that as i need to launch my site ASAP ?

Thanks in advance Frosticek.



« Last Edit: August 14, 2019, 11:18:13 AM by pitbull »

Marked as best answer by frosticek on August 14, 2019, 02:25:12 PM
*

MB Themes

Re: Show single attribute outside of hook position
« Reply #1 on: August 14, 2019, 11:22:02 AM »
@pitbul
You can create your own function:
Code: [Select]
// SHOW ATTRIBUTE BASED ON ID
function atr_show_attribute2($attribute_id, $label = false) {
  $attribute = ModelATR::newInstance()->getAttributeDetail($attribute_id);

  $cats = array_filter(explode(',', $attribute['s_category_id']));

  $item = osc_item();

  if(empty($cats) || in_array($item['fk_i_category_id'], $cats)) {
    return atr_single_attribute($attribute, $item['pk_i_id'], $label);
  }
}
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

pitbull

  • **
  • 98 posts
Re: Show single attribute outside of hook position - PROBLEM
« Reply #2 on: August 14, 2019, 11:46:58 AM »
Thank you Frosticek. Now it shows the attribute only in correct category.

The problem now is that hides the label which i want it to be shown.   So i changed the first line of your code to:

Code: [Select]
function atr_show_attribute2($attribute_id, $label = true) {
Now it displays the label but still keeps it visible if the value of the attribute is empty. Is there any condition to check if the attribute value is empty? Something like this code for example....

Code: [Select]
if (atr_value !='') {
//SHOW LABEL
}

I noticed that when the attributes are displayed into hook position the label/value works fine. If the value is empty, then label is not visible!

Thanks again

*

pitbull

  • **
  • 98 posts
Re: Show single attribute outside of hook position - PROBLEM
« Reply #3 on: August 14, 2019, 12:54:29 PM »
Frosticek ?? :)

*

MB Themes

Re: Show single attribute outside of hook position - PROBLEM
« Reply #4 on: August 14, 2019, 01:40:15 PM »
@pitbull
Quote
2ND problem: The attribute label is still been visible no matter if the attribute value is empty or not.

So I am done.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

pitbull

  • **
  • 98 posts
Re: Show single attribute outside of hook position - PROBLEM
« Reply #5 on: August 14, 2019, 01:46:20 PM »
@pitbull
Quote
2ND problem: The attribute label is still been visible no matter if the attribute value is empty or not.

So I am done.


I solved it by creating a new function and a new hook. So now i can position this new hook anywhere i want. If the value of the attribute is empty now the label is also hidden.

Problem Fixed ;)

Re: Show single attribute outside of hook position - PROBLEM
« Reply #6 on: November 19, 2019, 12:02:58 AM »
hi i'm interested, you can share it with us