<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of cls_cart
 *
 * @author Asha S
 */
class Cart {
    //put your code here
    
     /*
     Function to get cart item count
    */
    public static function getCartCount($userId='',$visitorId='')
    {
    	$objResult                      =   new stdClass();
    	$tableName                      =   DbHelper::setTablePrefix('cart');
    	$andCase                        =   '';
        
       //echo $userId."-------".$visitorId;
    	 if($visitorId!='')
                 $andCase.= 'visitor_cart_id = "'.generalMethods::escapeString($visitorId).'"  ';
            if($userId!='')
                 $andCase.= 'user_id = "'.generalMethods::escapeString($userId).'"  ';
    	//$andCase.=   rtrim($andCase, " AND");
         $objResultRow                   =   DbHelper::selectRecord($tableName,'COUNT(cart_id) as cart_count',$andCase);
    	//Check Cart Details exist for the selected  Cart ID
    	if($objResultRow){
    		// Assign Cart details to object
                $objResult->status        = SUCCESS;
    		$objResult->data          =    $objResultRow;
        }
    	else {
    		$objResult->status      =   ERROR;
    		//$objResult->message     =   CART_QUANTITY_NOT_EXIST; // Cart details not exists
    	}
    	return $objResult;
    	 
    }
    
    
    // function to check gift certificate items count in cart 
    
      /*
     Function to get cart item count
    */
    public static function getGiftCertificateItemsCartCount($userId='',$visitorId='')
    {
    	$objResult                      =   new stdClass();
    	$tableName                      =   DbHelper::setTablePrefix('cart');
    	$andCase                        =   '';
        
         if($userId!='')
             $andCase   = 'user_id = "'.generalMethods::escapeString($userId).'"  ';
    	  if($visitorId!='')
                 $andCase   = 'visitor_cart_id = "'.generalMethods::escapeString($visitorId).'"  ';
           
           $andCase.= ' AND gift_product_flag = "Y"  ';
             
    	//$andCase                        =   rtrim($andCase, " AND");
    	$objResultRow                   =   DbHelper::selectRecord($tableName,'COUNT(cart_id) as gift_count',$andCase);
    	//Check Cart Details exist for the selected  Cart ID
       
    	if($objResultRow)
    		// Assign Cart details to object
        {
                $objResult->status        =    SUCCESS;
    		$objResult->data          =    $objResultRow;
        }
    	else {
    		$objResult->status        =   ERROR;
    		//$objResult->message     =   CART_QUANTITY_NOT_EXIST; // Cart details not exists
    	}
    	return $objResult;
    	 
    }
    
    
    // Get Non Gift Products Cart Count 
    
     public static function getNonGiftItemsCartCount($userId='',$visitorId='')
    {
    	$objResult                      =   new stdClass();
    	$tableName                      =   DbHelper::setTablePrefix('cart');
    	$andCase                        =   '';
    	 if($visitorId!='')
                 $andCase   = 'visitor_cart_id = "'.generalMethods::escapeString($visitorId).'"  ';
            if($userId!='')
                 $andCase   = 'user_id = "'.generalMethods::escapeString($userId).'"  ';
        $andCase.= 'AND gift_product_flag!="Y"  ';
    	//$andCase                        =   rtrim($andCase, " AND");
        
    	$objResultRow                   =  DbHelper::selectRecord($tableName,'COUNT(cart_id) as itemscount',$andCase);
    	//Check Cart Details exist for the selected  Cart ID
    	if($objResultRow)
    		// Assign Cart details to object
        {
                $objResult->status        =    SUCCESS;
    		$objResult->data          =    $objResultRow;
        }
    	else {
    		$objResult->status        =   ERROR;
    		//$objResult->message     =   CART_QUANTITY_NOT_EXIST; // Cart details not exists
    	}
    	return $objResult;
    	 
    }
    
    //Get Digital Prouducts Count in Cart 
    
    // Get Non Gift Products Cart Count 
    
