J2Commerce Documentation
DownloadExtensions
  • Welcome to J2Commerce
  • Getting Started
    • Introduction to J2Commerce
    • Getting started with J2Commerce
    • Technical Requirements
    • Installation
    • Update
    • Upgrade from FREE version to PRO version of J2Commerce
  • Migrating from J2Store 3 to 4 3 to 4
  • Set up
    • Content plugin settings
    • Configuration
    • Currency
    • Custom fields
    • Set up multi-currency
  • Quickstart guide
  • Product Types
    • Simple product
    • Variable product
    • Configurable product
    • Flexible variable product
    • Downloadable product
  • Layout
    • Products List View
    • Products Tag View
    • Usecases
    • Category Tree for displaying filters
    • Special module positions
  • Catalog
    • Assigning a product to multiple categories
    • Product Description
    • Short codes
    • Adding specifications to your products
    • Advanced Pricing
    • Setting up tax for your products
    • Options
      • Import product options
      • How to create options and add them to your products
    • Filters
      • Product filters
      • Translating filters to your language
    • Manufacturers
    • Vendors
    • Adding related products
    • Ordering products on your storefront
  • Subscriptions and Memberships
    • Introduction to subscriptions and memberships in J2Commerce
    • Quickstart
    • Requirements and Installation
    • Basic Settings
    • Creating subscription based products
    • Simple Subscription Product
    • Paypal Reference Transactions for Subscriptions
    • Usecases
    • Customizing the subscription mail templates
    • Frequently Asked Questions
  • Partial Payments
    • Introduction to Partial payments
    • Basic Settings
    • Setting up plans for Partial Payments
    • Instances
    • Usecases
  • Booking and Reservations
    • Limitation of the booking products type
    • Requirements and Installation
    • Basic settings and Booking Management
    • Booking and Reservations
    • Creating a Bookable Product
    • how to restrict multiple booking for a product person based restriction
    • Usecases
  • Localisation
  • Translation
    • Translate J2Commerce into your language
    • Setting up the store in your Language
    • How to write language override for plugin in multilingual site
    • Language overrides in Joomla with examples
    • Translating Product Options
  • Design
    • Email templates
    • Invoice Template (Pro Feature)
  • Tax configuration
    • Untitled
    • Recommended Tax configuration for US States
    • Recommended Tax configuration for Canadian Stores
    • Recommended Tax Configuration for EU stores
    • Setting up European VAT Rules for selling Physical Goods with J2store
    • A simplified guide for New EU VAT rules 2015 for digital goods and setting them up in J2Store
    • How Tax is Calculated
  • Easy Checkout
    • Easy checkout
    • Trouble shooting issues
  • Shipping methods
    • Free Shipping
      • How to create coupons for free shipping
    • How to set up local store pick up shipping method
    • Australia post shipping plugin
    • Bring shipping plugin
    • Canadapost shipping plugin
    • FedEx shipping plugin
    • Purolator
    • Postal Code shipping plugin
    • Royal Mail Shipping
    • Standard shipping methods
    • Table Rate Shipping
    • UPS Shipping
    • USPS Shipping
    • United States postal service Shipping Plugin
    • USPS Advanced
  • Payment Methods
    • AliPay Payment Plugin
    • Authorize.Net plugin
    • Bank Transfer
    • Barclays Payment plugin
    • Braintree payment plugin
    • Cash on Delivery
    • CardSave Payment plugin
    • CCAvenue payment plugin
    • CECA Payment
    • Checkout fi¨
    • Culqi Payment
    • DIBS payment plugin
    • Direcpay Payment Plugin
    • EBS Payment Plugin
    • Elavon Coverage/Virtual Merchant Payment Plugin
    • eway Payment Gateway for j2store
    • First Data Plugin
    • Flo2Cash for J2Store
    • GestPay
    • Heartland Payment Plugin
    • Icepay Payment Plugin
    • Interpay
    • Klarna Payment Plugin
    • Mollie payment plugin
    • Money Order
    • Moneris eselectplus Hosted Paypage
    • MultiSafe Payment Plugin
    • Nochex Payment Plugin
    • NMI Payment Gateway
    • Ogone Payment plugin
    • Pagseguro Payment plugin
    • Paybox Payment plugin
    • Payeezy
    • Payfast Payment plugin
    • Paygate Payment
    • Paymate
    • Paypal Sandbox
    • Paypal Adavnced Payment plugin
    • Payment Express for J2Store
    • Payment Sense
    • Paypal Express Checkout
    • Paypal payment plugin
    • Paypal Pro Payment Plugin
    • Payseal Payment Plugin
    • Paysera Payment Plugin
    • Payson Payment Plugin
    • Payson Invoice Payment Plugin
    • Pay U Latam
    • PayUMoney plugin
    • Poli Payment Plugin
    • Post Finance
    • QuickPay
    • Razorpay
    • Rabobank Omnikassa
    • RealEx Payment Plugin
    • Redsys/Servired/Sermepa Payment Plugin
    • Sagepay Form Payment Plugin
    • Secure Trading Plugin
    • Sepa Payment
    • Sisow Payment for J2Store
    • Skrill Payment Plugin
    • Sofort Banking
    • Stripe
    • Squareup Payments
    • Tranzila Payment Plugin
    • USAePay Payment Plugin
    • Voguepay Payment Plugin
    • Worldpay Payment Plugin
    • 2Checkout Plugin
  • Sales
    • Coupons
    • Vouchers
    • Customers
    • Orders
  • Report Sales
  • Modules
    • Product search module
    • J2store Detailed Cart
    • Product categories module
    • Product display module
  • Apps
    • Add to user group
    • Additional fee
    • Ask question / quote
    • Availability-notification
    • Bundled Products
    • Bulk discounts
    • Change Password
    • Checkout Redirect
    • Custom Tabs
    • Data validation
    • Donation
    • Drop-box
    • Email basket Plugin
      • Email basket issues
    • GDPR compliance
    • Google-analytics-ecommerce-tracking
    • Group Products
    • How to send download links through email notifications
    • Image Popup
    • Invoice Prefix Generator
    • Open hours (time based restriction)
    • Pay later/Pay against invoice
    • Points and Rewards
    • Re-Order
    • Shipstation
    • Simple CSV import and export tool
    • Tax Utilities
    • Upload file in checkout
    • Quantity dropdown
  • Frequently Asked Questions
    • Where can i find my sub-template
    • Products not aligned properly on list view
    • SCA support for payment plugins
    • To show the base price instead of price range in flexivariable products
    • Where do I add the CSS on my site
    • Unable to save the settings in any app
    • Difference between product types
    • Commonly found issues
    • Frequently Asked Questions
    • Quantity Restriction
  • Troubleshooting Guide
    • Products not visible on storefront
    • Cart not Working
    • Troubleshooting Cart related Issues
    • Moving the description
    • Troubleshooting Checkout Issues
    • Troubleshooting Common Issues
    • How to disable shipping address and payment in checkout
    • Joomla Article Error decoding json data
    • Troubleshooting Email Issues
    • Troubleshooting Paypal related Issues
    • Troubleshooting Product Display Module Issues
    • How to create a custom thank you message
    • Troubleshooting Shipping Issues
    • Troubleshooting Tax Issues
    • Troubleshooting Translate related Issues
  • Common Overrides
    • To add options to downloadable products
    • Moving additional image list to the left of the main image in product view page
    • To display the UPCE/BAN/ISBN on the product page
    • To Display Both the main Image and the additional image in the product view page
  • Video Tutorials
    • Quick Start
    • Catalog Management
    • Subscriptions
    • Booking and Reservation
    • Partial Payments
    • Tax
    • Shipping Methods
    • Discounts
    • Language
    • Apps
    • Email and Invoice Template
    • Checkout and Payment
    • Sales and Orders
    • J2Store CPanel
  • General
    • How to set cron job on your server
    • How to create an FTP account and super user account in Joomla
  • Developer Guide
    • Introduction
    • Queue System
    • App for J2store
    • Sub-templates
    • Creating an integration plugin for your component
    • Payment plugin
    • Templates
  • Canonical URL Plugin
