<?php
/**
 * @package    VP Email Manager
 * @copyright  Copyright (C) 2012-2021 VirtuePlanet Services LLP. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 * @author     Abhishek Das <info@virtueplanet.com>
 * @link       https://www.virtueplanet.com
 */

defined ('_JEXEC') or die;

use \Joomla\CMS\Factory;

class VpemHelperProductdata extends VpemHelperMustache
{
	public function __construct($data = null, $mustache = null, $constructor = null)
	{
		parent::__construct($data, $mustache, $constructor);
		
		if (!empty($this->product) && !empty($this->product->virtuemart_product_id))
		{
			$app     = Factory::getApplication();
			$isAdmin = method_exists($app, 'isClient') ? !$app->isClient('site') : $app->isAdmin();
			
			if ($isAdmin)
			{
				$menuItemID   = shopFunctionsF::getMenuItemId(vmLanguage::getLanguage()->getTag());
				$product_link = JUri::root() . 'index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $this->product->virtuemart_product_id . '&Itemid=' . $menuItemID;
			}
			else
			{
				if (!empty($this->product->link))
				{
					$product_link = JRoute::_($this->product->link, true, false, true);
				}
				else
				{
					$product_link = JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $this->product->virtuemart_product_id, true, 0, true);
				}
			}
			
			$this->product->product_url = $product_link;
			
			
			if (!empty($this->product->images))
			{
				$this->product_thumbnail = $this->product->images[0]->displayMediaThumb(['style' => 'max-width: 100%; height: auto; border: 0; outline: none;'], false, '', true, false, true);
			}
			else
			{
				$this->product_thumbnail = '';
			}
		}
		
		$this->setVendor();
	}
}