I have a custom node template based on a custom content type and I want to display products with their "Add to Cart" buttons from this custom node template.
In the content type (actually a field collection), I added the Product reference. In the template (node--{content type}.tpl.php) I do this type of thing:
$wrapper = entity_metadata_wrapper('node', $node);
// Since it's a field collection, I loop these:
foreach ($wrapper->field_content_group as $group) {
//Now each "$group" has the fields I want to display
//I permit N products (not just 1), so I can get product information,
//like price for example, like this:
if($group->field_featured_product) {
$product_references = $group->field_featured_product->value();
foreach($product_references as $product_reference) {
$product = commerce_product_load(intval($product_reference->product_id));
$price = entity_metadata_wrapper('commerce_product',
$product)->commerce_price->value();
print $price_display = commerce_currency_format($price['amount'],
$price['currency_code'], $product);
}
}
}
I don't need to alter the display, I'm happy with that. I'd like to just call something that prints the product, price, etc., along with the "Add to Cart" button. I'm thinking I call commerce_product_load and then some method(s) that gives me the completed form. Is there such a thing that I can call?
NOTE: Yes, I know about separation of concerns and that code is best placed outside of the template file.