Example app for Merchium that demonstrates the use of external JavaScript, external HTML/Smarty content, webhooks, and payment service integration.
The app implements the following features:
1. Snowfall for the storefront
1. Welcome popup
1. The "Add to cart" counter
1. Example payment
The app is based on the Yii 2 Basic Application Template.
PHP 5.4.0 and a web server supporting it.
In the example below we'll use PHP's built-in server, SQLite, and ngrok. You can use MySQL or any other database.
Check the requirements with php requirements.php
.
-
Clone repo and switch to the app directory:
$ git clone https://github.com/merchium/merchium-advanced-app.git $ cd merchium-advanced-app
-
Install the plugin and dependencies by running the following command:
$ composer global require "fxp/composer-asset-plugin:1.0.0" $ composer update
-
Create a DB from the provided example:
$ cp sqlite.db merchium-advanced-app.db
-
Create a DB config from the provided example:
$ cp config/db.php.example config/db.php
-
Edit the DB config (note that the DB path must be absolute):
<?php return [ 'class' => 'yii\db\Connection', 'dsn' => 'sqlite:/absolute/path/to/merchium-advanced-app.db', 'charset' => 'utf8', ];
Note: The DB template sqlite.db already has some data. If you're starting from scratch or using a different database (e.g. MySQL), apply the migrations:
$ php yii migrate
-
Run PHP's built-in dev server:
php -S localhost:8000
-
Use ngrok to get an https URL pointing to your server:
$ ngrok http 8000 ... Forwarding https://3cd89e8a.ngrok.com -> 127.0.0.1:8000 ...
- Go to https://3cd89e8a.ngrok.com/web/index.php?r=site%2Flogin and login to the dashboard with username admin and password admin.
You'll see the app's admin panel and install page URLs.
-
Open your Merchium partner page on a new tab and create an app. Use the admin panel and install page URLs from the dashboard.
-
Switch to App permissions and check the following permissions:
- View, create, edit, and delete custom script connections (ScriptTags)
- View, create, edit, and delete custom HTML and Smarty 3 content connections to hooks (TemplateHooks)
- View, create, edit, and delete payment processors (PaymentProcessors)
- Create, edit, and delete webhooks (Webhooks)
-
Create a config from the provided example:
$ cp config/params.php.example config/params.php
-
Open
config/params.php
and paste the App key and Client secret values from the Merchium partner page into the respective params:<?php return [ 'adminEmail' => 'admin@example.com', 'applicationName' => 'Merchium Example App', 'companyName' => 'My Company', 'userPasswordResetTokenExpire' => 3600, /** * Application params. Required for installation. */ 'appKey' => 'APPKEY12345', 'clientSecret' => 'CLIENTSECRET12345', ];
-
Restart the server to apply the new params.
-
Create a dev store in your Merchium partner panel.
-
Go to the app page and install it to the dev store.
assets/ assets definition
behaviors/ behaviors definition
commands/ console commands (controllers)
config/ application configurations
controllers/ Web controller classes
mail/ view files for e-mails
models/ model classes
runtime/ files generated during runtime
tests/ various tests for the basic application
vendor/ dependent 3rd-party packages
views/ view files for the Web application
web/ the entry script and Web resources
widgets/ widgets for view files for the Web application