addJs('assets/javascript/product_maps.js');
$this['product_id'] = $this->param('product_id');
$this['category'] = $this->param('cat_name');
$this['loggedIn'] = Session::has("AccessToken") == true ? true : false ;
if($this['loggedIn']){
$this['ClientType'] = Session::get('ClientType');
$this['DefaultWishlist'] = Session::get('DefaultWishlist');
}
$protocol = stripos($_SERVER['SERVER_PROTOCOL'],'https') === true ? 'https://' : 'http://';
$this['page_url'] = urlencode($protocol.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
$this['raw_page_url'] = $protocol.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$this['OGurl'] = FunctionHelper::getCurrentUrl();
$directory = base_path().'/themes/eshop/assets/images/brands/normal';
$this['brand_images'] = array_diff(scandir($directory), array('..', '.'));
if(Request::get('pRef') != null){
$match = (str_replace(['filter', 'search', 'order'], '', \Url::previous()) != \Url::previous());
if($match == 1){
$this['pRefParameterKeyValue'] = '&pRef='.$_GET['pRef'];
} else {
$this['pRefParameterKeyValue'] = '?pRef='.$_GET['pRef'];
}
}
if(\Url::previous()==\Url::to('/')) {
$this["previous_url"] = \Url::to('/').'/products';
} else {
$this['previous_url'] = preg_replace('/&pRef=[0-9]*/','', \Url::previous());
$this['previous_url'] = preg_replace('/\?pRef=[0-9]*/','', \Url::previous());
$this['previous_url'] .= $this['pRefParameterKeyValue'];
}
$this->getDistilleries();
$apiHelper = new APIHelper();
$apiHelper
->setTake(5)
->setSkip(0)
->setAvailableOnly(10)
->setOrderBy(1)
->setFilter("/description5/".$this->param('product_id'));
if(Session::get('CartNo') < 0){
$apiHelper->setIsGuest(0);
}
try {
//dd($apiHelper->getRequestUserInfo());
$response = $apiHelper->makeAPIrequest('products/productsonlylist');
$productExists = false;
$this["unitCode"] = "";
//($response->ResponseData->ProductsList[0]);
if($response->ResponseData->ProductsList == null){
//Log::debug('PRODUCT 404'.json_encode($apiHelper->getRequestUserInfo()));
return redirect('/404');
}
$productDesc10 = $response->ResponseData->ProductsList[0]->Description10;
$productDesc12 = $response->ResponseData->ProductsList[0]->Description12;
$productDesc13 = $response->ResponseData->ProductsList[0]->Description13;
if ($productDesc10 != ""){
$pieces = explode("\r\n", $productDesc10);
if(count($pieces) > 1){
$headlinedel = $pieces[0];
$textdel = $pieces[1];
$this['desc10headline'] = $headlinedel;
unset($pieces[0]);
$this['desc10text'] = implode("
", $pieces);
}else{
}
}
if ($productDesc13 != ""){
$pieces = explode("\r\n", $productDesc13);
if(count($pieces) > 1){
$textdel = $pieces[0];
$urldel = $pieces[1];
$this['desc13text'] = $textdel;
$this['desc13url'] = $urldel;
}else{
}
}
if ($productDesc12 != ""){
$youtubepieces = explode("\r\n", $productDesc12);
if(count($youtubepieces) > 1){
$textdelYoutube = $youtubepieces[0];
$urldelYoutube = $youtubepieces[1];
$this['desc13textYoutube'] = $textdelYoutube;
$this['desc13urlYoutube'] = $urldelYoutube;
}
}
if($response->ResponseInfo->Status == 0 && $response->ResponseData->ProductsListInfo->Total > 0){
$responseData = $response->ResponseData;
$this['product'] = $responseData->ProductsList[0];
$this['imagesInfo'] = $responseData->ImagesInfo;
$this['product_gallery'] = $this->getGalleryImages($this['product']->ImageNom);
if(Session::has('AccessToken')){
$this->getWishlistsItems($this['DefaultWishlist']);
}
}
}catch (ClientException $e) {
$response = $e->getResponse();
$responseData = json_decode($response->getBody()->getContents());
if(property_exists($responseData, "ResponseInfo") && $responseData->ResponseInfo->Status == -1){
echo $responseData->ResponseInfo->ErrorMessage;
}
}
}
/*
* Max nambuer of images are 9
* From -01 to -09.
*/
function getGalleryImages($imgName){
$ext = strpos($imgName, '.jpg');
$gallery_images = array();
for($i = 1 ; $i < 10 ; $i++){
if($ext){
$gallery_img = str_replace('.jpg', '-0'.$i.'.jpg', $imgName);
}
else{
$gallery_img = str_replace('.png', '-0'.$i.'.jpg', $imgName);
}
$gallery_original = $this['imagesInfo']->ImgPathOriginal;
$gallery_lightbox = str_replace("original", "lightbox", $gallery_original);
$src_headers = @get_headers($gallery_lightbox.$gallery_img);
if($src_headers[0] == 'HTTP/1.1 200 OK') {
$gallery_images[] = $gallery_img;
} else {
break;
}
}
if(count($gallery_images) > 0){
$this['dataimagelightbox'] = 'f';
} else {
$this['dataimagelightbox'] = 'y';
}
return $gallery_images;
}
function urlExists($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_exec($ch);
$error = curl_error($ch);
$errno = curl_errno($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
//var_dump($errno, $error, $status); // debug
return ($status == 200);
}
function getCategories($catName){
$apiHelper = new APIHelper();
$apiHelper->setProductID($this['product']->NRPRODUIT)->setCat1($catName);
try {
$response = $apiHelper->makeAPIrequest('products/categorynames');
if($response && $response->ResponseInfo && $response->ResponseInfo->Status == 0){
return $response->ResponseData->CategoryNames;
}
}
catch (ClientException $e) {
$response = $e->getResponse();
$responseData = json_decode($response->getBody()->getContents());
if(property_exists($responseData, "ResponseInfo") && $responseData->ResponseInfo->Status == -1){
echo $responseData->ResponseInfo->ErrorMessage;
}
}
}
function getProductUnitsList($productRef){
try {
$apiHelper = new APIHelper();
$apiHelper->setProductRef($productRef);
$response = $apiHelper->makeAPIrequest('products/unitslist');
if($response && $response->ResponseInfo && $response->ResponseInfo->Status == 0){
$responseData = $response->ResponseData->ProductUnitsList[0];
if($response->ResponseData->ProductUnitsList && count($response->ResponseData->ProductUnitsList) > 0){
$this["unitsList"] = $response->ResponseData->ProductUnitsList;
$this["unitsListExists"] = false;
if(count($this["unitsList"]) > 0){
$this["unitsListExists"] = true;
}
}
}
}catch (ClientException $e) {
$response = $e->getResponse();
$responseData = json_decode($response->getBody()->getContents());
$this["unitsList"] = [];
}
}
function getCategoriesMenu(){
$apiHelper = new APIHelper();
$responseCats = $apiHelper->makeAPIrequest('products/categories1');
$this['allCategories'] = $responseCats->ResponseData->Categories;
$menu_items = [];
if(count($this['allCategories']) > 0){
foreach($this['allCategories'][0]->FilterList as $menu_item){
if($menu_item->FilterDesc != ""){
$menu_items[] = $menu_item;
}
}
}
$this['menu_items'] = $menu_items;
}
function onAddToCart(){
$product_id = post('productID');
$apiHelper = new APIHelper();
$apiHelper->setProductRef($product_id)->setQty(post("qty"))->setUnitCode(post("unitCode"));
try {
$response = $apiHelper->makeAPIrequest('cartdetails/add');
if($response && $response->ResponseInfo && $response->ResponseInfo->Status == 0){
Log::debug('Sent request'.json_encode($apiHelper->getRequestUserInfo()));
$ResponseUserInfo = $response->ResponseUserInfo;
Session::put('CartNo', $ResponseUserInfo->CartNo);
}
return json_encode($response);
}catch (ClientException $e) {
$response = $e->getResponse();
$responseData = json_decode($response->getBody()->getContents());
if(property_exists($responseData, "ResponseInfo") && $responseData->ResponseInfo->Status == -1){
return json_encode($responseData->ResponseInfo->ErrorMessage);
}
}
}
function onAddToCartOBSOLETE(){
$product_id = post('productID');
$vgSettingsModel = new VGSettings();
$headers = $vgSettingsModel->getDefaultHeader();
$requestBody = $vgSettingsModel->getRequestBodyUserInfo();
$requestBody["RequestInfo"] = new stdClass();
$requestBody["RequestInfo"]->ProductRef = $product_id;
$requestBody["RequestInfo"]->Qty = post("qty");
$requestBody["RequestInfo"]->UnitCode = post("unitCode");
try {
$apiUrlModel = new VGApiUrlCalls();
$apiUrl = $apiUrlModel->getApUrl("add-to-cart");
$client = new Client();
$jsonResponse = $client->request('POST', $apiUrl->api_url, ['headers' => $headers,'json' => $requestBody]);
$response = json_decode($jsonResponse->getBody());
if($response && $response->ResponseInfo && $response->ResponseInfo->Status == 0){
$ResponseUserInfo = $response->ResponseUserInfo;
Session::put('CartNo', $ResponseUserInfo->CartNo);
Session::put('ddworks', 'Yes it works');
$apiHelper = new APIHelper();
$apiHelper->setCartNumber($response->ResponseUserInfo->CartNo);
}
return json_encode($response);
}catch (ClientException $e) {
$response = $e->getResponse();
$responseData = json_decode($response->getBody()->getContents());
if(property_exists($responseData, "ResponseInfo") && $responseData->ResponseInfo->Status == -1){
return json_encode($responseData->ResponseInfo->ErrorMessage);
}
}
}
function onDownloadPDF(){
$pdf = App::make('snappy.pdf.wrapper');
$pdf->loadHTML('
Test
');
return $pdf->inline();
//return post('productID');
}
function onWishlistCreate(){
$apiHelper = new APIHelper();
$apiHelper
->setWishlistName(post('wishlist_name'));
$wishlist = $apiHelper->makeAPIrequest('wishlist/add');
$apiHelper
->setWishlistID($wishlist->ResponseData->WishlistItem->WishlistId)
->setProductRef(post('product_id'));
$apiHelper->makeAPIrequest('wishlist/detailsadd');
try {
$apiHelper->makeAPIrequest('wishlist/detailsadd');
return json_encode(['status' => 'success', 'wishlist_id' => $wishlist->ResponseData->WishlistItem->WishlistId]);
} catch (Exception $e) {
echo $e->getMessage();
return json_encode(['status' => 'error']);
}
}
function onWishlistDetailsAdd()
{
$apiHelper = new APIHelper();
$apiHelper
->setWishlistID(post('wishlistID'))
->setProductRef(post('productID'));
try {
$apiHelper->makeAPIrequest('wishlist/detailsadd');
return json_encode(['status' => 'success']);
} catch (Exception $e) {
echo $e->getMessage();
return json_encode(['status' => 'error']);
}
}
function onWishlistDetailsDel()
{
$apiHelper = new APIHelper();
$apiHelper
->setWishlistID(post('wishlistID'))
->setProductRef(post('productID'));
try {
$apiHelper->makeAPIrequest('wishlist/detailsdel');
return json_encode(['status' => 'success']);
} catch (Exception $e) {
echo $e->getMessage();
return json_encode(['status' => 'error']);
}
}
function getWishlistsItems($wishlistID){
$apiHelper = new APIHelper();
$apiHelper->setWishlistID($wishlistID);
#Call Wishlist service
$response = $apiHelper->makeApiRequest('wishlist/detailslist');
$wishlistItems = $response->ResponseData->ProductsList;
$this['inWishlist'] = false;
if(is_array($wishlistItems) && count($wishlistItems) > 0){
foreach ($wishlistItems as $items){
if($items->NRPRODUIT == $this['product']->NRPRODUIT){
$this['inWishlist'] = true;
}
}
}
}
function getDistilleries(){
$helper = new functionHelper();
$this['whiskies'] = Cache::has('whiskies') ? Cache::get('whiskies') : $helper->getDistilleriesWhisky();
$this['rhums'] = Cache::has('rhums') ? Cache::get('rhums') : $helper->getDistilleriesRhum();
$this['brandies'] = Cache::has('brandies') ? Cache::get('brandies') : $helper->getDistilleriesBrandy();
}
function onGetNextItem(){
$productID = post('productID');
$productCategory = post('productCategory');
$apiHelper = new APIHelper();
$apiHelper->setFilter('cat1/'.$productCategory)->setTake(20);
$response = $apiHelper->makeAPIrequest('products/productsonlylist');
$productCount = (is_array($response->ResponseData->ProductsList)) ? count($response->ResponseData->ProductsList) : 0;
if($response && $response->ResponseInfo && $response->ResponseInfo->Status == 0){
if($productCount > 1){
foreach ($response->ResponseData->ProductsList as $key => $value){
if($value->NRPRODUIT == $productID){
$category = $response->ResponseData->ProductsList[$key+1]->CatDescr1 != "" ? $response->ResponseData->ProductsList[$key+1]->CatDescr1 : 'spirit';
$slug = $response->ResponseData->ProductsList[$key+1]->Description5 !="" ? $response->ResponseData->ProductsList[$key+1]->Description5 : '';
$next = strtolower($category.'/'.$slug);
return $next;
} else {
$theKey = rand(0, $productCount - 1);
$category = $response->ResponseData->ProductsList[$theKey]->CatDescr1 != "" ? $response->ResponseData->ProductsList[$theKey]->CatDescr1 : 'spirit';
$slug = $response->ResponseData->ProductsList[$theKey]->Description5 !="" ? $response->ResponseData->ProductsList[$theKey]->Description5 : '';
$next = strtolower($category.'/'.$slug);
return $next;
}
}
} else {
return $next = '#';
}
}
}
function getRelatedProducts($nomCourt){
$apiHelper = new APIHelper();
$apiHelper->setFilter('NomCourt/'.$nomCourt)->setAvailableOnly(1)->setOrderBy(1)->setSkip(0)->se