<?php
/**
 *
 * Copyright (C) Die Randgruppe GmbH
 *
 * http://www.randshop.com
 * http://www.dierandgruppe.com
 *
 * Unter der Lizenz von Die Randgruppe GmbH:
 * http://www.randshop.com/Lizenz
 *
 */

include_once('../../conf/config.inc.php');
include_once(DATEIPFAD . 'conf/db.inc.php');
include_once(DATEIPFAD . 'includes/functions.shopeinstellung.inc.php');
include_once(DATEIPFAD . 'includes/functions.artikel.inc.php');
include_once(DATEIPFAD . 'includes/functions.seo.inc.php');
include_once(DATEIPFAD . 'includes/functions.easymarketing.inc.php');

$einstellungen = GetEinstellungen('access_token', 'easymarketing');
if($_GET['shop_token'] !== getShopToken() || !$einstellungen->easymarketing->access_token) {
    header($_SERVER["SERVER_PROTOCOL"] . ' 401 Unauthorized');
    echo '<h1>Error 401 - You are not allowed to access this resource</h1>';
    exit;
}

$waehrung = GetWaehrungDetail();

$artikel = GetArtikelDetail($_GET['id']);

$resultArtikel = new stdClass();
$resultArtikel->id = intval($artikel->id);
$resultArtikel->name = $artikel->artikel_name;
$resultArtikel->categories = array();
foreach($artikel->kategorie_array as $kategorie) {
    $resultArtikel->categories[] = intval($kategorie['id']);
}
$resultArtikel->price = floatval($artikel->preis_brutto);
$resultArtikel->currency = $waehrung->isocode;
$seoUrlArray = GetSEOURLArray(array($resultArtikel->id), SEOURL_TYPE_ARTIKEL, GetDefaultLanguageID(), array());
$resultArtikel->url = GetArtikelLink($resultArtikel->id, '', '', '', '', '', '', $seoUrlArray);
$resultArtikel->description = $artikel->beschreibung;
$resultArtikel->gtin = $artikel->ean;
if($artikel->bigImage) {
    $resultArtikel->image_url = IMAGEPFAD . 'dbimages/' . $artikel->bigImage;
}

echo json_encode($resultArtikel);