     public static function getDigitalItemsCartCount($userId='',$visitorId='')
    {
    	$objResult                      =   new stdClass();
    	$tableName                      =   DbHelper::setTablePrefix('cart');
    	$andCase                        =   '';
    	 if($visitorId!='')
                 $andCase   = 'visitor_cart_id = "'.generalMethods::escapeString($visitorId).'"  ';
            if($userId!='')
                 $andCase   = 'user_id = "'.generalMethods::escapeString($userId).'"  ';
        $andCase.= 'AND digital_product_flag="Y"  ';
    	//$andCase                        =   rtrim($andCase, " AND");
        
    	$objResultRow                   =  DbHelper::selectRecord($tableName,'COUNT(cart_id) as digitalcount',$andCase);
    	//Check Cart Details exist for the selected  Cart ID
    	if($objResultRow)
    		// Assign Cart details to object
        {
                $objResult->status        =    SUCCESS;
    		$objResult->data          =    $objResultRow;
        }
    	else {
    		$objResult->status        =   ERROR;
    		//$objResult->message     =   CART_QUANTITY_NOT_EXIST; // Cart details not exists
    	}
    	return $objResult;
    	 
    }
    
    //Delete Gift Items in Cart if cart contains non digital items 
    
      public static function clearNonGiftItemsinCart($userId='',$visitorId='')
    {
    	$objResult                      =   new stdClass();
    	$tableName                      =   DbHelper::setTablePrefix('cart');
    	$andCase                        =   '';
    	 if($visitorId!='')
                 $andCase   = 'visitor_cart_id = "'.generalMethods::escapeString($visitorId).'"  ';
            if($userId!='')
                 $andCase   = 'user_id = "'.generalMethods::escapeString($userId).'"  ';
            
         $andCase.= 'AND gift_product_flag!="Y"  ';
    	//$andCase                        =   rtrim($andCase, " AND");
        //echo $andCase;
    	$objResultRow                   =  DbHelper::selectResult($tableName,'cart_id',$andCase);
            
    	//Check Cart Details exist for the selected  Cart ID
        
           //echopre($objResultRow);
            
    	if($objResultRow)
    		// Assign Cart details to object
        {   foreach($objResultRow as $dataVals) {
                $arrCart[]    =   $dataVals->cart_id;
        }
        
        if(!empty($arrCart))
        {
            $cartids    =   implode("','",$arrCart);
            $delObj     =   self::deleteCartItems($cartids);
            if($delObj>0) {  
                    $objResult->status                  =    SUCCESS;
                    $objResult->data                    =    $delObj; 
                 }else{
                     $objResult->status                 =    ERROR;
                 }
        }
                
             
        }
    	else {
    		$objResult->status        =   ERROR;
    		//$objResult->message     =   CART_QUANTITY_NOT_EXIST; // Cart details not exists
    	}
    	
        return $objResult;
    	 
    }
    
    
    // Delete Cart Items using cart id
    
    public static function deleteCartItems($cartIds)
    {
            $objResult                           = new stdClass();
            $tableName                           = DbHelper::setTablePrefix('cart');
            $where                               = "cart_id IN('".$cartIds. "') " ;
            $affectedRows                        = DbHelper::delete($tableName,$where);
            
         if($affectedRows>0) {  
            $objResult->status                   =    SUCCESS;
            $objResult->data                     =    $affectedRows; 
         }else{
             $objResult->status                  =    ERROR;
         }
            
         return $objResult;
    }
    
    
    
     // function to check the item is digital product or not  in cart 
     public static function isDigitalIteminCart($cartId)
    {
                 $objResult                      = new stdClass();
                 $tableName                      = DbHelper::setTablePrefix('cart');
                 $selectCase                     =  "cart_id =".generalMethods::escapeString($cartId);
                $objResultRow                   = DbHelper::selectSingleValue($tableName,'digital_product_flag',$selectCase);
         // If user exists then assign user data to result object
                 if($objResultRow) {
                      $objResult->status         =    SUCCESS;
                      $objResult->data           =   $objResultRow; // Assign user record  to object
                 }
                 else{
                     $objResult->status          =  ERROR;
                  }

         return $objResult;

    }
    
