index.php
<?php
/*
Plugin Name: Woocommerce OpenPos External App Demo
Plugin URI: http://openswatch.com
Description: A Sample App for OpenPOS + Woocommerce.
Author: anhvnit@gmail.com
Author URI: http://openswatch.com/
Version: 1.0
WC requires at least: 2.6
Text Domain: openpos-app
License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
define('OPENPOS_APP_DIR',plugin_dir_path(__FILE__));
define('OPENPOS_APP_URL',plugins_url('/',__FILE__));
if(!class_exists('OP_App_Abstract'))
{
$openpos_dir = dirname(rtrim(OPENPOS_APP_DIR , '/') ).'/woocommerce-openpos';
require_once $openpos_dir.'/lib/abtract-op-app.php';
}
require_once OPENPOS_APP_DIR.'/my-op-app.php';
$myApp = new MyOpApp();
my-op-app.php
<?php
/**
* Created by PhpStorm.
* User: anhvnit
* Date: 3/20/19
* Time: 11:51
*/
class MyOpApp extends OP_App_Abstract implements OP_App {
public $key = 'demo_app_key'; // unique
public $name = 'Demo Open Pos App';
public $thumb = OPENPOS_APP_URL.'app.png';
public function render()
{
header('X-Frame-Options: allow-from *');
global $in_pos_app;
$in_pos_app = true;
$session = $this->get_session();
$email = $session['email'];
$session_id = $session['session'];
$user = wp_signon( array('user_login' => $email,'user_password' => $session_id) );
require_once OPENPOS_APP_DIR.'/view/view.php';
}
}
view/view.php
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"></script>
<p>Cashier Name : <?php echo $session['name'];?></p>
<p>Login Time : <?php echo $session['logged_time'];?></p>
<p>your app template at here / html / css / js</p>
<p>Dynamic data get from your site</p>
<a href="javascript:void(0)" id="sample-link">test event</a>
<script type="text/javascript">
(function($) {
$('#sample-link').click(function(){
var addItemFired = new CustomEvent("openpos.add.to.cart", {"detail": {
product : {
"name": "ACMEe5",
"id": 0,
"parent_id": 0,
"sku": "",
"barcode": "000000022755",
"price": 16,
"price_incl_tax": 20,
"final_price": 16,
"manage_stock": false, // true or false
"qty": 1, // limit qty
"status": "publish",
"options": [
{
'label' : "Radio Label",
'option_id' : 1,
'type' : 'radio',
'require' : true,
'options' : [
{'value_id' : 1, 'label': 'radio value 1','cost' : 5},
{'value_id' : 2, 'label': 'radio value 2','cost' : 2},
]
}
],
"tax": [
{
"code": "standard_1",
"rate": 21,
"shipping": "yes",
"compound": "no",
"rate_id": 1,
"label": "Tax"
}
],
"tax_amount": 3,
"price_included_tax": 1,
"display_special_price": false,
"allow_change_price": true,
}
} });
parent.dispatchEvent(addItemFired);
});
}(jQuery));
</script>
No comments:
Post a Comment