Hello everyone,

I have been trying to theme the way products are displayed using a custom node.tpl for a product display content type. I have succeeded in getting this done but my problem is, I am unable to render the "Commerce Product SKU" and "Commerce Product Title" fields. I have decided to hide the Product Display Title and rather display the Commerce Product Title together with the Commerce Product SKU. Is this really possible? Am counting on your usual support. Thank you in advance for your support.

Comments

giorgosk’s picture

it would be nice if SKU and status and other hardcoded attributes of product were available on
admin/structure/types/manage/product_display/display and still get the ADD TO CART FORM but they aren't

I am on the same boat as you

mr.moses’s picture

I am looking for something a little different, but I believe the problem is the same: you can only display one item from the product (title, sku, OR add to cart form).

I would like to display the title (from node or product), followed by the SKU (from the product), then a description (node body), then the add to cart form (from product). But right now it seems you can only display one thing from the product (title, sku, OR add to cart). How do you dislpay more than 1 ?

giorgosk’s picture

there is no easy way yet

tap into the function THEMENAME_preprocess_node(&$vars)

and use something like this to get SKU into content and let the CART be displayed using the field formatter settings


  if($vars["type"] == "product_display")  {
    ....
    //output sku 
    //next line if title module is not used need to use some other field to grab the product object
    $prod = $vars["content"]["product:title_field"]["#object"]; 
    $sku["#markup"] = "<div class='skufield field field-label-inline clearfix'><div class='field-label'>"
      .t("Product Code").":&nbsp;</div><div class='field-items'>".$prod->sku."</div></div>";
    $sku["#weight"] = "1";
    $sku["#access"] = 1;
    $vars["content"]["product:sku"] = $sku;
    ....
  }
MickL’s picture

I am so sad about this!

I can use print $title to show the title of the node. But i can't use something similiar to show the title or the sku of the product :(

mr.moses’s picture

I was able to show the sku by adding this into my node template without using any theme preprocess functions:

<?php print $content['product:commerce_price']['#object']->sku; ?>

I have the 'Add to Cart form' selected as the field formatter for the Product reference field on my node. I think you could also get the title of the commerce product like this: <?php print $content['product:commerce_price']['#object']->title; ?>

rszrama’s picture

@benchi - Don't be sad... get involved. Try out others' solutions and eventually we'll work this into the core code itself. : P

If I'm not mistaken, this may be a duplicate of: #983830: Render title/sku data in the product reference formatter instead of just field data

If that were to be fixed, you should have these variables available in your templates, right? If so, we can leave this open as documentation for the short term, but I'll go ahead and tag that one for the 1.1 release. It's long overdue.

MickL’s picture

print sku:

 print $content['product:commerce_price']['#object']->sku; // Print sku
<?php print $content['product:commerce_price']['#object']->title; // Print product title (machine name)
<?php print $content['product:commerce_price']['#object']->type;  // Print product type

this is what i looked for!! fantastic!

But there is a big problem:
Unlike the price: print render($content['product:commerce_price']); it does not changes dynamically (ajax) !!! :(

rszrama’s picture

Status: Active » Closed (duplicate)

Right, that problem would be solved by the other issue I linked to. I think I will go ahead and mark this one a duplicate.

NaliPL’s picture

please look here:

admin/structure/types/manage/{uour-display-name}/display then here you have list of fields probably "Product: SKU" is not set to visible,

othervise you could make an hook_preprocess_node() function

/**
* Implements hook_preprocess_node().
*/
function MODULE_NAME_preprocess_node(&$vars) {
if($vars['type'] == 'your_displan_name_here') {
$vars['content']['product:sku']['#access'] = TRUE;
}
}

jnavane’s picture

Issue summary: View changes

Hi NaliPL,

Your suggestion(s) solved my problem. Thanks.