       // function to check the item is subscription product or not  in cart 
     public static function isSubscriptionIteminCart($cartId)
    {
                 $objResult                      = new stdClass();
                 $tableName                      = DbHelper::setTablePrefix('cart');
                 $selectCase                     =  "cart_id =".generalMethods::escapeString($cartId);
                $objResultRow                    = DbHelper::selectSingleValue($tableName,'subscription_flag',$selectCase);
         // If user exists then assign user data to result object
                 if($objResultRow) {
                      $objResult->status         =    SUCCESS;
                      $objResult->data           =   $objResultRow; // Assign user record  to object
                 }
                 else{
                     $objResult->status          =  ERROR;
                  }

         return $objResult;

    }
    
      //function to check shipping selection required
     public static function checkShippingRequired($userId='',$visitorId='',$totalAmt='')
    {
                 $objResult                      =      new stdClass();
                 
                 $cartTotalCount                 =      0;
                 $cartDigitalCount               =      0;
                 $cartGiftCount                  =      0;
                 $hide_shipping_division         =      1;
                 $cartFreeShiptCount             =      0;
                 
                 //Get Cart Total Count
                 $objCart                        =     self::getCartCount($userId,$visitorId);
                 if($objCart->status==SUCCESS)
                 {
                        $cartObjVal         =   $objCart->data;
                        
                        $cartTotalCount     =  $cartObjVal->cart_count;  
                 }
                 
                 // Get Digital Products Count  
                 
                 /*$objDigitalCart                        =     self::getDigitalItemsCartCount($userId,$visitorId);
                 if($objDigitalCart->status==SUCCESS)
                 {
                        $cartDigitalObjVal         =    $objDigitalCart->data;
                        $cartDigitalCount          =    $cartDigitalObjVal->digitalcount;  
                 }*/
                
                 //Get Gift Product Count in cart 
                 $objGiftCart                 =     self::getGiftCertificateItemsCartCount($userId,$visitorId);
                 if($objGiftCart->status==SUCCESS)
                 {
                        $cartGiftObjVal         =    $objGiftCart->data;
                        $cartGiftCount          =    $cartGiftObjVal->gift_count;  
                 }
                 
                 
                 // Get Physical Items Count in Cart 
                 
                  $objPhysicalCart                 =     self::getPhysicalItemsCartCount($userId,$visitorId);
                 if($objPhysicalCart->status==SUCCESS)
                 {
                        $cartPhysicalObjVal             =    $objPhysicalCart->data;
                        $cartPhysicalCount              =    $cartPhysicalObjVal->physicalcount;  
                 }
                 
                 // Free ship items count
                 
                $cartFreeShiptCount              =     self::getFreeshipItemsCount($userId,$visitorId);
                $orderFreeShip                   =     self::getFreeshipOrderWise($totalAmt);
           
                 /*if($cartDigitalCount>0) {
                        if($cartDigitalCount>=$cartTotalCount) {
                            $hide_shipping_division = 0;

                        }
                    }else{
                        if($cartGiftCount>0) {
                                if($cartGiftCount>=$cartTotalCount) {
                                    $hide_shipping_division = 0;

                                }
                        }
                    }*/
                    
                    //$freeshipItemsCount      =    $cartFreeShiptCount + $cartDigitalCount;
                    if($cartTotalCount>0)
                    {
                        if((int)$cartTotalCount == ((int)$cartFreeShiptCount)) {
                                $hide_shipping_division = 0;
                        }
                    } 
                    if($orderFreeShip>0){
                                $hide_shipping_division = 0;
                    }

         return $hide_shipping_division;

    }
    
    
    
    // Check free shipping items count in cart 
    
