Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added: "Channel Manager Connector" module to QloApps #516

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions install/models/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ public function getModulesList()
'statsequipment',
'blockcart',
'blockuserinfo',
'qlochannelmanagerconnector',
);
}
return $modules;
Expand Down
Empty file.
125 changes: 125 additions & 0 deletions modules/qlochannelmanagerconnector/CustomizationPolicy.txt

Large diffs are not rendered by default.

223 changes: 223 additions & 0 deletions modules/qlochannelmanagerconnector/LICENSE.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions modules/qlochannelmanagerconnector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## Channel Manager Connector
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* 2010-2023 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <[email protected]>
* @copyright 2010-2023 Webkul IN
* @license https://store.webkul.com/license.html
*/

class QcmcChannelManagerBooking extends ObjectModel
{
public $id_order;
public $date_add;

public static $definition = array(
'table' => 'qcmc_channel_manager_booking',
'primary' => 'id_channel_manager_booking',
'fields' => array(
'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false),
),
);

/**
* Returns bookings created by api by channel manager
* @param integer $idOrder : send id_order if you want booking of a particular order
* @param string $orderWay : Send order way (DESC|ASC) sorted by date_add
* @return [array of bookings | false]
*/
public static function getChannelManagerBookings($idOrder = 0, $orderWay = 'ASC')
{
$sql = 'SELECT * FROM `'._DB_PREFIX_.'qcmc_channel_manager_booking` WHERE 1';

if ($idOrder) {
$sql .= ' AND `id_order` = '.(int)$idOrder;
}

$sql .= ' ORDER BY `date_add` '.$orderWay;

if ($result = Db::getInstance()->executeS($sql)) {
if ($idOrder) {
// if needs only one order row then send only one row from the array
$result = $result[0];
}
}

return $result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* 2010-2023 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through LICENSE.txt file inside our module
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to CustomizationPolicy.txt file inside our module for more information.
*
* @author Webkul IN
* @copyright 2010-2023 Webkul IN
* @license LICENSE.txt
*/

class QcmcChannelManagerConnectorDb
{
public function createTables()
{
$sql = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'qcmc_channel_manager_booking` (
`id_channel_manager_booking` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`id_order` INT(11) UNSIGNED NOT NULL,
`date_add` DATETIME NOT NULL,
PRIMARY KEY (`id_channel_manager_booking`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8';

if (!Db::getInstance()->execute(trim($sql))) {
return false;
}

return true;
}

public function dropTables()
{
return Db::getInstance()->execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'qcmc_channel_manager_booking');
}
}
22 changes: 22 additions & 0 deletions modules/qlochannelmanagerconnector/classes/QcmcClassInclude.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* 2010-2023 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <[email protected]>
* @copyright 2010-2023 Webkul IN
* @license https://store.webkul.com/license.html
*/

require_once _PS_MODULE_DIR_.'qlochannelmanagerconnector/classes/QcmcChannelManagerConnectorDb.php';
require_once _PS_MODULE_DIR_.'qlochannelmanagerconnector/classes/QcmcChannelManagerBooking.php';
29 changes: 29 additions & 0 deletions modules/qlochannelmanagerconnector/classes/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* 2010-2023 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through LICENSE.txt file inside our module
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to CustomizationPolicy.txt file inside our module for more information.
*
* @author Webkul IN
* @copyright 2010-2023 Webkul IN
* @license LICENSE.txt
*/

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../../../');
exit;
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?php
/**
* 2010-2023 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <[email protected]>
* @copyright 2010-2023 Webkul IN
* @license https://store.webkul.com/license.html
*/

class AdminQloappsChannelManagerConnectorController extends ModuleAdminController
{
public function __construct()
{
$this->table = 'qcmc_channel_manager_booking';
$this->className = 'QcmcChannelManagerBooking';
$this->bootstrap = true;
$this->toolbar_title = $this->l('Channel Manager Bookings');
$this->context = Context::getContext();
$this->identifier = 'id_channel_manager_booking';

parent::__construct();

$this->_join .= ' INNER JOIN `'._DB_PREFIX_.'orders` ord ON (a.id_order = ord.`id_order`)';

$this->_select .= ' ord.`source`, ord.`total_paid`, ord.`total_paid_real`, IF(a.id_order, 1, 0) badge_success';

$this->_orderWay = 'DESC';

$this->fields_list = array(
'id_order' => array(
'title' => $this->l('Id order'),
'align' => 'center',
'havingFilter' => true,
'callback' => 'getOrderLink',
),
'source' => array(
'title' => $this->l('Channel'),
'align' => 'center',
),
'total_paid' => array(
'title' => $this->l('Order total'),
'align' => 'center',
'callback' => 'setPriceCurrency',
'badge_success' => true,
),
'total_paid_real' => array(
'title' => $this->l('Recieved amount'),
'align' => 'center',
'callback' => 'setPriceCurrencyWithBadge',
),
'date_add' => array(
'title' => $this->l('Created on'),
'align' => 'center',
),
);

$this->list_no_link = true;
}

public function getOrderLink($id_order, $row)
{
$displayData = '';
if ($id_order) {
$displayData .= '#'.$id_order;
// $displayData .= '<a target="_blank" href="'.$this->context->link->getAdminLink('AdminOrders').'&id_order='.$id_order.
// '&vieworder">#'.$id_order.'</a>';
}
return $displayData;
}

public function setPriceCurrency($value, $row)
{
if (Validate::isLoadedObject($objOrder = new Order($row['id_order']))) {
return Tools::displayPrice($value, (int)$objOrder->id_currency);
}
}

public function setPriceCurrencyWithBadge($value, $row)
{
$displayData = '';
if (Validate::isLoadedObject($objOrder = new Order($row['id_order']))) {
$displayData .= '<span class="badge '.(($row['total_paid'] == $row['total_paid_real']) ? 'badge-success' : 'badge-danger').'">';
$displayData .= Tools::displayPrice($value, (int)$objOrder->id_currency);
$displayData .= '</span>';
}

return $displayData;
}

public function displayViewLink($token, $idRow, $name = null)
{
if (Validate::isLoadedObject($objChannelManagerBooking = new QcmcChannelManagerBooking($idRow))) {
return '<a class="btn btn-default" href="'.$this->context->link->getAdminLink('AdminOrders').'&id_order='.$objChannelManagerBooking->id_order.
'&vieworder" title="'.$this->l('view details').'"><i class="icon-search-plus"></i> '.$this->l('View Order Detail').'</a>';
}
}

public function renderList()
{
if ($channelManagerBookings = QcmcChannelManagerBooking::getChannelManagerBookings(0, 'DESC')) {
$this->context->smarty->assign(
array (
'icon' => 'icon-list',
'toolbar_title' => 'icon-list',
// As we get the bookings in descending order according to the date_add. So in the 0 index last booking will be found
'last_booking_datetime' => Tools::displayDate($channelManagerBookings[0]['date_add'], null, true),
)
);

// because in helper list tpl_vars is given priority and we need different List title than list title
// In HelperList.php assigned: 'title' => array_key_exists('title', $this->tpl_vars) ? $this->tpl_vars['title'] : $this->title
$this->tpl_list_vars['title'] = $this->l('Below is the list of all the bookings created by channel manager.');

unset($this->toolbar_btn['new']);

$this->addRowAction('view');

return parent::renderList();
} else {
$this->context->smarty->assign(
array (
'module_dir' => _MODULE_DIR_,
'current_datetime' => Tools::displayDate(date('Y-m-d H:i:s'), null, true),
)
);
$this->content .= $this->context->smarty->fetch(
_PS_MODULE_DIR_.
'qlochannelmanagerconnector/views/templates/admin/qloapps_channel_manager_connector/channel_manager_connect_info.tpl'
);
}
}

public function setMedia()
{
parent::setMedia();

if (QcmcChannelManagerBooking::getChannelManagerBookings()) {
$this->addCSS(_MODULE_DIR_.'qlochannelmanagerconnector/views/css/admin/wk_cm_booking_list.css');
$this->addJS(_MODULE_DIR_.'qlochannelmanagerconnector/views/js/admin/wk_cm_booking_list.js');
} else {
$this->addCSS(_MODULE_DIR_.'qlochannelmanagerconnector/views/css/admin/wk_cm_info.css');
}
}
}
29 changes: 29 additions & 0 deletions modules/qlochannelmanagerconnector/controllers/admin/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* 2010-2023 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <[email protected]>
* @copyright 2010-2023 Webkul IN
* @license https://store.webkul.com/license.html
*/

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../../../');
exit;
29 changes: 29 additions & 0 deletions modules/qlochannelmanagerconnector/controllers/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* 2010-2023 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through LICENSE.txt file inside our module
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to CustomizationPolicy.txt file inside our module for more information.
*
* @author Webkul IN
* @copyright 2010-2023 Webkul IN
* @license LICENSE.txt
*/

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../../../');
exit;
Loading