Driving online sales through socialengine site using wordpress

In the era of online shopping, any organization wants to sell their products in effective manner along with the social networking platform. These organization would like to sell their products to their social networks as review by community shall be more reliable. One of our client demanded this functionality because he is facing problem in managing products on a single  social community. We recommended him to create a custom plugins which can integrate socialengine and wordpress seamlessly . In this article, we shall demonstrate how implemented this and allow our customer to sell products.

Lets dive into wordpress development

For creating this we have created a plugin in wordpress and  created a file named as main.php in controller folder. This file consist of the functions that gives the necessary informations like all the products of wordpress, categories of the products and tags of the products.

The function feed_wpproduct() provide us all the information regarding product such as, name of the product, url of the product, description of the product etc. in this function we have  follow the rss action of the wordpress which has given the output in the xml format.

function feed_wpproduct()
       $args = array(
	       'orderby' => $orderBy, 
	       'paged' => $paged,
	       'posts_per_page' => $posts_per_page,
	       'product_cat' => $cat,
	       'product_tag' => $tag,
	       'meta_key' => 'wpb_post_views_count'
       $posts_array = get_posts( $args );
       <?php foreach($posts_array as $post): ?>
       <?php the_post(); ?>
                <title><![CDATA[<?php echo $post->post_title; ?>]]></title>
                <link><?php echo get_permalink($post->ID); ?></link>
                <id> <?php echo $post->ID;?></id>
                <?php $author_id=$post->post_author ?>
                <usermeta><?php echo the_author_meta('user_email',$author_id) ?></usermeta>
                <comments><?php echo get_comments_link($post->ID); ?></comments>
                <commentcount><?php echo $post->comment_count; ?></commentcount>                                         <viewcount><?php echo get_post_meta($post->ID,'wpb_post_views_count',true);?></viewcount>
                <productprice><?php echo $price = get_post_meta($post->ID, '_price',true);?>
                <thumb><![CDATA[<?php echo get_the_post_thumbnail($post->ID,array(50,50)); ?>]]></thumb>
      //...... this will give us the products information

Likewise for getting the product categories and product tags we have wrote two functions “feed_productcategory()”  and  “feed_producttags()” . These two functions have given us the categories and the tags of the products in the xml format. which has been get in the socialengine side.

function feed_producttags()
    $tags = get_categories(array('taxonomy'=>'product_tag')); ?>
    <?php foreach($tags as $tag): ?>
           <title><?php echo $tag->name; ?></title>
           <link><?php echo get_category_link($tag->term_id);?></link>
           <id><?php echo $tag->term_id; ?></id>
           <slug><?php echo $tag->slug; ?></slug>
           <description><?php echo $tag->description; ?></description>
           <posts><?php echo $tag->count; ?></posts>
   //.... this will gives all the information related with product categories.

Now to call these function we have wrote this function in the add_feed hook of the wordpress. The add_feed hook  added  a new feed, if  you want to read more about add_feed you can refer this link. the add feed hook is called in the constructor of the class. which added these feeds, whenever the plugin is installed.

Lets dive into SocialEngine development

In socialegine, we has created a new module to get all these wordpress products,whenever they have created. To do so we  need to configure few urls in the admin section of the socialengine. so we have created a admin controller and create a admin section for the settings. the Index action has saved all the settings into database. to store the settings into database we have created a new table and a new form under Form section and in the model section of the module respectively.

public function indexAction()
		$log = Zend_Registry::get('Zend_Log');
		$this->view->navigation = $navigation = Engine_Api::_()->getApi('menus', 'core')
		->getNavigation('ipwpproduct_admin_main', array(), 'ipwpproduct_admin_main_settings');
		$this->view->form = $form = new Ipwpproduct_Form_Admin_Setting();
		$url_table = Engine_Api::_()->getDbTable('urls','Ipwpproduct');
		$url_select = $url_table->select();
		$url_exist = $url_table->fetchRow($url_select);
		if (!$this->getRequest()->isPost()) 
		if (!$form->isValid($this->getRequest()->getPost())) 
		       $this->view->formErrors = $form->getMessages(null, true);
                //.... this will save the urls in the database.


Now we have created a widget which will display the products in the socialengine. For the settings of widget we have created a form in the content.php file under settings folder. which  got the categories and tags from the wordpress and filter the product based on the preference set in the form.



In the widget we have got all the product form the wordpress and make a listing of that products with the help of the For each looping function of the php. For getting the products we have used the php function “file_get_contents()“. this function has given us the content based upon the url given to the function. This function returns content in the xml format. then we have converted it with the help of  “SimpleXmlElement()” function. After getting products we can display them with the help of the widget.

$content = file_get_contents($feed_url);
$feeds = new SimpleXmlElement($content);
$this->view->feeds = $feeds;
foreach($feeds->channel->item as $feed)
   $feedusers[] = (string)$feed->usermeta;
   $posts[] = $feed;



Hence by following this approach, we can display wordpress products in the socialengine site. To reduce your efforts and time we have create a plugin which will display wordpress products in socialengine. Please contact us if you have further queries.

Leave a Comment

Scroll to Top