    public static function getFreeshipItemsCount($userId='',$visitorId='',$sellerid='')
    {
            global $tableprefix;
            
                    $QueryWishItems="SELECT count(c.cart_id) as freeshipCount
                    FROM ".$tableprefix."cart c
                    INNER JOIN ".$tableprefix."products p ON p.product_id = c.product_id  WHERE p.allow_free_shipping='Y' ";
                    if($userId!='')
                    {
                      $QueryWishItems.=' AND c.user_id = "'.generalMethods::escapeString($userId).' "';
                    }
                    if($visitorId!='')
                    {
                      $QueryWishItems.=' AND c.visitor_cart_id = "'.generalMethods::escapeString($visitorId).' "';
                    }
                    if($sellerid!='')
                    {
                      $QueryWishItems.=' AND c.seller_id = "'.generalMethods::escapeString($sellerid).' "';
                    }
                    
                  
                    //echo $QueryWishItems;
                    /*WHERE f.nUserId ='".$userID."'
                    AND f.nProductId = '".$productID."'
                    AND f.nProductOptionId = '".$productOptionID."' ";*/
                    $resSet             =   DbHelper::execute($QueryWishItems);
                    $data               =   DbHelper::fetchOne($resSet);
                   
                    $freeship_count     =   $data;
                
              return $freeship_count;
            
    }
    
    public static function getFreeshipOrderWise($orderAmt){
         global $tableprefix;  
         $select_settings_value = "SELECT enable_free_shipping,min_order_amount FROM ".$tableprefix."settings WHERE 1";
         $result_settings_value = mysql_query($select_settings_value) or die(mysql_error());
         $settings_row = mysql_fetch_assoc($result_settings_value);
         $freeshipEnable  = $settings_row['enable_free_shipping'];
         $freeshipAmt     = round($settings_row['min_order_amount']);
        
         if($freeshipEnable=="Y"){
             if(round($orderAmt)>=$freeshipAmt)
                 $returnVal = 1;
             else
                  $returnVal = 0;
             
         }else{
              $returnVal = 0;
         }
         return $returnVal;
         
    }
    
    
    //Get Physical Items count in cart 
    
