How to Create j2Store App Plugin

Apps are used to extend j2Store E-commerce platform.

Naming

The name of the app folder should start with the prefix "app". Make sure that the name of the file and folder is in lower case and there are no spaces or any other characters in the name.

For example, app_example.

Plugin Folder Name: plg_j2store_app_example

In the plugin folder, there will be two files and one subfolder:

  • app_example.php
  • app_example.xml
  • app_example (subfolder)
    • controller.php
    • tmpl (subfolder)
      • form.php
      • default.php
    • models
      • appexample.php

Manifest File

File Name: app_example.xml

The manifest file follows the Joomla plugin system. The group should be j2store.

Primary File: app_example.php

The name of the class suffix should be same as your app filename. It should extend the J2StoreAppPlugin class.

defined('_JEXEC') or die;
require_once(JPATH_ADMINISTRATOR.'/components/com_j2store/library/plugins/app.php');

class plgJ2StoreApp_example extends J2StoreAppPlugin
{
var $_element = 'app_example';

function onJ2StoreGetAppView($row)
{

}
function viewList()
{

}
}

onJ2StoreGetAppView

This method is used to check if it is a app_example or not.

function onJ2StoreGetAppView($row)
{
if (!$this->_isMe($row))
{
return null;
}

$html = $this->viewList();
return $html;
}

viewList

This method is a controller for the plugin.

$html = $this->_getLayout('default', $vars);

The above line will call the template layout for the app_example from /app_example/tmpl/default.php

Model File

File Name: appexample.php

defined('_JEXEC') or die;
require_once (JPATH_ADMINISTRATOR . '/components/com_j2store/library/appmodel.php');

class J2StoreModelAppExample extends J2StoreAppModel
{
public $_element = 'app_example';

}

Controller File

File Location: /app_example

File Name: controller.php

defined('_JEXEC') or die;
require_once (JPATH_ADMINISTRATOR . '/components/com_j2store/library/appcontroller.php');

class J2StoreControllerAppExample extends J2StoreAppController
{
var $_element = 'app_example';

}

Events

Display on Product Page

  • onJ2StoreBeforeRenderingProductPrice($product)
  • onJ2StoreAfterRenderingProductPrice($product)
  • onJ2StoreBeforeAddToCartButton($product,$context)
  • onJ2StoreAfterAddToCartButton($product,$context)
  • onJ2StoreViewProduct(&$product,&$view)

Display on My Profile Page

  • onJ2StoreAddMyProfileTab()
  • onJ2StoreAddMyProfileTabContent($order)
  • onJ2StoreAddMessagesToMyProfileTop($order)

These plugins are called by default layout of myprofile view:

$plugin_title_html = J2Store::plugin()->eventWithHtml('AddMyProfileTab');
$plugin_content_html = J2Store::plugin()->eventWithHtml('AddMyProfileTabContent', array($this->orders));
$messages_above_profile_html = J2Store::plugin()->eventWithHtml('AddMessagesToMyProfileTop', array($this->orders));

Currencies

  • onJ2StoreUpdateCurrencies($rows, $force)

Cron

  • onJ2StoreProcessCron($command)

Others

  • onJ2StoreAfterDisplayProductForm($view,$item)
  • onJ2StoreProductAfterSave($context,$product)
  • onJ2StoreAfterDisplayShippingPayment($order)
  • onJ2StoreCheckoutValidateShippingPayment($data)
  • onJ2StoreAfterUpdateProduct($data)