Powered by GitBook
On this page
  • Introduction
  • The Concept
  • Integrating with your component
  1. Developer Guide

Creating an integration plugin for your component

This topic is split into the following sections to make it easier for you to understand:

  • Introduction

  • The concept

  • Integrating with your component

  • Get the product form fields

  • Save product data

  • Supply item data to J2Store Display the cart

Introduction

Integrating J2Store with your extension is pretty straightforward. Since Version 3, we implement a flexible Plugin API and the entire J2Store core is re-written from scratch using the Framework on Framework (FOF).

So all you have to do is create an integration plugin for your component (using your component’s events). It can be a system plugin or a plugin specific to your component.

The Concept

J2Store can treat any item (an article, an event, a photo) as a product. All it needs is the name of the source (read as your component’s name. Example: com_foo) and the source item’s ID.You can use your component’s plugin events to display the J2Store’s Product Form, Save it and then Render it (in the front end)So basically three events are sufficient to integrate J2Store in your component.

Let me give you an example of how J2Store is integrated with the Joomla articles

  1. onContentPrepareForm

Here we inject the J2Store’s Product Form into the Article’s Edit view. So the store owner treats the article as product and fills in the form.

  1. onContentAfterSaveHere, we catch the data of the filled-in product form and save it to the J2Store’s tables. While saving, we save two important variables

  2. product_source = The name of the component which serves as the catalog source. In this case, com_content

  3. productsourceid = The id of the item that is treated as a product. In this case, the article id.

  4. onContentAfterDisplay So, we have displayed the form, saved the data. Now it is time to inject the cart block (price, quantity field, Add to cart button) into the article.This method takes care of it.