        public static function getPhysicalItemsCartCount($userId='',$visitorId='')
    {
        global $tableprefix;    
    	$objResult                      =   new stdClass();
        
        /*******/
        $QueryWishItems="SELECT count(c.cart_id) as physicalcount
                    FROM ".$tableprefix."cart c
                    INNER JOIN " . $tableprefix . "product_options po ON po.product_option_id = c.product_option_id
                    INNER JOIN ".$tableprefix."products p ON p.product_id = c.product_id    
                    WHERE p.allow_free_shipping!='Y' AND c.gift_product_flag='N'  AND c.digital_product_flag ='N' ";
                    if($userId!='')
                    {
                      $QueryWishItems.=' AND c.user_id = "'.generalMethods::escapeString($userId).' "';
                    }
                    if($visitorId!='')
                    {
                      $QueryWishItems.=' AND c.visitor_cart_id = "'.generalMethods::escapeString($visitorId).' "';
                    }
                    if($sellerid!='')
                    {
                      $QueryWishItems.=' AND c.seller_id = "'.generalMethods::escapeString($sellerid).' "';
                    }
            	
        $objResultRow                   =  DbHelper::customRecord($QueryWishItems);
    	//Check Cart Details exist for the selected  Cart ID
    	if($objResultRow)
    		// Assign Cart details to object
        {
                $objResult->status        =    SUCCESS;
    		$objResult->data          =    $objResultRow;
        }
    	else {
    		$objResult->status        =   ERROR;
    		//$objResult->message     =   CART_QUANTITY_NOT_EXIST; // Cart details not exists
    	}
    	return $objResult;
    	 
    }
    
    
    // Get Subscription Product Cart Count
    
        
        public static function getSubscriptionItemsCartCount($userId='',$visitorId='')
    {
    	$objResult                      =   new stdClass();
    	$tableName                      =   DbHelper::setTablePrefix('cart');
    	$andCase                        =   '';
    	 if($visitorId!='')
                 $andCase   = 'visitor_cart_id = "'.generalMethods::escapeString($visitorId).'"  ';
            if($userId!='')
                 $andCase   = 'user_id = "'.generalMethods::escapeString($userId).'"  ';
        $andCase.= 'AND subscription_flag = "Y" ';
    	//$andCase                        =   rtrim($andCase, " AND");
        
    	$objResultRow                   =  DbHelper::selectRecord($tableName,'COUNT(cart_id) as subscriptioncount',$andCase);
    	//Check Cart Details exist for the selected  Cart ID
    	if($objResultRow)
    		// Assign Cart details to object
        {
                $objResult->status        =    SUCCESS;
    		$objResult->data          =    $objResultRow;
        }
    	else {
    		$objResult->status        =   ERROR;
    		//$objResult->message     =   CART_QUANTITY_NOT_EXIST; // Cart details not exists
    	}
    	return $objResult;
    	 
    }
    
    
    // Function to check the product already added to cart 
         public static function checkProductAddedtoCart($userId='',$visitorId='',$productid,$product_option_id)
    {
    	$objResult                      =   new stdClass();
    	$tableName                      =   DbHelper::setTablePrefix('cart');
    	$andCase                        =   '';
    	 if($visitorId!='')
                 $andCase   = 'visitor_cart_id = "'.generalMethods::escapeString($visitorId).'"  ';
            if($userId!='')
                 $andCase   = 'user_id = "'.generalMethods::escapeString($userId).'"  ';
        $andCase.= ' AND product_id="'.generalMethods::escapeString($productid).'" AND product_option_id="'.generalMethods::escapeString($product_option_id).'"';
    	//$andCase                        =   rtrim($andCase, " AND");
       // echo  $andCase;

    	$objResultRow                   =  DbHelper::selectRecord($tableName,'cart_id',$andCase);
    	//Check Cart Details exist for the selected  Cart ID
    	if($objResultRow)
    		// Assign Cart details to object
        {
                $objResult->status        =    SUCCESS;
    		$objResult->data          =    $objResultRow;
        }
    	else {
    		$objResult->status        =   ERROR;
    		//$objResult->message     =   CART_QUANTITY_NOT_EXIST; // Cart details not exists
    	}
    	return $objResult;
    	 
    }
    // Get all cart items
        public static function getAllCartitems($userId='',$visitorId='')
    {
    	$objResult                      =   new stdClass();
    	$tableName                      =   DbHelper::setTablePrefix('cart');
    	$andCase                        =   '';
    	 if($visitorId!='')
                 $andCase   = 'visitor_cart_id = "'.generalMethods::escapeString($visitorId).'"  ';
            if($userId!='')
                 $andCase   = 'user_id = "'.generalMethods::escapeString($userId).'"  ';
       
    	//$andCase                        =   rtrim($andCase, " AND");
        
    	$objResultRow                   =  DbHelper::selectResult($tableName,'*',$andCase);
    	//Check Cart Details exist for the selected  Cart ID
    	if($objResultRow)
    		// Assign Cart details to object
        {
                $objResult->status        =    SUCCESS;
    		$objResult->data          =    $objResultRow;
        }
    	else {
    		$objResult->status        =   ERROR;
    		//$objResult->message     =   CART_QUANTITY_NOT_EXIST; // Cart details not exists
    	}
    	return $objResult;
    	 
    }    

    //Get Count of same seller products in cart // if single account for seller and buyer

