<?php
/***************************************************************************
 *                                                                          *
 * Copyright (c) 2005 ISPG Technologies (I) Pvt Ltd. All rights reserved.   *
 *                                                                          *
 * This  is  commercial  software,  only  users  who have purchased a valid *
 * license  and  accept  to the terms of the  License Agreement can install *
 * and use this program.                                                    *
 *                                                                          *
 ****************************************************************************
 * PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
 * "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
 ****************************************************************************/ //
//$Id: IndexController.php, v 1.0 2011/06/14 20:52:11
//
class IndexController extends Controller {
    public function __construct() {
        parent::__construct();
        $this->ObjView->assign('statPageName', 'home');
    }
   
    public function indexAction() {
        // Get Current Language
        $languageIDs = $this->ObjView->languageIDs;
        // Set Design Mode
        //get promotion banners in home page	
        $ObjWidget          = new WidgetModel();
        $ObjBanner          = new BannerModel();
        $ObjProductList	    = new ProductListModel();
        $ObjCustomOption    = new CustomOptionModel();
        $ObjDevice	    = new Device();
        if(	$ObjDevice->isMobile() || $ObjDevice->isTablet() ){
                $platform 	= 	'mobile';
        }else{
                $platform 	= 	'desktop';
        }
        $this->ObjSession->setSession("MODELTEST","");
        $resBanner   = $ObjBanner->listBannersOnTypes($languageIDs, "2", '', '', $platform,'',$this->ObjCommon->brandID);
        $this->ObjView->assign('platform', $platform);
        $this->ObjView->assign('resBanner', $resBanner);
        
        // Set settings values
        $previewMode                    = ($this->getRequestValue("preview") != "") ? "Yes" : "No";        
        $siteUrl                        = $this->getSettingValue('site_settings', 'global_http_url');
        $settingsDateFormat             = $this->getSettingValue('site_settings', 'date_format');
        $settingsTimeFormat             = $this->getSettingValue('site_settings', 'time_format');
        $settingsTwitterWidgetCode      = $this->getSettingValue('social_media_settings', 'twitter_widget_code');
        $settingsTwitterEnableFeeds     = $this->getSettingValue('social_media_settings', 'twitter_enable_feeds');
        $settingsFacebookLikeButtonCode = $this->getSettingValue('social_media_settings', 'facebook_like_button_code');
        $settingsHomeFooterText         = 	$this->getSettingValue('seo_settings','home_footer_text');
        $this->ObjView->assign('settingsHomeFooterText', $settingsHomeFooterText);
        $this->ObjView->assign('previewMode', $previewMode);
        $this->ObjView->assign('siteUrl', $siteUrl);        
        $this->ObjView->assign('settingsDateFormat', $settingsDateFormat);
        $this->ObjView->assign('settingsTimeFormat', $settingsTimeFormat);
        $this->ObjView->assign('settingsTwitterWidgetCode', html_entity_decode(stripslashes($settingsTwitterWidgetCode)));
        $this->ObjView->assign('settingsTwitterEnableFeeds', $settingsTwitterEnableFeeds);
        $this->ObjView->assign('settingsFacebookLikeButtonCode', stripslashes($settingsFacebookLikeButtonCode));
        /*         
        // List product for home
        // Query Order: if any product found in previous list it will avoid in the next list 
        $queryOrderGroups		= array(
        'best_sellers'	=> 'Best Sellers',
        'spcl_offers'	=> 'Special offers',
        'featured'		=> 'Featured Products',
        'new_products'	=> 'New Products'
        );
        $resListProducts		= $this->listProductsForHome($queryOrderGroups);
        $this->ObjView->assign('resListProducts', $resListProducts);
        // Listing order in the User's Index Page 
        $arrHighlightGroups		= array(
        'featured'		=> 'lblFeaturedProducts',
        'spcl_offers'	=> 'lblSpecialoffers',
        'best_sellers'	=> 'lblBestSellers',
        'new_products'	=> 'lblNewProducts'
        );
        $this->ObjView->assign('arrHighlightGroups', $arrHighlightGroups);
        */
        
        $rviEnable        = $this->getSettingValue('product_cart_settings', 'recently_viewed_items');
        $enableRecentView = 0;
        if ($rviEnable == 'Yes') {
            if ($this->ObjCookie->getCookie("RVI_IDS")) {
                $enableRecentView = 1;
            }
        }
        $this->ObjView->assign('enableRecentView', $enableRecentView);
        //$this->ObjView->assign('resListProducts', $resListProducts);
        $this->ObjView->assign('languageID', $languageIDs['Current']);
        $this->listWidgets();
        $params = array('languageIDs' => $languageIDs,
                        'brandID' => $this->ObjCommon->brandID,
                        'userGroupID' => (int) $this->ObjCommon->REGISTERED_USER_GROUP_ID
                        );
        
        $listWidgetItemDet  = $ObjWidget->listWidgetItems($params);
        if(!empty($listWidgetItemDet)) {
            foreach($listWidgetItemDet as $resProduct) {
                
                  
                   $currProdID                       = $resProduct['productID'];
                   $productOptionID                  = $resProduct['productOptionID'];
                   
                    $args                             = array(
                       'productID' => $currProdID
                   );
                  
                   /* function call for Product option count */
                   $resProduct['productOptionCount']                   = $ObjProductList->getProductOptionCount($args);
                  

                   if ($resProduct['productOptionCount'] > 0) {
                       if (isset($productOptionID) && $productOptionID > 0) {
                           /*$params                        = array(
                               'languageIDs' => $languageIDs,
                               'productID' => $currProdID,
                               'productOptionID' => $productOptionID,
                               'inventoryTrackLevel' => $resProduct['InventoryTrackLevel'],
                               'showQuantityAvailable' => $resProduct['showQuantityAvailable'],
                               'userGroupID' => (int) $this->ObjCommon->REGISTERED_USER_GROUP_ID
                           );
                           $resProduct['options'] = $ObjProductList->fetchProductOptionsInfo($params);*/
                           $resProduct['options'][0]['productOptionID']          = $productOptionID;
                           $resProduct['options'][0]['productOptionQuantity']    = ($resProduct['InventoryTrackLevel']=='Options')?$resProduct['productOptionQuantitySum']:$resProduct['productOptionQuantity'];
                           $resProduct['options'][0]['productQuantityUnlimited'] = ($resProduct['InventoryTrackLevel']=='No')?1:0;
                           $resProduct['options'][0]['isProductDeal']            = $resProduct['isProductDeal'];
                           $resProduct['options'][0]['dealPrice']                = $resProduct['dealPrice'];
                           $resProduct['options'][0]['productOptionName']        = $resProduct['productOptionName'];
                           $resProduct['options'][0]['productOptionRegularPrice']= $resProduct['productOptionRegularPrice'];
                           $resProduct['options'][0]['productOptionProductPrice']= $resProduct['productOptionProductPrice'];
                           $resProduct['options'][0]['offerPrice']               = $resProduct['offerPrice'];
                           $resProduct['options'][0]['productOptionOfferDiscount']= $resProduct['productOptionOfferDiscount'];
                           $resProduct['options'][0]['productOptionDiscount']     = $resProduct['productOptionDiscount'];
                           $resProduct['options'][0]['productOptionSavePrice']    = $resProduct['productOptionSavePrice'];
                           
                       } else {
                           $params                        = array(
                               'languageIDs' => $languageIDs,
                               'productID' => $currProdID,
                               'productOptionID' => 0,
                               'inventoryTrackLevel' => $resProduct['InventoryTrackLevel'],
                               'showQuantityAvailable' => $resProduct['showQuantityAvailable'],
                               'userGroupID' => (int) $this->ObjCommon->REGISTERED_USER_GROUP_ID
                           );
                           $resProduct['options'] = $ObjProductList->fetchProductOptionsInfo($params);
                       }
                       /*foreach ($resProduct['options'] as $key => $option) {
                           $params                                            = array(
                               'productOptionID' => $option['productOptionID'],
                               'offerPrice' => $option['offerPrice'],
                               'userGroupID' => (int) $this->ObjCommon->REGISTERED_USER_GROUP_ID
                           );
                           $resProduct['options'][$key]['tierPrices'] = $ObjProductList->listTierPrices($params);
                       }*/
                       $resProduct['customOptionCount'] = $ObjCustomOption->getProductCustomOptionsCount($currProdID);
                   }
                  
                   $resProducts[] = $resProduct;
             
           
              
            }
            if (count($resProducts) > 0) {            
                  $this->ObjView->assign('productsToJs', json_encode($resProducts));
              }
        }
        $this->ObjView->display('catalog/Index.tpl');
    }
    /* 
    public function listProductsForHome($prodHighlightGroups)
    {
    $ObjProductList			= new ProductListModel();
    $ObjCustomOption		= new CustomOptionModel();
    $languageIDs			= $this->ObjView->languageIDs;               
    $languageID            	= $languageIDs['Current'];
    $userGroupID            = (int)$this->ObjCommon->REGISTERED_USER_GROUP_ID;
    
    $hide_out_of_stock_in_homepage= $this->getSettingValue('product_cart_settings', 'hide_out_of_stock_in_homepage');
    $selectedProductIDs	= array();
    $args				= array(
    'requestedBy'		=> 'customer',
    'languageIDs'		=> $languageIDs,
    'limitFrom'			=> 0,
    'limitTo'			=> 3,
    'previewOnly'		=> 'No',
    'customOrderBy'		=> '',
    'userGroupID'		=> $userGroupID,
    'hide_out_of_stock_in_homepage'=> $hide_out_of_stock_in_homepage,
    );
    foreach($prodHighlightGroups as $groupKey=>$groupTitle) 
    {
    $args['customOrderBy']		= $groupKey;
    $args['exceptProductIDs']		= $selectedProductIDs;
    $resSelectProducts		= $ObjProductList->listHomePageProducts($args);
    $resSelectProductsCount = count($resSelectProducts);
    $currDateTime  = date('Y-m-d H:i:s');
    for($product_i = 0;$product_i < $resSelectProductsCount; $product_i++) 
    {
    $productID			= 	$resSelectProducts[$product_i]['productID'];
    $productOptionID	= 	$resSelectProducts[$product_i]['productOptionID'];
    $offerPrice		= 	$resSelectProducts[$product_i]['offerPrice'];
    
    // START : to get the minimum tier price 
    $params=array(
    'productOptionID'	=> $productOptionID,
    'offerPrice'	=> $offerPrice,
    'userGroupID'	=> $userGroupID
    );
    $resSelectProducts[$product_i]['tierPrice']	= $ObjProductList->getMinTierPrices($params); 
    // END : to get the minimum tier price 
    
    // Time left if there is end time 
    
    if($resSelectProducts[$product_i]['productEndTime']!='0000-00-00'){ 
    $seconds = strtotime($resSelectProducts[$product_i]['productEndTime']) - strtotime($currDateTime);
    $resSelectProducts[$product_i]['daysLeft'] =ceil($seconds/3600/24);
    }
    // Already selected product IDs in previous sections
    
    array_push($selectedProductIDs,$productID);
    if(isset($resSelectProducts[$product_i]['timeZoneDiff']))
    $timeZoneDiff				= $resSelectProducts[$product_i]['timeZoneDiff'];
    
    if($resSelectProducts[$product_i]['multiOptionsAvailable'] == "No") 
    {
    $resSelectProducts[$product_i]['customOptionCount']	= $ObjCustomOption->getProductCustomOptionsCount($productID);
    }
    }
    if($resSelectProductsCount >0)
    $resAllProducts[$groupKey]		= $resSelectProducts;
    }
    $resAllProducts	= isset($resAllProducts)?$resAllProducts:array();
    return $resAllProducts;
    }
    */
    public function ajaxQuickViewAction() {
        
        $productAndOptionID     = $this->getRequestValue("id");
        $originCatalogID        = $this->getRequestValue("originCatalogID");
        $languageIDs['Current'] = $this->getRequestValue("l");
        
        /* $checked==true when the user already added this product into compare box */
        $checked                = $this->getRequestValue("checked");
        $arrProductAndOptionIDs = explode('-', $productAndOptionID);
        $currProductID          = $arrProductAndOptionIDs[0];
        $productUniqueView      = true;
        $settingsProductReview  = $this->getSettingValue('product_cart_settings', 'allow_product_reviews');
        
        /* START :  Recently Viewed Items */
        if (($this->ObjCookie->getCookie("RVI_IDS"))) {
            $recentlyViewedItems = $this->ObjCookie->getCookie("RVI_IDS");
            $recentlyViewedItems = unserialize($recentlyViewedItems);
        } else {
            $recentlyViewedItems = array();
        }
        $ObjCategory    = new ProductCategoryModel();
        $params         = array(
            'productID' => $currProductID
        );
        $selCategoryDet = $ObjCategory->getCategoryInfoByProductID($params);
        $params         = array(
            'productCategoryID' => $selCategoryDet['productCategoryID'],
            'categoryLevel' => $selCategoryDet['categoryLevel'],
            'currentLanguageID' => $languageIDs['Current']
        );
        $resBreadcrumbs = $ObjCategory->getBreadcrumbsTree($params);
        if (count($recentlyViewedItems) > 0) {
            $recently_viewed_product_id = array_key_exists($currProductID, $recentlyViewedItems);
            if ($recently_viewed_product_id !== FALSE) {
                $productUniqueView = false;
                //Remove the existing product to put it on the top later
                unset($recentlyViewedItems[$currProductID]);
            }
            $current[$currProductID] = array(
                'productID' => $currProductID,
                'catID' => isset($resBreadcrumbs[0]['productCategoryID']) ? $resBreadcrumbs[0]['productCategoryID'] : 0
            );
            $recentlyViewedItems     = $current + $recentlyViewedItems;
        } else if (isset($recentlyViewedItems) && count($recentlyViewedItems) == 0) {
            $recentlyViewedItems[$currProductID] = array(
                'productID' => $currProductID,
                'catID' => $resBreadcrumbs[0]['productCategoryID']
            );
        }
        if (isset($currProductID) && (int) $currProductID > 0) {
            $recentlyViewed = serialize($recentlyViewedItems);
            $this->ObjCookie->setCookie("RVI_IDS", $recentlyViewed);
        }
        
        /* END : Recently Viewed Items */
        if (!($languageIDs['Current'] > 0) || !($currProductID > 0)) {
            exit;
        }
        $ObjProductList  = new ProductListModel();
        $ObjBrand        = new BrandModel();
        $ObjCustomOption = new CustomOptionModel();
        $ObjWishList     = new WishlistModel();
        /* =======================================================================*/
        $viewType        = ($productUniqueView) ? "uniqueView" : "view";
        $ObjProductList->updateProductPopularity($currProductID, $viewType);
        
        /* =======================================================================*/
        //URL REWRITE CHNAGE
        $languageIDArr          = $this->ObjView->languageIDs;
        $languageIDs['Default'] = $languageIDArr['Default'];
        //ENDS
        $productType            = array(
            'productTypeKey' => 'product_product',
            'productTypeUrlKey' => '',
            'productTypeName' => $this->getLanguageValue('lblProducts')
        );
        $args                   = array(
            'languageIDs' => $languageIDs,
            'limitFrom' => 0,
            'limitTo' => 1,
            'productType' => $productType,
            'currDateTime' => date('Y-m-d'),
            'selectedProductID' => $currProductID,
            'userGroupID' => (int) $this->ObjCommon->REGISTERED_USER_GROUP_ID
            
        );
        $resultProducts         = $ObjProductList->listActiveProducts($args);
        $resultProduct          = $resultProducts[0];       
        
        if (isset($resultProduct) && is_array($resultProduct)) {
            $productOptionID             = $resultProduct['productOptionID'];
            $offerPrice                  = $resultProduct['offerPrice'];
            $params                      = array(
                'productOptionID' => $productOptionID,
                'offerPrice' => $offerPrice,
                'userGroupID' => (int) $this->ObjCommon->REGISTERED_USER_GROUP_ID
            );
            $resultProduct['tierPrices'] = $ObjProductList->listTierPrices($params);
            if ($resultProduct['productEndTime'] != '0000-00-00 00:00:00') {
                $seconds                   = strtotime($resultProduct['productEndTime']) - strtotime($resultProduct['timeZoneConverted']);
                $resultProduct['daysLeft'] = ceil($seconds / 3600 / 24);
            }
            $resProdDetails = $ObjProductList->fetchProductDetails($languageIDs, $currProductID);
            $resultProduct  = array_merge($resultProduct, $resProdDetails);
            if ($settingsProductReview == 'Yes') {
                $resProdReviews = $ObjProductList->fetchProductReviews($currProductID);
                $resultProduct  = array_merge($resultProduct, $resProdReviews);
            }
            $resultProduct['images']     = $ObjProductList->fetchProductImages($currProductID, $resultProduct['productOptionID']);
            $params                      = array(
                'languageIDs' => $languageIDs,
                'productID' => $currProductID,
                'productOptionID' => $resultProduct['productOptionID'],
                'inventoryTrackLevel' => $resultProduct['InventoryTrackLevel'],
                'showQuantityAvailable' => $resultProduct['showQuantityAvailable'],
                'userGroupID' => (int) $this->ObjCommon->REGISTERED_USER_GROUP_ID
            );
            $resProdCurrOption           = $ObjProductList->fetchProductOptionsInfo($params);
            $resultProduct['options'][0] = array(
                'productOptionID' => $resProdCurrOption[0]['productOptionID'],
                'productOptionProductPrice' => $resProdCurrOption[0]['productOptionProductPrice'],
                'productOptionRegularPrice' => $resProdCurrOption[0]['productOptionRegularPrice'],
                'productOptionQuantity' => $resProdCurrOption[0]['productOptionQuantity'],
                'offerPrice' => $resProdCurrOption[0]['offerPrice'],
                'productOptionOfferDiscount' => $resProdCurrOption[0]['productOptionOfferDiscount'],
                'productQuantityUnlimited' => $resProdCurrOption[0]['productQuantityUnlimited'],
                'productOptionSavePrice' => ($resProdCurrOption[0]['productOptionSavePrice']),
                'productOptionDiscount' => number_format($resProdCurrOption[0]['productOptionDiscount'], 2) . "%",
                'productOptionName' => $resProdCurrOption[0]['productOptionName'],
                'showQuantityAvailable' => $resProdCurrOption[0]['showQuantityAvailable'],
                'InventoryTrackLevel' => $resProdCurrOption[0]['InventoryTrackLevel']
            );
            if ($resultProduct['brandID'] > 0) {
                $params   = array(
                    'languageIDs' => $languageIDs,
                    'brandID' => $resultProduct['brandID']
                );
                $getBrand = $ObjBrand->getBrand($params);
                if (!empty($getBrand)) {
                    $resultProduct = array_merge($resultProduct, $getBrand);
                } else {
                    $resultProduct = $resultProduct;
                }
            }
        }
        
        
        $customOption = $ObjCustomOption->getProductCustomOptions($languageIDs, $currProductID);
        if (count($customOption) > 0) {
            foreach ($customOption as $key => $option) {
                $variants                       = $ObjCustomOption->getCustomOptionVariants($languageIDs, $option['customOptionID']);
                $customOption[$key]['variants'] = $variants;
            }
        }
        $params       = array(
            'productID' => $currProductID,
            'view' => 'No',
            'status' => 'A',
            'languageIDs' => $languageIDs
        );
        $combinations = $ObjCustomOption->getProductCombination($params);
        $this->setProductSharingSettings();
        $regUserID = $this->ObjSession->getSession("REGISTERED_USER_ID");
        if ($resultProduct['productID'] > 0 && $regUserID > 0) {
            $wishlistProducts = $ObjWishList->checkInWishlist($resultProduct['productID'], $regUserID);
            $this->ObjView->assign('wishlistProducts', $wishlistProducts['count']);
        }
        $this->ObjView->assign('regUserID', $regUserID);
        if ($checked != 'undefined') {
            $this->ObjView->assign('checked', $checked);
        }
        $this->ObjView->assign('customOption', $customOption);
        $this->ObjView->assign('encodedCustomOption', json_encode($customOption));
        $this->ObjView->assign('encodedCombinations', json_encode($combinations));
        $this->ObjView->assign('selectedProductID', $currProductID);
        $this->ObjView->assign('productsToJs', json_encode(array(
            0 => $resultProduct
        )));
                
        $this->ObjView->assign('uniqueID', $productAndOptionID);
        $this->ObjView->assign('resultProduct', $resultProduct);
        $this->ObjView->assign('resultProductProduct', $resultProducts);        
        $this->ObjView->assign('originCatalogID', $originCatalogID);
        $params = array(
            'productCategoryID' => $originCatalogID,
            'pageLayoutType' => 'grid'
        );
        $this->ObjCommon->setCommonSefPath(array(
            'product'
        ), array(
            "0" => $currProductID
        ));
        $pageLayout = $this->ObjCommon->getPageLayout($params);
        $this->ObjView->assign('pageLayout', $pageLayout);
        $this->ObjView->display($pageLayout . 'ListingQuickView.tpl');        
    }
    //Set Product Sharing through Social Networking Sites 
    public function setProductSharingSettings() {
        $languageIDs                       = $this->ObjView->languageIDs;
        //Twitter
        $settingsTwitterPostNewProductOn   = $this->getSettingValue('social_media_settings', 'twitter_post_new_product_on');
        $settingsTwitterProductPostMessage = $this->getSettingValue('social_media_settings', 'twitter_product_post_message');
        $this->ObjView->assign('settingsTwitterPostNewProductOn', $settingsTwitterPostNewProductOn);
        $this->ObjView->assign('settingsTwitterProductPostMessage', preg_replace('/\s+/', ' ', str_replace("<br />", '\n', nl2br($settingsTwitterProductPostMessage))));
        //Facebook	
        $settingsFacebookNewProductOnWall   = $this->getSettingValue('social_media_settings', 'facebook_new_product_on_wall');
        $settingsFacebookProductPostMessage = $this->getSettingValue('social_media_settings', 'facebook_product_post_message');
        $this->ObjView->assign('settingsFacebookNewProductOnWall', $settingsFacebookNewProductOnWall);
        $this->ObjView->assign('settingsFacebookProductPostMessage', $settingsFacebookProductPostMessage);
        //Google Plus
        $settingsGooglePlusNewProductOnWall = $this->getSettingValue('social_media_settings', 'googleplus_new_product_on_wall');
        $this->ObjView->assign('settingsGooglePlusNewProductOnWall', $settingsGooglePlusNewProductOnWall);
        //Pinterest
        $settingsPinterestNewProductOnWall   = $this->getSettingValue('social_media_settings', 'pinterest_new_product_on_wall');
        $settingsPinterestProductPostMessage = $this->getSettingValue('social_media_settings', 'pinterest_product_post_message');
        $this->ObjView->assign('settingsPinterestNewProductOnWall', $settingsPinterestNewProductOnWall);
        $this->ObjView->assign('settingsPinterestProductPostMessage', preg_replace('/\s+/', ' ', str_replace("<br />", '\n', nl2br($settingsPinterestProductPostMessage))));
    }
    public function destroyCookieAction() {
        $this->unsetMessage("index", "maxQuantityError");
    }
    public function addtocartAction() {
        //Old add to cart issue in API and Ref, redirecting to index page
        $this->setRedirect("/");
    }
    public function AjaxresetlanguageAction() {
        $languageID    = $_POST['languageID'];
        $newLCIDString = $_POST['newLCIDString'];
        $oldLCIDString = $_POST['oldLCIDString'];
        $this->ObjCookie->setCookie($this->ObjView->_section . '_CurrentLanguageID', $languageID);
        $this->ObjCookie->setCookie($this->ObjView->_section . '_LanguageLCIDstring', $newLCIDString);
        //URL Rewrite
        $sefParams      = array(
            'languageID' => $languageID,
            'newLCIDString' => $newLCIDString,
            'oldLCIDString' => $oldLCIDString
        );
        $newRequestPath = $this->ObjCommon->getSefLangRequestPath($sefParams);
        if ($newRequestPath != '') {
            echo $newRequestPath;
        }
        //@Usage=>AnalyticsModule
        //For Saving The users Opted Language
        $this->recordVisitorlanguage($languageID);
        //Saving Visitors- Language For Anlytics Ends Here               
        exit;
    }
    public function AjaxresetcurrencyAction() {
        $currencyID    = $_POST['currencyID'];
        $this->ObjCookie->setCookie($this->ObjView->_section . '_currentCurrency', $currencyID);
        exit;
    }
    //Function To Record Visitors Language
    public function recordVisitorlanguage($languageID) {
        $ObjLog             = new AnalyticsModel();
        $visitorID          = $this->ObjCookie->getCookie("GT_VISITORID");
        $setVisitorLanguage = $ObjLog->setVisitorLanguage($languageID, $visitorID);
    }
    /* START : Widget Module */
    /* START : Function to assign the list widgets and tab into view . ( Note: No products ) */
    private function listWidgets() {
        $ObjWidget              = new WidgetModel();
        $languageIDs            = $this->ObjView->languageIDs;
        $languageIDs['Content'] = $languageIDs['Current'];
        $params                 = array(
            'languageIDs' => $languageIDs,
            'widgetDisplayedOn' => 'home',
            'status' => 'A',
			'hasTabs'=>true,
            'currentDate' => date('Y-m-d')
        );
		$ObjDevice		= new Device();
		if(	$ObjDevice->isMobile() || $ObjDevice->isTablet() ){
			$params['widgetPlatform'] 	= 	'mobile';
		}else{
			$params['widgetPlatform'] 	= 	'desktop';
		}
                $params['brandID'] = $this->ObjCommon->brandID;
        $listWidget             = $ObjWidget->listWidget($params);
        /*
		foreach ($listWidget as $key => $widget) {
            $widgetID                       = $widget['widgetID'];
            $params                         = array(
                'widgetID' => $widgetID,
                'status' => 'A',
                'languageIDs' => $languageIDs
            );
            $listWidget[$key]['widgetTabs'] = $ObjWidget->listWidgetTab($params);
        }
		*/
        $this->ObjView->assign("listWidget", $listWidget);
    }
	
