2
Answers
Vote up!
0
Vote down!

Connectivity for Blog posts and Products

First I want to say I think this thread is a good idea. I always feel guilty clogging up the front page with questions.

I working with Drupal Commerce Kickstart 2.0 and currently have a blog and product line configured. I am trying to find the most efficient way to be able to connect both of them. I would also like to connect posts from the Media Gallery Module (https://drupal.org/project/media_gallery) However, I feel like that will not be possible.

What I am looking to do is to connect users viewing a blog post to the product that is being displayed in the blog post. I would also like to have a link that is generated on the product page to blog posts of that product.

I know this will need the creation of quite a few different views to filter out the "view blog posts of this product" pages, and that taxonomies should be the driving force behind this feature. I have tried working with tags, but that will get far too messy in the future and has a high potential of creating errors.

**tl;dr:** How can I connect my blog posts to my products and vice-versa?

Asked by: Eric Shell
on September 23, 2013

2 Answers

Vote up!
0
Vote down!

I haven't ever needed to do this, but I can think of some modules that might help (there's probably more than one route to set up functionality like this):

Entity reference
Boxes
Panels
Context
Commerce rules extra

Answer by: mjcarter
Posted: Sep 24, 2013
Vote up!
0
Vote down!

Hi

Add a new field in product content type.For example a field named related_blog with type 'Entity Reference'.In the edit filed
you need to give Unlimited values in the field settings .In entity selection mode select blog entry.
Now your blog adding part finished. Edit you product and add any number of related blogs.

To show this in front end we need to create a block with following code

<?php
$node       
=     node_load(arg(1));
$product_id    =     $node->field_product['und'][0]['product_id'];
$product    =     commerce_product_load($product_id);
/* For viewing your product details you can just var_dump($product)*/

$arrRelatedBlogs = $product->display_context['entity']->field_related_blog["und"];

if ( !empty (
$arrRelatedBlogs ) )
{
?>
    <?php
      
    foreach ($arrRelatedBlogs as $blog )
      {
         
    $blog_id  $blog['target_id'];
         
    $node_blog node_load( $blog_id);
     
         
    $blog_img  = theme_image_style(array( 'path' => $node_blog->field_blog_entry_image['und']['0']['uri'], 'style_name' => 'thumbnail'));
         
    ?>
  • <?php
     
    print  $blog_img 
    ?>
  • <?php
     

     
    }
    ?>

<?php
}
?>

Now assign this block to product display .

I achieved this with above Code.I dont know whether there are better way to do this?.

Hopes this idea will be helpful to you.

Answer by: ajaichandran
Posted: Sep 24, 2013