         public static function getCartCountBySellerId($userId='',$visitorId='',$sellerid)
    {
    	$objResult                      =   new stdClass();
    	$tableName                      =   DbHelper::setTablePrefix('cart');
    	$andCase                        =   '';
         if($visitorId!='')
                 $andCase   = 'visitor_cart_id = "'.generalMethods::escapeString($visitorId).'"  ';
            if($userId!='')
                 $andCase   = 'user_id = "'.generalMethods::escapeString($userId).'"  ';
            
                 $andCase.= ' AND seller_id = "'.generalMethods::escapeString($sellerid).'"  ';
    	//$andCase                        =   rtrim($andCase, " AND");

    	$objResultRow                   =  DbHelper::selectRecord($tableName,'COUNT(cart_id) as selleritemCount',$andCase);
    	//Check Cart Details exist for the selected  Cart ID
    	if($objResultRow)
    		// Assign Cart details to object
        {
                $objResult->status        =    SUCCESS;
    		$objResult->data          =    $objResultRow;
        }
    	else {
    		$objResult->status        =   ERROR;
    		//$objResult->message     =   CART_QUANTITY_NOT_EXIST; // Cart details not exists
    	}
    	return $objResult;

    }


    // Get Distint Cart Sellers

    public static function getCartSellerwiseItems($userId='',$visitorId='')
    {
    	$objResult                      =   new stdClass();
    	$tableName                      =   DbHelper::setTablePrefix('cart');
    	$andCase                        =   '';
            if($userId!='')
                 $andCase   = 'user_id = "'.generalMethods::escapeString($userId).'"  ';
    	//$andCase                        =   rtrim($andCase, " AND");

        $cartArray                      =   array();
    	$objResultRow                   =   DbHelper::selectResult($tableName,'seller_id,cart_id,product_id',$andCase);
    	//Check Cart Details exist for the selected  Cart ID
    	if($objResultRow)
    		// Assign Cart details to object
        {
                foreach($objResultRow as $data)
                    {
                        $artistId                   =     $data->seller_id;
                        $cartArray[$artistId][]     =     $data;
                    }
        }
    	return $cartArray;

    }
        

    // Function get seller wise shipping Total


    public static function getCartSellerShippingWeight($userId='',$sellerid='')
    {
            global $tableprefix;

                    $QueryWishItems="SELECT sum(po.product_shipping_weight)as shipWeight
                    FROM ".$tableprefix."cart c
                    INNER JOIN " . $tableprefix . "product_options po ON po.product_option_id = c.product_option_id
                    INNER JOIN " . $tableprefix . "products p ON p.product_id = po.product_id ";
                    if($userId!='')
                    {
                      $QueryWishItems.=' WHERE c.user_id = "'.generalMethods::escapeString($userId).' "';
                    }
                   
                    if($sellerid!='')
                    {
                      $QueryWishItems.=' AND c.seller_id = "'.generalMethods::escapeString($sellerid).' "';
                    }

                   // echo $QueryWishItems;
                    /*WHERE f.nUserId ='".$userID."'
                    AND f.nProductId = '".$productID."'
                    AND f.nProductOptionId = '".$productOptionID."' ";*/
                    $resSet             =   DbHelper::execute($QueryWishItems);
                    $data               =   DbHelper::fetchOne($resSet);
                    $ship_weight        =   $data['shipWeight'];

              return $ship_weight;

    }
    
    
    
    //Get CArt Category and seller details 
    
        public static function getAllCartitemsWithCategoryandSellerInfo($userId)
    {
    	$objResult                      =   new stdClass();
    	
    	//$andCase                        =   rtrim($andCase, " AND");
         global $tableprefix;
        
          $QueryCartItems="SELECT c.*,p.product_category,cat.category_name,p.product_name
                    FROM ".$tableprefix."cart c
                    INNER JOIN " . $tableprefix . "product_options po ON po.product_option_id = c.product_option_id
                    INNER JOIN " . $tableprefix . "products p ON p.product_id = po.product_id INNER JOIN " . $tableprefix . "categories cat ON cat.category_id = p.product_category";
                    if($userId!='')
                    {
                      $QueryCartItems.=' WHERE c.user_id = "'.generalMethods::escapeString($userId).' "';
                    }
                   
                    $objResultRow             =   DbHelper::customQuery($QueryCartItems);
                    
                  
                    
    	//Check Cart Details exist for the selected  Cart ID
    	if($objResultRow)
    		// Assign Cart details to object
        {
                $objResult->status        =    SUCCESS;
    		$objResult->data          =    $objResultRow;
        }
    	else {
    		$objResult->status        =   ERROR;
    		//$objResult->message     =   CART_QUANTITY_NOT_EXIST; // Cart details not exists
    	}
        
          ///echopre($objResult);
        
    	return $objResult;
    	 
    }    



