<?php

/*
 * Smarty plugin
 * -------------------------------------------------------------
 * Type:     function
 * Name:     eval
 * Purpose:  evaluate a template variable as a template
 * -------------------------------------------------------------
 */

function smarty_function_get_cj_info($params, &$smarty)
{
    $type = '';
    $view = $params['view'];
    if (!$view) {
        return '';
    }
    if ($view instanceof \KupShop\ContentBundle\View\HomeView) {
        $type = 'homepage';
    } elseif ($view instanceof \KupShop\CatalogBundle\View\CategoryView) {
        $type = 'category';
    } elseif ($view instanceof \KupShop\ContentBundle\View\ProductView) {
        $type = 'productDetail';
    } elseif ($view instanceof \KupShop\ContentBundle\View\CartView) {
        $type = 'cart';
    } elseif ($view instanceof \KupShop\CatalogBundle\View\SearchView) {
        $type = 'searchResults';
    } elseif ($view instanceof \KupShop\UserBundle\View\UserView && $params['view']->newUser()) {
        $type = 'accountSignup';
    } elseif ($view instanceof \KupShop\UserBundle\View\LoginView) {
        $type = 'accountCenter';
    } elseif ($view instanceof \KupShop\ContentBundle\View\OrderView && $view->getTemplate() == 'ordering.success.tpl') {
        $type = 'conversionConfirmation';
    }

    if (!empty($params['assign'])) {
        $smarty->assign($params['assign'], $type);
    } else {
        return $type;
    }
}
