0

enter image description here

I know by looking in the database that CL1 is equal to 6. How would i print_r or echo out this statement below. Also is there a way to just echo it out in terminal? I know if i change CL1 to Taxable Goods it would echo out a different id.. 2. I'm just not sure how to actually do it..

$product = Mage::getModel('catalog/product'); // Might not need this if product is already loaded
$attribute = $product->getResource()->getAttribute('tax_class_id');
if ($attribute->usesSource()) {
    $optionId = $attribute->getSource()->getOptionId('CL1');
}

Do i wrap the whole statement or just try to echo out the $optionId variable?

Any help would be greatly appreciated.

Sam
  • 7,252
  • 16
  • 46
  • 65
thismethod
  • 523
  • 1
  • 6
  • 25

2 Answers2

1

to log it in the console: (edited)

echo("<script>console.log('".$optionId."');</script>");

print it out:

print($optionId); //or
echo($optionId);
Hazonko
  • 1,025
  • 1
  • 15
  • 30
  • Also, can you elaborate on how to use the console.log... run that inside of my terminal? Do i have to be in the same directory or same page? – thismethod Mar 17 '16 at 17:42
  • I got it to print on the page but still a bit confused on how to do it inside my terminal using ubuntu/bash – thismethod Mar 17 '16 at 17:55
  • console.log wont put it in the terminal console, but into the browsers console. i'm affraid i wouldn't know how to watch it from outside the browser, unless you were to put a watch against it in your IDE. I, personally, just use the browsers console to print out any debugging i do. – Hazonko Mar 18 '16 at 09:59
  • How can the accepted answer to a PHP question be one that suggests using the **JavaScript** console? – Álvaro González Mar 21 '16 at 09:25
0

Mostly for printing purpose you better you var_export() please check this link.

Community
  • 1
  • 1
Zumry Mohamed
  • 9,318
  • 5
  • 46
  • 51
  • How would i use var export with that class and that if statement.. I just want to know the id of that variable. – thismethod Mar 17 '16 at 17:40