aktualizacja modułu dpd

This commit is contained in:
2026-02-02 10:46:49 +01:00
parent dfc86a1895
commit 764d54f8d5
722 changed files with 70854 additions and 1051 deletions

View File

@@ -0,0 +1,145 @@
<?php
/**
* Copyright 2024 DPD Polska Sp. z o.o.
*
* NOTICE OF LICENSE
*
* Licensed under the EUPL-1.2 or later.
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* It is also bundled with this package in the file LICENSE.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an AS IS basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* @author DPD Polska Sp. z o.o.
* @copyright 2024 DPD Polska Sp. z o.o.
* @license https://joinup.ec.europa.eu/software/page/eupl
*/
use DpdShipping\Config\Config;
if (!defined('_PS_VERSION_')) {
exit;
}
class dpdshippingPickupGetAddressAjaxModuleFrontController extends ModuleFrontController
{
public function initContent()
{
parent::initContent();
$this->ajax = true;
}
public function displayAjax()
{
if ($this->validate() === true) {
try {
$pudoAddress = $this->getPudoAddress($this->getPudoCode());
if ($pudoAddress != null) {
$response = ['success' => true, 'data' => $pudoAddress];
} else {
$response = ['success' => false, 'message' => 'Undefined error'];
}
} catch (Exception $e) {
$response = ['success' => false, 'message' => $e->getMessage()];
}
die(json_encode($response));
} else {
die(json_encode(['success' => false, 'message' => 'Undefined error']));
}
}
private function validate(): bool
{
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
die(json_encode(['success' => false, 'message' => 'Method not allowed']));
}
if ($this->getCsrf() != Tools::getToken(false)) {
die(json_encode(['success' => false, 'message' => 'Invalid token.']));
}
if ($this->getToken() != sha1(_COOKIE_KEY_ . 'dpdshipping')) {
die(json_encode(['success' => false, 'message' => 'Invalid token']));
}
if (empty($this->getPudoCode())) {
die(json_encode(['success' => false, 'message' => 'Invalid params']));
}
return true;
}
/**
* @return false|mixed
*/
public function getCsrf()
{
return Tools::getValue('dpdshipping_csrf');
}
/**
* @return false|mixed
*/
public function getToken()
{
return Tools::getValue('dpdshipping_token');
}
/**
* @return false|mixed
*/
public function getPudoCode()
{
return Tools::getValue('dpdshipping_pudo_code');
}
public function getPudoAddress($pudoCode)
{
if (empty($pudoCode)) {
return null;
}
$ch = curl_init();
$url = sprintf(Config::DPD_PUDO_WS_URL, $pudoCode);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate, sdch, br');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Encoding: gzip, deflate, sdch, br',
'Accept-Language: en-US,en;q=0.8',
'Cache-Control: max-age=0',
'Connection: keep-alive',
'Host: mypudo.dpd.com.pl',
'Upgrade-Insecure-Requests: 1',
'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
]);
$result = curl_exec($ch);
curl_close($ch);
if (!$result) {
return null;
}
$xml = new SimpleXMLElement($result);
if (!isset($xml->PUDO_ITEMS) || !isset($xml->PUDO_ITEMS->PUDO_ITEM)) {
return null;
}
return implode(', ', [
$xml->PUDO_ITEMS->PUDO_ITEM->ADDRESS1,
$xml->PUDO_ITEMS->PUDO_ITEM->ZIPCODE,
$xml->PUDO_ITEMS->PUDO_ITEM->CITY,
$xml->PUDO_ITEMS->PUDO_ITEM->PUDO_ID]);
}
}

View File

@@ -0,0 +1,145 @@
<?php
/**
* Copyright 2024 DPD Polska Sp. z o.o.
*
* NOTICE OF LICENSE
*
* Licensed under the EUPL-1.2 or later.
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* It is also bundled with this package in the file LICENSE.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an AS IS basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* @author DPD Polska Sp. z o.o.
* @copyright 2024 DPD Polska Sp. z o.o.
* @license https://joinup.ec.europa.eu/software/page/eupl
*/
use DpdShipping\Config\Config;
if (!defined('_PS_VERSION_')) {
exit;
}
class dpdshippingPickupIsCodPointAjaxModuleFrontController extends ModuleFrontController
{
public function initContent()
{
parent::initContent();
$this->ajax = true;
}
public function displayAjax()
{
if ($this->validate() === true) {
try {
$pudoAddress = $this->isPudoPointWithCod();
if ($pudoAddress != null) {
$response = ['success' => true, 'data' => $pudoAddress];
} else {
$response = ['success' => false, 'message' => 'Undefined error'];
}
} catch (Exception $e) {
$response = ['success' => false, 'message' => $e->getMessage()];
}
die(json_encode($response));
} else {
die(json_encode(['success' => false, 'message' => 'Undefined error']));
}
}
private function validate(): bool
{
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
die(json_encode(['success' => false, 'message' => 'Method not allowed']));
}
if ($this->getCsrf() != Tools::getToken(false)) {
die(json_encode(['success' => false, 'message' => 'Invalid token.']));
}
if ($this->getToken() != sha1(_COOKIE_KEY_ . 'dpdshipping')) {
die(json_encode(['success' => false, 'message' => 'Invalid token']));
}
if (empty($this->getPudoCode())) {
die(json_encode(['success' => false, 'message' => 'Invalid params']));
}
return true;
}
/**
* @return false|mixed
*/
public function getCsrf()
{
return Tools::getValue('dpdshipping_csrf');
}
/**
* @return false|mixed
*/
public function getToken()
{
return Tools::getValue('dpdshipping_token');
}
/**
* @return false|mixed
*/
public function getPudoCode()
{
return Tools::getValue('dpdshipping_pudo_code');
}
public function isPudoPointWithCod()
{
if (empty($this->getPudoCode())) {
return 0;
}
$ch = curl_init();
$url = sprintf(Config::DPD_PUDO_WS_URL, $this->getPudoCode());
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate, sdch, br');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Encoding: gzip, deflate, sdch, br',
'Accept-Language: en-US,en;q=0.8',
'Cache-Control: max-age=0',
'Connection: keep-alive',
'Host: mypudo.dpd.com.pl',
'Upgrade-Insecure-Requests: 1',
'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
]);
$result = curl_exec($ch);
curl_close($ch);
if (!$result) {
return null;
}
$xml = new SimpleXMLElement($result);
if (!isset($xml->PUDO_ITEMS) || !isset($xml->PUDO_ITEMS->PUDO_ITEM) || !isset($xml->PUDO_ITEMS->PUDO_ITEM->SERVICE_PUDO)) {
return 0;
}
if (strpos($xml->PUDO_ITEMS->PUDO_ITEM->SERVICE_PUDO, '101') !== false) {
return 1;
}
return 0;
}
}

