<?php
/******************************************************************************/
//                                                                            //
//                             Smarty plugin                                  //
//                            @package Smarty                                 //
//							 @subpackage plugins                              //
//                        http://life-style.uz/                               //
//                   produced by Life Style, life-style.uz                    //
//                                                                            //
/******************************************************************************/

function smarty_function_fetch_product($params, &$smarty) {

	$assign        = fetch_getParam('assign', $params, 'product');
	$fields        = fetch_getParam('fields', $params, 'articleId, sectionId, publishedOn, title, alias, url, brand');
	$status        = fetch_getParam('status', $params, 'V');
	$productId     = (int) fetch_getParam('articleId', $params);

	/* conditions */
	if (!empty($status)) connect()->where('status', $status);
	if ($productId > 0) connect()->where('articleId', $productId);

    if ($product = connect()->table('products')->select($fields)->get('array')) {

        $product = prepareArticle($product);

        $product['features'] = getProductFeatureValues($product['articleId']);
        $variants = getVariants(['productId' => $product['articleId']]);
        if (!empty($variants)) {
            foreach ($variants as $variantId => &$variant) {
                $product['variants'][$variantId] = $variant;
            }
        }
    }

//	print_r($product);
	$smarty->assign($assign, $product);


	return null;
}



?>