716 lines
27 KiB
PHP
716 lines
27 KiB
PHP
<?php
|
|
/**
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This file is licenced under the Software License Agreement.
|
|
* With the purchase or the installation of the software in your application
|
|
* you accept the licence agreement.
|
|
*
|
|
* You must not modify, adapt or create derivative works of this source code
|
|
*
|
|
* @author PrestaHelp.com
|
|
* @copyright 2019 PrestaHelp
|
|
* @license LICENSE.txt
|
|
*/
|
|
|
|
class InpostPack
|
|
{
|
|
|
|
/**
|
|
* Sprawdzenie czy koszyk jest dodany do bazy
|
|
* @param int $id_cart
|
|
* @return array list of cart info
|
|
*/
|
|
public static function issetCart($id_cart)
|
|
{
|
|
return Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'inpostship_cart`
|
|
WHERE `id_cart` = '.(int)$id_cart);
|
|
}
|
|
|
|
/**
|
|
* Dodanie informacji o koszyku do przesyłki
|
|
* @param int $id_cart
|
|
* @param string $point
|
|
* @param int $courier
|
|
* @param $week
|
|
* @param $id_lang
|
|
* @return bool result of add data to db
|
|
*/
|
|
public static function setInpostShip($id_cart, $point, $courier, $week, $id_lang)
|
|
{
|
|
$date = date('Y-m-d H:i:s');
|
|
$cod = 0;
|
|
$carrier = new Carrier((int)$courier, (int)$id_lang);
|
|
if ((int)$carrier->id_reference == Configuration::get('INPOSTSHIP_CARRIER_2')
|
|
&& Configuration::get('INPOSTSHIP_CARRIER_PACZKOMATY_COD_SHOW') == 0) {
|
|
$cod = 1;
|
|
}
|
|
return Db::getInstance()->insert('inpostship_cart', array(
|
|
'id_cart' => (int)$id_cart,
|
|
'id_carrier' => (int)$courier,
|
|
'receiver_machine' => $point,
|
|
'cod' => $cod,
|
|
'week' => $week,
|
|
'created' => 0,
|
|
'date_add' => $date,
|
|
'date_upd' => $date,
|
|
));
|
|
}
|
|
|
|
/**
|
|
* Aktualizacja informacji o koszyku do przesyłki
|
|
* @param int $id_cart
|
|
* @param string $point
|
|
* @param $id_carrier
|
|
* @param $week
|
|
* @param $id_lang
|
|
* @return bool result of add data to db
|
|
*/
|
|
public static function updateInpostShip($id_cart, $point, $id_carrier, $week, $id_lang)
|
|
{
|
|
$date = date('Y-m-d H:i:s');
|
|
$cod = 0;
|
|
$carrier = new Carrier((int)$id_carrier, (int)$id_lang);
|
|
if ((int)$carrier->id_reference == Configuration::get('INPOSTSHIP_CARRIER_2') && Configuration::get('INPOSTSHIP_INSTALL_CARRIER_2') == 1) {
|
|
$cod = 1;
|
|
}
|
|
return Db::getInstance()->update('inpostship_cart', array(
|
|
'receiver_machine' => $point,
|
|
'id_carrier' => $id_carrier,
|
|
'date_upd' => $date,
|
|
'cod' => $cod,
|
|
'week' => $week,
|
|
), 'id_cart = '.(int)$id_cart);
|
|
}
|
|
|
|
/**
|
|
* @param int $id_cart
|
|
* @param int $courier
|
|
* @param int $id_lang
|
|
* @return bool
|
|
*/
|
|
public static function setInpostShipCourier($id_cart, $courier, $id_lang)
|
|
{
|
|
$date = date('Y-m-d H:i:s');
|
|
$cod = 0;
|
|
$carrier = new Carrier((int)$courier, (int)$id_lang);
|
|
if ((int)$carrier->id_reference == Configuration::get('INPOSTSHIP_CARRIER_4')
|
|
&& Configuration::get('INPOSTSHIP_INSTALL_CARRIER_4') == 1) {
|
|
$cod = 1;
|
|
}
|
|
return (bool)Db::getInstance()->insert('inpostship_cart', array(
|
|
'id_cart' => (int)$id_cart,
|
|
'id_carrier' => $courier,
|
|
'receiver_machine' => '',
|
|
'cod' => (int)$cod,
|
|
'created' => 0,
|
|
'date_add' => $date,
|
|
'date_upd' => $date,
|
|
));
|
|
}
|
|
|
|
/**
|
|
* @param int $id_cart
|
|
* @param int $courier
|
|
* @param int $id_lang
|
|
* @return bool
|
|
*/
|
|
public static function updateInpostShipCourier($id_cart, $courier, $id_lang)
|
|
{
|
|
$date = date('Y-m-d H:i:s');
|
|
$cod = 0;
|
|
$carrier = new Carrier((int)$courier, (int)$id_lang);
|
|
if ((int)$carrier->id_reference == Configuration::get('INPOSTSHIP_CARRIER_4')
|
|
&& Configuration::get('INPOSTSHIP_INSTALL_CARRIER_4') == 1) {
|
|
$cod = 1;
|
|
}
|
|
return (bool)Db::getInstance()->update('inpostship_cart', array(
|
|
'id_carrier' => (int)$courier,
|
|
'date_upd' => $date,
|
|
'cod' => (int)$cod,
|
|
), 'id_cart = '.(int)$id_cart);
|
|
}
|
|
|
|
/**
|
|
* Pobranie paczkomatu wg ID koszyka
|
|
* @param int $id_cart
|
|
* @return string - name of point
|
|
*/
|
|
public static function getPointByCart($id_cart)
|
|
{
|
|
return Db::getInstance()->getValue('SELECT `receiver_machine` FROM `'._DB_PREFIX_.'inpostship_cart`
|
|
WHERE `id_cart` = '.(int)$id_cart);
|
|
}
|
|
|
|
/**
|
|
* Pobranie informacji o utworzonej przesyłce
|
|
* @param type $id_cart
|
|
* @return array of pack info
|
|
*/
|
|
public static function getInpostShip($id_cart)
|
|
{
|
|
return Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'inpostship` WHERE `id_cart` = '.(int)$id_cart);
|
|
}
|
|
|
|
/**
|
|
* Pobranie informacji o utworzonej przesyłce
|
|
* @param int $id_pack
|
|
* @return array of pack info
|
|
*/
|
|
public static function getInpostShipByIdPack($id_pack)
|
|
{
|
|
return Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'inpostship` WHERE `id_pack` = '.(int)$id_pack);
|
|
}
|
|
|
|
/**
|
|
* Pobranie informacji o dodanym koszyku
|
|
* @param $id
|
|
* @return array of cart
|
|
*/
|
|
public static function getInpostShipCart($id)
|
|
{
|
|
return Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'inpostship_cart` WHERE `id_cart` = '.(int)$id);
|
|
}
|
|
|
|
/**
|
|
* Aktualizacja informacji o utworzonej paczce dla danego koszyka
|
|
* @param int $id_cart - Shop cart ID
|
|
* @return bool
|
|
*/
|
|
public static function updateCreatedCart($id_cart)
|
|
{
|
|
return (bool)Db::getInstance()->update('inpostship_cart', array(
|
|
'created' => 1,
|
|
'date_upd' => date('Y-m-d H:i:s'),
|
|
), 'id_cart = '.(int)$id_cart);
|
|
}
|
|
|
|
/**
|
|
* Pobranie listy koszyków z niewygenerowanymi paczkami
|
|
* @return array|bool|mysqli_result|PDOStatement|resource|null
|
|
*/
|
|
public static function getNewPack()
|
|
{
|
|
return Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'inpostship_cart` WHERE `created` = 0 ORDER BY `date_add` DESC');
|
|
}
|
|
|
|
/**
|
|
* Utworzenie przesyłki w bazie danych
|
|
* @param int $id_order
|
|
* @param string $email
|
|
* @param number $phone
|
|
* @param string $packtype
|
|
* @param string $sendtype
|
|
* @param string $machine
|
|
* @param int $insurance
|
|
* @param double $cod_value
|
|
* @param array $sizes
|
|
* @return bool
|
|
*/
|
|
public static function setInpostPackage($id_order, $email, $phone, $packtype, $sendtype, $machine, $insurance, $cod_value = null, $sizes = array())
|
|
{
|
|
$cod_values = '';
|
|
$cod = 0;
|
|
if ($cod_value != '') {
|
|
$cod = 1;
|
|
$cod_values = $cod_value;
|
|
}
|
|
$size = '';
|
|
if (!empty($sizes)) {
|
|
$size = implode('x', $sizes);
|
|
}
|
|
return (bool)Db::getInstance()->insert('inpostship', array(
|
|
'id_order' => (int)$id_order,
|
|
'sendtype' => $sendtype,
|
|
'packtype' => $packtype,
|
|
'receiver_email' => $email,
|
|
'receiver_mobile' => $phone,
|
|
'receiver_machine' => $machine,
|
|
'insurance' => $insurance,
|
|
'executes' => 1,
|
|
'cod' => $cod,
|
|
'cod_value' => $cod_values,
|
|
'sizes' => $size,
|
|
'date_add' => date('Y-m-d H:i:s'),
|
|
'date_upd' => date('Y-m-d H:i:s'),
|
|
));
|
|
}
|
|
|
|
/**
|
|
* Aktualizacja danych do przesyłki - status oraz kod paczki
|
|
* @param int $id_pack
|
|
* @param string $status
|
|
* @param int $id
|
|
* @return bool
|
|
*/
|
|
public static function updateInpostShipped($id_pack, $status, $id)
|
|
{
|
|
return (bool)Db::getInstance()->update('inpostship', array(
|
|
'status' => $status,
|
|
'packcode' => $id,
|
|
'executes' => 1,
|
|
'status_date' => date('Y-m-d H:i:s'),
|
|
'date_upd' => date('Y-m-d H:i:s'),
|
|
), 'id_pack = '.(int)$id_pack);
|
|
}
|
|
|
|
/**
|
|
* Aktualizacja danych o przesyłce = status oraz ID oferty
|
|
* @param type $id_pack
|
|
* @param type $status
|
|
* @param type $offer_id
|
|
* @return bool
|
|
*/
|
|
public static function updateInpostOffer($id_pack, $status, $offer_id)
|
|
{
|
|
$date = date('Y-m-d H:i:s');
|
|
return (bool)Db::getInstance()->update('inpostship', array(
|
|
'status' => $status,
|
|
'offer_id' => $offer_id,
|
|
'executes' => 2,
|
|
'status_date' => $date,
|
|
'date_upd' => $date,
|
|
), 'id_pack = '.(int)$id_pack);
|
|
}
|
|
|
|
/**
|
|
* Aktualizacja danych o przesyłce
|
|
* @param int $id_pack
|
|
* @param int $id_order
|
|
* @param int $id_employee
|
|
* @param string $status
|
|
* @param number $tracking_number
|
|
* @return bool
|
|
*/
|
|
public static function updateInpostBuy($id_pack, $id_order, $id_employee, $status, $tracking_number, $subject, $module)
|
|
{
|
|
$date = date('Y-m-d H:i:s');
|
|
if (Configuration::get('INPOSTSHIP_TRACKING_SAVE') == 1) {
|
|
Db::getInstance()->update('order_carrier', array(
|
|
'tracking_number' => $tracking_number
|
|
), 'id_order = '.(int)$id_order);
|
|
}
|
|
if (Configuration::get('INPOSTSHIP_ORDER_STATUS_CHANGE') == 1) {
|
|
$history = new OrderHistory();
|
|
$history->id_order = (int)$id_order;
|
|
$history->id_employee = (int)$id_employee;
|
|
$history->changeIdOrderState((int)Configuration::get('INPOSTSHIP_ORDER_STATUS'), $id_order);
|
|
$history->addWithemail(true, array());
|
|
}
|
|
if (Configuration::get('INPOSTSHIP_SEND_TRACKING') == 1) {
|
|
InpostPack::sendTrackingEmail((int)$id_order, (int)$id_pack, $tracking_number, $subject, $module);
|
|
}
|
|
return (bool)Db::getInstance()->update('inpostship', array(
|
|
'status' => $status,
|
|
'reference_number' => $tracking_number,
|
|
'executes' => 3,
|
|
'status_date' => $date,
|
|
'date_upd' => $date,
|
|
), 'id_pack = '.(int)$id_pack);
|
|
}
|
|
|
|
/**
|
|
* Zmiana statusu paczki
|
|
* @param int $id_pack
|
|
* @return bool
|
|
*/
|
|
public static function updateInpostBuyInfo($id_pack)
|
|
{
|
|
$date = date('Y-m-d H:i:s');
|
|
return (bool)Db::getInstance()->update('inpostship', array(
|
|
'executes' => 4,
|
|
'date_upd' => $date,
|
|
), 'id_pack = '.(int)$id_pack);
|
|
}
|
|
|
|
/**
|
|
* Pobranie wsystkich paczek do zamówienia
|
|
* @param int $id_order
|
|
* @return array of package list
|
|
*/
|
|
public static function getOrderPackageList($id_order)
|
|
{
|
|
return Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'inpostship`
|
|
WHERE `id_order` = '.(int)$id_order.' ORDER BY `date_add` DESC');
|
|
}
|
|
|
|
/**
|
|
* Pobranie wsystkich paczek
|
|
* @return array of list
|
|
*/
|
|
public static function getAllPackageList()
|
|
{
|
|
return Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'inpostship` ORDER BY `date_add` DESC');
|
|
}
|
|
|
|
/**
|
|
* Pobieranie paczek, które mają status inny niż dostarczono/0
|
|
* @return mixed
|
|
*/
|
|
public static function getAllNotDeliveredPackageList($debug = false)
|
|
{
|
|
if ($debug) {
|
|
return Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'inpostship` ORDER BY `date_add` DESC');
|
|
}
|
|
return Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'inpostship` WHERE `statue` is null OR (`statue` != "delivered" AND `statue` != "--") ORDER BY `date_add` DESC');
|
|
}
|
|
|
|
/**
|
|
* Pobranie listy paczek - paginacja
|
|
* @param $start
|
|
* @param $limit
|
|
* @return mixed
|
|
*/
|
|
public static function getPaginPackageList($start, $limit, $filter = array())
|
|
{
|
|
if (empty($filter)) {
|
|
return Db::getInstance()->executeS('SELECT * FROM `' . _DB_PREFIX_ . 'inpostship` ORDER BY `date_add` DESC LIMIT ' . (int)$start . ', ' . (int)$limit);
|
|
} else {
|
|
$filter_usluga = $filter['orderFilter_country_usluga'];
|
|
$filter_nadanie = $filter['orderFilter_country_nadanie'];
|
|
$filter_id = $filter['orderFilter_id_inpost'];
|
|
$filter_order = $filter['orderFilter_id_order'];
|
|
$filter_customer = $filter['orderFilter_customer'];
|
|
$filter_tracking = $filter['orderFilter_tracking'];
|
|
|
|
$where = array();
|
|
if (!empty($filter_id)) {
|
|
$where[] = 'packcode = '.(int)$filter_id;
|
|
}
|
|
if (!empty($filter_order)) {
|
|
$where[] = 'id_order = '.(int)$filter_order;
|
|
}
|
|
if (!empty($filter_customer)) {
|
|
|
|
$ino = '';
|
|
$customers = Customer::searchByName($filter_customer);
|
|
$idc = array();
|
|
if (!empty($customers)) {
|
|
foreach ($customers as $customer) {
|
|
$orders = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'orders` WHERE `id_customer` = '.(int)$customer['id_customer']);
|
|
if (!empty($orders)) {
|
|
foreach ($orders as $order) {
|
|
$idc[] = $order['id_order'];
|
|
}
|
|
}
|
|
}
|
|
if (!empty($idc)) {
|
|
$ino = implode(',', $idc);
|
|
}
|
|
}
|
|
$where[] = 'id_order IN ('.$ino.')';
|
|
}
|
|
if (!empty($filter_tracking)) {
|
|
$where[] = 'reference_number LIKE "%'.(int)$filter_tracking.'%"';
|
|
}
|
|
if (!empty($filter_nadanie)) {
|
|
$sendtype = 'parcel_locker';
|
|
switch ($filter_nadanie) {
|
|
case 1:$sendtype = 'dispatch_order';break;
|
|
case 2:$sendtype = 'parcel_locker';break;
|
|
case 3:$sendtype = 'pop';break;
|
|
default:$sendtype = 'parcel_locker';break;
|
|
}
|
|
$where[] = 'sendtype = "'.$sendtype.'"';
|
|
}
|
|
|
|
$whereSql = '';
|
|
if (!empty($where)) {
|
|
$whereSql = 'WHERE ';
|
|
foreach ($where as $key => $w) {
|
|
$whereSql .= ($key == 0 ? '' : ' AND ').$w;
|
|
}
|
|
}
|
|
|
|
$result = Db::getInstance()->executeS('SELECT * FROM `' . _DB_PREFIX_ . 'inpostship` '.$whereSql.' ORDER BY `date_add` DESC LIMIT ' . (int)$start . ', ' . (int)$limit);
|
|
if (!empty($result)) {
|
|
foreach ($result as $key => $item) {
|
|
if (!empty($filter_usluga)) {
|
|
$order = new Order($item['id_order']);
|
|
$id_cart = (int)$order->id_cart;
|
|
$inpost_cart = InpostPack::getInpostShipCart((int)$id_cart);
|
|
$c1 = Configuration::get('INPOSTSHIP_CARRIER_1');
|
|
$c1i = Configuration::get('INPOSTSHIP_INSTALL_CARRIER_1');
|
|
$c2 = Configuration::get('INPOSTSHIP_CARRIER_2');
|
|
$c2i = Configuration::get('INPOSTSHIP_INSTALL_CARRIER_2');
|
|
$c3 = Configuration::get('INPOSTSHIP_CARRIER_3');
|
|
$c3i = Configuration::get('INPOSTSHIP_INSTALL_CARRIER_3');
|
|
$c4 = Configuration::get('INPOSTSHIP_CARRIER_4');
|
|
$c4i = Configuration::get('INPOSTSHIP_INSTALL_CARRIER_4');
|
|
$c5 = Configuration::get('INPOSTSHIP_CARRIER_5');
|
|
$c6 = Configuration::get('INPOSTSHIP_CARRIER_6');
|
|
$service = 0;
|
|
$c_type = 0;
|
|
$id_carrier = (int)$inpost_cart['id_carrier'];
|
|
if ($id_carrier != $order->id_carrier) {
|
|
$id_carrier = (int)$order->id_carrier;
|
|
}
|
|
$carrier = new Carrier((int)$id_carrier);
|
|
$cref = $carrier->id_reference;
|
|
if ($c1i == 1) {
|
|
if ($cref == $c1) {
|
|
$service = 1; // Inpost paczkomaty
|
|
}
|
|
}
|
|
if ($c2i == 1) {
|
|
if ($cref == $c2) {
|
|
$service = 1; // Inpost paczkomaty
|
|
$c_type = 1; // za pobraniem
|
|
}
|
|
}
|
|
if ($c3i == 1) {
|
|
if ($c3 == $cref) {
|
|
$service = 2; // kurier
|
|
}
|
|
}
|
|
if ($c4i == 1) {
|
|
if ($c4 == $cref) {
|
|
$service = 2; // kurier
|
|
$c_type = 1; // za pobraniem
|
|
}
|
|
}
|
|
if ($c5 == $cref) {
|
|
$service = 5; // Paczkomaty PwW
|
|
}
|
|
if ($c6 == $cref) {
|
|
$service = 6; // Paczkomaty PwW
|
|
$c_type = 1; // za pobraniem
|
|
}
|
|
switch ($filter_usluga) {
|
|
case 1:
|
|
// paczkomaty
|
|
if ($service == 1 && $c_type == 0) {
|
|
|
|
} else {
|
|
unset($result[$key]);
|
|
}
|
|
break;
|
|
case 2:
|
|
// paczkomaty za pobraniem
|
|
if ($service == 1 && $c_type == 1) {
|
|
|
|
} else {
|
|
unset($result[$key]);
|
|
}
|
|
break;
|
|
case 3:
|
|
// kurier
|
|
if ($service == 2 && $c_type == 0) {
|
|
|
|
} else {
|
|
unset($result[$key]);
|
|
}
|
|
break;
|
|
case 4:
|
|
// kurier za pobraniem
|
|
if ($service == 2 && $c_type == 1) {
|
|
|
|
} else {
|
|
unset($result[$key]);
|
|
}
|
|
break;
|
|
case 5:
|
|
// paczkomat pww
|
|
if ($service == 5 && $c_type == 0) {
|
|
|
|
} else {
|
|
unset($result[$key]);
|
|
}
|
|
break;
|
|
case 6:
|
|
// paczkomaty pww za pobraniem
|
|
if ($service == 6 && $c_type == 1) {
|
|
|
|
} else {
|
|
unset($result[$key]);
|
|
}
|
|
break;
|
|
case 7:
|
|
// brak danych
|
|
if ($service == 0) {
|
|
|
|
} else {
|
|
unset($result[$key]);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Usunięcie paczki z bazy
|
|
* @param int $id_pack
|
|
* @return bool
|
|
*/
|
|
public static function deletePackById($id_pack)
|
|
{
|
|
return (bool)Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'inpostship`
|
|
WHERE `id_pack` = '.(int)$id_pack);
|
|
}
|
|
|
|
/**
|
|
* Aktualizacja numeru zamówienia kuriera dla paczki
|
|
* @param int $id_pack
|
|
* @param int $dispatch_id
|
|
* @return bool
|
|
*/
|
|
public static function updateDispatchId($id_pack, $dispatch_id)
|
|
{
|
|
return (bool)Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'inpostship`
|
|
SET `dispatch_id` = "'.(int)$dispatch_id.'" WHERE `id_pack` = '.(int)$id_pack);
|
|
}
|
|
|
|
/**
|
|
* Wysyłka wiadomości e-mail z numerem śledzenia zamówienia
|
|
* @param int $id_order
|
|
* @param number $tracking_number
|
|
*/
|
|
public static function sendTrackingEmail($id_order, $id_pack, $tracking_number, $subject, $module)
|
|
{
|
|
$order = new Order((int)$id_order);
|
|
$ship = InpostPack::getInpostShipByIdPack((int)$id_pack);
|
|
if (!empty($ship['receiver_machine'])) {
|
|
$configuration = Configuration::getMultiple(array(
|
|
'PS_SHOP_EMAIL',
|
|
'PS_MAIL_METHOD',
|
|
'PS_MAIL_SERVER',
|
|
'PS_MAIL_USER',
|
|
'PS_MAIL_PASSWD',
|
|
'PS_SHOP_NAME'
|
|
));
|
|
$customer = new Customer($order->id_customer);
|
|
$point = InpostPoint::getPointInfo($ship['receiver_machine']);
|
|
$id_lang = (int)Context::getContext()->language->id;
|
|
$id_carrier = (int)$order->id_carrier;
|
|
$carrier = new Carrier((int)$id_carrier, $id_lang);
|
|
$template = 'tracking';
|
|
$template_vars = array(
|
|
'{point_code}' => $point['point_code'],
|
|
'{point_address}' => $point['point_address1'].', '.$point['point_address2'],
|
|
'{point_description}' => $point['point_desc'],
|
|
'{point_lat}' => $point['point_lat'],
|
|
'{point_lng}' => $point['point_lng'],
|
|
'{firstname}' => $customer->firstname,
|
|
'{lastname}' => $customer->lastname,
|
|
'{tracking_url}' => 'https://inpost.pl/sledzenie-przesylek?number='.$tracking_number,
|
|
'{inpost_tracking_url}' => 'https://inpost.pl/sledzenie-przesylek',
|
|
'{tracking_number}' => $tracking_number,
|
|
'{carrier}' => $carrier->name,
|
|
'{id_order}' => $order->id,
|
|
'{order_reference}' => $order->reference,
|
|
'{order_total}' => $order->total_paid
|
|
);
|
|
$iso = Language::getIsoById($id_lang);
|
|
if (file_exists(dirname(__FILE__).'/../mails/'.$iso.'/'.$template.'.txt')
|
|
&& file_exists(dirname(__FILE__).'/../mails/'.$iso.'/'.$template.'.html')) {
|
|
Mail::Send($id_lang, $template, $subject, $template_vars, $customer->email, null, $configuration['PS_SHOP_EMAIL'], $configuration['PS_SHOP_NAME'], null, null, dirname(__FILE__).'/../mails/');
|
|
}
|
|
} // end parcel_locker
|
|
}
|
|
|
|
/**
|
|
* Wysyłka wiadomości e-mail z modułu
|
|
* @param int $id_order
|
|
*/
|
|
public static function sendPointEmail($id_order, $subject, $module)
|
|
{
|
|
$order = new Order((int)$id_order);
|
|
$ship = InpostPack::issetCart((int)$order->id_cart);
|
|
if (!empty($ship['receiver_machine'])) {
|
|
$configuration = Configuration::getMultiple(array(
|
|
'PS_SHOP_EMAIL',
|
|
'PS_MAIL_METHOD',
|
|
'PS_MAIL_SERVER',
|
|
'PS_MAIL_USER',
|
|
'PS_MAIL_PASSWD',
|
|
'PS_SHOP_NAME'
|
|
));
|
|
$customer = new Customer($order->id_customer);
|
|
$point = InpostPoint::getPointInfo($ship['receiver_machine']);
|
|
$id_lang = (int)Context::getContext()->language->id;
|
|
$id_carrier = (int)$order->id_carrier;
|
|
$carrier = new Carrier((int)$id_carrier, $id_lang);
|
|
|
|
$ion = Configuration::get('INPOSTSHIP_ORDER_NUMBER', 1);
|
|
$order_number = $order->id;
|
|
if ($ion == 2) {
|
|
$order_number = $order->reference;
|
|
}
|
|
|
|
$template_vars = array(
|
|
'{point_code}' => $point['point_code'],
|
|
'{point_address}' => $point['point_address1'].', '.$point['point_address2'],
|
|
'{point_description}' => $point['point_desc'],
|
|
'{point_lat}' => $point['point_lat'],
|
|
'{point_lng}' => $point['point_lng'],
|
|
'{firstname}' => $customer->firstname,
|
|
'{lastname}' => $customer->lastname,
|
|
'{carrier}' => $carrier->name,
|
|
'{id_order}' => $order->id,
|
|
'{order_reference}' => $order->reference,
|
|
'{order_total}' => $order->total_paid,
|
|
'{order_number}' => $order_number
|
|
);
|
|
$iso = Language::getIsoById($id_lang);
|
|
if (Configuration::get('INPOSTSHIP_SEND_POINT_CUSTOMER') == 1) {
|
|
$template = 'point_customer';
|
|
if (file_exists(dirname(__FILE__).'/../mails/'.$iso.'/'.$template.'.txt')
|
|
&& file_exists(dirname(__FILE__).'/../mails/'.$iso.'/'.$template.'.html')) {
|
|
Mail::Send($id_lang, $template, $subject, $template_vars, $customer->email, null, $configuration['PS_SHOP_EMAIL'], $configuration['PS_SHOP_NAME'], null, null, dirname(__FILE__).'/../mails/');
|
|
}
|
|
}
|
|
if (Configuration::get('INPOSTSHIP_SEND_POINT_ADMIN') == 1) {
|
|
$template2 = 'point_admin';
|
|
if (file_exists(dirname(__FILE__).'/../mails/'.$iso.'/'.$template2.'.txt')
|
|
&& file_exists(dirname(__FILE__).'/../mails/'.$iso.'/'.$template2.'.html')) {
|
|
Mail::Send($id_lang, $template2, $subject, $template_vars, $configuration['PS_SHOP_EMAIL'], null, $configuration['PS_SHOP_EMAIL'], $configuration['PS_SHOP_NAME'], null, null, dirname(__FILE__).'/../mails/');
|
|
}
|
|
}
|
|
} // end receiver_machine
|
|
}
|
|
|
|
/**
|
|
* @param $id_cart
|
|
* @param $machineName
|
|
* @param $order
|
|
*/
|
|
public static function changeReceiverMachine($id_cart, $machineName, $order)
|
|
{
|
|
if (!empty(InpostPack::issetCart((int)$id_cart))) {
|
|
Db::getInstance()->update('inpostship_cart', array(
|
|
'receiver_machine' => $machineName
|
|
), '`id_cart` = '.(int)$id_cart);
|
|
} else {
|
|
Db::getInstance()->insert('inpostship_cart', array(
|
|
'id_cart' => (int)$id_cart,
|
|
'receiver_machine' => $machineName,
|
|
'id_carrier' => $order->id_carrier,
|
|
'cod' => 0,
|
|
'date_add' => date('Y-m-d H:i:s'),
|
|
'date_upd' => date('Y-m-d H:i:s'),
|
|
));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param $id_customer
|
|
* @return mixed
|
|
*/
|
|
public static function getCustomerPackage($id_customer)
|
|
{
|
|
return Db::getInstance()->executeS('SELECT i.* FROM `'._DB_PREFIX_.'inpostship` i LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = i.`id_order` WHERE o.`id_customer` = '.(int)$id_customer);
|
|
}
|
|
|
|
public static function setCurrentStatePack($id_pack, $state)
|
|
{
|
|
return Db::getInstance()->update('inpostship', array(
|
|
'statue' => $state
|
|
), 'id_pack = '.(int)$id_pack);
|
|
}
|
|
|
|
}
|