first commit
This commit is contained in:
240
modules/epaka/src/EpakaDB.php
Normal file
240
modules/epaka/src/EpakaDB.php
Normal file
@@ -0,0 +1,240 @@
|
||||
<?php
|
||||
class EpakaDB
|
||||
{
|
||||
public static function addAdminController($className, $module, $position = 1)
|
||||
{
|
||||
if(Tab::getIdFromClassName($className) === false){
|
||||
$sql = "INSERT INTO ". _DB_PREFIX_ ."tab
|
||||
(id_tab, id_parent, class_name, module, position, active, hide_host_mode)
|
||||
VALUES (NULL, '-1', '".pSQL($className)."', '".pSQL($module)."' , '".$position."', '1', '0')";
|
||||
return Db::getInstance()->execute($sql);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function createTable($tableName, $columnsArr, $primaryKeys = null, $engineDb, $charset = 'utf8', $collate = 'utf8_general_ci')
|
||||
{
|
||||
$query = 'CREATE TABLE IF NOT EXISTS '._DB_PREFIX_.$tableName.'(';
|
||||
$i = 0;
|
||||
foreach ($columnsArr as $column => $values){
|
||||
$i++;
|
||||
$query .= $column.' '.$values;
|
||||
if ($i < count($columnsArr)) {
|
||||
$query .= ', ';
|
||||
}
|
||||
}
|
||||
if (!empty($primaryKeys)) {
|
||||
$query .= ', PRIMARY KEY ('.implode(',',$primaryKeys ).'))';
|
||||
} else {
|
||||
$query .= ')';
|
||||
}
|
||||
$query .= 'ENGINE = '.pSQL($engineDb);
|
||||
$query .= ' CHARSET = '.pSQL($charset);
|
||||
$query .= ' COLLATE = '.pSQL($collate);
|
||||
|
||||
return DB::getInstance()->execute($query);
|
||||
}
|
||||
|
||||
public static function dropTable($tableName)
|
||||
{
|
||||
$query = 'DROP TABLE IF EXISTS '._DB_PREFIX_.$tableName.';';
|
||||
return DB::getInstance()->execute($query);
|
||||
}
|
||||
|
||||
public static function deleteFromTable($tableName, $columnName, $value)
|
||||
{
|
||||
$query = 'DELETE FROM '._DB_PREFIX_.$tableName.' WHERE '.$columnName.'="'.$value.'";';
|
||||
return DB::getInstance()->execute($query);
|
||||
}
|
||||
|
||||
public static function existsTable($tableName)
|
||||
{
|
||||
$query = 'SELECT 1 FROM '._DB_PREFIX_.$tableName.' LIMIT 1;';
|
||||
try {
|
||||
$result = DB::getInstance()->execute($query);
|
||||
} catch (PrestaShopException $e) {
|
||||
$result = false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getCourriers($type = null)
|
||||
{
|
||||
$sql = new DbQuery();
|
||||
$sql->select('*');
|
||||
$sql->from('epaka_carriers', 'ec');
|
||||
if (!empty($type)) {
|
||||
$sql->where('delivery_type = '.$type);
|
||||
}
|
||||
$result = Db::getInstance()->executeS($sql);
|
||||
// $array = array();
|
||||
// foreach ($result as $row) {
|
||||
// $array[$row['machine']] = $row['id_machine_type'];
|
||||
// }
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getCourriersRelations($idPresta = null, $idEpaka = null)
|
||||
{
|
||||
$sql = new DbQuery();
|
||||
$sql->select('*');
|
||||
$sql->from('epaka_carriers_relations', 'ecr');
|
||||
if (!empty($idPresta)) {
|
||||
$sql->where('ecr.prestashop_id = '.$idPresta.'');
|
||||
}
|
||||
if (!empty($idEpaka)) {
|
||||
$sql->where('ecr.epaka_id = '.$idEpaka.'');
|
||||
}
|
||||
$result = Db::getInstance()->executeS($sql);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function clearCourriersRelations()
|
||||
{
|
||||
return Db::getInstance()->delete('epaka_carriers_relations');
|
||||
}
|
||||
|
||||
public static function addCourriersRelation($idPresta, $idEpaka, $epakaCariers = null)
|
||||
{
|
||||
if (empty($epakaCariers)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// polaczone z epaka.pl
|
||||
if (!empty($idEpaka)) {
|
||||
foreach ($epakaCariers as $eCTmp) {
|
||||
if ($eCTmp->courierId == $idEpaka) {
|
||||
if (!empty((array)$eCTmp->courierMapSourceId) && $eCTmp->courierPointDelivery == "1") {
|
||||
$epakaCarrierDeliveryType = 'p2p';
|
||||
} else {
|
||||
$epakaCarrierDeliveryType = 'd2d';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// NIE polaczone z epaka.pl
|
||||
else {
|
||||
$epakaCarrierDeliveryType = 'onp';
|
||||
}
|
||||
|
||||
return Db::getInstance()->insert('epaka_carriers_relations', array(
|
||||
'prestashop_id' => (int)$idPresta, 'epaka_id' => (int)$idEpaka, 'epaka_carrier_delivery_type' => $epakaCarrierDeliveryType
|
||||
));
|
||||
}
|
||||
|
||||
public static function getBasketDelivery($idCart = null)
|
||||
{
|
||||
$result = false;
|
||||
|
||||
$sql = new DbQuery();
|
||||
$sql->select('*');
|
||||
$sql->from('epaka_delivery', 'ed');
|
||||
|
||||
if (!empty($idCart)) {
|
||||
$sql->where('id_cart = '.(int)$idCart);
|
||||
$result = Db::getInstance()->getRow($sql);
|
||||
} else {
|
||||
$result = Db::getInstance()->executeS($sql);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/* public static function getCarrierTypes($id_carrier_prestashop = null)
|
||||
{
|
||||
$sql = new DbQuery();
|
||||
$sql->select('ec.epaka_id, ec.epaka_name, ec.epaka_name_short, c.id_carrier as presta_id, c.name as presta_name');
|
||||
$sql->from('epaka_carriers_relations', 'ecr');
|
||||
$sql->innerJoin('epaka_carriers', 'ec', 'ecr.epaka_id = ec.epaka_id');
|
||||
$sql->innerJoin(
|
||||
'carrier',
|
||||
'c',
|
||||
'c.id_carrier = ecr.prestashop_id AND active = 1 AND deleted = 0');
|
||||
|
||||
if (!empty($id_carrier_prestashop)) {
|
||||
$sql->where('ecr.prestashop_id = '.$id_carrier_prestashop);
|
||||
}
|
||||
|
||||
$result = Db::getInstance()->executeS($sql);
|
||||
|
||||
if(empty($result)){
|
||||
return array();
|
||||
}
|
||||
|
||||
return $result;
|
||||
} */
|
||||
|
||||
public static function getCarrierByShort($short)
|
||||
{
|
||||
$sql = new DbQuery();
|
||||
$sql->select('*');
|
||||
$sql->from('epaka_carriers', 'ec');
|
||||
$sql->where('ec.epaka_name_short LIKE "'.$short.'"');
|
||||
|
||||
return Db::getInstance()->getRow($sql);
|
||||
}
|
||||
|
||||
public static function checkIfIsOrderReferenceIsOK($id_cart = null, $id_carrier_prestashop = null, $id_carrier_epaka = null)
|
||||
{
|
||||
$sql = new DbQuery();
|
||||
$sql->select('*');
|
||||
$sql->from('epaka_delivery', 'ed');
|
||||
if (!empty($id_cart)) {
|
||||
$sql->where('ed.id_cart = '.$id_cart.'');
|
||||
}
|
||||
if (!empty($id_carrier_prestashop)) {
|
||||
$sql->where('ed.id_carrier_prestashop = '.$id_carrier_prestashop.'');
|
||||
}
|
||||
if (!empty($id_carrier_epaka)) {
|
||||
$sql->where('ed.id_carrier_epaka = '.$id_carrier_epaka.'');
|
||||
}
|
||||
|
||||
return Db::getInstance()->getRow($sql);
|
||||
}
|
||||
|
||||
public static function addEpakaId($id_cart = null, $id_epaka_order = null)
|
||||
{
|
||||
$sql = 'UPDATE '._DB_PREFIX_.'epaka_delivery';
|
||||
$sql .= ' SET id_epaka_order = '.pSQL($id_epaka_order);
|
||||
$sql .= ' WHERE id_cart = '.pSQL($id_cart);
|
||||
$sql .= ';';
|
||||
|
||||
return DB::getInstance()->execute($sql);
|
||||
}
|
||||
|
||||
public static function delEpakaId($id_cart = null)
|
||||
{
|
||||
$sql = 'UPDATE '._DB_PREFIX_.'epaka_delivery';
|
||||
$sql .= ' SET id_epaka_order = NULL';
|
||||
$sql .= ' WHERE id_cart = '.pSQL($id_cart);
|
||||
$sql .= ';';
|
||||
|
||||
return DB::getInstance()->execute($sql);
|
||||
}
|
||||
|
||||
public static function insertRelation($id_cart, $id_carrier_prestashop, $id_carrier_epaka, $point_code = null, $point_name = null, $id_epaka_order = null)
|
||||
{
|
||||
$insertData = [
|
||||
'id_cart' => $id_cart,
|
||||
'id_carrier_prestashop' => $id_carrier_prestashop,
|
||||
'id_carrier_epaka' => $id_carrier_epaka,
|
||||
'point_code' => $point_code,
|
||||
'point_name' => $point_name,
|
||||
'id_epaka_order' => $id_epaka_order
|
||||
];
|
||||
|
||||
return Db::getInstance()->insert('epaka_delivery',$insertData, false, true, Db::ON_DUPLICATE_KEY);;
|
||||
}
|
||||
|
||||
public static function getUnfinishedPrestaOrders()
|
||||
{
|
||||
$sql = 'SELECT * FROM '._DB_PREFIX_.'orders';
|
||||
$sql .= ' WHERE current_state <> 4'; // 4 -Dostarczane;
|
||||
$sql .= ';';
|
||||
|
||||
return DB::getInstance()->executeS($sql);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user