<?php
//Multicart 3.0 Data Maigration / Scalability settings 
include_once '../includes/class.upload.php';

$productObj     =   Utils::getProductInfo();
if(!empty($productObj))
{
        //Update Product default settings for Scalability
        Utils::UpdateProductInfoforUpgarde();
        Utils::UpdateDefaultValues();
        Utils::UpdateProductAlias($productObj);
        
        Utils::UpdateCategoryAlias($productObj);
        
        //check More Image Exists and resize to thumb size 
       
}
//Multicart 3.0 Data Maigration / Scalability settings 
//Check Shipping Informations Added and Update with Seller 

$shippingObj     =   Utils::getShippingInfo();

if(!empty($shippingObj))
{
     Utils::UpdateShippingValues();
}

//Delete Cart Table If Items Alreday Exists 
$cartObj     =   Utils::getCartInfo();

if(!empty($cartObj))
{
    Utils::DeleteCart();
}
// Currency List Update
$currency_list_array = Utils::GetCountryList();

//Check currency codes already updated to table , if no value exists then save data to table
$currencyObj    =   Utils::getCurrencyCodeCount();

if($currencyObj->status==SUCCESS)
        {
            //Delete and insert Data
            $currencyObjVal =   $currencyObj->data;
            $currencyCount  =   $currencyObjVal->currency_count;
            if($currencyCount>0)
                {
                   // Save currency data to table // get Json data from global array and insert to table
                    $sqlDel     = "TRUNCATE TABLE ".$txtDBPrefix."currency_master";
                     mysql_query($sqlDel) or die(mysql_error());
                     
                } 
                if(!empty($currency_list_array))
                    {
                        foreach($currency_list_array->results as $key=>$objVals)
                            {
                                $objCurrencyVo->vcurrency_name      = $objVals->currencyName;
                                $objCurrencyVo->vcurrency_code      = $objVals->currencyId;
                                $objCurrencyVo->vcurrency_symbol    = $objVals->currencySymbol;
                                $objCurrencyVo->nexchange_price     = '1';
                                $objCurrencyVo->vactive             = "Y";
                                $currencyInfo                       =  Utils::saveAllCurrencyCodes($objCurrencyVo);
                            }
                    }

            
        }
          
 // Check Images and update to thumb size 
     $moreObj = Utils::getProductMoreImageInfo();
        $dir_dest = "../products";
        if(!empty($moreObj))
        {
            foreach($moreObj as $moreImg)
            {
                $filename               =   $moreImg->vimage_name;
                $file_extn              =   end(explode(".",$filename)); 
                //$productid              =   $moreImg->nimage_productid;
                $moreImage_noextn       =   preg_replace('/.[^.]*$/', '', $filename);
                //$moreImageName          =   $moreImage_noextn.".".$file_extn;
                 if(file_exists('../products/'.$filename))
                 {
                     
                    $handle = new Upload('../products/'.$filename);
                    $more_thumb_file_name           =    "thumb_".$moreImage_noextn;
                    $handle->file_new_name_body     =    $more_thumb_file_name;
                    $handle->image_resize           =   true;
                    $handle->image_x                =   82;
                    $handle->image_y                =   79;
                    $handle->image_ratio_y          = true;
                    $handle->process($dir_dest);
                    $moreImageNameThumb = $handle->file_dst_name; 
                 }
            }
        }
       
  // Big Image resize to thumb       
    
 $ProductImageObj = Utils::getProductImageInfo();
 
  if(!empty($ProductImageObj))
        {
            foreach($ProductImageObj as $moreImg1)
            {
                $filename_small         =   $moreImg1->image_small;
                $file_extn              =    end(explode(".",$filename_small)); 
                //$productid              =   $moreImg->nimage_productid;
                $smallImage_noextn       =   preg_replace('/.[^.]*$/', '', $filename_small);
                // Big Image 
                $filename_big         =   $moreImg1->image_big;
                $file_extn            =   end(explode(".",$filename_big)); 
                //$productid              =   $moreImg->nimage_productid;
                $bigImage_noextn      =   preg_replace('/.[^.]*$/', '', $filename_big);
              
             if($moreImg1->image_big!='')  { 
                 if(file_exists('../products/'.$filename_big))
                 {
                        $handle = new Upload('../products/'.$filename_big);
                        $small_thumb_file_name           =   "thumb_".$bigImage_noextn;
                        $handle->file_new_name_body      =   $small_thumb_file_name;
                        $handle->image_resize            =   true;
                        $handle->image_x                 =   82;
                        $handle->image_y                 =   79;
                        $handle->image_ratio_y           = true;
                        $handle->process($dir_dest);
                                        
                 }
             }
             else  {
                 
                     if(file_exists('../products/'.$filename_small))
                 {
                        $handle = new Upload('../products/'.$filename_small);
                        $small_thumb_file_name           =   "thumb_".$smallImage_noextn;
                        $handle->file_new_name_body      =   $small_thumb_file_name;
                        $handle->image_resize            =   true;
                        $handle->image_x                 =   82;
                        $handle->image_y                 =   79;
                        $handle->image_ratio_y           = true;
                        $handle->process($dir_dest);
                                        
                 }
                 
             }
            
            }
        } 
?>
