Skip to content

1. Plugin development guide

Krzysztof Kasowski edited this page Jan 22, 2016 · 2 revisions

Adding settings page

add_filter('jigoshop\admin\settings', function($tabs){
    $tabs[] = new SettingsTab();
}

Where SettingsTab() must implement Jigoshop\Admin\Settings\TabInterface interface. Here you can find an [implementation] (https://github.com/jigoshop/Jigoshop2/blob/master/src/Jigoshop/Admin/Settings/GeneralTab.php)

Adding payment gateways

add_filter('jigoshop\payment\gateways', function($tabs){
    $tabs[] = new Gateway();
}

Where Gateway() must implement Jigoshop\Payment\Method interface. Here you can find an [implementation] (https://github.com/jigoshop/Jigoshop2/blob/master/src/Jigoshop/Payment/Cheque.php)

Adding shipping methods

add_filter('jigoshop\shipping\methods', function($tabs){
    $tabs[] = new Method();
}

Where Method() must implement Jigoshop\Shipping\Method interface. Here you can find an [implementation] (https://github.com/jigoshop/Jigoshop2/blob/master/src/Jigoshop/Shipping/FlatRate.php)

Managing Jigoshop Options

To get access to Jigoshop\Core\Options object. use:

$options = \Jigoshop\Integration::getOptions();

####To manage a single option

$options->get('extensions.plugin_slug.settings.option1', $default);
$options->manage('extensions.plugin_slug.settings.option1', $value);

$default variable will be returned when extensions.plugin_slug.settings.option1 does not exists.

####To get all plugin settings

$options = \Jigoshop\Integration::getOptions()->get('extensions.plugin_slug', $default)

it will then return an array:

array(
    'settings' => array(
        'option1' => 'value'
    )
);

Adding settings page

add_filter('jigoshop\admin\settings', function($tabs){
    $tabs[] = new SettingsTab();
}

Where SettingsTab() must implement Jigoshop\Admin\Settings\TabInterface interface. Here you can find an [implementation] (https://github.com/jigoshop/Jigoshop2/blob/master/src/Jigoshop/Admin/Settings/GeneralTab.php)

Adding payment gateways

add_filter('jigoshop\payment\gateways', function($tabs){
    $tabs[] = new Gateway();
}

Where Gateway() must implement Jigoshop\Payment\Method interface. Here you can find an [implementation] (https://github.com/jigoshop/Jigoshop2/blob/master/src/Jigoshop/Payment/Cheque.php)

Adding shipping methods

add_filter('jigoshop\shipping\methods', function($tabs){
    $tabs[] = new Method();
}

Where Method() must implement Jigoshop\Shipping\Method interface. Here you can find an [implementation] (https://github.com/jigoshop/Jigoshop2/blob/master/src/Jigoshop/Shipping/FlatRate.php)

Managing Jigoshop Options

To get access to object [Jigoshop\Core\Options] (https://github.com/jigoshop/Jigoshop2/blob/master/src/Jigoshop/Core/Options.php) use:

$options = \Jigoshop\Integration::getOptions();

To manage a single option use:

$options->get('extensions.plugin_slug.settings.option1', $default);
$options->manage('extensions.plugin_slug.settings.option1', $value);

$default variable will be returned when extensions.plugin_slug.settings.option1 does not exists.

To get all of your plugin settings use:

$options = \Jigoshop\Integration::getOptions()->get('extensions.plugin_slug', $default)

It will then return an array:

array(
    'settings' => array(
        'option1' => 'value'
    )
);

###To get Cart for the current user use:

\Jigoshop\Integration::getCart();

It will return a \Jigoshop\Entity\Cart object.

###To get an Order object use:

\Jigoshop\Integration::getOrderService()->find($id);

It will return a [\Jigoshop\Entity\Order] (https://github.com/jigoshop/Jigoshop2/blob/master/src/Jigoshop/Entity/Order.php) object specified by $id. To use other ways to get the order please check the implementation of Jigoshop\Service\OrderService

###To get a Product object use:

\Jigoshop\Integration::getProductService()->find($id);

It will return a \Jigoshop\Entity\Product object specified by $id. To use other ways to get the product please check the implementation of Jigoshop\Service\ProductService

To check which Jigoshop page is loaded use:

\Jigoshop\Frontend\Pages::is($page);

The list of avaliable pages you can find [here] (https://github.com/jigoshop/Jigoshop2/blob/master/src/Jigoshop/Frontend/Pages.php#L17)

###To get the Cart for the current user use:
```php
\Jigoshop\Integration::getCart();

It will return a \Jigoshop\Entity\Cart object.

###To get an Order object use:

\Jigoshop\Integration::getOrderService()->find($id);

It will return a \Jigoshop\Entity\Order object specified by $id. To use other ways to get the order please check the implementation of Jigoshop\Service\OrderService interface.

###To get a Product object use:

\Jigoshop\Integration::getProductService()->find($id);

It will return a \Jigoshop\Entity\Product object specified by $id. To use other ways to get product please check the implementation of Jigoshop\Service\ProductService

To check which Jigoshop page is loaded use:

For frontend

\Jigoshop\Frontend\Pages::is($page);

The list of avaliable pages you can find [here] (https://github.com/jigoshop/Jigoshop2/blob/master/src/Jigoshop/Frontend/Pages.php#L17)

For backend

\Jigoshop\Integration::getAdminPages()->isProductsList();

Which will return an \Jigoshop\Admin\Pages object.