47 lines
1.9 KiB
PHP
47 lines
1.9 KiB
PHP
<?php
|
|
|
|
require_once __DIR__.'/../../classes/InpostPack.php';
|
|
require_once __DIR__.'/../../classes/ShipX.php';
|
|
|
|
class inpostshipcustomerPointModuleFrontController extends ModuleFrontController
|
|
{
|
|
|
|
public function initContent()
|
|
{
|
|
parent::initContent();
|
|
$id_customer = (int)$this->context->customer->id;
|
|
$customer_points = array();
|
|
$return = array();
|
|
if ($id_customer > 0) {
|
|
$carts = Db::getInstance()->executeS('SELECT `id_cart` FROM `'._DB_PREFIX_.'cart` WHERE `id_customer` = '.(int)$id_customer);
|
|
$cart_list = array();
|
|
if (!empty($carts)) {
|
|
foreach ($carts as $cart) {
|
|
$cartInpost = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'inpostship_cart` WHERE `id_cart` = '.(int)$cart['id_cart']);
|
|
if (!empty($cartInpost)) {
|
|
$cart_list[] = $cartInpost['receiver_machine'];
|
|
}
|
|
}
|
|
}
|
|
if (!empty($cart_list)) {
|
|
$cart_list = array_unique($cart_list);
|
|
if (!empty($cart_list)) {
|
|
$inpostapi = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX'), $this->debug);
|
|
foreach ($cart_list as $key => $item) {
|
|
$point = $inpostapi->getPointInfo($item);
|
|
if (!empty($point->name)) {
|
|
$customer_points[$key]['name'] = $point->name;
|
|
$customer_points[$key]['address'] = $point->address->line1 . ' ' . $point->address->line2;
|
|
$customer_points[$key]['desc'] = $point->location_description;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$return['points'] = $customer_points;
|
|
echo json_encode($return);
|
|
exit();
|
|
}
|
|
|
|
}
|