View File

@@ -0,0 +1,124 @@
<?php
/**
* Copyright 2024 DPD Polska Sp. z o.o.
*
* NOTICE OF LICENSE
*
* Licensed under the EUPL-1.2 or later.
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* It is also bundled with this package in the file LICENSE.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an AS IS basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* @author DPD Polska Sp. z o.o.
* @copyright 2024 DPD Polska Sp. z o.o.
* @license https://joinup.ec.europa.eu/software/page/eupl
*/
if (!defined('_PS_VERSION_')) {
exit;
}
class DpdshippingPickupSavePointAjaxModuleFrontController extends ModuleFrontController
{
public function initContent()
{
parent::initContent();
$this->ajax = true;
}
public function displayAjax()
{
if ($this->validate() === true) {
try {
$db = Db::getInstance();
$idShop = (int) Context::getContext()->shop->id;
$sql = '
INSERT INTO `' . _DB_PREFIX_ . 'dpdshipping_cart_pickup` (`id_shop`, `id_cart`, `pudo_code`)
VALUES (' . $idShop . ', ' . $this->getIdCart() . ', "' . pSQL($this->getPudoCode()) . '")';
$db->execute($sql);
$response = ['success' => true, 'message' => $this->getPudoCode(), 'cart' => $this->getIdCart()];
} catch (Exception $e) {
$response = ['success' => false, 'message' => $e->getMessage()];
}
die(json_encode($response));
} else {
die(json_encode(['success' => false, 'message' => 'Undefined error']));
}
}
private function validate(): bool
{
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
die(json_encode(['success' => false, 'message' => 'Method not allowed']));
}
if ($this->getCsrf() != Tools::getToken(false)) {
die(json_encode(['success' => false, 'message' => 'Invalid token.']));
}
if ($this->getToken() != sha1(_COOKIE_KEY_ . 'dpdshipping')) {
die(json_encode(['success' => false, 'message' => 'Invalid token']));
}
if (empty($this->getPudoCode()) || empty($this->getIdCart())) {
die(json_encode(['success' => false, 'message' => 'Invalid params']));
}
$cart = new Cart($this->getIdCart());
if (!Validate::isLoadedObject($cart)) {
die(json_encode(['success' => false, 'message' => 'Cart error']));
}
if ($cart->orderExists()) {
die(json_encode(['success' => false, 'message' => 'Order exist']));
}
if (Validate::isLoadedObject($this->context->customer) && $cart->id_customer != $this->context->customer->id) {
die(json_encode(['success' => false, 'message' => 'Invalid customer']));
}
return true;
}
/**
* @return false|mixed
*/
public function getCsrf()
{
return Tools::getValue('dpdshipping_csrf');
}
/**
* @return false|mixed
*/
public function getToken()
{
return Tools::getValue('dpdshipping_token');
}
/**
* @return false|mixed
*/
public function getPudoCode()
{
return Tools::getValue('dpdshipping_pudo_code');
}
/**
* @return int
*/
public function getIdCart(): int
{
return Tools::getValue('dpdshipping_id_cart');
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* Copyright 2024 DPD Polska Sp. z o.o.
*
* NOTICE OF LICENSE
*
* Licensed under the EUPL-1.2 or later.
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* It is also bundled with this package in the file LICENSE.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an AS IS basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* @author DPD Polska Sp. z o.o.
* @copyright 2024 DPD Polska Sp. z o.o.
* @license https://joinup.ec.europa.eu/software/page/eupl
*/
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;

View File

@@ -0,0 +1,33 @@
<?php
/**
* Copyright 2024 DPD Polska Sp. z o.o.
*
* NOTICE OF LICENSE
*
* Licensed under the EUPL-1.2 or later.
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* It is also bundled with this package in the file LICENSE.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an AS IS basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* @author DPD Polska Sp. z o.o.
* @copyright 2024 DPD Polska Sp. z o.o.
* @license https://joinup.ec.europa.eu/software/page/eupl
*/
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;