	public function ajaxgetwidgetAction(){
                
		$ObjWidget 			= 	new WidgetModel();
                $ObjProductList                 =       new ProductListModel();
                $ObjCustomOption                =       new CustomOptionModel();
		$widgetID 			= 	$this->getRequestValue('widgetid');
		$widgetDisplayedOn 	= 	$this->getRequestValue('widgetdisplayedon');
		$widgetKey 			= 	$this->getRequestValue('key');
		$new_arrival_date_limit		= 	$this->getSettingValue('product_cart_settings', 'new_arrival_date_limit');		
		$languageIDs		= 	$this->ObjView->languageIDs;
		$languageIDs['Content'] = $languageIDs['Current'];
		$params=array(
			'widgetID'=>$widgetID,
			'status'=>'A',
			'languageIDs'=>$languageIDs
		);
		$widget 		= $ObjWidget->getWidget($params);
		$listWidgetTab 	= $ObjWidget->listWidgetTab($params);  
                $fillData       = 0;
		foreach($listWidgetTab as $tabkey=>$widgetTab){
			$widgetTabID 		= 	$widgetTab['widgetTabID'];
			$widgetType			=   $widgetTab['widgetType'];

			$params	=	array(
				'widgetTabID'	=>	$widgetTabID,
				'languageIDs'	=>	$languageIDs,
				'userGroupID'	=>	(int)$this->ObjCommon->REGISTERED_USER_GROUP_ID
			);
			$getWidgetTab 	= 	$ObjWidget->getWidgetTabFrontend($params);
			$listingType 	= 	$getWidgetTab['listingType'];
			$itemCount 		= 	$getWidgetTab['itemCount'];
			
			$viewMoreLabelType 		= 	$getWidgetTab['viewMoreLabelType'];
			$enableViewMore 		= 	$getWidgetTab['enableViewMore'];
			$viewMoreLabel 			= 	$getWidgetTab['viewMoreLabel'];
			$widgetViewMoreLink		= 	$getWidgetTab['viewMoreLink'];
			$showItemLabel			= 	$getWidgetTab['showItemLabel'];
			$staticWidgetContent	= 	$getWidgetTab['staticWidgetContent'];
			
                        
                        $bundleID                       = 	isset($widgetTab['bundleID'])?$widgetTab['bundleID']:0;
                        if($fillData<=0){

						$bundleType =   "No";
						$listWidgetBundle           =   array();

                        
				
			
				$params['listingType'] 	= 	$listingType;
				$params['itemCount'] 	= 	$itemCount;
				$params['new_arrival_date_limit'] 	= 	$new_arrival_date_limit;
				$params['hide_out_of_stock_in_homepage']=       $this->getSettingValue('product_cart_settings', 'hide_out_of_stock_in_homepage');
				if($listingType=='custom') {
                                    $listWidgetTabItems = array();
                                } else {
                                    $listWidgetTabItems 	= 	$ObjWidget->listWidgetTabItems($params);                                
                                }   
				/* if($listingType=='combo'){
					$ObjProduct 		= 	new ProductModel();
					$itemCount = 0;
					$sefproduct_idArray =	array();
					foreach($listWidgetTabItems as $key=>$comboProduct){
						$comboID = $comboProduct['combo_id'];
						$params=array(
							'comboID'		=>	$comboID,
							'userGroupID'	=>	(int)$this->ObjCommon->REGISTERED_USER_GROUP_ID,
							'languageIDs'	=>	$languageIDs
						);
						$listWidgetTabItems[$key]['products'] = $ObjProduct->listComboItemProducts($params);
						if(!empty($listWidgetTabItems[$key]['products'])){
							foreach($listWidgetTabItems[$key]['products'] as $product){
								$sefproduct_idArray[] = $product['product_id'];
								if($product['productQuantity'] <= 0){
									unset($listWidgetTabItems[$key]); 
								}
							}
						}else{
							unset($listWidgetTabItems[$key]); 
						}
					}
					$this->ObjCommon->setCommonSefPath(array(
						'product'
					), $sefproduct_idArray);
				} */
						
				
				//START  : SEF
				$sefproduct_idArray		= array(); 
				if($listingType=='you_may_like' || $listingType=='custom' || $listingType=='auction' || $listingType=='categories'){
					foreach($listWidgetTabItems as $keyw=>$item){
						$sefproduct_idArray[] = $item['itemID'];
                                                $listWidgetTabItems[$keyw]['customOptionCount'] = $ObjCustomOption->getProductCustomOptionsCount($item['itemID']);
					}
                                        if($listingType=='categories') {                                             
                                            $this->ObjCommon->setCategorySefUrlByID($sefproduct_idArray);    
                                        } else {
                                            $this->ObjCommon->setCommonSefPath(array('product'),$sefproduct_idArray);
                                        }
					
				}
                                
				//END  : SEF
				
				$remainingItemsNeeded	=	$itemCount - count($listWidgetTabItems);
				if( $remainingItemsNeeded >0 ){
					/*START : Already Selected Items */
					$selectedItems 		= 	array();
					$listRemainingItem	= 	array();
					$listRemainingItems = 	array();
					foreach($listWidgetTabItems as $items){
						$selectedItems[] = $items['itemID'];
					}
					/*END : Already Selected Items */
							
					switch($listingType){
						case 'teams':
							$ObjTeam = new TeamModel();
							$params	=array(
								'languageIDs'=>$languageIDs,
								'limitFrom'=>0,
								'fields'=>"
									team.team_id AS itemID,
									team_key AS itemKey,
									CASE 
										WHEN 
											team.team_logo!='' 
											THEN 
												CONCAT('team/logo/',team.team_logo) 
										ELSE 
											'' 
									END AS itemIcon,
									team_name AS itemName,
									'' AS itemPrice ",
								'excludeTeams'=>$selectedItems,
								'limitTo'=>$remainingItemsNeeded
							);
							
							$listRemainingItems = $ObjTeam->listTeam($params);
							break;
						case 'brands':
							$ObjBrand = new BrandModel();
							$params	=array(
								'languageIDs'=>$languageIDs,
								'limitFrom'=>0,
								'fields'=>"
									brand.brandID AS itemID,
									brandKey AS itemKey,
									CASE 
										WHEN 
											brand.brandIcon!='' 
											THEN 
												CONCAT('brand/small/',brand.brandIcon) 
										ELSE 
											'' 
									END AS itemIcon,
									brandName AS itemName,
									'' AS itemPrice ",
								'excludeBrands'=>$selectedItems,
								'limitTo'=>$remainingItemsNeeded
							);
							$listRemainingItems = $ObjBrand->listBrand($params);
							break;
						case 'categories':
                                                    
							$ObjCategory 	= 	new ProductCategoryModel();
							$selectFields 	= 	"
								productCat.productCategoryID AS itemID,
								productCategoryKey AS itemKey,
								CASE 
									WHEN 
										productCategoryImage!='' 
										THEN 
											CONCAT('product-category/',productCategoryImage) 
									ELSE 
										'' 
								END AS itemIcon,
								productCategoryName AS itemName,
								'' AS itemPrice 
							";
							$listRemainingItems = $ObjCategory->listProductCategories($languageIDs,'','user','',0,$remainingItemsNeeded,$selectFields,$selectedItems);
							break;	
						case 'you_may_like':break;
							$ObjProductList 	= 	new ProductListModel();
							$ObjProduct 		= 	new ProductModel();
							if(($this->ObjCookie->getCookie("RVI_IDS"))){
								$recentlyViewedItems	=	$this->ObjCookie->getCookie("RVI_IDS");
								$recentlyViewedItems	=	unserialize($recentlyViewedItems);
							}
							else{
								$recentlyViewedItems	=	array(array('productID'=>1));
							}
							$sefproduct_idArray		= array();
							foreach($recentlyViewedItems as $key=>$items){
								$recentItem = $items['productID'];                                                
								
								$args			  = array(
									'limitFrom'		=> 	0,
									'limitTo'		=> 	1,
									'languageIDs'	=> 	$languageIDs,
									'productType'		=> 	array(
									'isFeatured'	=>1,
									'limitMainListing'=>'',
									'limitDefListing'=>'',
									'selectedproduct_id'=> 	$recentItem,
									'userGroupID'	=>	(int)$this->ObjCommon->REGISTERED_USER_GROUP_ID,
									'productStatus'	=> 	'Active'
											)
									);
								$productdtls =  $ObjProduct->getProductDetailsFrontend($args);
								$params		= array(
									'languageIDs'	=> 	$languageIDs,
									'productID'		=> 	$recentItem,
									'excludeProducts' =>$selectedItems,
									'itemCount'		=>	$remainingItemsNeeded,
									'new_arrival_date_limit'		=>	$new_arrival_date_limit,
									'attribute_set_id'=>  (isset($productdtls[0]['attribute_set_id']))?$productdtls[0]['attribute_set_id']:'',
									'minTierPrice'  =>  (isset($productdtls[0]['offerPrice']))?$productdtls[0]['offerPrice']:'',
									'userGroupID'	=>	(int)$this->ObjCommon->REGISTERED_USER_GROUP_ID
								);
								$listRecommendedProducts	= 	$ObjProductList->listRecommendedProducts($params);
								if(!$key){
									$listRemainingItem 	= 	$listRecommendedProducts;
								}
								else{
									$listRemainingItem =array_merge($listRemainingItem,$listRecommendedProducts );
								}
								if(count($listRemainingItem) >= $remainingItemsNeeded){
									break;
								}
							}
							
							$listRemainingItem = array_unique($listRemainingItem, SORT_REGULAR);
							foreach($listRemainingItem as $key=>$items){
								$sefproduct_idArray[] = $items['productID'];
								$listRemainingItems[$key]['itemID'] 	= 	$items['productID'];
								$listRemainingItems[$key]['itemKey'] 	= 	$items['productID'];
								$listRemainingItems[$key]['itemIcon'] 	= 	'catalog/product/thumb/'.$items['productImage'] ;
								$listRemainingItems[$key]['itemName'] 	= 	$items['productTitle'];
								$listRemainingItems[$key]['itemDiscount'] 		= 	$items['itemDiscount'];
								$listRemainingItems[$key]['newArrival'] 		= 	$items['newArrival'];
								$listRemainingItems[$key]['enable_presale'] 	= 	$items['enable_presale'];
								$listRemainingItems[$key]['custom_label'] 		= 	$items['custom_label'];
								$listRemainingItems[$key]['itemFeaturedStatus'] = 	$items['featuredStatus'];
								$listRemainingItems[$key]['is_customizable'] 	= 	$items['is_customizable'];
								$listRemainingItems[$key]['itemPrice'] 			= 	$items['offerPrice'];
								$listRemainingItems[$key]['itemOptionQuantitySum'] 	= 	$items['productOptionQuantitySum'];  
								$listRemainingItems[$key]['itemRegularPrice'] 		= 	$items['price'];  
                                                                $listRemainingItems[$key]['customOptionCount']          =       $ObjCustomOption->getProductCustomOptionsCount($items['productID']);
							} 
							$this->ObjCommon->setCommonSefPath(array('product'),$sefproduct_idArray);
							break;	
						case 'custom':
							$params=array(
								'conditions'=>unserialize($getWidgetTab['conditions']),
								'itemCount'		=> 	$remainingItemsNeeded,
								'listingType'	=> 	$listingType,
								'selectedItems' =>      $selectedItems,
								'userGroupID'	=>	(int)$this->ObjCommon->REGISTERED_USER_GROUP_ID,
                                                             'hide_out_of_stock_in_homepage' => $this->getSettingValue('product_cart_settings', 'hide_out_of_stock_in_homepage')
							);
							$listCustomProducts = 	$ObjWidget->listCustomProducts($params,'Y');
							
							
							
							$listRemainingItems	=	array();
							if(!empty($listCustomProducts)){
								$params=array(
									'languageIDs'	=> 	$languageIDs,
									'itemCount'		=> 	$remainingItemsNeeded,
									'productIDs'	=>	$listCustomProducts,
									'listingType'	=>	$listingType,
									'new_arrival_date_limit'	=> 	$new_arrival_date_limit,
									'userGroupID'	=>	(int)$this->ObjCommon->REGISTERED_USER_GROUP_ID,
                                                                        'hide_out_of_stock_in_homepage' => $this->getSettingValue('product_cart_settings', 'hide_out_of_stock_in_homepage')
								);
								$listRemainingItems	=	$ObjWidget->listWidgetProducts($params);
                                                                if(!empty($listRemainingItems)) {
                                                                    foreach($listRemainingItem as $key=>$items){
                                                                        $listRemainingItem[$key]['customOptionCount']          =       $ObjCustomOption->getProductCustomOptionsCount($items['productID']);
                                                                    }
                                                                }
							}                                     
							$this->ObjCommon->setCommonSefPath(array('product'),$listCustomProducts);
							break;	
					}
					/* Merge the items which are getting through runtime */
                                        
					$listWidgetTabItems =array_merge($listWidgetTabItems,$listRemainingItems );
                                        if(!empty($listWidgetTabItems)) {
                                            $fillData = $fillData + 1;
                                        }
                                        
                                        
				}

                     }  else {
                         $listWidgetTabItems = '';
                     }
				$this->ObjCommon->setCommonSefPath('team');
				
				$listWidgetTab[$tabkey]['uniqueID'] = uniqid();
				$listWidgetTab[$tabkey]['viewMoreLabel'] = $viewMoreLabel;
				$listWidgetTab[$tabkey]['widgetDisplayedOn'] = $widgetDisplayedOn;
				$listWidgetTab[$tabkey]['enableViewMore'] = $enableViewMore;
				$listWidgetTab[$tabkey]['showItemLabel'] = $showItemLabel;
				$listWidgetTab[$tabkey]['widgetType'] = $widgetType;
				$listWidgetTab[$tabkey]['staticWidgetContent'] = $staticWidgetContent;
				$listWidgetTab[$tabkey]['widgetViewMoreLink'] = $widgetViewMoreLink;
				$listWidgetTab[$tabkey]['widgetKey'] = $widgetKey;
				$listWidgetTab[$tabkey]['viewMoreLabelType'] = $viewMoreLabelType;
				$listWidgetTab[$tabkey]['listWidgetTabItems'] = $listWidgetTabItems;
                                $listWidgetTab[$tabkey]['listWidgetBundles'] = $listWidgetBundle;
				$listWidgetTab[$tabkey]['widgetViewMoreLabel'] = 'View More Products';
				$listWidgetTab[$tabkey]['listingType'] = $listingType;
                                $listWidgetTab[$tabkey]['bundleType'] = $bundleType;
                               
				if(empty($listWidgetTabItems) && count($listWidgetTab)==1 && count($listWidgetTab)==($tabkey+1)){
					if($widgetType!='static') {
						unset($listWidgetTab[$tabkey]);
					}
				}
                               
		}
                
                //echo "<pre>";print_r($listWidgetTab);exit;
		
		/* START : image dimensions */
		$category_image_width	= 	$this->getSettingValue('product_cart_settings', 'category_image_width');
		$category_image_height	= 	$this->getSettingValue('product_cart_settings', 'category_image_height');
		$thumb_width			= 	$this->getSettingValue('product_cart_settings', 'thumb_width');
		$thumb_height			= 	$this->getSettingValue('product_cart_settings', 'thumb_height');
		
		$this->ObjView->assign("category_image_width", $category_image_width);
		$this->ObjView->assign("category_image_height", $category_image_height);
		$this->ObjView->assign("thumb_width", $thumb_width);
		$this->ObjView->assign("thumb_height", $thumb_height);
		/* END : image dimensions */
		
		$this->ObjView->assign("listWidgetTab", $listWidgetTab);
		$this->ObjView->assign("widget", $widget);
                $this->ObjView->assign("widgetID", $widget['widgetID']);
		$this->ObjView->display('catalog/AjaxCatalogWidget.tpl');
		
		
	}
	
	
    /* END : Function to assign the list widgets and tab into view . ( Note: No products ) */
    /* START : To get the products into widget tabs */
    public function ajaxGetWidgetTabItemsAction() {
        $ObjWidget              = new WidgetModel();
        $ObjCustomOption        = new CustomOptionModel();
        $languageIDs            = $this->ObjView->languageIDs;
        $languageIDs['Content'] = $languageIDs['Current'];
        $widgetDisplayedOn      = $this->getRequestValue('widgetdisplayedon');
        $categoryID             = $this->getRequestValue('category');
        $widgetTabID            = $this->getRequestValue('widgettab');
        $widgetKey 		= $this->getRequestValue('key');
        $tabCount 		= $this->getRequestValue('cn');
        $new_arrival_date_limit	= $this->getSettingValue('product_cart_settings', 'new_arrival_date_limit');
        $params                 = array(
            'widgetTabID' => $widgetTabID,
            'languageIDs' => $languageIDs,
            'userGroupID' => (int) $this->ObjCommon->REGISTERED_USER_GROUP_ID,
            'hide_out_of_stock_in_homepage' => $this->getSettingValue('product_cart_settings', 'hide_out_of_stock_in_homepage')
        );
        $getWidgetTab           = $ObjWidget->getWidgetTab($params);
                      
        $bundleID               = isset($widgetTab['bundleID'])?$widgetTab['bundleID']:0;
        //$bundleID               = $getWidgetTab['bundleID'];
        $listingType            = $getWidgetTab['listingType'];
        $itemCount              = $getWidgetTab['itemCount'];
        $viewMoreLabelType      = $getWidgetTab['viewMoreLabelType'];
        $enableViewMore         = $getWidgetTab['enableViewMore'];
        $viewMoreLabel          = $getWidgetTab['viewMoreLabel'];
        $widgetViewMoreLink     = $getWidgetTab['viewMoreLink'];
        $showItemLabel          = $getWidgetTab['showItemLabel'];
        $staticWidgetContent	= $getWidgetTab['staticWidgetContent'];
        $params['listingType']  = $listingType;
        $params['itemCount']    = $itemCount;
        $tabkey                 = 0;
        $widgetTabs['uniqueID']            = uniqid();
        $widgetTabs['widgetID']            = $getWidgetTab['widgetID'];
        $widgetTabs['widgetTabID']         = $widgetTabID;
        $widgetTabs['viewMoreLabel']       = $viewMoreLabel;
        $widgetTabs['widgetDisplayedOn']   = $widgetDisplayedOn;
        $widgetTabs['enableViewMore']      = $enableViewMore;
        $widgetTabs['showItemLabel']       = $showItemLabel;
        $widgetTabs['widgetType']          = $getWidgetTab['widgetType'];
        $widgetTabs['staticWidgetContent'] = $staticWidgetContent;
        $widgetTabs['widgetViewMoreLink']  = $widgetViewMoreLink;
        $widgetTabs['widgetKey']           = $widgetKey;
        $widgetTabs['viewMoreLabelType']   = $viewMoreLabelType; 
        $widgetTabs['widgetViewMoreLabel'] = 'View More Products';
        $widgetTabs['listingType']         = $listingType;       

		$bundleType =   "No";
		$listWidgetBundle           =   array();

        $widgetTabs['listWidgetBundles'] = $listWidgetBundle;
        $widgetTabs['bundleType']        = $bundleType;                
        $listWidgetTabItems     = $ObjWidget->listWidgetTabItems($params);        
        $remainingItemsNeeded   = $itemCount - count($listWidgetTabItems);
        
        if ($remainingItemsNeeded > 0) {
            /*START : Already Selected Items */
            $selectedItems      = array();
            $listRemainingItem  = array();
            $listRemainingItems = array();
            foreach ($listWidgetTabItems as $items) {
                $selectedItems[] = $items['itemID'];
            }
			 $this->ObjCommon->setCommonSefPath(array(
				'product'
			), $selectedItems);
            /*END : Already Selected Items */
            switch ($listingType) {
                case 'teams':
                    $ObjTeam = new TeamModel();
                    $params	=array(
                            'languageIDs'=>$languageIDs,
                            'limitFrom'=>0,
                            'fields'=>"
                                    team.team_id AS itemID,
                                    team_key AS itemKey,
                                    CASE 
                                            WHEN 
                                                    team.team_logo!='' 
                                                    THEN 
                                                            CONCAT('team/logo/',team.team_logo) 
                                            ELSE 
                                                    '' 
                                    END AS itemIcon,
                                    team_name AS itemName,
                                    '' AS itemPrice ",
                            'excludeTeams'=>$selectedItems,
                            'limitTo'=>$remainingItemsNeeded
                    );

                    $listRemainingItems = $ObjTeam->listTeam($params);
                    break;
                case 'brands':
                    $ObjBrand           = new BrandModel();
                    $params             = array(
                        'languageIDs' => $languageIDs,
                        'limitFrom' => 0,
                        'fields' => "
							brand.brandID AS itemID,
							brandKey AS itemKey,
							CASE 
								WHEN 
									brand.brandIcon!='' 
									THEN 
										CONCAT('brand/small/',brand.brandIcon) 
								ELSE 
									'' 
							END AS itemIcon,
							brandName AS itemName,
							'' AS itemPrice ",
                        'excludeBrands' => $selectedItems,
                        'limitTo' => $remainingItemsNeeded
                    );
                    $listRemainingItems = $ObjBrand->listBrand($params);
                    break;
                case 'categories':
                    $ObjCategory        = new ProductCategoryModel();
                    $selectFields       = "
						productCat.productCategoryID AS itemID,
						productCategoryKey AS itemKey,
						CASE 
							WHEN 
								productCategoryImage!='' 
								THEN 
									CONCAT('product-category/',productCategoryImage) 
							ELSE 
								'' 
						END AS itemIcon,
						productCategoryName AS itemName,
						'' AS itemPrice 
					";
                    
                    $listRemainingItems = $ObjCategory->listProductCategories($languageIDs, '', 'user', '', 0, $remainingItemsNeeded, $selectFields, $selectedItems);
                    break;
                case 'you_may_like':
                    $ObjProductList = new ProductListModel();                    
                    $ObjProduct     = new ProductModel();
                    if (($this->ObjCookie->getCookie("RVI_IDS"))) {
                        $recentlyViewedItems = $this->ObjCookie->getCookie("RVI_IDS");
                        $recentlyViewedItems = unserialize($recentlyViewedItems);
                    } else {
                        $recentlyViewedItems = array();
                    }
                    $sefProductIDArray = array();
                    foreach ($recentlyViewedItems as $key => $items) {
                        $recentItem              = $items['productID'];
                        $sefProductIDArray[]     = $recentItem; 
                        $args                    = array(
                            'limitFrom' => 0,
                            'limitTo' => 1,
                            'languageIDs' => $languageIDs,
                            'productType' => array(
                                'productTypeID' => 1,
                                'productTypeKey' => 'product_product',
                                'productTypeUrlKey' => '',
                                'isFeatured' => 1,
                                'limitMainListing' => '',
                                'limitDefListing' => '',
                                'productTypeName' => $this->getLanguageValue('lblProducts')
                            ),
                            'selectedProductID' => $recentItem,
                            'userGroupID' => (int) $this->ObjCommon->REGISTERED_USER_GROUP_ID,
                            'productStatus' => 'Active'
                        );
                        $productdtls             = $ObjProduct->getProductDetails($args);
                        $params                  = array(
                            'languageIDs' => $languageIDs,
                            'productID' => $recentItem,
                            'excludeProducts' => $selectedItems,
                            'itemCount' => $remainingItemsNeeded,
                            'new_arrival_date_limit'=> $new_arrival_date_limit,
                            'attributeSetID' => (isset($productdtls[0]['attributeSetID'])) ? $productdtls[0]['attributeSetID'] : '',
                            'minTierPrice' => (isset($productdtls[0]['offerPrice'])) ? $productdtls[0]['offerPrice'] : '',
                            'userGroupID' => (int) $this->ObjCommon->REGISTERED_USER_GROUP_ID
                        );
                        $listRecommendedProducts = $ObjProductList->listRecommendedProducts($params);
                        if (!$key) {
                            $listRemainingItem = $listRecommendedProducts;
                        } else {
                            $listRemainingItem = array_merge($listRemainingItem, $listRecommendedProducts);
                        }
                        if (count($listRemainingItem) >= $remainingItemsNeeded) {
                            break;
                        }
                    }
                    $this->ObjCommon->setCommonSefPath(array(
                        'product'
                    ), $sefProductIDArray);
                    $listRemainingItem = array_unique($listRemainingItem, SORT_REGULAR);
                    foreach ($listRemainingItem as $key => $items) {
                        $listRemainingItems[$key]['itemID']                = $items['productID'];
                        $listRemainingItems[$key]['itemOptionID']          = $items['productOptionID'];
                        $listRemainingItems[$key]['itemKey']               = $items['productID'];
                        $listRemainingItems[$key]['itemIcon']              = 'catalog/product/thumb/' . $items['productImage'];
                        $listRemainingItems[$key]['itemName']              = $items['productTitle'];
                        $listRemainingItems[$key]['itemPrice']             = $items['offerPrice'];
                        $listRemainingItems[$key]['itemOptionQuantitySum'] = $items['productOptionQuantitySum'];
                        $listRemainingItems[$key]['itemRegularPrice']      = $items['productOptionRegularPrice'];
                        $listRemainingItems[$key]['customOptionCount']     = $ObjCustomOption->getProductCustomOptionsCount($items['productID']);
                    }
                    
                    break;
                case 'custom':                    
                    $params             = array(
                        'conditions' => unserialize($getWidgetTab['conditions']),
                        'itemCount' => $remainingItemsNeeded,
                        'listingType'	=> 	$listingType,
			'selectedItems' =>      $selectedItems,
                        'userGroupID' => (int) $this->ObjCommon->REGISTERED_USER_GROUP_ID
                    );//echo '<pre>'; print_r($params);exit;
                    $listCustomProducts = $ObjWidget->listCustomProducts($params,'Y');
                    $listRemainingItems = array();
                    if (!empty($listCustomProducts)) {
                        $params             = array(
                            'languageIDs' => $languageIDs,
                            'itemCount' => $remainingItemsNeeded,
                            'productIDs' => $listCustomProducts,
                            'listingType'	=>	$listingType,
                            'new_arrival_date_limit'	=> 	$new_arrival_date_limit,
                            'userGroupID' => (int) $this->ObjCommon->REGISTERED_USER_GROUP_ID,
                            'hide_out_of_stock_in_homepage' => $this->getSettingValue('product_cart_settings', 'hide_out_of_stock_in_homepage')
                        );
                        $listRemainingItems = $ObjWidget->listWidgetProducts($params);
                        if (!empty($listRemainingItems)) {
                            foreach ($listRemainingItems as $keyr => $items) {
                                $listRemainingItems[$keyr]['customOptionCount']     = $ObjCustomOption->getProductCustomOptionsCount($items['productID']);    
                            }
                        }
                    }
                    $this->ObjCommon->setCommonSefPath(array(
                        'product'
                    ), $listCustomProducts);
                    break;
            }

            /* Merge the items which are getting through runtime */
            $listWidgetTabItems = array_merge($listWidgetTabItems, $listRemainingItems);
			
        } elseif(!empty($listWidgetTabItems) && $remainingItemsNeeded<=0) {
            $selectedItems      = array();
            foreach ($listWidgetTabItems as $keyw=>$items) {
                $selectedItems[]                                    = $items['itemID'];
                $listWidgetTabItems[$keyw]['customOptionCount']     = $ObjCustomOption->getProductCustomOptionsCount($items['itemID']);
            }
            
            $this->ObjCommon->setCommonSefPath(array('product'), $selectedItems);
        }
        $widgetTabs['listWidgetTabItems'] = $listWidgetTabItems;
        //echo "<pre>";print_r($listWidgetTabItems);exit;
        /* START : image dimensions */
        $brand_icon_width      = $this->getSettingValue('product_cart_settings', 'brand_icon_width');
        $brand_icon_height     = $this->getSettingValue('product_cart_settings', 'brand_icon_height');
        $category_image_width  = $this->getSettingValue('product_cart_settings', 'category_image_width');
        $category_image_height = $this->getSettingValue('product_cart_settings', 'category_image_height');
        $thumb_width           = $this->getSettingValue('product_cart_settings', 'thumb_width');
        $thumb_height          = $this->getSettingValue('product_cart_settings', 'thumb_height');
        $this->ObjView->assign("brand_icon_width", $brand_icon_width);
        $this->ObjView->assign("brand_icon_height", $brand_icon_height);
        $this->ObjView->assign("category_image_width", $category_image_width);
        $this->ObjView->assign("category_image_height", $category_image_height);
        $this->ObjView->assign("thumb_width", $thumb_width);
        $this->ObjView->assign("thumb_height", $thumb_height);
        /* END : image dimensions */
        $this->ObjView->assign("uniqueID", uniqid());
        $this->ObjView->assign("viewMoreLabel", $viewMoreLabel);
        $this->ObjView->assign("enableViewMore", $enableViewMore);
        $this->ObjView->assign("showItemLabel", $showItemLabel);
        $this->ObjView->assign("widgetViewMoreLink", $widgetViewMoreLink);
        $this->ObjView->assign("viewMoreLabelType", $viewMoreLabelType);
        $this->ObjView->assign("widgetID", $getWidgetTab['widgetID']);
        //$this->ObjView->assign("listWidgetTab", $listWidgetTabItems);
        $this->ObjView->assign("widgetTabs", $widgetTabs);
        $this->ObjView->assign("widgetViewMoreLabel", 'View More Products');
        $this->ObjView->assign("listingType", $listingType);
        $this->ObjView->assign("tabCount", $tabCount);
        //$this->ObjView->assign("bundleType", $bundleType); 
        $pageLayout = 'catalog/default/';       
        $this->ObjView->display($pageLayout . 'AjaxCatalogWidget.tpl');
    }
    /* END : To get the products into widget tabs */
    /* END : Widget Module */
    //TO LIST SHIPPING CITIES
    public function shippingcitiesAjaxAction() {
        
        $objCity           = new CityModel();
        $ObjUser           = new UserModel();
        $shippingcountryID = $_REQUEST['shippingcountryID'];
        $shippingcitiesList = '';
        if ($shippingcountryID > 0) {
            $shippingcitiesList = $objCity->listCitiesFrontend($shippingcountryID);            
        }
	
        $this->ObjView->assign('shippingCity', isset($_REQUEST['shippingCity'])?$_REQUEST['shippingCity']:'');
        $this->ObjView->assign('shippingcitiesList', $shippingcitiesList);
        $this->ObjView->display('account/CitiesShippingAjaxList.tpl');
    }
    
    
    public function copyImagesAction() {
        $languageIDs = $this->ObjView->languageIDs;
        $ObjBanner = new BannerModel();
        $resBanner     = $ObjBanner->copyBanners($languageIDs);
        
    }
    