    // Get productwise quantity from cart

    public static function getCartItemQuantity($userId)
    {
    	$objResult                      =   new stdClass();
    	$tableName                      =   DbHelper::setTablePrefix('cart');
    	$andCase                        =   '';
            if($userId!='')
                 $andCase   = 'user_id = "'.generalMethods::escapeString($userId).'"  ';
    	//$andCase                        =   rtrim($andCase, " AND");
        $cartArray                      =   array();
        $groupBy                        =   " GROUP BY product_id";
    	$objResultRow                   =   DbHelper::selectResult($tableName,'product_id,sum(quantity) as cartQuantity',$andCase,$groupBy);
    	//Check Cart Details exist for the selected  Cart ID
    	if($objResultRow)
    		// Assign Cart details to object
        {
                return $objResultRow;
        }
    	//return $cartArray;

    }



    public static function checkShippingBlockRequired($userId='',$visitorId='')
    {
                 $objResult                      =      new stdClass();

                 $cartTotalCount                 =      0;
                 $cartDigitalCount               =      0;
                 $cartGiftCount                  =      0;
                 $hide_shipping_division         =      1;
                 $cartFreeShiptCount             =      0;

                 //Get Cart Total Count
                 $objCart                        =     self::getCartCount($userId,$visitorId);
                 if($objCart->status==SUCCESS)
                 {
                        $cartObjVal         =   $objCart->data;

                        $cartTotalCount     =  $cartObjVal->cart_count;
                 }

                 // Get Digital Products Count

                 $objDigitalCart                        =     self::getDigitalItemsCartCount($userId,$visitorId);
                 if($objDigitalCart->status==SUCCESS)
                 {
                        $cartDigitalObjVal         =    $objDigitalCart->data;
                        $cartDigitalCount          =    $cartDigitalObjVal->digitalcount;
                 }

                 //Get Gift Product Count in cart
                 $objGiftCart                 =     self::getGiftCertificateItemsCartCount($userId,$visitorId);
                 if($objGiftCart->status==SUCCESS)
                 {
                        $cartGiftObjVal         =    $objGiftCart->data;
                        $cartGiftCount          =    $cartGiftObjVal->gift_count;
                 }


                 // Get Physical Items Count in Cart

                  $objPhysicalCart                 =     self::getPhysicalItemsCartCount($userId,$visitorId);
                 if($objPhysicalCart->status==SUCCESS)
                 {
                        $cartPhysicalObjVal             =    $objPhysicalCart->data;
                        $cartPhysicalCount              =    $cartPhysicalObjVal->physicalcount;
                 }

                 // Free ship items count

               // $cartFreeShiptCount                   =     self::getFreeshipItemsCount($userId,$visitorId);

                $cartNonDigitalItemsCount             =     0;

                $cartDigitalAndGiftItemsCount         =    $cartGiftCount +$cartDigitalCount;
                 /*if($cartDigitalCount>0) {
                        if($cartDigitalCount>=$cartTotalCount) {
                            $hide_shipping_division = 0;

                        }
                    }else{
                        if($cartGiftCount>0) {
                                if($cartGiftCount>=$cartTotalCount) {
                                    $hide_shipping_division = 0;

                                }
                        }
                    }*/

                    //$freeshipItemsCount      =    $cartFreeShiptCount + $cartDigitalCount;
                    if($cartTotalCount>0)
                    {
                        if((int)$cartTotalCount == ((int)$cartDigitalAndGiftItemsCount)) {
                                $hide_shipping_division = 0;
                        }
                    }

         return $hide_shipping_division;

    }



    //


}
