<?php

namespace OfficeBrain\CustomBundle\ProductBundle\Manager\AbstractManager;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerInterface as Container;
use OfficeBrain\Bundle\ProductBundle\Manager\AbstractManager\ProductAbstract as BaseProductAbstract;

abstract class ProductAbstract extends BaseProductAbstract
{
    protected $request;
    protected $productApi;
    protected $serviceContainer;
    protected $productBreadCrumbArray;
    protected $flag;
    protected $paginatorManager;
    
	/**
	 * @author Employee Id: 4464
	 * OB eCommerce Product - Product Info Abstract class
	 * Initialize the required variable on class load
	 */
	public function __construct($request, $productApi, $serviceContainer, $commonLibraryManager, $entityManager, $searchManager)
	{
		parent::__construct($request, $productApi, $serviceContainer, $commonLibraryManager, $entityManager);
	}
	
	public function getPaginatorService()
	{
		return $this->paginatorService;
	}
	
	public function setPaginatorService($paginatorService)
	{
		$this->paginatorService = $paginatorService;
	}
	
	public function getProjectSetting()
	{
		return $this->paginatorService;
	}
	
	public function setProjectSetting($projectSetting)
	{
		$this->projectSetting = $projectSetting;
	}
	
    public function getProductDetailBySlug($productSlug, $culture)
    {
    }
    
    public function getProductDetailById($productId, $culture)
    {
    }
    
    public function downloadImageZip($productSKU, $supplierId)
    {	
    }
    
    public function downloadPdfTemplate($productSKU, $supplierId)
    {
    }

    public function downloadFileFromRemoteToLocal($downloadPathUrlAbsolute, $supplierId, $productImageUrl, $downloadPathUrlRelative, $filename)
    {	
    	$sourceZipFile = $productImageUrl.$supplierId.'/'.$filename;
    	$destinationZip = $downloadPathUrlAbsolute.$supplierId.'/'.$filename;
    	$destinationRelativeZip = $downloadPathUrlRelative.$supplierId.'/'.$filename;
    	$destinationZipFolder =  $downloadPathUrlRelative.$supplierId;
    	
	    if (!file_exists($destinationRelativeZip)) {
	    		$this->commonLibraryManager->makeDir($destinationZipFolder);
	    		$this->commonLibraryManager->saveUrlToFile($sourceZipFile, $destinationZip);
	    }
	   	$this->forceFullyDownloadFile($filename, $destinationZipFolder);
    		
    }
    
    public function forceFullyDownloadFile($filename, $dynamicFilePath)
    {
    	//echo $dynamicFilePath.'/'.$filename; die;	
    	$downloadFile = $dynamicFilePath.'/'.$filename;
    	header('Content-Description: File Transfer');
    	header('Content-Type: application/octet-stream');
    	header('Content-Disposition: attachment; filename=' .$filename);
    	header('Expires: 0');
    	header('Cache-Control: must-revalidate');
    	header('Pragma: public');
    	//echo 'file downloaded'; die;
    	readfile($downloadFile);
    }
    public function getProductInventoryDetails($itemNo='')
    {
    	$params = array( 'ItemNo' => $itemNo);
    	$this->productApi->init('product_inventory_lookup');
    	$this->productApi->setCallParameters($params);
    	$returnData=$this->productApi->doProcess();
    	unset($params);
    	return $returnData;
    }
}