    public function updCitiesDBAction(){
        $objState           = new StateModel();
        $languageIDs            = $this->ObjView->languageIDs;
        $languageIDs['Current'] = $languageIDs['Content'];
        $languageIDs['AllList'] = $languageIDs['All'];
        
        $citylist   =   'Abha~*Abqaiq~*Al Badayea~*Alhada~*Al Hassa~*Al Hofuf~*Al-Jsh~*Al Jubail~*Al Kharj~*Al Khobar~*Al Majmaah~*Al Oyun - Hofuf~*Al Qatif~*AlRass~*Anak~*Arar~*Ash Shuqaiq~*Ath Thybiyah~*Awamiah~*Bahara~*Baqayq - Hofuf~*Bishah~*Bukeiriah~*Buraydah~*Dammam~*Dhahran~*Domat Al Jandal~*Dumah Al Jandal~*Hafar Al Batin~*Hail~*Jafar~*Jazan~*Jeddah~*Jouf~*Khamis Mushait~*Khodaria~*King Khalid Military City~*Mecca~*Medina~*Mubaraz~*Nabiya~*Qarah~*Qassim~*Rahima~*Ras Tanura~*Riyadh Al Khabra~*Safwa~*Sakaka~*Seihat~*Taif~*Tarut~*Udhailiyah - Hofuf~*Unayzah~*Uyun~*Yanbu~*Yanbu Al Baher';
        $cityArr    =   explode("~*",$citylist);
        $POST['countryID']  =   184;
        
        $POST['stateStatus']  =   'Active';
        
        for($i=0;$i<count($cityArr);$i++){
            $POST['stateName']  =   $cityArr[$i];
            $POST['stateShortName']  =   $POST['stateName'][0].strtoupper($POST['stateName'][strlen($POST['stateName'])-1]);
            $objState->saveStateDetails($languageIDs, $POST);
        }
    }

}