Integrating with your component

Let us integrate J2Store with your component

NOTE: This guide assumes that you have a good understanding of Joomla Plugins and Events

Start the integration by creating a system plugin or plugin specific to your component. The plugin should have four events for

  1. Display the product form fields in your item

  2. Save the product data (after your item data is saved)

  3. Supply data to j2Store (via a J2Store event)

  4. Display the cart

Display the product form fields

The first and foremost task is to get the J2Store’s Product form fields to display inside your component’s item.

If your component fire’s an event after displaying the form, then the task is pretty easy. You can create a system plugin with the event and call the following lines

  ```$app = JFactory::getApplication();
     //the id of your item. This will be treated as the product_source_id
  	 	$id = $app->input->getInt('cid');

  	 	$productTable = F0FTable::getAnInstance('Product' ,'J2StoreTable');
  			
  	$productTable->load(array('product_source'=>'com_foo', 'product_source_id' =>$id));
  	
  		$product_id = (isset($productTable->j2store_product_id)) ? $productTable->j2store_product_id : '';

  	 	$inputvars = array(
  	 			'task' =>'edit',
  	 			'render_toolbar'        => '0',
  	 			'product_source_id'=>$id,
  	 			'id' =>$product_id,
  	 			'product_source'=>'com_foo',
  	 			'form_prefix'=>''
  	 	);
  	 	$input = new F0FInput($inputvars);

  	 	@ob_start();
  		F0FDispatcher::getTmpInstance('com_j2store', 'product', array('layout'=>'form', 'tmpl'=>'component', 'input' => $input))->dispatch();
  		$html = ob_get_contents();
  		ob_end_clean();
  		return $html;```

Save the product data

Saving the data is also very simple. Just capture the filled-in form data (Usually in your After Save event)Then just pass the data (can be either an array or an object) to

```F0FModel::getTmpInstance('Products', 'J2StoreModel')->save($data);```

IMPORTANT: The array or object should have the product_source and product_source_id . Otherwise, J2Store will not be able to process your item as product.

Example:

product_source='com_foo'
product_source_id=$id //the ID of your item

Supply product data

You will have to supply a few important information to J2Store. Example, the product name, its url etc. J2Store has an event called: onJ2StoreAfterGetProduct(&$product) NOTE: If your Integration plugin is specific to your component, then you should create a system plugin with this event. Refer the K2 integration plugin for example.

function onJ2StoreAfterGetProduct(&$product) {	if(isset($product->product_source) && $product->product_source == 'com_foo' ) {		//assign		$product->product_name = $name;	

//supply a url to edit the item. This is essential. Because j2store will use this to link

Display the cart block

Time to get the add to cart block for your item.Here are the three lines that will get you the entire cart block.

$html = '';
$product = F0FTable::getAnInstance ( 'Product', 'J2StoreTable' )->getClone ();
if ($product->get_product_by_source ( 'com_foo', $id )) {
		$html = $product->get_product_html();
	}
	echo $html;

You have a number of methods in the product object.

To get the main image

$product->get_product_images_html(‘main’);

To get cross sell products

$product->get_product_cross_sells_html();

To get up sell products

$product->get_product_upsells_html();

Refer the the content plugin of J2Store for more detailed information and methods of implementing.(plugins/content/j2store/j2store.php)

PreviousSub-templatesNextPayment plugin

Last updated 6 months ago