4

Im sure this is something simple, but I would really appreciate some help with it. How to check by php if the node is an ubercart product? Empty sku field might work but how can it be accessed ?

4
  • What context do you need to know this in? hook_node_view() or similar?
    – Clive
    Apr 2, 2012 at 20:02
  • It meant to be a rule for Page manager to customize layout only for nodes that are ubercart 3 products
    – ijujym
    Apr 2, 2012 at 20:07
  • Sorry, not really sure why I asked that; as long as you've got a $node object in the context it doesn't really matter
    – Clive
    Apr 2, 2012 at 20:13
  • Cant tell if it is good idea but Iv made it with reverse rule and this code $var = ctools_context_keyword_substitute('%node:product', array(), $contexts); if (empty($var)) { // not product }
    – ijujym
    Apr 2, 2012 at 21:03

2 Answers 2

3

I think the most solid way to test would be to check that the node's type is one that the uc_product module considers to be a product node type. You can do that by using the uc_product_types() function:

$node_types = array_keys(uc_product_types());
if (in_array($node->type, $node_types)) {
  // The node is a product
}
1
  • It is greate idea, Thanks. but for some reason this error shows up on node page Notice: Undefined variable: node in eval() (line 2 of /sites/all/modules/ctools/plugins/access/php.inc(55) : eval()'d code). Notice: Trying to get property of non-object in eval() (line 2 of /sites/all/modules/ctools/plugins/access/php.inc(55) : eval()'d code).
    – ijujym
    Apr 2, 2012 at 22:45
1

Not really. The most solid way is to use the function Ubercart provides for just this purpose: uc_product_is_product().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.