<?php

namespace OfficeBrain\Bundle\ServiceGroupBundle\Manager\AbstractManager;

use OfficeBrain\Bundle\SearchBundle\Form\Type\ProductSearchType;
use OfficeBrain\Bundle\SearchBundle\Form\Data\ProductSearchData;
use OfficeBrain\Bundle\SearchBundle\Helper\SearchHelper;
use OfficeBrain\Bundle\ServiceGroupBundle\Entity\ServiceRuleMappingInnerConditions;
use OfficeBrain\Bundle\CoreBundle\Cache\RedisCacheService;

/**
 * @author OfficeBrain 4589 <info@officebrain.com>
 *
 * Description : Service Group Discount Abstract Class
 */
abstract class ServiceRuleAbstract extends ServiceGroupBaseAbstract
{
	protected $ruleType;
	CONST MAX_QTY = 999999;

    public function __construct($entityManager, $request, $session, $serviceContainer, $countries, $languages, $coreManager, $productTagManager, $serviceGroupAPiClient=null, $translatorService,  $twigExtension)
    {
        parent::__construct($entityManager, $request, $session, $serviceContainer, $countries, $languages, $coreManager);
        
        $this->container = $serviceContainer;
        $this->serviceGroupAPiClient = $serviceGroupAPiClient;
        $this->printSideAndVariation = $this->serviceContainer->getParameter("print_side_and_variation");
        $this->productTagManager = $productTagManager;
        $this->translatorService = $translatorService;
        $this->TwigExtension = $twigExtension;
        $this->localizationArray = null;
        $this->discountCodes = $this->getDiscountCodeArray();
        
        $this->productDetailManager = $this->serviceContainer->get('office_brain_product_detail_manager');
        $this->serviceRuleMainConditionRepository = $this->entityManager->getRepository('OfficeBrainServiceGroupBundle:ServiceRuleMainCondition')
                                                        ->setProjectSetting($this->projectSetting);

        $this->serviceRuleInnerConditionRepository = $this->entityManager->getRepository('OfficeBrainServiceGroupBundle:ServiceRuleInnerCondition')
        ->setProjectSetting($this->projectSetting);

        $this->serviceRuleMappingMainConditionsRepository = $this->entityManager->getRepository('OfficeBrainServiceGroupBundle:ServiceRuleMappingMainConditions')
        ->setProjectSetting($this->projectSetting);

        $this->serviceRuleMappingInnerConditionsRepository = $this->entityManager->getRepository('OfficeBrainServiceGroupBundle:ServiceRuleMappingInnerConditions')
        ->setProjectSetting($this->projectSetting);

        $this->serviceRuleProductPriceRepository = $this->entityManager->getRepository('OfficeBrainServiceGroupBundle:ServiceRuleProductPrice')
        ->setProjectSetting($this->projectSetting);

        $this->serviceRuleChargeProductPriceRepository = $this->entityManager->getRepository('OfficeBrainServiceGroupBundle:ServiceRuleChargeProductPrice')
        ->setProjectSetting($this->projectSetting);

        $this->serviceGroupRepository = $this->entityManager->getRepository('OfficeBrainServiceGroupBundle:ServiceGroup')
        ->setProjectSetting($this->projectSetting);

        $this->serviceGroupRepository->setServiceContainer($this->serviceContainer);

        $this->serviceRuleMappingMasterRepository = $this->entityManager->getRepository('OfficeBrainServiceGroupBundle:ServiceRuleMappingMaster')
        ->setProjectSetting($this->projectSetting);

        $this->serviceRuleMappingMasterRepository->setPaginatorService($this->paginatorService);
        
        /* Code for getting edit place order data */
        $this->preAddToCartRepository= $this->entityManager->getRepository('OfficeBrainOrderBundle:PreAddToCart');
        
        $this->statsh_cache_wrapper=RedisCacheService::create();
    }

    public function setRuleType($ruleType)
    {
        $this->ruleType = $ruleType;

        return $this;
    }

    public function getRuleType()
    {
        return $this->ruleType;
    }

    public function setServiceRule($form, $id = null)
    {
    }

    public function getServiceRule()
    {
    }

    public function deleteServiceRule($id)
    {
    }

    public function setLocalization($localizationArray)
    {
        $this->localizationArray = $localizationArray;
        return $this;
    }

    public function getLocalization()
    {
        return $this->localizationArray;
    }


    /**
     * @author Employee Id: 4589
     * Description :
     *
     * @param 1 : bool $isRuleMapping
     *
     * @return array
     * */
    public function setRuleKeyNameArray($isRuleMapping)
    {
        $this->isRuleMapping = $isRuleMapping;
        if ($this->isRuleMapping) {
            $this->ruleKeyNameAry = array('parent_id' => 'parentId', 'display_order' => 'displayOrder', 'main_condition' => 'mainCondition'
                , 'condition_field' => 'conditionField', 'condition_operator' => 'conditionOperator', 'condition_value' => 'conditionValue'
                , 'service_rule_main_condition_id' => 'ruleMapMainCondId', 'if_condition_is' => 'ifConditionIs',
            );
        } else {
            $this->ruleKeyNameAry = array('parent_id' => 'parentId', 'display_order' => 'displayOrder', 'main_condition' => 'mainCondition'
                , 'condition_field' => 'conditionField', 'condition_operator' => 'conditionOperator', 'condition_value' => 'conditionValue'
                , 'service_rule_main_condition_id' => 'serviceRuleInnerConditionId', 'if_condition_is' => 'ifConditionIs',
            );
            /* $this->ruleKeyNameAry = array('parent_id' => 'parent_id','display_order' => 'display_order','main_condition' => 'main_condition'
              ,'condition_field' => 'condition_field','condition_operator' => 'condition_operator','condition_value' => 'condition_value'
              ,'service_rule_main_condition_id' => 'service_rule_main_condition_id','if_condition_is' => 'if_condition_is',
              ); */
        }

        return $this->ruleKeyNameAry;
    }

    /**
     * @author Employee Id: 4589
     * Description :
     *
     * @return array
     * */
    public function getSelectedCultures()
    {
        $options = $this->countries;
        $newCultureList = array();
        if ($options && count($options) > 0) {
            foreach ($options as $country_code => $country) {
                $newCultureList[$country['id']] = $country['name'];
            }
        }

        return $newCultureList;
    }

    /**
     * @author Employee Id: 4589
     * Description :
     *
     * @param 1 : int $culture_id
     *
     * @return string
     * */
    public function getCultureNameById($culture_id)
    {
        $options = $this->countries;

        if ($options && count($options) > 0) {
            foreach ($options as $country_code => $country) {
                if ($culture_id == $country['id']) {
                    return $country['name'];
                }
            }
        }
    }

    /**
     * @author Employee Id: 4589
     * Description :
     *
     * @param 1 : string $culture
     *
     * @return int
     * */
    public function getCultureIdByName($culture)
    {
        $cultureArray = explode('_', $culture);
        if (isset($cultureArray[1])) {
            $cultureName = $cultureArray[1];
        } else {
            $cultureName = $cultureArray[0];
        }
        $options = $this->countries;

        if ($options && count($options) > 0) {
            foreach ($options as $country_code => $country) {
                if ($cultureName == $country_code) {
                    return $country['id'];
                }
            }
        }
    }

    /**
     * @author Employee Id: 4589
     * Description :
     *
     * @param 1 : object $serviceRuleMastID
     * */
    public function removeExistingRuleCondition($serviceRuleMastID)
    {
        $MainConditions = $this->serviceRuleMainConditionRepository
                ->getServiceRuleMainConditionByRuleMastId($serviceRuleMastID);
        if ($MainConditions) {
            foreach ($MainConditions as $mainCond) {
                $mainCondId = $mainCond->getId();
                $isDeletedRuleInnerCond = $this->serviceRuleInnerConditionRepository
                        ->deleteServiceRuleInnerCondition($mainCondId);

                $isDeletedRuleMainCond = $this->serviceRuleMainConditionRepository
                        ->deleteServiceRuleMainCondition($mainCondId);
            }
        }
    }

    /**
     * @author Employee Id: 4589
     * Description :
     *
     * @param 1 : object $serviceRuleMappingMastID
     * */
    public function removeExistingRuleMappingCondition($serviceRuleMappingMastID)
    {
        $MainConditions = $this->serviceRuleMappingMainConditionsRepository
                ->getServiceRuleMappingMainConditionByRuleMastId($serviceRuleMappingMastID);
        if ($MainConditions) {
            foreach ($MainConditions as $mainCond) {
                $mainCondId = $mainCond->getId();
                $isDeletedRuleInnerCond = $this->serviceRuleMappingInnerConditionsRepository
                        ->deleteServiceRuleMappingInnerCondition($mainCondId);

                $isDeletedRuleMainCond = $this->serviceRuleMappingMainConditionsRepository
                        ->deleteServiceRuleMappingMainCondition($mainCondId);
            }
        }
    }

    /**
     * @author Employee Id: 4589
     * Description :
     *
     * @param 1 : int    $ruleId
     * @param 2 : object $MapRulesObj
     * @param 3 : int    $parentId
     * @param 4 : int    $mapParentId
     * @param 5 : int    $level
     * */
    public function addRuleConditionFromRuleMaster($ruleId, $MapRulesObj, $parentId = 0, $mapParentId = 0, $level = 0)
    {
        $mainCondition = $this->serviceRuleMainConditionRepository
                ->getServiceRuleMainConditionByRuleMastIdParentId($ruleId, $parentId);
        if ($mainCondition) {
            foreach ($mainCondition as $condition) {
                $MappingMainCondition = $this->serviceRuleMappingMainConditionsRepository
                        ->addServiceRuleMappingMainCondition($MapRulesObj, $mapParentId, $condition['mainCondition']);

                $InnerCondition = $this->serviceRuleInnerConditionRepository
                        ->getServiceRuleInnerConditionByRuleMainConditionId($condition['id']);

                foreach ($InnerCondition as $InnCond) {
                    $MappingInnerCondition = $this->serviceRuleMappingInnerConditionsRepository
                            ->addServiceRuleMappingInnerCondition($MappingMainCondition, $InnCond['conditionField'], $InnCond['conditionOperator'], $InnCond['conditionValue'], $InnCond['displayOrder']);
                }

                $this->addRuleConditionFromRuleMaster($ruleId, $MapRulesObj, $condition['id'], $MappingMainCondition->getId(), $level);
            }
        }
    }

    /**
     * @author Employee Id: 4589
     * Description : To validate Rule values on Submitting data
     *
     * @param 1 : array  $rulesAry
     * @param 2 : string $errorType
     * @param 3 : object &$error
     *
     * @return object
     * */
    public function validateRules($rulesAry, $errorType = 'master', &$error = null)
    {
        foreach ($rulesAry as $rule) {
            if (isset($rule['rules'])) {
                $this->validateRules($rule['rules'], $error);
            } else {
                if (isset($this->conditionAry[$rule['field']]['validate']) && $this->conditionAry[$rule['field']]['validate'] == true) {
                    $operators = $this->conditionAry[$rule['field']]['operators'];
                    $validationClass = null;
                    foreach ($operators as $op) {
                        if (isset($op['class']) && $op['class'] != '' && $op['id'] == $rule['operator']) {
                            $validationClass = $op['class'];
                            break;
                        }
                    }

                    $fieldVal = $rule['value'];
                    $errorFieldname = $rule['field_class'];
                    if ($validationClass == 'decimal_only') {
                        if (!preg_match('/^\d+\.\d+$/', $fieldVal) && !is_numeric($fieldVal)) {
                            $error[$errorFieldname] = ($errorType == 'master' ? '' : $errorFieldname.'::').'The value of '.$this->conditionAry[$rule['field']]['label'].' is not proper Decimal.';
                        }
                    } elseif ($validationClass == 'numeric_only') {
                        if (!is_numeric($fieldVal)) {
                            $error[$errorFieldname] = ($errorType == 'master' ? '' : $errorFieldname.'::').'The value of '.$this->conditionAry[$rule['field']]['label'].' is not proper Numeric.';
                        }
                    } elseif ($validationClass == 'datepicker') {
                        if (!$this->checkMyCorrectDate($fieldVal)) {
                            $error[$errorFieldname] = ($errorType == 'master' ? '' : $errorFieldname.'::').'The value of '.$this->conditionAry[$rule['field']]['label'].' is not proper Date.';
                        }
                    }
                }
            }
        }

        return $error;
    }

    /**
     * @author Employee Id: 4589
     * Description :
     *
     * @return array
     * */
    public function getConditionMultipleValueList()
    {
        return array('in', 'not_in');
    }

    /**
     * @author Employee Id: 4589
     * Description :
     *
     * @return array
     * */
    public function getConditionNegativeValueList()
    {
        return array('is_not', 'not_in', 'not_equal', 'is_null');
    }

    /**
     * @author Employee Id: 4589
     * Description :
     *
     * @return array
     * */
    public function getActionTypes()
    {
        return $array = array(1 => 'Product', 'Sample', 'Cart');
    }



    /**
     * @author Employee Id: 4273
     * Description : bind status dropdown
     *
     * @return array
     **/
    public function getRuleStatus()
    {
        return array(1 => $this->translatorService->trans('admin.service_group_manager.status.active'),0 => $this->translatorService->trans('admin.service_group_manager.status.inactive'));
    }

    /**
     * @author Employee Id: 4273
     * Description : bind status dropdown
     *
     * @return array
     **/
    public function getActionChargesOperators()
    {
        return array('plus' => '+','minus' => '-', 'multiply' => '*', 'divide' => '/');
    }


    /**
     * @author Employee Id: 4589
     * Description :
     *
     * @return array
     * */
    public function getActionLimitPer()
    {
        return $array = array(1 => 'User', 'Total Uses'); //,'Category','Product');
    }

    /**
     * @author Employee Id: 4589
     * Description :
     *
     * @return array
     * */
    public function getActionRuleTypes()
    {
        return $array = array(1 => $this->translatorService->trans('admin.service_group_manager.rule_type.discount'), $this->translatorService->trans('admin.service_group_manager.rule_type.markup'));
    }

    /**
     * @author Employee Id: 4589
     * Description :
     *
     * @return array
     * */
    public function getActionChargeTypes()
    {
        return $array = array('setup' => $this->translatorService->trans('admin.service_group_manager.charge_type.setup'), 'embroidery' => $this->translatorService->trans('admin.service_group_manager.charge_type.embroidery'), 'location' => $this->translatorService->trans('admin.service_group_manager.charge_type.location'), 'color' => $this->translatorService->trans('admin.service_group_manager.charge_type.color'), 'pms' => $this->translatorService->trans('admin.service_group_manager.charge_type.pms'));
    }

    /**
     * @author Employee Id: 4589
     * Description :
     *
     * @return array
     * */
    public function getActionAmountTypes()
    {
        return $array = array(1 => $this->translatorService->trans('admin.service_group_manager.amount_type.fixed'), $this->translatorService->trans('admin.service_group_manager.amount_type.percentage')); //, 'Product EQP Based Percent','Prod EQP Based Fixed Amount');
    }

    /**
     * @author Employee Id: 4589
     * Description : Get all country list
     *
     * @return array
     * */
    public function getCultureList()
    {
        $options = $this->countries;
        $newCultureList = array();
        if ($options && count($options) > 0) {
            foreach ($options as $country_code => $country) {
                $newCultureList[$country['id']] = $country['name'];
            }
        }

        return $newCultureList;
    }

    /**
     * @author Employee Id: 4589
     * Description : Get all users list
     *
     * @return array
     * */
    public function getAllUserList()
    {
        return array();
        $userObj = $this->entityManager->getRepository('OfficeBrainUserBundle:User')->getAllUsers();

        $user = array();
        foreach ($userObj as $u) {
            $user[$u['id']] = $u['firstName'].' '.$u['lastName'].' ( '.$u['email'].' )';
        }

        return $user;
    }

    /**
     * @author Employee Id: 4589
     * Description : Get all product list
     *
     * @param 1 : string $culture
     *
     * @return array
     * */
    public function getAllProductList($culture)
    {
        $cultures = explode('_', $culture);
        $languageId = $this->getLanguageIdByCode($cultures[0]);

        $searchparam = '';
        $prods = $this->getProduct($searchparam, $languageId);
        $prodArray = array();
        foreach ($prods as $prod) {
            $prodArray[$prod['product_id']] = $prod['sku'].' ('.$prod['title'].')';
        }

        return $prodArray;
    }

    /**
     * @author Employee Id: 4589
     * Description : Get all category list
     *
     * @param 1 : string $culture
     *
     * @return array
     * */
    public function getAllCategoryList($culture)
    {
        //TODO: Remove kernel
        //global $kernel;
        $container = $this->serviceContainer;
        $language = 'en';
        if ((int) $culture > 0) {
            $language = $this->getLanguageField($culture, 'id', 'code');
        } else {
            $cultures = explode('_', $culture);
            $language = $cultures[0];
        }

        $apiManager = $container->get('officebrain_category_api_manager');
        $categories = $apiManager->getList(array($language));
        $categoryAry = $categories[$language];

        global $newCategoryAry;
        $newCategoryAry = array();
        if ($categoryAry && sizeof($categoryAry) > 0) {
            foreach ($categoryAry as $cat) {
                //print_r($cat);exit;
                $extraSpace = '';

                $newCategoryAry[$cat['cat_master_id']] = $extraSpace.$cat['cat_name'];

                if (isset($cat['child']) && count($cat['child']) > 0) {
                    $this->getCategoryRecursive($cat['child'], $extraSpace);
                }
            }
        }
        $catArray = $newCategoryAry;
        unset($newCategoryAry);

        return $catArray;
    }

    public function getCategoryRecursive($categoryAry, $extraSpace)
    {
        global $newCategoryAry;
        $extraSpace .= '&nbsp;&nbsp;>>&nbsp;&nbsp;';
        foreach ($categoryAry as $cat) {
            $newCategoryAry[$cat['cat_master_id']] = $extraSpace.$cat['cat_name'];
            if (isset($cat['child']) && count($cat['child']) > 0) {
                $this->getCategoryRecursive($cat['child'], $extraSpace);
            }
        }
    }

    /**
     * @author Employee Id: 4589
     * Description : Get all brand list
     *
     * @return array
     * */
    public function getAllBrandList($culture)
    {
        //TODO: Remove kernel
        return array();
        //global $kernel;
        $container = $this->serviceContainer;

        $language = 'en';
        if ((int) $culture > 0) {
            $language = $this->getLanguageField($culture, 'id', 'code');
        } else {
            $cultures = explode('_', $culture);
            $language = $cultures[0];
        }

        $brandApiManager = $container->get('officebrain_brand_api_manager');
        $brands = $brandApiManager->getList($language);
        $brandAry = $brands[$language];

        $newBrandAry = array();
        if ($brandAry && sizeof($brandAry) > 0) {
            foreach ($brandAry as $brand) {
                $newBrandAry[$brand['brand_id']] = $brand['name'];
            }
        }

        return $newBrandAry;
    }

    /**
     * @author Employee Id: 4589
     * Description : Get all color list
     *
     * @param 1 : string $culture
     *
     * @return array
     * */
    public function getAllColorList($culture)
    {
        return array();
        $colorAry = array();
        /* $this->apiClient->init('get_all_culture_color');
          $this->apiClient->setCulture($culture);
          $this->apiClient->doProcess();
          if ($this->apiClient->isSuccess()) {
          $colorAry = $this->apiClient->getResultArray();
          } */
        $newColorAry = array();
        if ($colorAry && sizeof($colorAry) > 0) {
            foreach ($colorAry as $color) {
                $newColorAry[$color['id']] = $color['color'];
            }
        }

        return $newColorAry;
    }

    /**
     * @author Employee Id: 4589
     * Description : Get service rule mapping by Id
     *
     * @param 1 : Rule Mapping Id
     *
     * @return type : ServiceRuleMapping
     *
     * @throws Exception: Null
     */
    public function getServiceRuleMappingById($id, $exludeDeleted = null)
    {
        return $this->serviceRuleMappingMasterRepository->getServiceRuleMappingById($id, $exludeDeleted);
    }

    /**
     * @author Employee Id: 4273
     * Description : Get service rule mapping by priority
     *
     * @param 1 : Rule Mapping priority
     *
     * @return type : ServiceRuleMapping
     *
     * @throws Exception: Null
     */
    public function getServiceRuleMappingByPriority($priority, $exludeDeleted = null)
    {
        return $this->serviceRuleMappingMasterRepository->getServiceRuleMappingByPriority($priority, $exludeDeleted);
    }

    /**
     * @author Employee Id: 4589
     * Description : Edit service rule mapping rules
     *
     * @param 1 : Rule Id
     *
     * @return type : true or false
     *
     * @throws Exception: Null
     */
    public function applyRuleMapping($id, $allFields = false)
    {
        $this->ruleMappingMaster = $this->getServiceRuleMappingById($id, true);

        $searchFilters = array();

        if ($this->ruleMappingMaster) {

            //is apply in shedule or now
            if ($this->ruleMappingMaster->getStartDate()) {
                $startDate = \DateTime::createFromFormat("Y-m-d", $this->ruleMappingMaster->getStartDate()->format("Y-m-d"));
                $currentDate = \DateTime::createFromFormat("Y-m-d", date("Y-m-d"));
                if ($startDate > $currentDate) {
                    return false;
                }
            }

            //check if expiried
            if ($this->ruleMappingMaster->getEndDate()) {
                $endDate = \DateTime::createFromFormat("Y-m-d", $this->ruleMappingMaster->getEndDate()->format("Y-m-d"));
                $currentDate = \DateTime::createFromFormat("Y-m-d", date("Y-m-d"));
                if ($endDate < $currentDate) {
                    // set is deleted flag if expire with same priority
                    $this->deleteRuleMapping($this->ruleMappingMaster->getId());
                    //$this->serviceRuleProductPriceRepository->removeProductByPriority($this->ruleMappingMaster->getPriority());
                    return false;
                }
            }

            //check if status inactive
            if ($this->ruleMappingMaster->getStatus() != 1) {
                // set is deleted flag if expire with same priority
                $this->deleteRuleMapping($this->ruleMappingMaster->getId());
                //$this->serviceRuleProductPriceRepository->removeProductByPriority($this->ruleMappingMaster->getPriority());
                return false;
            }

            //check if removed
            if ($this->ruleMappingMaster->getDeletedAt()) {
                $this->serviceRuleProductPriceRepository->removeProductByPriority($this->ruleMappingMaster->getPriority());
                return false;
            }

            $ruleMappingRules = $this->ruleMappingMaster->getRuleMapMasterId();
            if ($ruleMappingRules->count() > 0) {
                $ruleMappingMainConditions = $ruleMappingRules[0]->getRuleMapRulesId();
                if ($ruleMappingMainConditions->count() > 0) {
                    foreach ($ruleMappingMainConditions as $ruleMappingMainCondition) {
                        $catIdArray =  $productIdArray = $productTagIdArray = $maxPriceArray = $minPriceArray = $eqpArray = $imprintMethodArray = $imprintLocationArray = $maxNoOfColorArray = $minNoOfColorArray = $maxNoOfLocationArray = $minNoOfLocationArray = array();
                        $catIdNotArray =  $productIdNotArray = $productTagIdNotArray = $maxPriceNotArray = $minPriceNotArray = $eqpNotArray = $imprintMethodNotArray = $imprintLocationNotArray = $maxNoOfColorNotArray = $minNoOfColorNotArray = $maxNoOfLocationNotArray = $minNoOfLocationNotArray = array();

                        $ruleMappingInnerConditions = $ruleMappingMainCondition->getRuleMapMainCondId();
                        $ruleCondition = $ruleMappingMainCondition->getMainCondition();
                        $parentId = $ruleMappingMainCondition->getParentId();

                        if ($ruleMappingInnerConditions->count() > 0) {
                            foreach ($ruleMappingInnerConditions as $ruleMappingInnerCondition) {
                                switch ($ruleMappingInnerCondition->getConditionField()) {
                                    case "category":
                                        if (in_array($ruleMappingInnerCondition->getConditionOperator(), $this->getConditionNegativeValueList())) {
                                            $catIdNotArray = array_merge($catIdNotArray, $this->getApplyRuleValue($ruleMappingInnerCondition));
                                        } else {
                                            $catIdArray = array_merge($catIdArray, $this->getApplyRuleValue($ruleMappingInnerCondition));
                                        }

                                        break;

                                    case "product":
                                        if (in_array($ruleMappingInnerCondition->getConditionOperator(), $this->getConditionNegativeValueList())) {
                                            $productIdNotArray = array_merge($productIdNotArray, $this->getApplyRuleValue($ruleMappingInnerCondition));
                                        } else {
                                            $productIdArray = array_merge($productIdArray, $this->getApplyRuleValue($ruleMappingInnerCondition));
                                        }
                                        break;

                                    case "product_tag":
                                        if (in_array($ruleMappingInnerCondition->getConditionOperator(), $this->getConditionNegativeValueList())) {
                                            $productTagIdNotArray = array_merge($productTagIdNotArray, $this->getApplyRuleValue($ruleMappingInnerCondition));
                                        } else {
                                            $productTagIdArray = array_merge($productTagIdArray, $this->getApplyRuleValue($ruleMappingInnerCondition));
                                        }
                                        break;

                                    case "price":

                                        switch ($ruleMappingInnerCondition->getConditionOperator()) {
                                            case "equal":
                                                $maxPriceArray[] = $minPriceArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                            case "not_equal":
                                                $maxPriceNotArray[] = $minPriceNotArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                            case "less":
                                            case "less_or_equal":
                                                $maxPriceArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                            case "greater":
                                            case "greater_or_equal":
                                                $minPriceArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                        }

                                    case "eqp":
                                        // value is true or false
                                        $eqpArray[] = $ruleMappingInnerCondition->getConditionValue();
                                        break;

                                    case "imprint_method":
                                        // value is true or false
                                        if (in_array($ruleMappingInnerCondition->getConditionOperator(), $this->getConditionNegativeValueList())) {
                                            $imprintMethodNotArray = array_merge($imprintMethodNotArray, $this->getApplyRuleValue($ruleMappingInnerCondition));
                                        } else {
                                            $imprintMethodArray = array_merge($imprintMethodArray, $this->getApplyRuleValue($ruleMappingInnerCondition));
                                        }
                                        break;
                                    case "imprint_location":
                                        // value is true or false
                                        $imprintLocationArray[] = $ruleMappingInnerCondition->getConditionValue();
                                        if (in_array($ruleMappingInnerCondition->getConditionOperator(), $this->getConditionNegativeValueList())) {
                                            $imprintLocationNotArray = array_merge($imprintLocationNotArray, $this->getApplyRuleValue($ruleMappingInnerCondition));
                                        } else {
                                            $imprintLocationArray = array_merge($imprintLocationArray, $this->getApplyRuleValue($ruleMappingInnerCondition));
                                        }
                                        break;
                                    case "no_of_selected_color":
                                        // value is true or false
                                        switch ($ruleMappingInnerCondition->getConditionOperator()) {
                                            case "equal":
                                                $maxNoOfColorArray[] = $minNoOfColorArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                            case "not_equal":
                                                $maxNoOfColorNotArray[] = $minNoOfColorNotArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                            case "less":
                                            case "less_or_equal":
                                                $maxNoOfColorArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                            case "greater":
                                            case "greater_or_equal":
                                                $minNoOfColorArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                        }
                                        break;
                                    case "no_of_selected_location":
                                        // value is true or false
                                        switch ($ruleMappingInnerCondition->getConditionOperator()) {
                                            case "equal":
                                                $maxNoOfLocationArray[] = $minNoOfLocationArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                            case "not_equal":
                                                $maxNoOfLocationNotArray[] = $minNoOfLocationNotArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                            case "less":
                                            case "less_or_equal":
                                                $maxNoOfLocationArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                            case "greater":
                                            case "greater_or_equal":
                                                $minNoOfLocationArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                        }
                                        break;
                                }
                            }
                        }

                        $searchParam = array(
                                "category" => $catIdArray,
                                "product" => $productIdArray,
                                "product_tag" => $productTagIdArray,
                                "min_price" => $minPriceArray,
                                "max_price" => $maxPriceArray,

                                "category_not" => $catIdNotArray,
                                "product_not" => $productIdNotArray,
                                "product_tag_not" => $productTagIdNotArray,
                                "min_price_not" => $minPriceNotArray,
                                "max_price_not" => $maxPriceNotArray,
                                "main_search_type" => $ruleCondition,
                                "rule_mapping_id" => $ruleMappingMainCondition->getId(),
                                "rule_mapping_parent_id" => $parentId,
                                "is_eqp" => $eqpArray,
                        );

                        $restFields = array();
                        if ($allFields) {
                            $restFields = array(
                                    'imprintMethod' => $imprintMethodArray,
                                    'imprintLocation' => $imprintLocationArray,
                                    'minNoOfSelectedColor' => $minNoOfColorArray,
                                    'maxNoOfSelectedColor' => $maxNoOfColorArray,
                                    'minNoOfSelectedLocation' => $minNoOfLocationArray,
                                    'maxNoOfSelectedLocation' => $maxNoOfLocationArray,

                                    'imprintMethodNot' => $imprintMethodNotArray,
                                    'imprintLocationNot' => $imprintLocationNotArray,
                                    'minNoOfSelectedColorNot' => $minNoOfColorNotArray,
                                    'maxNoOfSelectedColorNot' => $maxNoOfColorNotArray,
                                    'minNoOfSelectedLocationNot' => $minNoOfLocationNotArray,
                                    'maxNoOfSelectedLocationNot' => $maxNoOfLocationNotArray,
                            );
                        }
                        //echo "<pre>SEARCHPARAM<br />",print_r($searchParam);
                        $sFilters = $this->getSearchArray($searchParam);
                        $sFilters['product_search'] = array_merge($sFilters['product_search'], $restFields);
                        $searchFilters[] = $sFilters;
                    }
                }
            }
        }

        if ($searchFilters && !empty($searchFilters)) {
            return $searchFilters;
        }

        return false;
    }

    /**
     * @author Employee Id: 4273
     * Description : apply charges rule mapping
     *
     * @param 1 : Rule Id
     *
     * @return type : true or false
     *
     * @throws Exception: Null
     */
    public function applyChargesRuleMapping($id, $allFields = false)
    {
        $this->ruleMappingMaster = $this->getServiceRuleMappingById($id, true);

        $searchFilters = array();

        if ($this->ruleMappingMaster) {

            //is apply in shedule or now
            if ($this->ruleMappingMaster->getStartDate()) {
                $startDate = \DateTime::createFromFormat("Y-m-d", $this->ruleMappingMaster->getStartDate()->format("Y-m-d"));
                $currentDate = \DateTime::createFromFormat("Y-m-d", date("Y-m-d"));
                if ($startDate > $currentDate) {
                    return false;
                }
            }

            //check if expiried
            if ($this->ruleMappingMaster->getEndDate()) {
                $endDate = \DateTime::createFromFormat("Y-m-d", $this->ruleMappingMaster->getEndDate()->format("Y-m-d"));
                $currentDate = \DateTime::createFromFormat("Y-m-d", date("Y-m-d"));
                if ($endDate < $currentDate) {
                    // set is deleted flag if expire with same priority
                    $this->deleteRuleMapping($this->ruleMappingMaster->getId());
                    //$this->serviceRuleChargeProductPriceRepository->removeProductByPriority($this->ruleMappingMaster->getPriority());
                    return false;
                }
            }

            //check if status inactive
            if ($this->ruleMappingMaster->getStatus() != 1) {
                // set is deleted flag if expire with same priority
                $this->deleteRuleMapping($this->ruleMappingMaster->getId());
                //$this->serviceRuleChargeProductPriceRepository->removeProductByPriority($this->ruleMappingMaster->getPriority());
                return false;
            }

            //check if removed
            if ($this->ruleMappingMaster->getDeletedAt()) {
                $this->serviceRuleChargeProductPriceRepository->removeProductByPriority($this->ruleMappingMaster->getPriority());
                return false;
            }

            $ruleMappingRules = $this->ruleMappingMaster->getRuleMapMasterId();
            if ($ruleMappingRules->count() > 0) {
                $ruleMappingMainConditions = $ruleMappingRules[0]->getRuleMapRulesId();
                if ($ruleMappingMainConditions->count() > 0) {
                    foreach ($ruleMappingMainConditions as $ruleMappingMainCondition) {
                        $catIdArray =  $productIdArray = $productTagIdArray = $maxPriceArray = $minPriceArray = $eqpArray = $imprintMethodArray = $imprintLocationArray = $maxNoOfColorArray = $minNoOfColorArray = $maxNoOfLocationArray = $minNoOfLocationArray = array();
                        $catIdNotArray =  $productIdNotArray = $productTagIdNotArray = $maxPriceNotArray = $minPriceNotArray = $eqpNotArray = $imprintMethodNotArray = $imprintLocationNotArray = $maxNoOfColorNotArray = $minNoOfColorNotArray = $maxNoOfLocationNotArray = $minNoOfLocationNotArray = array();

                        $ruleMappingInnerConditions = $ruleMappingMainCondition->getRuleMapMainCondId();
                        $ruleCondition = $ruleMappingMainCondition->getMainCondition();
                        $parentId = $ruleMappingMainCondition->getParentId();

                        if ($ruleMappingInnerConditions->count() > 0) {
                            foreach ($ruleMappingInnerConditions as $ruleMappingInnerCondition) {
                                switch ($ruleMappingInnerCondition->getConditionField()) {
                                    case "category":
                                        if (in_array($ruleMappingInnerCondition->getConditionOperator(), $this->getConditionNegativeValueList())) {
                                            $catIdNotArray = array_merge($catIdNotArray, $this->getApplyRuleValue($ruleMappingInnerCondition));
                                        } else {
                                            $catIdArray = array_merge($catIdArray, $this->getApplyRuleValue($ruleMappingInnerCondition));
                                        }

                                        break;

                                    case "product":
                                        if (in_array($ruleMappingInnerCondition->getConditionOperator(), $this->getConditionNegativeValueList())) {
                                            $productIdNotArray = array_merge($productIdNotArray, $this->getApplyRuleValue($ruleMappingInnerCondition));
                                        } else {
                                            $productIdArray = array_merge($productIdArray, $this->getApplyRuleValue($ruleMappingInnerCondition));
                                        }
                                        break;

                                    case "product_tag":
                                        if (in_array($ruleMappingInnerCondition->getConditionOperator(), $this->getConditionNegativeValueList())) {
                                            $productTagIdNotArray = array_merge($productTagIdNotArray, $this->getApplyRuleValue($ruleMappingInnerCondition));
                                        } else {
                                            $productTagIdArray = array_merge($productTagIdArray, $this->getApplyRuleValue($ruleMappingInnerCondition));
                                        }
                                        break;

                                    case "price":

                                        switch ($ruleMappingInnerCondition->getConditionOperator()) {
                                            case "equal":
                                                $maxPriceArray[] = $minPriceArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                            case "not_equal":
                                                $maxPriceNotArray[] = $minPriceNotArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                            case "less":
                                            case "less_or_equal":
                                                $maxPriceArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                            case "greater":
                                            case "greater_or_equal":
                                                $minPriceArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                        }

                                    case "eqp":
                                        // value is true or false
                                        $eqpArray[] = $ruleMappingInnerCondition->getConditionValue();
                                        break;

                                    case "imprint_method":
                                        // value is true or false
                                        if (in_array($ruleMappingInnerCondition->getConditionOperator(), $this->getConditionNegativeValueList())) {
                                            $imprintMethodNotArray = array_merge($imprintMethodNotArray, $this->getApplyRuleValue($ruleMappingInnerCondition));
                                        } else {
                                            $imprintMethodArray = array_merge($imprintMethodArray, $this->getApplyRuleValue($ruleMappingInnerCondition));
                                        }
                                        break;
                                    case "imprint_location":
                                        // value is true or false
                                        $imprintLocationArray[] = $ruleMappingInnerCondition->getConditionValue();
                                        if (in_array($ruleMappingInnerCondition->getConditionOperator(), $this->getConditionNegativeValueList())) {
                                            $imprintLocationNotArray = array_merge($imprintLocationNotArray, $this->getApplyRuleValue($ruleMappingInnerCondition));
                                        } else {
                                            $imprintLocationArray = array_merge($imprintLocationArray, $this->getApplyRuleValue($ruleMappingInnerCondition));
                                        }
                                        break;
                                    case "no_of_selected_color":
                                        // value is true or false
                                        switch ($ruleMappingInnerCondition->getConditionOperator()) {
                                            case "equal":
                                                $maxNoOfColorArray[] = $minNoOfColorArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                            case "not_equal":
                                                $maxNoOfColorNotArray[] = $minNoOfColorNotArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                            case "less":
                                            case "less_or_equal":
                                                $maxNoOfColorArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                            case "greater":
                                            case "greater_or_equal":
                                                $minNoOfColorArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                        }
                                        break;
                                    case "no_of_selected_location":
                                        // value is true or false
                                        switch ($ruleMappingInnerCondition->getConditionOperator()) {
                                            case "equal":
                                                $maxNoOfLocationArray[] = $minNoOfLocationArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                            case "not_equal":
                                                $maxNoOfLocationNotArray[] = $minNoOfLocationNotArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                            case "less":
                                            case "less_or_equal":
                                                $maxNoOfLocationArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                            case "greater":
                                            case "greater_or_equal":
                                                $minNoOfLocationArray[] = $ruleMappingInnerCondition->getConditionValue();
                                                break;

                                        }
                                        break;
                                }
                            }
                        }

                        $searchParam = array(
                                "category" => $catIdArray,
                                "product" => $productIdArray,
                                "product_tag" => $productTagIdArray,
                                "min_price" => $minPriceArray,
                                "max_price" => $maxPriceArray,

                                "category_not" => $catIdNotArray,
                                "product_not" => $productIdNotArray,
                                "product_tag_not" => $productTagIdNotArray,
                                "min_price_not" => $minPriceNotArray,
                                "max_price_not" => $maxPriceNotArray,
                                "main_search_type" => $ruleCondition,
                                "rule_mapping_id" => $ruleMappingMainCondition->getId(),
                                "rule_mapping_parent_id" => $parentId,
                                "is_eqp" => $eqpArray,
                        );

                        $restFields = array();
                        if ($allFields) {
                            $restFields = array(
                                    'imprintMethod' => $imprintMethodArray,
                                    'imprintLocation' => $imprintLocationArray,
                                    'minNoOfSelectedColor' => $minNoOfColorArray,
                                    'maxNoOfSelectedColor' => $maxNoOfColorArray,
                                    'minNoOfSelectedLocation' => $minNoOfLocationArray,
                                    'maxNoOfSelectedLocation' => $maxNoOfLocationArray,

                                    'imprintMethodNot' => $imprintMethodNotArray,
                                    'imprintLocationNot' => $imprintLocationNotArray,
                                    'minNoOfSelectedColorNot' => $minNoOfColorNotArray,
                                    'maxNoOfSelectedColorNot' => $maxNoOfColorNotArray,
                                    'minNoOfSelectedLocationNot' => $minNoOfLocationNotArray,
                                    'maxNoOfSelectedLocationNot' => $maxNoOfLocationNotArray,
                            );
                        }
                        //echo "<pre>SEARCHPARAM<br />",print_r($searchParam);
                        $sFilters = $this->getSearchArray($searchParam);
                        $sFilters['product_search'] = array_merge($sFilters['product_search'], $restFields);
                        $searchFilters[] = $sFilters;
                    }
                }
            }
        }

        if ($searchFilters && !empty($searchFilters)) {
            return $searchFilters;
        }

        return false;
    }

    protected function getApplyRuleValue(ServiceRuleMappingInnerConditions $ruleMappingInnerCondition)
    {
        $idArray = array();

        if (in_array($ruleMappingInnerCondition->getConditionOperator(), $this->getConditionMultipleValueList())) {
            $multipleIdArray = unserialize($ruleMappingInnerCondition->getConditionValue());
            if($multipleIdArray[0]!='all')
            	$idArray = $multipleIdArray;
            	
        } else {
            $idArray[0] = $ruleMappingInnerCondition->getConditionValue();
        }

        return $idArray;
    }

    /**
     * @author Employee Id: 4589
     * Description : This function is used for get array of all paramaters
     *
     *
     * @return array
     *
     * @throws Exception
     *
     **/

    public function getSearchArray($params)
    {
        $searchRequestArray = array();
        $searchRequestArray['product_search'] = array();
        $mainFilter = "keyword";

        if (isset($params['category']) && !empty($params['category'])) {
            $searchRequestArray['product_search']['categoryId'] = '["'.implode('","', $params['category']).'"]';
        }

        if (isset($params['category_not']) && !empty($params['category_not'])) {
            $searchRequestArray['product_search']['categoryIdNot'] = '["'.implode('","', $params['category_not']).'"]';
        }

        if (isset($params['product']) && !empty($params['product'])) {
            $searchRequestArray['product_search']['productId'] = '["'.implode('","', $params['product']).'"]';
        }

        if (isset($params['product_not']) && !empty($params['product_not'])) {
            $searchRequestArray['product_search']['productIdNot'] = '["'.implode('","', $params['product_not']).'"]';
        }

        if (isset($params['product_tag']) && !empty($params['product_tag'])) {
            $searchRequestArray['product_search']['tag'] = '["'.implode('","', $params['product_tag']).'"]';
        }
        if (isset($params['product_tag_not']) && !empty($params['product_tag_not'])) {
            $searchRequestArray['product_search']['tagNot'] = '["'.implode('","', $params['product_tag_not']).'"]';
        }
        if (isset($params['min_price']) && !empty($params['min_price'])) {
            $searchRequestArray['product_search']['min_price'] = $params['min_price'][0];
        }
        if (isset($params['max_price']) && !empty($params['max_price'])) {
            $searchRequestArray['product_search']['max_price'] = $params['max_price'][0];
        }

        if (isset($params['main_search_type'])) {
            $searchRequestArray['search']['main_search_type'] = $params['main_search_type'];
        }
        if (isset($params['rule_mapping_id'])) {
            $searchRequestArray['search']['rule_mapping_id'] = $params['rule_mapping_id'];
        }
        if (isset($params['rule_mapping_parent_id'])) {
            $searchRequestArray['search']['rule_mapping_parent_id'] = $params['rule_mapping_parent_id'];
        }
        if (isset($params['is_eqp']) && !empty($params['is_eqp'])) {
            $searchRequestArray['search']['is_eqp'] = $params['is_eqp'][0];
        }
        //$searchRequestArray['product_search']['supplierId'] = trim($this->request->query->get('supplier_filter', ''));
        //$searchRequestArray['product_search']['k'] = $params['product_tag'];
        //$searchRequestArray['product_search']['attribute'] = trim($this->request->query->get('attribute_filter', ''));
        $searchRequestArray['search']['query'] = "";
        $searchRequestArray['search']['main_filter'] = $mainFilter;
        $searchRequestArray['search']['culture'] = $this->projectSetting['locale_language'];

        /*if ($this->request->query->get('sku') != '') {
    	 $searchRequestArray['product_search']['sku'] = trim($this->request->query->get('sku', ''));
    	}*/

        /*if ($this->request->query->get('supplier_name') != '') {
    	 $searchRequestArray['product_search']['supplierName'] = trim($this->request->query->get('supplier_name', ''));
    	}*/
        $this->request->query->set($mainFilter, "");
        //     	echo '<pre>'; print_r($searchRequestArray); die;
        return $searchRequestArray;
    }

    /**
     * @author Employee Id: 4589
     * Description : Get product from solar
     *
     * @param 1 : string $searchParam
     * @param 2 : string $language
     *
     * @return array
     * */
    public function getProduct($params = array())
    {
        //return array();

        //TODO: Remove kernel
        //global $kernel;
        $container = $this->serviceContainer;

        //fetch all products from solr
        $products = $container->get('office_brain_search_manager')->searchService(true);
        if ($products && isset($products['search_result_array']) && isset($products['search_result_array']['data'])) {
            return $products['search_result_array']['data'];
        } else {
            return array();
        }
    }

    /**
     * @author Employee Id: 4589
     * Description : Get product from solar
     *
     * @param 1 : string $searchParam
     * @param 2 : string $language
     *
     * @return array
     * */
    public function getProductTags($params = array())
    {
        //fetch all products from service
        $productTags = $this->productTagManager->getAllTags(array('country_id'=>$this->countryId, 'language_id'=>$this->languageId));
        $productTagArray = array();
        foreach ($productTags as $tagType=>$productTag) {
            foreach ($productTag as $tag) {
                $key = $tag['slug']; //$tagType."_".$tag['tagId'];
                $productTagArray[$key] = $tag['tagName'];
            }
        }

        return $productTagArray;
    }

    /**
     * @author Employee Id: 4589
     * Description : Get ImprintLocation array
     *
     * @param 1 : Null
     *
     * @return array
     * */
    public function getImprintLocation()
    {
        //TODO: Remove kernel
        //global $kernel;
        $container = $this->serviceContainer;
        $imprintLocationId = $container->getParameter('imprint_position_master_id');

        $imprintLocations = $container->get('officebrain_attribute_api_manager')->getList($this->languageCode, $imprintLocationId, 1, array());
        $imprintLocationArray = array();
        if ($imprintLocations && isset($imprintLocations[$this->languageCode]) && isset($imprintLocations[$this->languageCode][0])
            && isset($imprintLocations[$this->languageCode][0]['attribute_values'])) {
            foreach ($imprintLocations[$this->languageCode][0]['attribute_values'] as $attribute) {
                $imprintLocationArray[$attribute['attribute_value_id']] = $attribute['attribute_value'];
            }
        }

        return $imprintLocationArray;
    }

    /**
     * @author Employee Id: 4589
     * Description : Get ImprintLocation array
     *
     * @param 1 : Null
     *
     * @return array
     * */
    public function getImprintMethod()
    {
        //TODO: Remove kernel
        //global $kernel;
        $container = $this->serviceContainer;
        $imprintMethodId = $container->getParameter('imprint_method_master_id');

        $imprintMethods = $container->get('officebrain_attribute_api_manager')->getList($this->languageCode, $imprintMethodId, 1, array());
        $imprintMethodArray = array();
        if ($imprintMethods && isset($imprintMethods[$this->languageCode]) && isset($imprintMethods[$this->languageCode][0])
            && isset($imprintMethods[$this->languageCode][0]['attribute_values'])) {
            foreach ($imprintMethods[$this->languageCode][0]['attribute_values'] as $attribute) {
                $imprintMethodArray[$attribute['attribute_value_id']] = $attribute['attribute_value'];
            }
        }

        return $imprintMethodArray;
    }



    /**
     * @author Employee Id: 4589
     * Description : Get all condition
     *
     * @param 1 : string $culture
     *
     * @return array
     * */
    public function getConditionArray($countryId = null)
    {
        if (!$countryId) {
            $countryId = $this->countryId;
        }

        $ruleOptionRepository = $this->entityManager->getRepository('OfficeBrainServiceGroupBundle:ServiceRuleOption');
        $ruleOptionRepository->setProjectSetting($this->projectSetting);
        $ruleOptions = $ruleOptionRepository->findByRuleType($this->ruleType);

        $optionArray = array();
        foreach ($ruleOptions as $ruleOption) {
            $inputType = 'text';
            $values = array();
            switch ($ruleOption->getRuleFieldType()) {
                case 'dropdown':
                case 'service':

                    $inputType = 'single_select';
                    break;
                case 'textbox':
                    $inputType = 'text';
                    break;
            }

            $className = 'none';
            switch ($ruleOption->getRuleFieldOption()) {
                case 'float':
                    $className = 'decimal_only';
                    break;
                case 'integer':
                    $className = 'numeric_only';
                    break;
                case 'textbox':
                    $className = '';
                    break;
                case 'datepicker':
                    $className = 'datepicker';
                    break;
                case 'autocomplete':
                    $className = 'autocomplete_single';
                    break;
                case 'officebrain_category_api_manager':
                    $values = $this->getAllCategoryList($this->cultureCode);
                    break;
                case 'office_brain_solr.product_search':
                    $values = $this->getAllProductList($this->cultureCode);
                    break;
                case 'officebrain_attribute_api_manager_imprint_location':
                    $values = $this->getImprintLocation();
                    break;
                   case 'officebrain_attribute_api_manager_imprint_method':
                    $values = $this->getImprintMethod();
                    break;
                case 'office_brain_product_tag_manager':
                    $values = $this->getProductTags();
                    break;
            }

            $operatorArray = array();

            foreach (json_decode($ruleOption->getRuleOperators()) as $slug => $value) {
                if ($inputType == 'single_select' && in_array($slug, $this->getConditionMultipleValueList())) {
                    $inputType = 'multi_select';
                }
                $operatorArray[] = array(
                    'id' => $slug,
                    'label' => $value,
                    'input' => $inputType,
                    'class' => $className,
                );
            }

            $optionArray[$ruleOption->getRuleSlug()] = array(
                'label' => $this->translatorService->trans('admin.service_group_manager.options_title.'.$ruleOption->getRuleSlug()),
                'id' => $ruleOption->getRuleSlug(),
                'operators' => $operatorArray,
            );

            if ($ruleOption->getRuleFieldType() == 'dropdown') {
                $optionArray[$ruleOption->getRuleSlug()]['values'] = json_decode($ruleOption->getRuleFieldOption(), true);
            } elseif ($ruleOption->getRuleFieldType() == 'service' && !empty($values)) {
                $optionArray[$ruleOption->getRuleSlug()]['values'] = $values;
            }

            if ($className != '') {
                $optionArray[$ruleOption->getRuleSlug()]['validate'] = true;
            }
        }

        return $optionArray;
        //$master = $this->container->get('office_brain_core_manager');
        $array = array(
            'price' => array(
                'label' => 'Price', 'id' => 'price', 'validate' => true,
                'operators' => array(
                    0 => array('id' => 'equal', 'label' => '=', 'input' => 'text', 'class' => 'decimal_only'),
                    1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text', 'class' => 'decimal_only'),
                    2 => array('id' => 'greater', 'label' => '>', 'input' => 'text', 'class' => 'decimal_only'),
                    3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text', 'class' => 'decimal_only'),
                    4 => array('id' => 'less', 'label' => '<', 'input' => 'text', 'class' => 'decimal_only'),
                    5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text', 'class' => 'decimal_only'),
                ),
            ),
            'product_weight' => array(
                'label' => 'Product Weight (lbs)', 'id' => 'product_weight', 'validate' => true,
                'operators' => array(
                    0 => array('id' => 'equal', 'label' => '=', 'input' => 'text', 'class' => 'decimal_only'),
                    1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text', 'class' => 'decimal_only'),
                    2 => array('id' => 'greater', 'label' => '>', 'input' => 'text', 'class' => 'decimal_only'),
                    3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text', 'class' => 'decimal_only'),
                    4 => array('id' => 'less', 'label' => '<', 'input' => 'text', 'class' => 'decimal_only'),
                    5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text', 'class' => 'decimal_only'),
                    6 => array('id' => 'is_null', 'label' => 'Is Null', 'input' => 'text', 'class' => 'none'),
                    7 => array('id' => 'is_not_null', 'label' => 'Is Not Null', 'input' => 'text', 'class' => 'none'),
                ),
            ),
            'product_size' => array(
                'label' => 'Product Size', 'id' => 'product_size',
                'operators' => array(
                    0 => array('id' => 'equal', 'label' => '=', 'input' => 'text', 'class' => ''),
                    1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text', 'class' => ''),
                    2 => array('id' => 'greater', 'label' => '>', 'input' => 'text', 'class' => ''),
                    3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text', 'class' => ''),
                    4 => array('id' => 'less', 'label' => '<', 'input' => 'text', 'class' => ''),
                    5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text', 'class' => ''),
                    6 => array('id' => 'is_null', 'label' => 'Is Null', 'input' => 'text', 'class' => 'none'),
                    7 => array('id' => 'is_not_null', 'label' => 'Is Not Null', 'input' => 'text', 'class' => 'none'),
                ),
            ),
            'product_stock' => array(
                'label' => 'Product Stock', 'id' => 'product_stock', 'validate' => true,
                'operators' => array(
                    0 => array('id' => 'equal', 'label' => '=', 'input' => 'text', 'class' => 'numeric_only'),
                    1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text', 'class' => 'numeric_only'),
                    2 => array('id' => 'greater', 'label' => '>', 'input' => 'text', 'class' => 'numeric_only'),
                    3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text', 'class' => 'numeric_only'),
                    4 => array('id' => 'less', 'label' => '<', 'input' => 'text', 'class' => 'numeric_only'),
                    5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text', 'class' => 'numeric_only'),
                    6 => array('id' => 'is_null', 'label' => 'Is Null', 'input' => 'text', 'class' => 'none'),
                    7 => array('id' => 'is_not_null', 'label' => 'Is Not Null', 'input' => 'text', 'class' => 'none'),
                ),
            ),
            'cart_total_qty' => array(
                'label' => 'Total Cart Quantity', 'id' => 'cart_total_qty', 'validate' => true,
                'operators' => array(
                    0 => array('id' => 'equal', 'label' => '=', 'input' => 'text', 'class' => 'numeric_only'),
                    1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text', 'class' => 'numeric_only'),
                    2 => array('id' => 'greater', 'label' => '>', 'input' => 'text', 'class' => 'numeric_only'),
                    3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text', 'class' => 'numeric_only'),
                    4 => array('id' => 'less', 'label' => '<', 'input' => 'text', 'class' => 'numeric_only'),
                    5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text', 'class' => 'numeric_only'),
                    6 => array('id' => 'is_null', 'label' => 'Is Null', 'input' => 'text', 'class' => 'none'),
                    7 => array('id' => 'is_not_null', 'label' => 'Is Not Null', 'input' => 'text', 'class' => 'none'),
                ),
            ),
            'cart_subtotal' => array(
                'label' => 'Cart Subtotal', 'id' => 'cart_subtotal', 'validate' => true,
                'operators' => array(
                    0 => array('id' => 'equal', 'label' => '=', 'input' => 'text', 'class' => 'decimal_only'),
                    1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text', 'class' => 'decimal_only'),
                    2 => array('id' => 'greater', 'label' => '>', 'input' => 'text', 'class' => 'decimal_only'),
                    3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text', 'class' => 'decimal_only'),
                    4 => array('id' => 'less', 'label' => '<', 'input' => 'text', 'class' => 'decimal_only'),
                    5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text', 'class' => 'decimal_only'),
                    6 => array('id' => 'is_null', 'label' => 'Is Null', 'input' => 'text', 'class' => 'none'),
                    7 => array('id' => 'is_not_null', 'label' => 'Is Not Null', 'input' => 'text', 'class' => 'none'),
                ),
            ),
            'cart_total_weight' => array(
                'label' => 'Cart Total Weight (lbs)', 'id' => 'cart_total_weight', 'validate' => true,
                'operators' => array(
                    0 => array('id' => 'equal', 'label' => '=', 'input' => 'text', 'class' => 'decimal_only'),
                    1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text', 'class' => 'decimal_only'),
                    2 => array('id' => 'greater', 'label' => '>', 'input' => 'text', 'class' => 'decimal_only'),
                    3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text', 'class' => 'decimal_only'),
                    4 => array('id' => 'less', 'label' => '<', 'input' => 'text', 'class' => 'decimal_only'),
                    5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text', 'class' => 'decimal_only'),
                    6 => array('id' => 'is_null', 'label' => 'Is Null', 'input' => 'text', 'class' => 'none'),
                    7 => array('id' => 'is_not_null', 'label' => 'Is Not Null', 'input' => 'text', 'class' => 'none'),
                ),
            ),
            /* 'product_price_rowtotal' => array(
              'label' => 'Product Price Row Total','id' => 'product_price_rowtotal','validate' => true,
              'operators' => array(
              0 => array('id' => 'equal', 'label' => '=', 'input' => 'text','class' => 'decimal_only'),
              1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text','class' => 'decimal_only'),
              2 => array('id' => 'greater', 'label' => '>', 'input' => 'text','class' => 'decimal_only'),
              3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text','class' => 'decimal_only'),
              4 => array('id' => 'less', 'label' => '<', 'input' => 'text','class' => 'decimal_only'),
              5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text','class' => 'decimal_only'),
              6 => array('id' => 'is_null', 'label' => 'Is Null', 'input' => 'text','class' => 'none'),
              7 => array('id' => 'is_not_null', 'label' => 'Is Not Null', 'input' => 'text','class' => 'none'),
              ),
              ),
              'product_qty_rowtotal' => array(
              'label' => 'Product Qty Row Total','id' => 'product_qty_rowtotal','validate' => true,
              'operators' => array(
              0 => array('id' => 'equal', 'label' => '=', 'input' => 'text','class' => 'numeric_only'),
              1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text','class' => 'numeric_only'),
              2 => array('id' => 'greater', 'label' => '>', 'input' => 'text','class' => 'numeric_only'),
              3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text','class' => 'numeric_only'),
              4 => array('id' => 'less', 'label' => '<', 'input' => 'text','class' => 'numeric_only'),
              5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text','class' => 'numeric_only'),
              6 => array('id' => 'is_null', 'label' => 'Is Null', 'input' => 'text','class' => 'none'),
              7 => array('id' => 'is_not_null', 'label' => 'Is Not Null', 'input' => 'text','class' => 'none'),
              ),
              ), */
            /* 'payment_method' => array(
              'label'=>'Payment Method','id'=>'payment_method',
              'operators'=>array(
              0=>array('id'=>'is', 'label'=>'Is', 'input'=>'single_select'),
              1=>array('id'=>'is_not', 'label'=>'Is Not', 'input'=>'single_select'),
              2=>array('id'=>'in', 'label'=>'In', 'input'=>'multi_select'),
              3=>array('id'=>'not_in', 'label'=>'Not In', 'input'=>'multi_select'),
              ),
              'values'=>array(1=>'Paypal','Autorize.net'),
              ), */
            'shipping_method' => array(
                'label' => 'Shipping Method', 'id' => 'shipping_method',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                ),
                'values' => array(1 => 'UPS', 'USPS', 'FedEx'),
            ),
            'shipping_postcode' => array(
                'label' => 'Shipping Postcode', 'id' => 'shipping_postcode',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'text'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'text'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'text'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'text'),
                    4 => array('id' => 'begins_with', 'label' => 'Begins With', 'input' => 'text'),
                    5 => array('id' => 'not_begins_with', 'label' => 'Does not Begins With', 'input' => 'text'),
                    6 => array('id' => 'ends_with', 'label' => 'Ends With', 'input' => 'text'),
                    7 => array('id' => 'not_ends_with', 'label' => 'Does not Ends With', 'input' => 'text'),
                    8 => array('id' => 'contains', 'label' => 'Contains', 'input' => 'text'),
                    9 => array('id' => 'not_contains', 'label' => 'Does not Contains', 'input' => 'text'),
                ),
            ),
            'shipping_region' => array(
                'label' => 'Shipping Region', 'id' => 'shipping_region',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'text'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'text'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'text'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'text'),
                    4 => array('id' => 'begins_with', 'label' => 'Begins With', 'input' => 'text'),
                    5 => array('id' => 'not_begins_with', 'label' => 'Does not Begins With', 'input' => 'text'),
                    6 => array('id' => 'ends_with', 'label' => 'Ends With', 'input' => 'text'),
                    7 => array('id' => 'not_ends_with', 'label' => 'Does not Ends With', 'input' => 'text'),
                    8 => array('id' => 'contains', 'label' => 'Contains', 'input' => 'text'),
                    9 => array('id' => 'not_contains', 'label' => 'Does not Contains', 'input' => 'text'),
                ),
            ),
            'shipping_state' => array(
                'label' => 'Shipping State/Region', 'id' => 'shipping_state',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'text'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'text'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'text'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'text'),
                    4 => array('id' => 'begins_with', 'label' => 'Begins With', 'input' => 'text'),
                    5 => array('id' => 'not_begins_with', 'label' => 'Does not Begins With', 'input' => 'text'),
                    6 => array('id' => 'ends_with', 'label' => 'Ends With', 'input' => 'text'),
                    7 => array('id' => 'not_ends_with', 'label' => 'Does not Ends With', 'input' => 'text'),
                    8 => array('id' => 'contains', 'label' => 'Contains', 'input' => 'text'),
                    9 => array('id' => 'not_contains', 'label' => 'Does not Contains', 'input' => 'text'),
                ),
            ),
            'shipping_country' => array(
                'label' => 'Shipping Country', 'id' => 'shipping_country',
                //'plugin' => 'autocomplete',
                //'plugin_config' => array('source' => $this->generateUrl('office_brain_core_bundle_country_auto_suggest', array('_locale' => $culture), true)),
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'text', 'class' => 'autocomplete_single'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'text', 'class' => 'autocomplete_single'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'text', 'class' => 'autocomplete_multiple'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'text', 'class' => 'autocomplete_multiple'),
                /* 4 => array('id' => 'begins_with', 'label' => 'Begins With', 'input' => 'text', 'class' => 'autocomplete_single'),
                  5 => array('id' => 'not_begins_with', 'label' => 'Does not Begins With', 'input' => 'text', 'class' => 'autocomplete_single'),
                  6 => array('id' => 'ends_with', 'label' => 'Ends With', 'input' => 'text', 'class' => 'autocomplete_single'),
                  7 => array('id' => 'not_ends_with', 'label' => 'Does not Ends With', 'input' => 'text', 'class' => 'autocomplete_single'),
                  8 => array('id' => 'contains', 'label' => 'Contains', 'input' => 'text', 'class' => 'autocomplete_single'),
                  9 => array('id' => 'not_contains', 'label' => 'Does not Contains', 'input' => 'text', 'class' => 'autocomplete_single'), */
                ),
            ),
            'imprint_method' => array(
                'label' => 'Imprint Method', 'id' => 'imprint_method',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                ),
                'values' => array(1 => 'Vibrant Digital Direct', 'Vibrant Heat Transfer'),
            ),
            'setup_type' => array(
                'label' => 'Setup Type', 'id' => 'setup_type',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                ),
                'values' => array(1 => 'Die', 'Laser'),
            ),
            'reorder' => array(
                'label' => 'ReOrder', 'id' => 'reorder',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                ),
                'values' => array(1 => 'Yes', 2 => 'No'),
            ),
            'product_tag' => array(
                'label' => 'Product Tag', 'id' => 'product_tag',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                ),
                'values' => array(1 => 'New', 'Feature', 'Closeout', 'Sale'),
            ),
            'imprint_location' => array(
                'label' => 'Imprint Location', 'id' => 'imprint_location',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                ),
                'values' => array(1 => 'Left', 'Top', 'Right', 'Bottom', 'Front', 'Back', 'Center', 'Outer Edge', 'Inner Edge', 'All Side', 'Barrel', 'Clip'),
            ),
            'no_of_selected_color' => array(
                'label' => 'No. Of selected Color', 'id' => 'no_of_selected_color', 'validate' => true,
                'operators' => array(
                    0 => array('id' => 'equal', 'label' => '=', 'input' => 'text', 'class' => 'numeric_only'),
                    1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text', 'class' => 'numeric_only'),
                    2 => array('id' => 'greater', 'label' => '>', 'input' => 'text', 'class' => 'numeric_only'),
                    3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text', 'class' => 'numeric_only'),
                    4 => array('id' => 'less', 'label' => '<', 'input' => 'text', 'class' => 'numeric_only'),
                    5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text', 'class' => 'numeric_only'),
                ),
            ),
            'purchase_date' => array(
                'label' => 'Purchase Date', 'id' => 'purchase_date', 'validate' => true,
                //'plugin'=> 'datetimepicker',
                //'plugin_config'=> array('format'=> 'YYYY-MM-DD','pickTime'=>false, 'autoclose'=> true),
                'plugin' => 'datepicker',
                'plugin_config' => array('dateFormat' => 'yy-mm-dd', 'pickTime' => false, 'autoclose' => true),
                'operators' => array(
                    0 => array('id' => 'equal', 'label' => '=', 'input' => 'text', 'class' => 'datepicker'),
                    1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text', 'class' => 'datepicker'),
                    2 => array('id' => 'greater', 'label' => '>', 'input' => 'text', 'class' => 'datepicker'),
                    3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text', 'class' => 'datepicker'),
                    4 => array('id' => 'less', 'label' => '<', 'input' => 'text', 'class' => 'datepicker'),
                    5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text', 'class' => 'datepicker'),
                ),
            ),
            'addition_imprint' => array(
                'label' => 'Additional Imprint', 'id' => 'addition_imprint',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                ),
                'values' => array(1 => 'Location/Color', 'Color', 'Location'),
            ),
            'eqp' => array(
                'label' => 'EQP', 'id' => 'eqp',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                ),
                'values' => array('true' => 'True', 'false' => 'False'),
            ),
        );

        $extraAry = array();
        $users = $this->getAllUserList();
        if (count($users) > 0) {
            $extraAry['user'] = array(
                'label' => 'User',
                'id' => 'user',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                    4 => array('id' => 'begins_with', 'label' => 'Begins With', 'input' => 'text'),
                    5 => array('id' => 'not_begins_with', 'label' => 'Does not Begins With', 'input' => 'text'),
                    6 => array('id' => 'ends_with', 'label' => 'Ends With', 'input' => 'text'),
                    7 => array('id' => 'not_ends_with', 'label' => 'Does not Ends With', 'input' => 'text'),
                    8 => array('id' => 'contains', 'label' => 'Contains', 'input' => 'text'),
                    9 => array('id' => 'not_contains', 'label' => 'Does not Contains', 'input' => 'text'),
                ),
                'values' => $users,
            );
        }

        $products = $this->getAllProductList($countryId);
        if (count($products) > 0) {
            $extraAry['product'] = array(
                'label' => 'Product', 'id' => 'product',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                    4 => array('id' => 'begins_with', 'label' => 'Begins With', 'input' => 'text'),
                    5 => array('id' => 'not_begins_with', 'label' => 'Does not Begins With', 'input' => 'text'),
                    6 => array('id' => 'ends_with', 'label' => 'Ends With', 'input' => 'text'),
                    7 => array('id' => 'not_ends_with', 'label' => 'Does not Ends With', 'input' => 'text'),
                    8 => array('id' => 'contains', 'label' => 'Contains', 'input' => 'text'),
                    9 => array('id' => 'not_contains', 'label' => 'Does not Contains', 'input' => 'text'),
                ),
                'values' => $products,
            );
        }

        $categories = $this->getAllCategoryList($countryId);
        if (count($categories) > 0) {
            $categories = array_merge(array('-1' => 'All Category'), $categories);

            $extraAry['category'] = array(
                'label' => 'Category', 'id' => 'category',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                    4 => array('id' => 'begins_with', 'label' => 'Begins With', 'input' => 'text'),
                    5 => array('id' => 'not_begins_with', 'label' => 'Does not Begins With', 'input' => 'text'),
                    6 => array('id' => 'ends_with', 'label' => 'Ends With', 'input' => 'text'),
                    7 => array('id' => 'not_ends_with', 'label' => 'Does not Ends With', 'input' => 'text'),
                    8 => array('id' => 'contains', 'label' => 'Contains', 'input' => 'text'),
                    9 => array('id' => 'not_contains', 'label' => 'Does not Contains', 'input' => 'text'),
                ),
                'values' => $categories,
            );
        }

        $brands = $this->getAllBrandList($countryId);
        if (count($brands) > 0) {
            $extraAry['product_brand'] = array(
                'label' => 'Product Brand', 'id' => 'product_brand',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                    4 => array('id' => 'begins_with', 'label' => 'Begins With', 'input' => 'text'),
                    5 => array('id' => 'not_begins_with', 'label' => 'Does not Begins With', 'input' => 'text'),
                    6 => array('id' => 'ends_with', 'label' => 'Ends With', 'input' => 'text'),
                    7 => array('id' => 'not_ends_with', 'label' => 'Does not Ends With', 'input' => 'text'),
                    8 => array('id' => 'contains', 'label' => 'Contains', 'input' => 'text'),
                    9 => array('id' => 'not_contains', 'label' => 'Does not Contains', 'input' => 'text'),
                    10 => array('id' => 'is_null', 'label' => 'Is Null', 'input' => 'text', 'class' => 'none'),
                    11 => array('id' => 'is_not_null', 'label' => 'Is Not Null', 'input' => 'text', 'class' => 'none'),
                ),
                'values' => $brands,
            );
        }

        $colors = $this->getAllColorList($countryId);
        if (count($colors) > 0) {
            $extraAry['product_color'] = array(
                'label' => 'Product Color', 'id' => 'product_color',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                    4 => array('id' => 'begins_with', 'label' => 'Begins With', 'input' => 'text'),
                    5 => array('id' => 'not_begins_with', 'label' => 'Does not Begins With', 'input' => 'text'),
                    6 => array('id' => 'ends_with', 'label' => 'Ends With', 'input' => 'text'),
                    7 => array('id' => 'not_ends_with', 'label' => 'Does not Ends With', 'input' => 'text'),
                    8 => array('id' => 'contains', 'label' => 'Contains', 'input' => 'text'),
                    9 => array('id' => 'not_contains', 'label' => 'Does not Contains', 'input' => 'text'),
                    10 => array('id' => 'is_null', 'label' => 'Is Null', 'input' => 'text', 'class' => 'none'),
                    11 => array('id' => 'is_not_null', 'label' => 'Is Not Null', 'input' => 'text', 'class' => 'none'),
                ),
                'values' => $colors,
            );
        }
        $newAry = array_merge($extraAry, $array);

        $aryNames = array();
        foreach ($newAry as $k => $d) {
            $aryNames[$k] = $d['label'];
        }

        array_multisort($aryNames, SORT_ASC, $newAry);

        return $newAry;
    }

    /**
     * @author Employee Id: 4589
     * Description : Get all condition
     *
     * @param 1 : string $culture
     *
     * @return array
     * */
    public function getChargesConditionArray($countryId = null)
    {
        if (!$countryId) {
            $countryId = $this->countryId;
        }

        $ruleOptionRepository = $this->entityManager->getRepository('OfficeBrainServiceGroupBundle:ServiceRuleOption');
        $ruleOptionRepository->setProjectSetting($this->projectSetting);
        $ruleOptions = $ruleOptionRepository->findByRuleType($this->ruleType);

        $optionArray = array();
        foreach ($ruleOptions as $ruleOption) {
            $inputType = 'text';
            $values = array();
            switch ($ruleOption->getRuleFieldType()) {
                case 'dropdown':
                case 'service':

                    $inputType = 'single_select';
                    break;
                case 'textbox':
                    $inputType = 'text';
                    break;
            }

            $className = 'none';
            switch ($ruleOption->getRuleFieldOption()) {
                case 'float':
                    $className = 'decimal_only';
                    break;
                case 'integer':
                    $className = 'numeric_only';
                    break;
                case 'textbox':
                    $className = '';
                    break;
                case 'datepicker':
                    $className = 'datepicker';
                    break;
                case 'autocomplete':
                    $className = 'autocomplete_single';
                    break;
                case 'officebrain_category_api_manager':
                    $values = $this->getAllCategoryList($this->cultureCode);
                    break;
                case 'office_brain_solr.product_search':
                    $values = $this->getAllProductList($this->cultureCode);
                    break;
                case 'officebrain_attribute_api_manager_imprint_location':
                    $values = $this->getImprintLocation();
                    break;
                   case 'officebrain_attribute_api_manager_imprint_method':
                    $values = $this->getImprintMethod();
                    break;
                case 'office_brain_product_tag_manager':
                    $values = $this->getProductTags();
                    break;
            }

            $operatorArray = array();

            foreach (json_decode($ruleOption->getRuleOperators()) as $slug => $value) {
                if ($inputType == 'single_select' && in_array($slug, $this->getConditionMultipleValueList())) {
                    $inputType = 'multi_select';
                }
                $operatorArray[] = array(
                    'id' => $slug,
                    'label' => $value,
                    'input' => $inputType,
                    'class' => $className,
                );
            }

            $optionArray[$ruleOption->getRuleSlug()] = array(
                'label' => $this->translatorService->trans('admin.service_group_manager.options_title.'.$ruleOption->getRuleSlug()),
                'id' => $ruleOption->getRuleSlug(),
                'operators' => $operatorArray,
            );

            if ($ruleOption->getRuleFieldType() == 'dropdown') {
                $optionArray[$ruleOption->getRuleSlug()]['values'] = json_decode($ruleOption->getRuleFieldOption(), true);
            } elseif ($ruleOption->getRuleFieldType() == 'service' && !empty($values)) {
                $optionArray[$ruleOption->getRuleSlug()]['values'] = $values;
            }

            if ($className != '') {
                $optionArray[$ruleOption->getRuleSlug()]['validate'] = true;
            }
        }

        return $optionArray;
        //$master = $this->container->get('office_brain_core_manager');
        $array = array(
            'price' => array(
                'label' => 'Price', 'id' => 'price', 'validate' => true,
                'operators' => array(
                    0 => array('id' => 'equal', 'label' => '=', 'input' => 'text', 'class' => 'decimal_only'),
                    1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text', 'class' => 'decimal_only'),
                    2 => array('id' => 'greater', 'label' => '>', 'input' => 'text', 'class' => 'decimal_only'),
                    3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text', 'class' => 'decimal_only'),
                    4 => array('id' => 'less', 'label' => '<', 'input' => 'text', 'class' => 'decimal_only'),
                    5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text', 'class' => 'decimal_only'),
                ),
            ),
            'product_weight' => array(
                'label' => 'Product Weight (lbs)', 'id' => 'product_weight', 'validate' => true,
                'operators' => array(
                    0 => array('id' => 'equal', 'label' => '=', 'input' => 'text', 'class' => 'decimal_only'),
                    1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text', 'class' => 'decimal_only'),
                    2 => array('id' => 'greater', 'label' => '>', 'input' => 'text', 'class' => 'decimal_only'),
                    3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text', 'class' => 'decimal_only'),
                    4 => array('id' => 'less', 'label' => '<', 'input' => 'text', 'class' => 'decimal_only'),
                    5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text', 'class' => 'decimal_only'),
                    6 => array('id' => 'is_null', 'label' => 'Is Null', 'input' => 'text', 'class' => 'none'),
                    7 => array('id' => 'is_not_null', 'label' => 'Is Not Null', 'input' => 'text', 'class' => 'none'),
                ),
            ),
            'product_size' => array(
                'label' => 'Product Size', 'id' => 'product_size',
                'operators' => array(
                    0 => array('id' => 'equal', 'label' => '=', 'input' => 'text', 'class' => ''),
                    1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text', 'class' => ''),
                    2 => array('id' => 'greater', 'label' => '>', 'input' => 'text', 'class' => ''),
                    3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text', 'class' => ''),
                    4 => array('id' => 'less', 'label' => '<', 'input' => 'text', 'class' => ''),
                    5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text', 'class' => ''),
                    6 => array('id' => 'is_null', 'label' => 'Is Null', 'input' => 'text', 'class' => 'none'),
                    7 => array('id' => 'is_not_null', 'label' => 'Is Not Null', 'input' => 'text', 'class' => 'none'),
                ),
            ),
            'product_stock' => array(
                'label' => 'Product Stock', 'id' => 'product_stock', 'validate' => true,
                'operators' => array(
                    0 => array('id' => 'equal', 'label' => '=', 'input' => 'text', 'class' => 'numeric_only'),
                    1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text', 'class' => 'numeric_only'),
                    2 => array('id' => 'greater', 'label' => '>', 'input' => 'text', 'class' => 'numeric_only'),
                    3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text', 'class' => 'numeric_only'),
                    4 => array('id' => 'less', 'label' => '<', 'input' => 'text', 'class' => 'numeric_only'),
                    5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text', 'class' => 'numeric_only'),
                    6 => array('id' => 'is_null', 'label' => 'Is Null', 'input' => 'text', 'class' => 'none'),
                    7 => array('id' => 'is_not_null', 'label' => 'Is Not Null', 'input' => 'text', 'class' => 'none'),
                ),
            ),
            'cart_total_qty' => array(
                'label' => 'Total Cart Quantity', 'id' => 'cart_total_qty', 'validate' => true,
                'operators' => array(
                    0 => array('id' => 'equal', 'label' => '=', 'input' => 'text', 'class' => 'numeric_only'),
                    1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text', 'class' => 'numeric_only'),
                    2 => array('id' => 'greater', 'label' => '>', 'input' => 'text', 'class' => 'numeric_only'),
                    3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text', 'class' => 'numeric_only'),
                    4 => array('id' => 'less', 'label' => '<', 'input' => 'text', 'class' => 'numeric_only'),
                    5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text', 'class' => 'numeric_only'),
                    6 => array('id' => 'is_null', 'label' => 'Is Null', 'input' => 'text', 'class' => 'none'),
                    7 => array('id' => 'is_not_null', 'label' => 'Is Not Null', 'input' => 'text', 'class' => 'none'),
                ),
            ),
            'cart_subtotal' => array(
                'label' => 'Cart Subtotal', 'id' => 'cart_subtotal', 'validate' => true,
                'operators' => array(
                    0 => array('id' => 'equal', 'label' => '=', 'input' => 'text', 'class' => 'decimal_only'),
                    1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text', 'class' => 'decimal_only'),
                    2 => array('id' => 'greater', 'label' => '>', 'input' => 'text', 'class' => 'decimal_only'),
                    3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text', 'class' => 'decimal_only'),
                    4 => array('id' => 'less', 'label' => '<', 'input' => 'text', 'class' => 'decimal_only'),
                    5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text', 'class' => 'decimal_only'),
                    6 => array('id' => 'is_null', 'label' => 'Is Null', 'input' => 'text', 'class' => 'none'),
                    7 => array('id' => 'is_not_null', 'label' => 'Is Not Null', 'input' => 'text', 'class' => 'none'),
                ),
            ),
            'cart_total_weight' => array(
                'label' => 'Cart Total Weight (lbs)', 'id' => 'cart_total_weight', 'validate' => true,
                'operators' => array(
                    0 => array('id' => 'equal', 'label' => '=', 'input' => 'text', 'class' => 'decimal_only'),
                    1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text', 'class' => 'decimal_only'),
                    2 => array('id' => 'greater', 'label' => '>', 'input' => 'text', 'class' => 'decimal_only'),
                    3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text', 'class' => 'decimal_only'),
                    4 => array('id' => 'less', 'label' => '<', 'input' => 'text', 'class' => 'decimal_only'),
                    5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text', 'class' => 'decimal_only'),
                    6 => array('id' => 'is_null', 'label' => 'Is Null', 'input' => 'text', 'class' => 'none'),
                    7 => array('id' => 'is_not_null', 'label' => 'Is Not Null', 'input' => 'text', 'class' => 'none'),
                ),
            ),
            /* 'product_price_rowtotal' => array(
              'label' => 'Product Price Row Total','id' => 'product_price_rowtotal','validate' => true,
              'operators' => array(
              0 => array('id' => 'equal', 'label' => '=', 'input' => 'text','class' => 'decimal_only'),
              1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text','class' => 'decimal_only'),
              2 => array('id' => 'greater', 'label' => '>', 'input' => 'text','class' => 'decimal_only'),
              3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text','class' => 'decimal_only'),
              4 => array('id' => 'less', 'label' => '<', 'input' => 'text','class' => 'decimal_only'),
              5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text','class' => 'decimal_only'),
              6 => array('id' => 'is_null', 'label' => 'Is Null', 'input' => 'text','class' => 'none'),
              7 => array('id' => 'is_not_null', 'label' => 'Is Not Null', 'input' => 'text','class' => 'none'),
              ),
              ),
              'product_qty_rowtotal' => array(
              'label' => 'Product Qty Row Total','id' => 'product_qty_rowtotal','validate' => true,
              'operators' => array(
              0 => array('id' => 'equal', 'label' => '=', 'input' => 'text','class' => 'numeric_only'),
              1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text','class' => 'numeric_only'),
              2 => array('id' => 'greater', 'label' => '>', 'input' => 'text','class' => 'numeric_only'),
              3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text','class' => 'numeric_only'),
              4 => array('id' => 'less', 'label' => '<', 'input' => 'text','class' => 'numeric_only'),
              5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text','class' => 'numeric_only'),
              6 => array('id' => 'is_null', 'label' => 'Is Null', 'input' => 'text','class' => 'none'),
              7 => array('id' => 'is_not_null', 'label' => 'Is Not Null', 'input' => 'text','class' => 'none'),
              ),
              ), */
            /* 'payment_method' => array(
              'label'=>'Payment Method','id'=>'payment_method',
              'operators'=>array(
              0=>array('id'=>'is', 'label'=>'Is', 'input'=>'single_select'),
              1=>array('id'=>'is_not', 'label'=>'Is Not', 'input'=>'single_select'),
              2=>array('id'=>'in', 'label'=>'In', 'input'=>'multi_select'),
              3=>array('id'=>'not_in', 'label'=>'Not In', 'input'=>'multi_select'),
              ),
              'values'=>array(1=>'Paypal','Autorize.net'),
              ), */
            'shipping_method' => array(
                'label' => 'Shipping Method', 'id' => 'shipping_method',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                ),
                'values' => array(1 => 'UPS', 'USPS', 'FedEx'),
            ),
            'shipping_postcode' => array(
                'label' => 'Shipping Postcode', 'id' => 'shipping_postcode',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'text'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'text'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'text'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'text'),
                    4 => array('id' => 'begins_with', 'label' => 'Begins With', 'input' => 'text'),
                    5 => array('id' => 'not_begins_with', 'label' => 'Does not Begins With', 'input' => 'text'),
                    6 => array('id' => 'ends_with', 'label' => 'Ends With', 'input' => 'text'),
                    7 => array('id' => 'not_ends_with', 'label' => 'Does not Ends With', 'input' => 'text'),
                    8 => array('id' => 'contains', 'label' => 'Contains', 'input' => 'text'),
                    9 => array('id' => 'not_contains', 'label' => 'Does not Contains', 'input' => 'text'),
                ),
            ),
            'shipping_region' => array(
                'label' => 'Shipping Region', 'id' => 'shipping_region',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'text'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'text'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'text'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'text'),
                    4 => array('id' => 'begins_with', 'label' => 'Begins With', 'input' => 'text'),
                    5 => array('id' => 'not_begins_with', 'label' => 'Does not Begins With', 'input' => 'text'),
                    6 => array('id' => 'ends_with', 'label' => 'Ends With', 'input' => 'text'),
                    7 => array('id' => 'not_ends_with', 'label' => 'Does not Ends With', 'input' => 'text'),
                    8 => array('id' => 'contains', 'label' => 'Contains', 'input' => 'text'),
                    9 => array('id' => 'not_contains', 'label' => 'Does not Contains', 'input' => 'text'),
                ),
            ),
            'shipping_state' => array(
                'label' => 'Shipping State/Region', 'id' => 'shipping_state',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'text'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'text'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'text'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'text'),
                    4 => array('id' => 'begins_with', 'label' => 'Begins With', 'input' => 'text'),
                    5 => array('id' => 'not_begins_with', 'label' => 'Does not Begins With', 'input' => 'text'),
                    6 => array('id' => 'ends_with', 'label' => 'Ends With', 'input' => 'text'),
                    7 => array('id' => 'not_ends_with', 'label' => 'Does not Ends With', 'input' => 'text'),
                    8 => array('id' => 'contains', 'label' => 'Contains', 'input' => 'text'),
                    9 => array('id' => 'not_contains', 'label' => 'Does not Contains', 'input' => 'text'),
                ),
            ),
            'shipping_country' => array(
                'label' => 'Shipping Country', 'id' => 'shipping_country',
                //'plugin' => 'autocomplete',
                //'plugin_config' => array('source' => $this->generateUrl('office_brain_core_bundle_country_auto_suggest', array('_locale' => $culture), true)),
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'text', 'class' => 'autocomplete_single'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'text', 'class' => 'autocomplete_single'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'text', 'class' => 'autocomplete_multiple'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'text', 'class' => 'autocomplete_multiple'),
                /* 4 => array('id' => 'begins_with', 'label' => 'Begins With', 'input' => 'text', 'class' => 'autocomplete_single'),
                  5 => array('id' => 'not_begins_with', 'label' => 'Does not Begins With', 'input' => 'text', 'class' => 'autocomplete_single'),
                  6 => array('id' => 'ends_with', 'label' => 'Ends With', 'input' => 'text', 'class' => 'autocomplete_single'),
                  7 => array('id' => 'not_ends_with', 'label' => 'Does not Ends With', 'input' => 'text', 'class' => 'autocomplete_single'),
                  8 => array('id' => 'contains', 'label' => 'Contains', 'input' => 'text', 'class' => 'autocomplete_single'),
                  9 => array('id' => 'not_contains', 'label' => 'Does not Contains', 'input' => 'text', 'class' => 'autocomplete_single'), */
                ),
            ),
            'imprint_method' => array(
                'label' => 'Imprint Method', 'id' => 'imprint_method',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                ),
                'values' => array(1 => 'Vibrant Digital Direct', 'Vibrant Heat Transfer'),
            ),
            'setup_type' => array(
                'label' => 'Setup Type', 'id' => 'setup_type',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                ),
                'values' => array(1 => 'Die', 'Laser'),
            ),
            'reorder' => array(
                'label' => 'ReOrder', 'id' => 'reorder',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                ),
                'values' => array(1 => 'Yes', 2 => 'No'),
            ),
            'product_tag' => array(
                'label' => 'Product Tag', 'id' => 'product_tag',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                ),
                'values' => array(1 => 'New', 'Feature', 'Closeout', 'Sale'),
            ),
            'imprint_location' => array(
                'label' => 'Imprint Location', 'id' => 'imprint_location',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                ),
                'values' => array(1 => 'Left', 'Top', 'Right', 'Bottom', 'Front', 'Back', 'Center', 'Outer Edge', 'Inner Edge', 'All Side', 'Barrel', 'Clip'),
            ),
            'no_of_selected_color' => array(
                'label' => 'No. Of selected Color', 'id' => 'no_of_selected_color', 'validate' => true,
                'operators' => array(
                    0 => array('id' => 'equal', 'label' => '=', 'input' => 'text', 'class' => 'numeric_only'),
                    1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text', 'class' => 'numeric_only'),
                    2 => array('id' => 'greater', 'label' => '>', 'input' => 'text', 'class' => 'numeric_only'),
                    3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text', 'class' => 'numeric_only'),
                    4 => array('id' => 'less', 'label' => '<', 'input' => 'text', 'class' => 'numeric_only'),
                    5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text', 'class' => 'numeric_only'),
                ),
            ),
            'purchase_date' => array(
                'label' => 'Purchase Date', 'id' => 'purchase_date', 'validate' => true,
                //'plugin'=> 'datetimepicker',
                //'plugin_config'=> array('format'=> 'YYYY-MM-DD','pickTime'=>false, 'autoclose'=> true),
                'plugin' => 'datepicker',
                'plugin_config' => array('dateFormat' => 'yy-mm-dd', 'pickTime' => false, 'autoclose' => true),
                'operators' => array(
                    0 => array('id' => 'equal', 'label' => '=', 'input' => 'text', 'class' => 'datepicker'),
                    1 => array('id' => 'not_equal', 'label' => '!=', 'input' => 'text', 'class' => 'datepicker'),
                    2 => array('id' => 'greater', 'label' => '>', 'input' => 'text', 'class' => 'datepicker'),
                    3 => array('id' => 'greater_or_equal', 'label' => '>=', 'input' => 'text', 'class' => 'datepicker'),
                    4 => array('id' => 'less', 'label' => '<', 'input' => 'text', 'class' => 'datepicker'),
                    5 => array('id' => 'less_or_equal', 'label' => '<=', 'input' => 'text', 'class' => 'datepicker'),
                ),
            ),
            'addition_imprint' => array(
                'label' => 'Additional Imprint', 'id' => 'addition_imprint',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                ),
                'values' => array(1 => 'Location/Color', 'Color', 'Location'),
            ),
            'eqp' => array(
                'label' => 'EQP', 'id' => 'eqp',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                ),
                'values' => array('true' => 'True', 'false' => 'False'),
            ),
        );

        $extraAry = array();
        $users = $this->getAllUserList();
        if (count($users) > 0) {
            $extraAry['user'] = array(
                'label' => 'User',
                'id' => 'user',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                    4 => array('id' => 'begins_with', 'label' => 'Begins With', 'input' => 'text'),
                    5 => array('id' => 'not_begins_with', 'label' => 'Does not Begins With', 'input' => 'text'),
                    6 => array('id' => 'ends_with', 'label' => 'Ends With', 'input' => 'text'),
                    7 => array('id' => 'not_ends_with', 'label' => 'Does not Ends With', 'input' => 'text'),
                    8 => array('id' => 'contains', 'label' => 'Contains', 'input' => 'text'),
                    9 => array('id' => 'not_contains', 'label' => 'Does not Contains', 'input' => 'text'),
                ),
                'values' => $users,
            );
        }

        $products = $this->getAllProductList($countryId);
        if (count($products) > 0) {
            $extraAry['product'] = array(
                'label' => 'Product', 'id' => 'product',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                    4 => array('id' => 'begins_with', 'label' => 'Begins With', 'input' => 'text'),
                    5 => array('id' => 'not_begins_with', 'label' => 'Does not Begins With', 'input' => 'text'),
                    6 => array('id' => 'ends_with', 'label' => 'Ends With', 'input' => 'text'),
                    7 => array('id' => 'not_ends_with', 'label' => 'Does not Ends With', 'input' => 'text'),
                    8 => array('id' => 'contains', 'label' => 'Contains', 'input' => 'text'),
                    9 => array('id' => 'not_contains', 'label' => 'Does not Contains', 'input' => 'text'),
                ),
                'values' => $products,
            );
        }

        $categories = $this->getAllCategoryList($countryId);
        if (count($categories) > 0) {
            $categories = array_merge(array('-1' => 'All Category'), $categories);

            $extraAry['category'] = array(
                'label' => 'Category', 'id' => 'category',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                    4 => array('id' => 'begins_with', 'label' => 'Begins With', 'input' => 'text'),
                    5 => array('id' => 'not_begins_with', 'label' => 'Does not Begins With', 'input' => 'text'),
                    6 => array('id' => 'ends_with', 'label' => 'Ends With', 'input' => 'text'),
                    7 => array('id' => 'not_ends_with', 'label' => 'Does not Ends With', 'input' => 'text'),
                    8 => array('id' => 'contains', 'label' => 'Contains', 'input' => 'text'),
                    9 => array('id' => 'not_contains', 'label' => 'Does not Contains', 'input' => 'text'),
                ),
                'values' => $categories,
            );
        }

        $brands = $this->getAllBrandList($countryId);
        if (count($brands) > 0) {
            $extraAry['product_brand'] = array(
                'label' => 'Product Brand', 'id' => 'product_brand',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                    4 => array('id' => 'begins_with', 'label' => 'Begins With', 'input' => 'text'),
                    5 => array('id' => 'not_begins_with', 'label' => 'Does not Begins With', 'input' => 'text'),
                    6 => array('id' => 'ends_with', 'label' => 'Ends With', 'input' => 'text'),
                    7 => array('id' => 'not_ends_with', 'label' => 'Does not Ends With', 'input' => 'text'),
                    8 => array('id' => 'contains', 'label' => 'Contains', 'input' => 'text'),
                    9 => array('id' => 'not_contains', 'label' => 'Does not Contains', 'input' => 'text'),
                    10 => array('id' => 'is_null', 'label' => 'Is Null', 'input' => 'text', 'class' => 'none'),
                    11 => array('id' => 'is_not_null', 'label' => 'Is Not Null', 'input' => 'text', 'class' => 'none'),
                ),
                'values' => $brands,
            );
        }

        $colors = $this->getAllColorList($countryId);
        if (count($colors) > 0) {
            $extraAry['product_color'] = array(
                'label' => 'Product Color', 'id' => 'product_color',
                'operators' => array(
                    0 => array('id' => 'is', 'label' => 'Is', 'input' => 'single_select'),
                    1 => array('id' => 'is_not', 'label' => 'Is Not', 'input' => 'single_select'),
                    2 => array('id' => 'in', 'label' => 'In', 'input' => 'multi_select'),
                    3 => array('id' => 'not_in', 'label' => 'Not In', 'input' => 'multi_select'),
                    4 => array('id' => 'begins_with', 'label' => 'Begins With', 'input' => 'text'),
                    5 => array('id' => 'not_begins_with', 'label' => 'Does not Begins With', 'input' => 'text'),
                    6 => array('id' => 'ends_with', 'label' => 'Ends With', 'input' => 'text'),
                    7 => array('id' => 'not_ends_with', 'label' => 'Does not Ends With', 'input' => 'text'),
                    8 => array('id' => 'contains', 'label' => 'Contains', 'input' => 'text'),
                    9 => array('id' => 'not_contains', 'label' => 'Does not Contains', 'input' => 'text'),
                    10 => array('id' => 'is_null', 'label' => 'Is Null', 'input' => 'text', 'class' => 'none'),
                    11 => array('id' => 'is_not_null', 'label' => 'Is Not Null', 'input' => 'text', 'class' => 'none'),
                ),
                'values' => $colors,
            );
        }
        $newAry = array_merge($extraAry, $array);

        $aryNames = array();
        foreach ($newAry as $k => $d) {
            $aryNames[$k] = $d['label'];
        }

        array_multisort($aryNames, SORT_ASC, $newAry);

        return $newAry;
    }

    /**
     * @author Employee Id: 4589
     * Description :
     *
     * @param 1 : array $condOrderAry
     * @param 2 : bool  $readOnly
     *
     * @return array
     * */
    public function setArrayWithJsonFormat($condOrderAry, $readOnly = false)
    {
        $new = array();

        foreach ($condOrderAry as $ruleCond) {
            $RuleName = $this->getLevelBasedArrayName($ruleCond['level'], $ruleCond['inner_order'], $new);
            if ($ruleCond['inner_order'] <= 0) {
                $ConditionName = substr($RuleName, 0, -strlen("['rules'][]"))."['condition']";
                eval('$new'.$ConditionName.' = $ruleCond[\'main_condition\'];');
            }
            $conditionField = $this->ruleKeyNameAry['condition_field'];
            $conditionVal = $this->ruleKeyNameAry['condition_value'];
            $conditionOpera = $this->ruleKeyNameAry['condition_operator'];

            $thisVal = $this->setProperRuleConditionValue($ruleCond[$conditionField], $ruleCond[$conditionOpera], $ruleCond[$conditionVal]);
            $condAry = array('id' => $ruleCond[$conditionField], 'operator' => $ruleCond[$conditionOpera], 'value' => $thisVal);
            if ($readOnly) {
                $condAry['readonly'] = true;
            }
            eval('$new'.$RuleName.' = $condAry;');
        }

        return $new;
    }

    /**
     * @author Employee Id: 4589
     * Description :
     *
     * @param 1 : int   $level
     * @param 2 : int   $innerOrder
     * @param 3 : array $newAry
     *
     * @return array
     * */
    public function getLevelBasedArrayName($level, $innerOrder, $newAry)
    {
        $returnName = '';
        $counterName = '';
        $counterAry = array();
        for ($i = 0; $i <= $level; ++$i) {
            $counterName .= '[\'rules\']';
            eval('$count = (isset($newAry'.$counterName.')?count($newAry'.$counterName.'):0);');
            $counterAry[$i] = ($count > 0) ? ($innerOrder <= 0 && $level - 1 == $i ? $count : $count - 1) : 0;
            $returnName .= '[\'rules\']';
            if ($level != $i) {
                $counterName .= '['.($count - 1).']';
                $returnName .= '['.($counterAry[$i]).']';
            }
        }

        return $returnName.'[]';
    }

    /**
     * @author Employee Id: 4589
     * Description :
     *
     * @param 1 : array $conditionAry
     * @param 2 : array $parentRelAry
     * @param 3 : int   $position
     * @param 4 : array $newAry
     * @param 5 : int   $level
     *
     * @return array
     * */
    public function getAllCondition($conditionAry, $parentRelAry, $position = 0, $newAry = array(), $level = 0)
    {
        $positionAry = array();
        foreach ($parentRelAry as $ak => $parentKey) {
            if ($parentKey == $position) {
                $positionAry[] = $ak;
            }
        }

        if (count($positionAry) <= 0) {
            return $newAry;
        }
        foreach ($positionAry as $position) {
            $rule = $conditionAry[$position];
            $innerOrder = 0;

            foreach ($rule[$this->ruleKeyNameAry['service_rule_main_condition_id']] as $ruleCond) {
                $thisAry = array('main_condition' => $rule[$this->ruleKeyNameAry['main_condition']], 'if_condition_is' => $rule[$this->ruleKeyNameAry['if_condition_is']], 'level' => $level, 'inner_order' => $innerOrder);
                $thisAry = array_merge($ruleCond, $thisAry);

                $newAry[] = $thisAry;
                ++$innerOrder;
            }
            $newAry = $this->getAllCondition($conditionAry, $parentRelAry, $rule['id'], $newAry, $level + 1);
        }

        return $newAry;
    }

    /**
     * @author Employee Id: 4589
     * Description :
     *
     * @param 1 : string $field
     * @param 2 : string $operator
     * @param 3 : string $value
     *
     * @return array
     * */
    public function setProperRuleConditionValue($field, $operator, $value)
    {
        if (isset($this->conditionAry[$field]['values']) && in_array($operator, $this->conditionMutlipleValueAry) && $value != '') {
            return unserialize($value);
        }

        return $value;
    }

    /**
     * @author Employee Id: 4589
     * Description :
     *
     * @param 1 : date $date
     *
     * @return bool
     * */
    public function checkMyCorrectDate($date)
    {
        if ($date && $date != null) {
            $datAry = explode('-', $date);
            if (count($datAry) < 3) {
                return false;
            }

            return (checkdate($datAry[1], $datAry[2], $datAry[0]));
        }

        return true;
    }

    public function setRuleMaster($form)
    {
    }

    public function copyRuleMaster()
    {
    }

    public function makeCopyRuleMaster($serviceRuleMaster, $countryId, $isActive)
    {
    }

    public function updateRuleMaster($form, $id, $culture)
    {
    }

    public function getRuleMasterList()
    {
    }

    public function deleteRuleMaster($id)
    {
    }

    public function setRuleCondition($masterIdObj, $ruleArray, $condOp, $parentId = 0, &$counter = 0)
    {
    }

    public function getRuleMasterListArray($culture, $searchQuery)
    {
    }

    public function setRuleMapping($form)
    {
    }

    public function copyRuleMappingMaster()
    {
    }

    public function makeCopyRuleMappingMaster($serviceRuleMappingMaster, $countryId, $isActive)
    {
    }

    public function updateRuleMapping($form, $id, $culture)
    {
    }

    /* public function deleteRuleMapping($id)
    {
    } */

    /**
     * @author Employee Id: 4589
     * Description : find service rule by Id
     *
     * @param 1 : Rule Id
     *
     * @return type : ServiceRuleMaster
     *
     * @throws Exception: Null
     */
    public function findOneById($ruleId)
    {
        return $this->entityManager->getRepository('OfficeBrainServiceGroupBundle:ServiceRuleMappingRules')->findOneById($ruleId);
    }

    /**
     * @author Employee Id: 4589
     * Description : Get Rule master By Id
     *
     * @param 1 : Rule Master Id
     *
     * @return type : Rule Master
     *
     * @throws Exception: Null
     */
    public function getRuleMasterById($id)
    {
        $ruleMasterRepo = $this->entityManager->getRepository('OfficeBrainServiceGroupBundle:ServiceRuleMaster');
        $ruleMasterRepo->setProjectSetting($this->projectSetting);
        $serviceGroup = $ruleMasterRepo->getServiceRuleMasterListById($id);

        return $serviceGroup;
    }

    public function addmanualSpecialPricingNotExpired($productDetailArray)
    {    	
    	$productArray = array();
    	
    	if (isset($productDetailArray['product_id'])) {
    		$productArray[] = $productDetailArray;
    	} elseif (isset($productDetailArray['products'])) {
    		$productArray = (array)$productDetailArray['products'];
    	} else {
    		$productArray = (array)$productDetailArray;
    	}
    	foreach ($productArray as $main_index=>$productDetail) {
    		if (!isset($productDetail['product_id'])) {
    			continue;
    		}    		
    		$productArray[$main_index]['manualSpecialPricingNotExpired'] = true;
    		if(array_key_exists('special_price_valid_up_to', $productArray[$main_index]['basic_information']) && $productArray[$main_index]['basic_information']['special_price_valid_up_to']!='') {
    			$manualSpecialPricingExpiryDateObj = \DateTime::createFromFormat('m-d-Y', $productArray[$main_index]['basic_information']['special_price_valid_up_to']);
    			// question here if $productDetail['pricing']['special'] will be an array even if the product has only one price
    			$todayDateObj = new \DateTime();
    			
    			// If manual special pricing is not expired, turned on the flag for the same
    			if($manualSpecialPricingExpiryDateObj < $todayDateObj)
    			{
    				$productArray[$main_index]['manualSpecialPricingNotExpired']= false;
    			}
    		}
    		else {
    			$manualSpecialPricingExpiryDateObj = "";
    		}
    		
    		/* Restructured the old br/tr structure with new one started */
    		/* Restructured the old br/tr structure with newer one for front */
    		if(isset($productArray[$main_index]['images']) && (!(empty($productArray[$main_index]['images']))))
    		{
    			foreach($productArray[$main_index]['images'] as $imageIndex => $imageData)
    			{
    				if(isset($imageData['color_name']) && $imageData['color_name'] != '' && (!(strstr($imageData['color_name'],"|"))))
    				{
    					$imageData['color_name'] = $imageData['color_name'] . '|' . $imageData['actual_color'];
    					$productArray[$main_index]['images'][$imageIndex]['color_name'] = $imageData['color_name'];
    				}
    			}
    		}   		
    		
    		/* Restructured the old br/tr structure with newer one for admin */
    		if(isset($productArray[$main_index]['prod_images']['other']) && (!(empty($productArray[$main_index]['prod_images']['other']))))
    		{
    			foreach($productArray[$main_index]['prod_images']['other']as $imageIndex => $imageData)
    			{
    				if(isset($imageData['colorCode']) && $imageData['colorCode'] != '' && (!(strstr($imageData['colorCode'],"|"))))
    				{
    					$imageData['colorCode'] = $imageData['colorCode'] . '|' . $imageData['attribute_value'];
    					$productArray[$main_index]['prod_images']['other'][$imageIndex]['colorCode'] = $imageData['colorCode'];
    				}
    			}
    		}
    		/* Restructured the old br/tr structure with new one ended */
    		
    	}
    	
    	if (isset($productDetailArray['product_id'])) {
    		$productDetailArray = reset($productArray);
    	} elseif (isset($productDetailArray['products'])) {
    		$productDetailArray['products'] = $productArray;
    	} else {
    		$productDetailArray = $productArray;
    	}
    	return $productDetailArray;
    }
    /**
     * @author Employee Id: 4589
     * Description : Overwrite productDetail array after API call
     *
     * @param 1 : productDetailArray
     *
     * @return type : productDetailArray
     *
     * @throws Exception: Null
     */
    public function updatePriceWithRule($productDetailArray, $parameters)
    {
    	/*echo "<pre>";
    	print_r($productDetailArray);exit;*/
        $serviceGroupId = null;//$this->serviceGroupId;
        $productArray = array();

        $isFromSolr = (isset($parameters['is_solr']) && $parameters['is_solr'] == 1) ? true : false;
        if ($isFromSolr && isset($parameters['instance_id'])) {
            $instanceId = $parameters['instance_id'];
        } else {
            $instanceId = $this->instanceId;
        }

        if (isset($productDetailArray['product_id'])) {
            $productArray[] = $productDetailArray;
        } elseif (isset($productDetailArray['products'])) {
            $productArray = (array)$productDetailArray['products'];
        } else {
            $productArray = (array)$productDetailArray;
        }

        //check is user logged in
        $userSettings = $this->request->get('project_user_setting');
        $loggedInUserServiceGroupId = null;

        $isLoggedIn = false;
        if (!$isFromSolr && isset($userSettings['user_data']) && $userSettings['user_data'] && $userSettings['user_data']->getServiceGroup()) {
            $loggedInUserServiceGroupId = $userSettings['user_data']->getServiceGroup()->getId();
            $isLoggedIn = true;
        }

        //check is supplier or association
        $isDiscountCodeApply = ($this->configurationRule['option']['apply_code_on_product_detail']['status']==1) ? true : false;

        foreach ($productArray as $main_index=>$productDetail) {
            if (!isset($productDetail['product_id'])) {
                continue;
            }
            
            $isRuleApplied = false;
            $serviceGroupUpdatedArray = array();           

			// Apply discount codes on folowing six places
			// 1) To decorative or blank prices
			// 2) To special price
			// 3) To decorative or blank country prices
            // 4) To special country prices
            // 5) To variation prices
            // 6) To special variation prices
            // apply discount code coding started
            if (!$isRuleApplied && !$isFromSolr) {
            	$discountCodes = null;
            	if ($isDiscountCodeApply && $isLoggedIn) { //$loggedInUserServiceGroupId
            		//call discount code API
            		$productArray[$main_index]= $this->applyDiscountCodeOnAllPricing($productDetail);
            	}
            
            	//apply discount code
            } elseif (!$isFromSolr) {
            	/*// We dont want to execute the discount for solr
            	$discountCodes = null;
            	if ($isDiscountCodeApply) {
            		//call discount code API
            		$discountCodes = $this->getDiscountCodeArray();
            	}
            
            	$serviceGroups = $this->serviceGroupRepository->getAllActiveServiceGroup($this->countryId, $isFromSolr);

            	foreach ($serviceGroups as $serviceGroup) {
            		$serviceGroupId = $serviceGroup->getId();
            
            		$isDefaultGroup = false;
            		if ($serviceGroup->getIsDefault()) {
            			$isDefaultGroup = true;
            		}
            
            		if (!in_array($serviceGroupId, $serviceGroupUpdatedArray)) {
            			//apply discount code & price matrix for group
            			$productArray = $this->defaultDiscountCodeApply($productArray, $productArray[$main_index]['pricing'], $main_index, $isFromSolr, $discountCodes, $serviceGroupId, $isDefaultGroup);
            			$productArray = $this->defaultDiscountCodeApplyForSpecialPrice($productArray, $productArray[$main_index]['pricing'], $main_index, $isFromSolr, $discountCodes, $serviceGroupId, $isDefaultGroup);
            			$isRuleApplied = true;
            		}
            	}//print_r($productArray);exit;
            	if (!$isRuleApplied) {
            		//apply price matrix and overwrite base price in solr if rule not apply
            		$productArray = $this->defaultDiscountCodeApply($productArray, $productArray[$main_index]['pricing'], $main_index, $isFromSolr);
            		$productArray = $this->defaultDiscountCodeApplyForSpecialPrice($productArray, $productArray[$main_index]['pricing'], $main_index, $isFromSolr);
            	}*/
            }
            // apply discount code coding ended
            
            /* coding for manual special pricing started */
            $isManualSpecialPricingEnabledForProject = (isset($this->projectSetting['configuration_rule']['product']['add_update']['pricing']['pricing_type']['special']) && (!empty($this->projectSetting['configuration_rule']['product']['add_update']['pricing']['pricing_type']['special'])))?1:"";
            $isManualSpecialPricingEnabledForProduct = (isset($productDetail['special_pricing']) && (!empty($productDetail['special_pricing'])))?1:"";
            $manualSpecialPricingArray = (isset($productArray[$main_index]['pricing']['special']) && is_array($productArray[$main_index]['pricing']['special']) && !(empty($productArray[$main_index]['pricing']['special'])))?$productArray[$main_index]['pricing']['special']:"";
            $manualSpecialPricingOtherCountryMainArray = (isset($productArray[$main_index]['pricing_for_other_country']) && is_array($productArray[$main_index]['pricing_for_other_country']) && !(empty($productArray[$main_index]['pricing_for_other_country'])))?$productArray[$main_index]['pricing_for_other_country']:"";
            
            if(isset($manualSpecialPricingOtherCountryMainArray) && is_array($manualSpecialPricingOtherCountryMainArray) && (!(empty($manualSpecialPricingOtherCountryMainArray))))
            {
	            foreach($manualSpecialPricingOtherCountryMainArray as $country=>$countryPricing)
	            {
	            	if(isset($countryPricing['special']))
	            	{
	            		$isManualSpecialPricingEnabledForProduct = 1;
	            	}
	            }
            }
            
            $manualSpecialPricingNotExpired = true;
        	if(array_key_exists('special_price_valid_up_to', $productArray[$main_index]['basic_information']) && $productArray[$main_index]['basic_information']['special_price_valid_up_to']!='') {
            	$manualSpecialPricingExpiryDateObj = \DateTime::createFromFormat('m-d-Y', $productArray[$main_index]['basic_information']['special_price_valid_up_to']);
            	// question here if $productDetail['pricing']['special'] will be an array even if the product has only one price
            	$todayDateObj = new \DateTime();

            	// If manual special pricing is not expired, turned on the flag for the same
            	if($manualSpecialPricingExpiryDateObj < $todayDateObj)
            	{
            		$manualSpecialPricingNotExpired= false;
            	}
            }
            else {
            	$manualSpecialPricingExpiryDateObj = "";
            }
            
            //currently we dont have any service rule pricing enabled for goldstar, and thats why we are disabling the service rule pricing by commenting the following line of code
            //in future whenever you need to enable service rule special pricing uncomment the following code
            //and in above area do such a coding that whenever any variation has manual special pricing, the following variable should be true $isManualSpecialPricingEnabledForProduct
            //if($isManualSpecialPricingEnabledForProject != "" && $isManualSpecialPricingEnabledForProduct != "")
            if($isManualSpecialPricingEnabledForProject != "" && $productArray[$main_index]['manualSpecialPricingNotExpired'])
            {
            	/* if condition coding for manual special pricing started */            	
            	$defaultGroup = $this->serviceGroupRepository->getServiceDefaultGroupData($this->countryId);							
            	if (!$isFromSolr && $defaultGroup) {
            		$loggedInUserServiceGroupId = $defaultGroup->getId();
            	}
            	/* code commented by emp id: 5460 */            	
            	
            	$country = $this->serviceContainer->getParameter('country');
            	$conid = explode('_', $this->projectSetting['locale_language']);
            	if (isset(array_keys($productArray[$main_index]['imprint_information']['imprint_method_information'])[0])) {
            		$imprint_id = $this->request->get('imprint_method_id');
            		$firstMethodId = array_keys($productArray[$main_index]['imprint_information']['imprint_method_information'])[0];
            		$firstMethodId = (isset($imprint_id))?$imprint_id:$firstMethodId;
            		
            		if (isset($conid[1]) && isset($productArray[$main_index]['imprint_information']['imprint_method_information'][$firstMethodId]['pricing_for_other_country'][$conid[1]])) {
            			$productArray[$main_index]['pricing'] = $productArray[$main_index]['imprint_information']['imprint_method_information'][$firstMethodId]['pricing_for_other_country'][$conid[1]];
            			$productDetail['pricing'] = $productArray[$main_index]['pricing'];
            		}
            	}
            	
            	/* changed by Emp id # 4835 -start*/
            	if (isset($conid[1]) && !isset($productDetail['pricing']['blank']) && isset($productDetail['blank_imprint_method_id']) && $productDetail['blank_imprint_method_id'] > 0 &&
            	isset($productArray[$main_index]['imprint_information']['imprint_method_information'][$productDetail['blank_imprint_method_id']]['price']['pricing']['blank'])) {
            		$productArray[$main_index]['pricing']['blank'] = $productArray[$main_index]['imprint_information']['imprint_method_information'][$productDetail['blank_imprint_method_id']]['pricing_for_other_country'][$conid[1]]['blank'];
            	}
            	/* changed by Emp id # 4835 -end*/
            	//  print_r( $productArray[$main_index]['pricing']); die;
            	
            	if ($manualSpecialPricingArray) {
            		$priceType = "decorative";
            		if (!isset($productDetail['pricing'][$priceType]) && isset($productDetail['pricing']['blank']) && !empty($productDetail['pricing']['blank'])) {
            			$priceType = "blank";
            		}
            	
            		if (isset($productDetail['pricing'][$priceType])) {
            			$index = 0;
            			$tmpServiceGroupId=$defaultGroup->getId();
            			$priority = 0;
            			foreach ($manualSpecialPricingArray as $newColumnQty) {
            				
            				/* code commented by emp id: 5460 */
            				/*if ($tmpServiceGroupId !=  $newColumnQty->getServiceGroupId()) {
            					if ($tmpServiceGroupId > 0) {
            						$index = 0;
            					}
            					$tmpServiceGroupId = $newColumnQty->getServiceGroupId();
            				}*/
            				/* code commented by emp id: 5460 */
            	
            				if (isset($productArray[$main_index]['pricing'][$priceType][$index])) {
            					if ($isFromSolr) {
            						$productArray[$main_index]['user_group_pricing'][$priceType][$tmpServiceGroupId][$index] = $productArray[$main_index]['pricing'][$priceType][$index];
            	
            						
            							$productArray[$main_index]['user_group_pricing'][$priceType][$tmpServiceGroupId][$index]['rate_orig'] = $productArray[$main_index]['pricing'][$priceType][$index]['rate'];
            						
            							$productArray[$main_index]['user_group_pricing'][$priceType][$tmpServiceGroupId][$index]['code_orig'] = $productArray[$main_index]['pricing'][$priceType][$index]['code'];
            						
            	
            						$productArray[$main_index]['user_group_pricing'][$priceType][$tmpServiceGroupId][$index]['rate'] = $newColumnQty['rate'];
            						$productArray[$main_index]['user_group_pricing'][$priceType][$tmpServiceGroupId][$index]['code'] = $newColumnQty['code'];
            						$productArray[$main_index]['user_group_pricing'][$priceType][$tmpServiceGroupId][$index]['expired_at'] = $manualSpecialPricingExpiryDateObj;
            	
            						$serviceGroupUpdatedArray[] = $tmpServiceGroupId;
            						
            					} elseif ($loggedInUserServiceGroupId && $loggedInUserServiceGroupId > 0) {
            						// if user logged in and assign group
            						
            							$productArray[$main_index]['pricing'][$priceType][$index]['rate_orig'] = $productArray[$main_index]['pricing'][$priceType][$index]['rate'];
            						
            							$productArray[$main_index]['pricing'][$priceType][$index]['code_orig'] = $productArray[$main_index]['pricing'][$priceType][$index]['code'];
            						
            	
            						$productArray[$main_index]['pricing'][$priceType][$index]['rate'] = $newColumnQty['rate'];
            						$productArray[$main_index]['pricing'][$priceType][$index]['code'] = $newColumnQty['code'];
            						$productArray[$main_index]['pricing'][$priceType][$index]['expired_at'] = $manualSpecialPricingExpiryDateObj;           	
            	
            						if ($index == 0) {
            							$productArray[$main_index]['unit_price'] = $productArray[$main_index]['pricing'][$priceType][$index]['rate'];
            							$productArray[$main_index]['regular_price'] = $productArray[$main_index]['pricing'][$priceType][$index]['rate'];
            							$productArray[$main_index]['minimum_quantity'] = $productArray[$main_index]['pricing'][$priceType][$index]['from'];
            							$productArray[$main_index]['minimum_quantity_range'] = $productArray[$main_index]['pricing'][$priceType][$index]['from']. "-" . $productArray[$main_index]['pricing'][$priceType][$index]['to'];
            							$productArray[$main_index]['min_price'] = $productArray[$main_index]['pricing'][$priceType][count($productArray[$main_index]['pricing'][$priceType])-1]['rate'];
            							$productArray[$main_index]['code'] = $productArray[$main_index]['pricing'][$priceType][count($productArray[$main_index]['pricing'][$priceType])-1]['code'];
            						}
            					} else {
            						//if not logged in than apply defalt group price if any
            						/* code commented by emp id: 5460 */
            						//if ($defaultGroup->getId() == $tmpServiceGroupId) {
            						/* code commented by emp id: 5460 */
            						
            								$productArray[$main_index]['pricing'][$priceType][$index]['rate_orig'] = $productArray[$main_index]['pricing'][$priceType][$index]['rate'];
            						
            								$productArray[$main_index]['pricing'][$priceType][$index]['code_orig'] = $productArray[$main_index]['pricing'][$priceType][$index]['code'];
            						
            							$productArray[$main_index]['pricing'][$priceType][$index]['rate'] = $newColumnQty['rate'];
            							$productArray[$main_index]['pricing'][$priceType][$index]['code'] = $newColumnQty['code'];
            							$productArray[$main_index]['pricing'][$priceType][$index]['expired_at'] = $manualSpecialPricingExpiryDateObj;
            	
            	
            							$productArray[$main_index]['unit_price'] = $productArray[$main_index]['pricing'][$priceType][$index]['rate'];
            							$productArray[$main_index]['regular_price'] = $productArray[$main_index]['pricing'][$priceType][$index]['rate'];
            							$productArray[$main_index]['minimum_quantity'] = $productArray[$main_index]['pricing'][$priceType][$index]['from'];
            							$productArray[$main_index]['minimum_quantity_range'] = $productArray[$main_index]['pricing'][$priceType][$index]['from']. "-" . $productArray[$main_index]['pricing'][$priceType][$index]['to'];
            							$productArray[$main_index]['min_price'] = $productArray[$main_index]['pricing'][$priceType][count($productArray[$main_index]['pricing'][$priceType])-1]['rate'];
            							$productArray[$main_index]['code'] = $productArray[$main_index]['pricing'][$priceType][count($productArray[$main_index]['pricing'][$priceType])-1]['code'];
            						/* code commented by emp id: 5460 */
            						//}
            						/* code commented by emp id: 5460 */
            					}
            					$isRuleApplied = true;
            				}
            				/* code commented by emp id: 5460 */
            				//$priority = $newColumnQty->getPriority();
            				/* code commented by emp id: 5460 */
            				
            				/*$tmpArray = $productArray[$main_index]['pricing'][$priceType];
            				 $tmpArray
            				$productArray[$main_index]['pricing']['user_group_pricing'][$priceType][$newColumnQty->getServiceGroupId()] = $productArray[$main_index]['pricing'][$priceType];*/
            				$index ++;
            			}
            	
            			/*foreach($productDetail['pricing'][$priceType] as $index => $qtyPrice){
            	
            			if(isset($serviceRulePrices[$index]) && $newColumnQty = $serviceRulePrices[$index]){
            			$productArray[$main_index]['pricing']['user_group_price'][$priceType][$newColumnQty->getServiceGroupId()][$index]['rate'] = $newColumnQty->getPrice();
            			$productArray[$main_index]['pricing']['user_group_price'][$priceType][$newColumnQty->getServiceGroupId()][$index]['code'] = $newColumnQty->getCode();
            			}
            	
            			}*/
            		}
            	
            		/* NOTE FOR THOSE WHO ARE USING PRODUCT API V2
            		 * If your client has demanded manual special pricing,
            		 * If you have enabled it from product,
            		 * If you have entered special pricing for any product,
            		 * CHANGE THE BELOW TWO IF CONDITION'S CODING AS PER YOUR REQUIREMENT  */
            		if ($priority > 0 && $priceType=='decorative' && isset($productDetail['pricing']['blank'])) { 
            			$i = 0;
            			$ruleMappingMaster = $this->getServiceRuleMappingByPriority($priority, false);
            			$discountCodes = $this->getDiscountCodeArray();
            			$newColumnQtyArray = array();
            	
            			if ($columnQtyArray = $ruleMappingMaster->getServiceRuleMappingQtyId() && $ruleMappingMaster->getServiceRuleMappingQtyId()->count() > 0) {
            				if ($columnQtyArray && is_array($columnQtyArray)) {
            					foreach ($columnQtyArray as $columnQty) {
            						$newColumnQtyArray[$columnQty->getColumnNo()] = $columnQty;
            					}
            				}
            			}
            			foreach ($productDetail['pricing']['blank'] as $price) {
            				$priceData = $this->calculateProductRulePrice($productArray[$main_index], $i, $ruleMappingMaster, $discountCodes, $newColumnQtyArray, $price['rate'], $price['code']);
            	
            				if ($productDetail['pricing']['blank'][$i]['rate'] != $priceData['productPrice']) {
            					$productArray[$main_index]['pricing']['blank'][$i]['rate_orig'] = $productDetail['pricing']['blank'][$i]['rate'];
            				}
            				if (isset($priceData['productCode']) && !empty($priceData['productCode'])) {
            					$productArray[$main_index]['pricing']['blank'][$i]['code_orig'] = $productArray[$main_index]['pricing']['blank'][$i]['code'];
            				}
            				$productArray[$main_index]['pricing']['blank'][$i]['rate'] = $priceData['productPrice'];
            				$productArray[$main_index]['pricing']['blank'][$i]['code'] = $priceData['productCode'];
            				$i++;
            			}
            		}
            		if ($priority > 0 && isset($productArray[$main_index]['imprint_information']['imprint_method_information']) && count($productArray[$main_index]['imprint_information']['imprint_method_information']) > 0) {
            			$ruleMappingMaster = $this->getServiceRuleMappingByPriority($priority, false);
            			$discountCodes = $this->getDiscountCodeArray();
            			$newColumnQtyArray = array();
            	
            			if ($columnQtyArray = $ruleMappingMaster->getServiceRuleMappingQtyId() && $ruleMappingMaster->getServiceRuleMappingQtyId()->count() > 0) {
            				if ($columnQtyArray && is_array($columnQtyArray)) {
            					foreach ($columnQtyArray as $columnQty) {
            						$newColumnQtyArray[$columnQty->getColumnNo()] = $columnQty;
            					}
            				}
            			}
            	
            			foreach ($productArray[$main_index]['imprint_information']['imprint_method_information'] as $key=>$valArray) {
            				if (isset($valArray['price']['pricing']['decorative']) || isset($valArray['price']['pricing']['blank'])) {
            					$i=0;
            					if (isset($valArray['price']['pricing']['decorative'])) {
            						$type = 'decorative';
            					} else {
            						$type = 'blank';
            					}
            					foreach ($valArray['price']['pricing'][$type] as $price) {
            						$priceData = $this->calculateProductRulePrice($productArray[$main_index], $i, $ruleMappingMaster, $discountCodes, $newColumnQtyArray, $price['rate'], $price['code']);
            	
            						if ($productArray[$main_index]['imprint_information']['imprint_method_information'][$key]['price']['pricing'][$type][$i]['rate'] != $priceData['productPrice']) {
            							$productArray[$main_index]['imprint_information']['imprint_method_information'][$key]['price']['pricing'][$type][$i]['rate_orig'] = $productArray[$main_index]['imprint_information']['imprint_method_information'][$key]['price']['pricing'][$type][$i]['rate'];
            						}
            						if (isset($priceData['productCode']) && !empty($priceData['productCode'])) {
            							$productArray[$main_index]['imprint_information']['imprint_method_information'][$key]['price']['pricing'][$type][$i]['code_orig'] = $productArray[$main_index]['imprint_information']['imprint_method_information'][$key]['price']['pricing'][$type][$i]['code'];
            						}
            	
            						$productArray[$main_index]['imprint_information']['imprint_method_information'][$key]['price']['pricing'][$type][$i]['rate'] = $priceData['productPrice'];
            						$productArray[$main_index]['imprint_information']['imprint_method_information'][$key]['price']['pricing'][$type][$i]['code'] = $priceData['productCode'];
            						$i++;
            					}
            				}
            				//$productArray[$main_index]['price']['pricing'];
            			}
            		}
            	}	
            	/* if condition coding for manual special pricing ended */
            	
            	if (isset($manualSpecialPricingOtherCountryMainArray) && is_array($manualSpecialPricingOtherCountryMainArray) && (!empty($manualSpecialPricingOtherCountryMainArray))) {
foreach($manualSpecialPricingOtherCountryMainArray as $countryCode=>$manualSpecialPricingOtherCountryArray)
{
            		$priceType = "decorative";
            		if (!isset($productDetail['pricing_for_other_country'][$countryCode][$priceType]) && isset($productDetail['pricing_for_other_country'][$countryCode]['blank']) && !empty($productDetail['pricing_for_other_country'][$countryCode]['blank'])) {
            			$priceType = "blank";
            		}
            	
            		if (isset($productDetail['pricing_for_other_country'][$countryCode][$priceType])) {
            			$index = 0;
            			$tmpServiceGroupId=$defaultGroup->getId();
            			$priority = 0;
            			if (isset($manualSpecialPricingOtherCountryArray['special'])) {
            			foreach ($manualSpecialPricingOtherCountryArray['special'] as $newColumnQty) {
            				
            				/* code commented by emp id: 5460 */
            				/*if ($tmpServiceGroupId !=  $newColumnQty->getServiceGroupId()) {
            					if ($tmpServiceGroupId > 0) {
            						$index = 0;
            					}
            					$tmpServiceGroupId = $newColumnQty->getServiceGroupId();
            				}*/
            				/* code commented by emp id: 5460 */
            	
            				if (isset($productArray[$main_index]['pricing_for_other_country'][$countryCode][$priceType][$index])) {
            					if ($isFromSolr) {
            						
            						// There is no coding for solr
            						
            					} elseif ($loggedInUserServiceGroupId && $loggedInUserServiceGroupId > 0) {
            						// if user logged in and assign group
            						
            							$productArray[$main_index]['pricing_for_other_country'][$countryCode][$priceType][$index]['rate_orig'] = $productArray[$main_index]['pricing_for_other_country'][$countryCode][$priceType][$index]['rate'];
            						
            							$productArray[$main_index]['pricing_for_other_country'][$countryCode][$priceType][$index]['code_orig'] = $productArray[$main_index]['pricing_for_other_country'][$countryCode][$priceType][$index]['code'];
            						
            	
            						$productArray[$main_index]['pricing_for_other_country'][$countryCode][$priceType][$index]['rate'] = $newColumnQty['rate'];
            						$productArray[$main_index]['pricing_for_other_country'][$countryCode][$priceType][$index]['code'] = $newColumnQty['code'];
            						$productArray[$main_index]['pricing_for_other_country'][$countryCode][$priceType][$index]['expired_at'] = $manualSpecialPricingExpiryDateObj;
            					} else {
            						//if not logged in than apply defalt group price if any
            						/* code commented by emp id: 5460 */
            						//if ($defaultGroup->getId() == $tmpServiceGroupId) {
            						/* code commented by emp id: 5460 */
            	
            								$productArray[$main_index]['pricing_for_other_country'][$countryCode][$priceType][$index]['rate_orig'] = $productArray[$main_index]['pricing_for_other_country'][$countryCode][$priceType][$index]['rate'];
            								$productArray[$main_index]['pricing_for_other_country'][$countryCode][$priceType][$index]['code_orig'] = $productArray[$main_index]['pricing_for_other_country'][$countryCode][$priceType][$index]['code'];
            	
            							$productArray[$main_index]['pricing_for_other_country'][$countryCode][$priceType][$index]['rate'] = $newColumnQty['rate'];
            							$productArray[$main_index]['pricing_for_other_country'][$countryCode][$priceType][$index]['code'] = $newColumnQty['code'];
            							$productArray[$main_index]['pricing_for_other_country'][$countryCode][$priceType][$index]['expired_at'] = $manualSpecialPricingExpiryDateObj;
            						/* code commented by emp id: 5460 */
            						//}
            						/* code commented by emp id: 5460 */
            					}
            					$isRuleApplied = true;
            				}
            				/* code commented by emp id: 5460 */
            				//$priority = $newColumnQty->getPriority();
            				/* code commented by emp id: 5460 */
            				
            				/*$tmpArray = $productArray[$main_index]['pricing_for_other_country'][$countryCode][$priceType];
            				 $tmpArray
            				$productArray[$main_index]['pricing_for_other_country'][$countryCode]['user_group_pricing'][$priceType][$newColumnQty->getServiceGroupId()] = $productArray[$main_index]['pricing_for_other_country'][$countryCode][$priceType];*/
            				$index ++;
            			}
            		}
            			/*foreach($productDetail['pricing_for_other_country'][$countryCode][$priceType] as $index => $qtyPrice){
            	
            			if(isset($serviceRulePrices[$index]) && $newColumnQty = $serviceRulePrices[$index]){
            			$productArray[$main_index]['pricing_for_other_country'][$countryCode]['user_group_price'][$priceType][$newColumnQty->getServiceGroupId()][$index]['rate'] = $newColumnQty->getPrice();
            			$productArray[$main_index]['pricing_for_other_country'][$countryCode]['user_group_price'][$priceType][$newColumnQty->getServiceGroupId()][$index]['code'] = $newColumnQty->getCode();
            			}
            	
            			}*/
            		}
            	
            		/* NOTE FOR THOSE WHO ARE USING PRODUCT API V2
            		 * If your client has demanded manual special pricing,
            		 * If you have enabled it from product,
            		 * If you have entered special pricing for any product,
            		 * CHANGE THE BELOW TWO IF CONDITION'S CODING AS PER YOUR REQUIREMENT  */
            		if ($priority > 0 && $priceType=='decorative' && isset($productDetail['pricing_for_other_country'][$countryCode]['blank'])) { 
            			$i = 0;
            			$ruleMappingMaster = $this->getServiceRuleMappingByPriority($priority, false);
            			$discountCodes = $this->getDiscountCodeArray();
            			$newColumnQtyArray = array();
            	
            			if ($columnQtyArray = $ruleMappingMaster->getServiceRuleMappingQtyId() && $ruleMappingMaster->getServiceRuleMappingQtyId()->count() > 0) {
            				if ($columnQtyArray && is_array($columnQtyArray)) {
            					foreach ($columnQtyArray as $columnQty) {
            						$newColumnQtyArray[$columnQty->getColumnNo()] = $columnQty;
            					}
            				}
            			}
            			
            			foreach ($productDetail['pricing_for_other_country'][$countryCode]['blank'] as $price) {
            				$priceData = $this->calculateProductRulePrice($productArray[$main_index], $i, $ruleMappingMaster, $discountCodes, $newColumnQtyArray, $price['rate'], $price['code']);
            	
            				if ($productDetail['pricing_for_other_country'][$countryCode]['blank'][$i]['rate'] != $priceData['productPrice']) {
            					$productArray[$main_index]['pricing_for_other_country'][$countryCode]['blank'][$i]['rate_orig'] = $productDetail['pricing_for_other_country'][$countryCode]['blank'][$i]['rate'];
            				}
            				if (isset($priceData['productCode']) && !empty($priceData['productCode'])) {
            					$productArray[$main_index]['pricing_for_other_country'][$countryCode]['blank'][$i]['code_orig'] = $productArray[$main_index]['pricing_for_other_country'][$countryCode]['blank'][$i]['code'];
            				}
            				$productArray[$main_index]['pricing_for_other_country'][$countryCode]['blank'][$i]['rate'] = $priceData['productPrice'];
            				$productArray[$main_index]['pricing_for_other_country'][$countryCode]['blank'][$i]['code'] = $priceData['productCode'];
            				$i++;
            			}
            		}
            		
            		if ($priority > 0 && isset($productArray[$main_index]['imprint_information']['imprint_method_information']) && count($productArray[$main_index]['imprint_information']['imprint_method_information']) > 0) {
            			$ruleMappingMaster = $this->getServiceRuleMappingByPriority($priority, false);
            			$discountCodes = $this->getDiscountCodeArray();
            			$newColumnQtyArray = array();
            			
            			if ($columnQtyArray = $ruleMappingMaster->getServiceRuleMappingQtyId() && $ruleMappingMaster->getServiceRuleMappingQtyId()->count() > 0) {
            				if ($columnQtyArray && is_array($columnQtyArray)) {
            					foreach ($columnQtyArray as $columnQty) {
            						$newColumnQtyArray[$columnQty->getColumnNo()] = $columnQty;
            					}
            				}
            			}
            		
            			foreach ($productArray[$main_index]['imprint_information']['imprint_method_information'] as $key=>$valArray) {
            				if (isset($valArray['price']['pricing']['decorative']) || isset($valArray['price']['pricing']['blank'])) {
            					$i=0;
            					if (isset($valArray['price']['pricing']['decorative'])) {
            						$type = 'decorative';
            					} else {
            						$type = 'blank';
            					}
            					
            					foreach ($valArray['price']['pricing'][$type] as $price) {
            						$priceData = $this->calculateProductRulePrice($productArray[$main_index], $i, $ruleMappingMaster, $discountCodes, $newColumnQtyArray, $price['rate'], $price['code']);
            	
            						if ($productArray[$main_index]['imprint_information']['imprint_method_information'][$key]['price']['pricing'][$type][$i]['rate'] != $priceData['productPrice']) {
            							$productArray[$main_index]['imprint_information']['imprint_method_information'][$key]['price']['pricing'][$type][$i]['rate_orig'] = $productArray[$main_index]['imprint_information']['imprint_method_information'][$key]['price']['pricing'][$type][$i]['rate'];
            						}
            						if (isset($priceData['productCode']) && !empty($priceData['productCode'])) {
            							$productArray[$main_index]['imprint_information']['imprint_method_information'][$key]['price']['pricing'][$type][$i]['code_orig'] = $productArray[$main_index]['imprint_information']['imprint_method_information'][$key]['price']['pricing'][$type][$i]['code'];
            						}
            	
            						$productArray[$main_index]['imprint_information']['imprint_method_information'][$key]['price']['pricing'][$type][$i]['rate'] = $priceData['productPrice'];
            						$productArray[$main_index]['imprint_information']['imprint_method_information'][$key]['price']['pricing'][$type][$i]['code'] = $priceData['productCode'];
            						$i++;
            					}
            				}
            				//$productArray[$main_index]['price']['pricing'];
            			}
            			
            			
            		}
            		
            	}	
            	}
            	
            	if(!$isFromSolr)
            	{
            		// this code should be executed only for product detail page, but must not be executed for solr, so we checked the solr condition above
            		/* variation manual special pricing started */
            		if (isset($productDetail['variation_pricing']) && is_array($productDetail['variation_pricing']) && (!empty($productDetail['variation_pricing']))) {
            			$priceType = "decorative";
            			foreach($productArray[$main_index]['variation_pricing'] as $variationId => $variationData)
            			{
            				if(isset($variationData['pricing']['special']) && is_array($variationData['pricing']['special']) && (!empty($variationData['pricing']['special'])))
            				{
            					if(isset($variationData['pricing'][$priceType]) && is_array($variationData['pricing'][$priceType]) && (!empty($variationData['pricing'][$priceType])))
            					{
            						foreach ($variationData['pricing']['special'] as $variationDataPricigIndex => $variationDataPricigData)
            						{
            							if (isset($productArray[$main_index]['variation_pricing'][$variationId]['pricing'][$priceType][$variationDataPricigIndex]))
            							{
            								$productArray[$main_index]['variation_pricing'][$variationId]['pricing'][$priceType][$variationDataPricigIndex]['rate_orig'] = $productArray[$main_index]['variation_pricing'][$variationId]['pricing'][$priceType][$variationDataPricigIndex]['rate'];
            								$productArray[$main_index]['variation_pricing'][$variationId]['pricing'][$priceType][$variationDataPricigIndex]['code_orig'] = $productArray[$main_index]['variation_pricing'][$variationId]['pricing'][$priceType][$variationDataPricigIndex]['code'];
            								
            								$productArray[$main_index]['variation_pricing'][$variationId]['pricing'][$priceType][$variationDataPricigIndex]['rate'] = $variationDataPricigData['rate'];
            								$productArray[$main_index]['variation_pricing'][$variationId]['pricing'][$priceType][$variationDataPricigIndex]['code'] = $variationDataPricigData['code'];
            								$productArray[$main_index]['variation_pricing'][$variationId]['pricing'][$priceType][$variationDataPricigIndex]['expired_at'] = $manualSpecialPricingExpiryDateObj;
            							}
            						}
            					}
            				}
            			}
            		}
            		if (isset($productDetail['variation_pricing_for_other_country']) && is_array($productDetail['variation_pricing_for_other_country']) && (!empty($productDetail['variation_pricing_for_other_country']))) {
            			$priceType = "decorative";
            			foreach($productArray[$main_index]['variation_pricing_for_other_country'] as $countryCode => $countryData)
            			{
            				foreach($countryData as $variationId => $variationData)
            				{
	            				if(isset($variationData['pricing']['special']) && is_array($variationData['pricing']['special']) && (!empty($variationData['pricing']['special'])))
	            				{
	            					if(isset($variationData['pricing'][$priceType]) && is_array($variationData['pricing'][$priceType]) && (!empty($variationData['pricing'][$priceType])))
	            					{
	            						foreach ($variationData['pricing']['special'] as $variationDataPricigIndex => $variationDataPricigData)
	            						{
	            							if (isset($productArray[$main_index]['variation_pricing_for_other_country'][$countryCode][$variationId]['pricing'][$priceType][$variationDataPricigIndex]))
	            							{
	            								$productArray[$main_index]['variation_pricing_for_other_country'][$countryCode][$variationId]['pricing'][$priceType][$variationDataPricigIndex]['rate_orig'] = $productArray[$main_index]['variation_pricing_for_other_country'][$countryCode][$variationId]['pricing'][$priceType][$variationDataPricigIndex]['rate'];
	            								$productArray[$main_index]['variation_pricing_for_other_country'][$countryCode][$variationId]['pricing'][$priceType][$variationDataPricigIndex]['code_orig'] = $productArray[$main_index]['variation_pricing_for_other_country'][$countryCode][$variationId]['pricing'][$priceType][$variationDataPricigIndex]['code'];
	            								
	            								$productArray[$main_index]['variation_pricing_for_other_country'][$countryCode][$variationId]['pricing'][$priceType][$variationDataPricigIndex]['rate'] = $variationDataPricigData['rate'];
	            								$productArray[$main_index]['variation_pricing_for_other_country'][$countryCode][$variationId]['pricing'][$priceType][$variationDataPricigIndex]['code'] = $variationDataPricigData['code'];
	            								$productArray[$main_index]['variation_pricing_for_other_country'][$countryCode][$variationId]['pricing'][$priceType][$variationDataPricigIndex]['expired_at'] = $manualSpecialPricingExpiryDateObj;
	            							}
	            						}
	            					}
	            				}
            				}
            			}
            		}
            		$productArray[$main_index] = $this->updateMinMaxParametersForVariations($productArray[$main_index]);
            		/* variation manual special pricing ended */
            	}
            }
            else
            {

            	$serviceRulePrices = $this->serviceRuleProductPriceRepository->findByProductIdAndGroupId($productDetail['product_id'], $loggedInUserServiceGroupId, $instanceId);
            	
            	$defaultGroup = $this->serviceGroupRepository->getServiceDefaultGroupData($this->countryId);
            	if (!$isFromSolr && !$serviceRulePrices && $defaultGroup) {
            	
            		//fetch price for default group if any
            		$serviceRulePrices = $this->serviceRuleProductPriceRepository->findByProductIdAndGroupId($productDetail['product_id'], $defaultGroup->getId(), $instanceId);
            		$loggedInUserServiceGroupId = $defaultGroup->getId();
            	}
            	
            	$country = $this->serviceContainer->getParameter('country');
            	$conid = explode('_', $this->projectSetting['locale_language']);
            	if (isset(array_keys($productArray[$main_index]['imprint_information']['imprint_method_information'])[0])) {
            		$imprint_id = $this->request->get('imprint_method_id');
            		$firstMethodId = array_keys($productArray[$main_index]['imprint_information']['imprint_method_information'])[0];
            		$firstMethodId = (isset($imprint_id))?$imprint_id:$firstMethodId;
            		if (isset($conid[1]) && isset($productArray[$main_index]['imprint_information']['imprint_method_information'][$firstMethodId]['pricing_for_other_country'][$conid[1]])) {
            			$productArray[$main_index]['pricing'] = $productArray[$main_index]['imprint_information']['imprint_method_information'][$firstMethodId]['pricing_for_other_country'][$conid[1]];
            			$productDetail['pricing'] = $productArray[$main_index]['pricing'];
            		}
            	}
            	/* changed by Emp id # 4835 -start*/
            	if (isset($conid[1]) && !isset($productDetail['pricing']['blank']) && isset($productDetail['blank_imprint_method_id']) && $productDetail['blank_imprint_method_id'] > 0 &&
            	isset($productArray[$main_index]['imprint_information']['imprint_method_information'][$productDetail['blank_imprint_method_id']]['price']['pricing']['blank'])) {
            		$productArray[$main_index]['pricing']['blank'] = $productArray[$main_index]['imprint_information']['imprint_method_information'][$productDetail['blank_imprint_method_id']]['pricing_for_other_country'][$conid[1]]['blank'];
            	}
            	/* changed by Emp id # 4835 -end*/
            	//  print_r( $productArray[$main_index]['pricing']); die;
            	
            	if ($serviceRulePrices) {
            		$priceType = "decorative";
            		if (!isset($productDetail['pricing'][$priceType]) && isset($productDetail['pricing']['blank']) && !empty($productDetail['pricing']['blank'])) {
            			$priceType = "blank";
            		}
            	
            		if (isset($productDetail['pricing'][$priceType])) {
            			$index = 0;
            			$tmpServiceGroupId=0;
            			$priority = 0;
            			foreach ($serviceRulePrices as $newColumnQty) {
            				if ($tmpServiceGroupId !=  $newColumnQty->getServiceGroupId()) {
            					if ($tmpServiceGroupId > 0) {
            						$index = 0;
            					}
            					$tmpServiceGroupId = $newColumnQty->getServiceGroupId();
            				}
            	
            				if (isset($productArray[$main_index]['pricing'][$priceType][$index])) {
            					if ($isFromSolr) {
            						$productArray[$main_index]['user_group_pricing'][$priceType][$tmpServiceGroupId][$index] = $productArray[$main_index]['pricing'][$priceType][$index];
            	
            						if ($newColumnQty->getPrice()!=$productArray[$main_index]['pricing'][$priceType][$index]['rate']) {
            							$productArray[$main_index]['user_group_pricing'][$priceType][$tmpServiceGroupId][$index]['rate_orig'] = $productArray[$main_index]['pricing'][$priceType][$index]['rate'];
            						}
            						if ($newColumnQty->getCode() && !empty($newColumnQty->getCode())) {
            							$productArray[$main_index]['user_group_pricing'][$priceType][$tmpServiceGroupId][$index]['code_orig'] = $productArray[$main_index]['pricing'][$priceType][$index]['code'];
            						}
            	
            						$productArray[$main_index]['user_group_pricing'][$priceType][$tmpServiceGroupId][$index]['rate'] = $newColumnQty->getPrice();
            						$productArray[$main_index]['user_group_pricing'][$priceType][$tmpServiceGroupId][$index]['code'] = $newColumnQty->getCode();
            	
            						$productArray[$main_index]['user_group_pricing'][$priceType][$tmpServiceGroupId][$index]['expired_at'] = $newColumnQty->getExpiredAt();
            	
            						$serviceGroupUpdatedArray[] = $tmpServiceGroupId;
            					} elseif ($loggedInUserServiceGroupId && $loggedInUserServiceGroupId > 0) {
            						// if user logged in and assign group
            						if ($newColumnQty->getPrice()!=$productArray[$main_index]['pricing'][$priceType][$index]['rate']) {
            							$productArray[$main_index]['pricing'][$priceType][$index]['rate_orig'] = $productArray[$main_index]['pricing'][$priceType][$index]['rate'];
            						}
            						if ($newColumnQty->getCode() && !empty($newColumnQty->getCode())) {
            							$productArray[$main_index]['pricing'][$priceType][$index]['code_orig'] = $productArray[$main_index]['pricing'][$priceType][$index]['code'];
            						}
            	
            						$productArray[$main_index]['pricing'][$priceType][$index]['rate'] = $newColumnQty->getPrice();
            						$productArray[$main_index]['pricing'][$priceType][$index]['code'] = $newColumnQty->getCode();
            						$productArray[$main_index]['pricing'][$priceType][$index]['expired_at'] = $newColumnQty->getExpiredAt();
            	
            	
            						if ($index == 0) {
            							$productArray[$main_index]['unit_price'] = $productArray[$main_index]['pricing'][$priceType][$index]['rate'];
            							$productArray[$main_index]['regular_price'] = $productArray[$main_index]['pricing'][$priceType][$index]['rate'];
            							$productArray[$main_index]['minimum_quantity'] = $productArray[$main_index]['pricing'][$priceType][$index]['from'];
            							$productArray[$main_index]['minimum_quantity_range'] = $productArray[$main_index]['pricing'][$priceType][$index]['from']. "-" . $productArray[$main_index]['pricing'][$priceType][$index]['to'];
            							$productArray[$main_index]['min_price'] = $productArray[$main_index]['pricing'][$priceType][count($productArray[$main_index]['pricing'][$priceType])-1]['rate'];
            							$productArray[$main_index]['code'] = $productArray[$main_index]['pricing'][$priceType][count($productArray[$main_index]['pricing'][$priceType])-1]['code'];
            						}
            					} else {
            	
            						//if not logged in than apply defalt group price if any
            						if ($defaultGroup->getId() == $tmpServiceGroupId) {
            							if ($newColumnQty->getPrice()!=$productArray[$main_index]['pricing'][$priceType][$index]['rate']) {
            								$productArray[$main_index]['pricing'][$priceType][$index]['rate_orig'] = $productArray[$main_index]['pricing'][$priceType][$index]['rate'];
            							}
            							if ($newColumnQty->getCode() && !empty($newColumnQty->getCode())) {
            								$productArray[$main_index]['pricing'][$priceType][$index]['code_orig'] = $productArray[$main_index]['pricing'][$priceType][$index]['code'];
            							}
            							$productArray[$main_index]['pricing'][$priceType][$index]['rate'] = $newColumnQty->getPrice();
            							$productArray[$main_index]['pricing'][$priceType][$index]['code'] = $newColumnQty->getCode();
            							$productArray[$main_index]['pricing'][$priceType][$index]['expired_at'] = $newColumnQty->getExpiredAt();
            	
            	
            							$productArray[$main_index]['unit_price'] = $productArray[$main_index]['pricing'][$priceType][$index]['rate'];
            							$productArray[$main_index]['regular_price'] = $productArray[$main_index]['pricing'][$priceType][$index]['rate'];
            							$productArray[$main_index]['minimum_quantity'] = $productArray[$main_index]['pricing'][$priceType][$index]['from'];
            							$productArray[$main_index]['minimum_quantity_range'] = $productArray[$main_index]['pricing'][$priceType][$index]['from']. "-" . $productArray[$main_index]['pricing'][$priceType][$index]['to'];
            							$productArray[$main_index]['min_price'] = $productArray[$main_index]['pricing'][$priceType][count($productArray[$main_index]['pricing'][$priceType])-1]['rate'];
            							$productArray[$main_index]['code'] = $productArray[$main_index]['pricing'][$priceType][count($productArray[$main_index]['pricing'][$priceType])-1]['code'];
            						}
            					}
            					$isRuleApplied = true;
            				}
            				$priority = $newColumnQty->getPriority();
            				/*$tmpArray = $productArray[$main_index]['pricing'][$priceType];
            				 $tmpArray
            				$productArray[$main_index]['pricing']['user_group_pricing'][$priceType][$newColumnQty->getServiceGroupId()] = $productArray[$main_index]['pricing'][$priceType];*/
            				$index ++;
            			}
            	
            			/*foreach($productDetail['pricing'][$priceType] as $index => $qtyPrice){
            	
            			if(isset($serviceRulePrices[$index]) && $newColumnQty = $serviceRulePrices[$index]){
            			$productArray[$main_index]['pricing']['user_group_price'][$priceType][$newColumnQty->getServiceGroupId()][$index]['rate'] = $newColumnQty->getPrice();
            			$productArray[$main_index]['pricing']['user_group_price'][$priceType][$newColumnQty->getServiceGroupId()][$index]['code'] = $newColumnQty->getCode();
            			}
            	
            			}*/
            		}
            	
            		if ($priority > 0 && $priceType=='decorative' && isset($productDetail['pricing']['blank'])) {
            			$i = 0;
            			$ruleMappingMaster = $this->getServiceRuleMappingByPriority($priority, false);
            			$discountCodes = $this->getDiscountCodeArray();
            			$newColumnQtyArray = array();
            	
            			if ($columnQtyArray = $ruleMappingMaster->getServiceRuleMappingQtyId() && $ruleMappingMaster->getServiceRuleMappingQtyId()->count() > 0) {
            				if ($columnQtyArray && is_array($columnQtyArray)) {
            					foreach ($columnQtyArray as $columnQty) {
            						$newColumnQtyArray[$columnQty->getColumnNo()] = $columnQty;
            					}
            				}
            			}
            			foreach ($productDetail['pricing']['blank'] as $price) {
            				$priceData = $this->calculateProductRulePrice($productArray[$main_index], $i, $ruleMappingMaster, $discountCodes, $newColumnQtyArray, $price['rate'], $price['code']);
            	
            				if ($productDetail['pricing']['blank'][$i]['rate'] != $priceData['productPrice']) {
            					$productArray[$main_index]['pricing']['blank'][$i]['rate_orig'] = $productDetail['pricing']['blank'][$i]['rate'];
            				}
            				if (isset($priceData['productCode']) && !empty($priceData['productCode'])) {
            					$productArray[$main_index]['pricing']['blank'][$i]['code_orig'] = $productArray[$main_index]['pricing']['blank'][$i]['code'];
            				}
            				$productArray[$main_index]['pricing']['blank'][$i]['rate'] = $priceData['productPrice'];
            				$productArray[$main_index]['pricing']['blank'][$i]['code'] = $priceData['productCode'];
            				$i++;
            			}
            		}
            		/* echo '<pre>'; print_r($productArray); die;*/
            		if ($priority > 0 && isset($productArray[$main_index]['imprint_information']['imprint_method_information']) && count($productArray[$main_index]['imprint_information']['imprint_method_information']) > 0) {
            			$ruleMappingMaster = $this->getServiceRuleMappingByPriority($priority, false);
            			$discountCodes = $this->getDiscountCodeArray();
            			$newColumnQtyArray = array();
            	
            			if ($columnQtyArray = $ruleMappingMaster->getServiceRuleMappingQtyId() && $ruleMappingMaster->getServiceRuleMappingQtyId()->count() > 0) {
            				if ($columnQtyArray && is_array($columnQtyArray)) {
            					foreach ($columnQtyArray as $columnQty) {
            						$newColumnQtyArray[$columnQty->getColumnNo()] = $columnQty;
            					}
            				}
            			}
            	
            			foreach ($productArray[$main_index]['imprint_information']['imprint_method_information'] as $key=>$valArray) {
            				if (isset($valArray['price']['pricing']['decorative']) || isset($valArray['price']['pricing']['blank'])) {
            					$i=0;
            					if (isset($valArray['price']['pricing']['decorative'])) {
            						$type = 'decorative';
            					} else {
            						$type = 'blank';
            					}
            					foreach ($valArray['price']['pricing'][$type] as $price) {
            						$priceData = $this->calculateProductRulePrice($productArray[$main_index], $i, $ruleMappingMaster, $discountCodes, $newColumnQtyArray, $price['rate'], $price['code']);
            	
            						if ($productArray[$main_index]['imprint_information']['imprint_method_information'][$key]['price']['pricing'][$type][$i]['rate'] != $priceData['productPrice']) {
            							$productArray[$main_index]['imprint_information']['imprint_method_information'][$key]['price']['pricing'][$type][$i]['rate_orig'] = $productArray[$main_index]['imprint_information']['imprint_method_information'][$key]['price']['pricing'][$type][$i]['rate'];
            						}
            						if (isset($priceData['productCode']) && !empty($priceData['productCode'])) {
            							$productArray[$main_index]['imprint_information']['imprint_method_information'][$key]['price']['pricing'][$type][$i]['code_orig'] = $productArray[$main_index]['imprint_information']['imprint_method_information'][$key]['price']['pricing'][$type][$i]['code'];
            						}
            	
            						$productArray[$main_index]['imprint_information']['imprint_method_information'][$key]['price']['pricing'][$type][$i]['rate'] = $priceData['productPrice'];
            						$productArray[$main_index]['imprint_information']['imprint_method_information'][$key]['price']['pricing'][$type][$i]['code'] = $priceData['productCode'];
            						$i++;
            					}
            				}
            				//$productArray[$main_index]['price']['pricing'];
            			}
            		}
            	}
            }
            
           /* //if no rule applied than default discount code applied if user logged in
            if (!$isRuleApplied && !$isFromSolr) {
                $discountCodes = null;
                if ($isDiscountCodeApply && $isLoggedIn) { //$loggedInUserServiceGroupId
                    //call discount code API
                    $discountCodes = $this->getDiscountCodeArray();
                }

                //apply discount code
                $productArray = $this->defaultDiscountCodeApply($productArray, $productArray[$main_index]['pricing'], $main_index, $isFromSolr, $discountCodes);
            } else*/
            if ($isFromSolr) {
                $discountCodes = null;

                $serviceGroups = $this->serviceGroupRepository->getAllActiveServiceGroup($this->countryId, $isFromSolr);

                foreach ($serviceGroups as $serviceGroup) {
                    $serviceGroupId = $serviceGroup->getId();

                    $isDefaultGroup = false;
                    if ($serviceGroup->getIsDefault()) {
                        $isDefaultGroup = true;
                    }

                    if (!in_array($serviceGroupId, $serviceGroupUpdatedArray)) {
                        //apply discount code & price matrix for group
                    	if ($isDiscountCodeApply && $isLoggedIn) { //$loggedInUserServiceGroupId
                    	$productArray[$main_index]= $this->applyDiscountCodeOnAllPricing($productDetail);
                    	}
                        /*$productArray = $this->defaultDiscountCodeApply($productArray, $productArray[$main_index]['pricing'], $main_index, $isFromSolr, $discountCodes, $serviceGroupId, $isDefaultGroup);
                        $productArray = $this->defaultDiscountCodeApplyForSpecialPrice($productArray, $productArray[$main_index]['pricing'], $main_index, $isFromSolr, $discountCodes, $serviceGroupId, $isDefaultGroup);
                        
                        //apply discount code to variation pricing if it exists
                        if(isset($productArray[$main_index]['price_type']) && $productArray[$main_index]['price_type'] == 'variations')
                        {
                        	$productArray = $this->defaultDiscountCodeApplyForVariation($productArray, $productArray[$main_index]['variation_pricing'], $main_index, $isFromSolr, $discountCodes, $serviceGroupId, $isDefaultGroup);
                        	$productArray = $this->defaultDiscountCodeApplyForVariationSpecialPrice($productArray, $productArray[$main_index]['variation_pricing'], $main_index, $isFromSolr, $discountCodes, $serviceGroupId, $isDefaultGroup);
                        }*/
                        $isRuleApplied = true;
                    }
                }
                if ($isDiscountCodeApply) {
                    //call discount code API
                    $discountCodes = $this->getDiscountCodeArray();
                }
            }
            
            $productTagArray= $this->serviceContainer->get("office_brain_search_manager")->getSolrProductTags($productDetail["basic_information"]["sku_number"], $productDetail["product_id"]);
            $productArray[$main_index]["custom_tag_style_ss"] = array();
            if (key_exists("custom_tag_style_ss", $productTagArray)) {
                $productArray[$main_index]["custom_tag_style_ss"] = $productTagArray["custom_tag_style_ss"];
            }
        }

        if (isset($productDetailArray['product_id'])) {
            $productDetailArray = reset($productArray);
        } elseif (isset($productDetailArray['products'])) {
            $productDetailArray['products'] = $productArray;
        } else {
            $productDetailArray = $productArray;
        }
       return $productDetailArray;
    }
    
    
    /**
     * @author Employee Id: 4589
     * Description : insert variation pricing for other country
     *
     * @param 1 : productDetailArray
     *
     * @return type : productDetailArray
     *
     * @throws Exception: Null
     */
    public function insertVariationPricingForOtherCountry($productDetailArray, $parameters)
    {
    	if (isset($productDetailArray['product_id'])) {
    		$productArray[] = $productDetailArray;
    	} elseif (isset($productDetailArray['products'])) {
    		$productArray = (array)$productDetailArray['products'];
    	} else {
    		$productArray = (array)$productDetailArray;
    	}
    	
    	foreach ($productArray as $main_index=>$productDetail) {
    		if (!isset($productDetail['product_id'])) {
    			continue;
    		}
    		
    		if (!($productDetail['price_type'] == 'variations')) {
    			continue;
    		}
    		
    		$countryPrefix = 'en_';
    		$currentCulture = $productDetail['culture'];
    		$currentCountry = str_replace($countryPrefix,"",$currentCulture);
    		
    		//reformat the variation_pricing_country_available array and specify the country code in place of index
    		//we are reformatting this array for using it into quantityWisePricePanel.html.twig
    		if(isset($productArray[$main_index]['variation_pricing_country_available']) && (!(empty($productArray[$main_index]['variation_pricing_country_available']))))
    		{
	    		foreach ($productArray[$main_index]['variation_pricing_country_available'] as $countryIndex=>$countryCode)
	    		{
	    			if($productArray[$main_index]['variation_pricing_country_available'][$countryIndex] == 1)
	    			{
	    				// Do Nothing
	    			}
	    			else
	    			{	    				
	    				unset($productArray[$main_index]['variation_pricing_country_available'][$countryIndex]);
	    				$productArray[$main_index]['variation_pricing_country_available'][$countryCode] = 1;
	    			}
	    		}
    		}
    		
    		// Now first store the variation details of current country
    		if(isset($productArray[$main_index]['variation_pricing']) && (!(empty($productArray[$main_index]['variation_pricing']))))
    		{
    			$productArray[$main_index]['variation_pricing_for_other_country'][$currentCountry] = $productArray[$main_index]['variation_pricing'];
    		}
    		if(isset($productArray[$main_index]['variation_matrix']) && (!(empty($productArray[$main_index]['variation_matrix']))))
    		{
    			$productArray[$main_index]['variation_matrix_for_other_country'][$currentCountry] = $productArray[$main_index]['variation_matrix'];
    		}
    		
    		// Now iterate through all the other countries, and store their details
    		if(isset($productArray[$main_index]['variation_pricing_country_available']) && (!empty($productArray[$main_index]['variation_pricing_country_available'])))
    		{
	    		foreach($productArray[$main_index]['variation_pricing_country_available'] as $countryCode => $countryValue)
	    		{	    			
	    			if(isset($productArray[$main_index]['variation_pricing_for_other_country'][$countryCode])
	    					&& is_array($productArray[$main_index]['variation_pricing_for_other_country'][$countryCode])
	    					&& (!(empty($productArray[$main_index]['variation_pricing_for_other_country'][$countryCode]))))
	    			{
	    				// Ignore
	    			}
	    			else
	    			{
	    				$productDetailOtherCulture = $this->productDetailManager->getProductDetailByIdDontApplyDiscount($productDetail['product_id'], $countryPrefix.$countryCode, '', true);
	    				
	    				if(isset($productDetailOtherCulture[$productDetail['product_id']]['variation_pricing']) && (!(empty($productDetailOtherCulture[$productDetail['product_id']]['variation_pricing']))))
	    				{
	    					$productArray[$main_index]['variation_pricing_for_other_country'][$countryCode] = $productDetailOtherCulture[$productDetail['product_id']]['variation_pricing'];
	    				}
	    				if(isset($productDetailOtherCulture[$productDetail['product_id']]['variation_matrix']) && (!(empty($productDetailOtherCulture[$productDetail['product_id']]['variation_matrix']))))
	    				{
	    					$productArray[$main_index]['variation_matrix_for_other_country'][$countryCode] = $productDetailOtherCulture[$productDetail['product_id']]['variation_matrix'];
	    				}
	    			}
	    		}
    		}
    	}
    	
    	if (isset($productDetailArray['product_id'])) {
    		$productDetailArray = reset($productArray);
    	} elseif (isset($productDetailArray['products'])) {
    		$productDetailArray['products'] = $productArray;
    	} else {
    		$productDetailArray = $productArray;
    	}
    	return $productDetailArray;
    }


    public function calculateProductRulePrice($product, $i, $ruleMappingMaster, $discountCodes, $newColumnQtyArray, $productPrice=0, $productCode = '', $fromQty=0)
    {
        $product_id = $product['product_id'];
        $discountedCodePrice = 0;
        //check is supplier or association
        $isDiscountCodeApply = ($this->configurationRule['option']['apply_code_on_product_detail']['status']==1) ? true : false;

        if ($isDiscountCodeApply) {
            $isMaxDiscountCodeApply = !$this->ruleMappingMaster->getIsDiscountOnCode();
        }

        //check column qty or all qty
        $oldPrice = $newRate = $productPrice; // $product ['min_qty_' . $i];
        $discountOrMarkup = $ruleMappingMaster->getRuleType();


        //check is price matrix apply
        $isPriceMatrixApply = (isset($product['matrix_details']) && isset($product['matrix_details']['price']) && count($product['matrix_details']['price']['values']) > 0 && $this->configurationRule['option']['apply_matrix']['status']==1) ? true : false;


        if ($isDiscountCodeApply && array_key_exists($productCode, $discountCodes) && $discountCodes [$productCode] > 0) {
            $discountedCodePrice = $productPrice * ($discountCodes [$productCode] / 100);
        }

            //apply price matrix
            if ($isPriceMatrixApply) {
                $priceMatrixValues = $product['matrix_details']['price']['values'];
            	foreach ($priceMatrixValues as $b){
                
                	if($fromQty >= $b['from_qty']){
                		
                		$newRate = isset($b['rate'])? $productPrice * $b['rate'] : $productPrice;
                	}
                }
                //$newRate = (isset($priceMatrixValues[$i]) && isset($priceMatrixValues[$i]['rate'])) ? $newRate * $priceMatrixValues[$i]['rate'] : $newRate;
            }

            //apply freight matrix
            /*if($isFreightMatrixApply){
             $freightMatrixValues = $product['matrix_details']['freight']['values'];
             $newRate = (isset($freightMatrixValues[$index]) && isset($freightMatrixValues[$index]['rate'])) ? $newRate * $freightMatrixValues[$index]['rate'] : $newRate;
             }*/

             if ($ruleMappingMaster->getIsColumnQty()) {
                 //column qty
                if (! isset($newColumnQtyArray [$i])) {
                    return array('productPrice' => $productPrice, 'productCode' => $productCode);
                }
                 $productPrice = $newRate;
                // check fix or percentage
                if ($ruleMappingMaster->getAmountType() == 1) {

                    // fix amount
                    if ($discountOrMarkup == 2 && $newColumnQtyArray [$i]->getColumnAmount() && $newColumnQtyArray [$i]->getColumnAmount() > 0) {
                        if (isset($discountedCodePrice)) {
                            $productPrice = $productPrice - $discountedCodePrice;
                        }
                        $productPrice = $productPrice + $newColumnQtyArray [$i]->getColumnAmount();
                    }
                } else {
                    // percentage amount
                    if ($newColumnQtyArray [$i]->getColumnAmount() && $newColumnQtyArray [$i]->getColumnAmount() > 0) {
                        $newAmount = $productPrice * ($newColumnQtyArray [$i]->getColumnAmount() / 100);

                        if (isset($discountedCodePrice) && $discountOrMarkup == 1) {
                            //check discounted code than chose max discount
                            if (isset($isMaxDiscountCodeApply) && $isMaxDiscountCodeApply) {
                                // find max discount from code and rule
                                $productPrice = $productPrice - max($discountedCodePrice, $newAmount);
                            } else {
                                // first apply code discount than apply rule discount
                                $productPrice = $productPrice - (($productPrice - $discountedCodePrice) * ($newColumnQtyArray [$i]->getColumnAmount() / 100));
                            }
                        } elseif (isset($discountedCodePrice) && $discountOrMarkup == 2) {
                            //check discounted code than apply first discount than add markup
                            $productPrice = ($productPrice - $discountedCodePrice) + $newAmount;
                        } else {
                            //check markup or discount in percentage only
                            $productPrice = ($discountOrMarkup == 1) ? $productPrice - $newAmount : $productPrice + $newAmount;
                        }
                    }
                }

                 if ($newColumnQtyArray [$i]->getColumnDiscountCode() && $newColumnQtyArray [$i]->getColumnDiscountCode() != "") {
                     $productCode = $newColumnQtyArray [$i]->getColumnDiscountCode();
                 }
             } else {
                 //all qty amount
                            if ($ruleMappingMaster->getAmountType() == 1) {
                                // fix amount
                                if ($discountOrMarkup == 2 && $ruleMappingMaster->getAmount() && $ruleMappingMaster->getAmount() > 0) {
                                    if (isset($discountedCodePrice)) {
                                        $productPrice = $productPrice - $discountedCodePrice;
                                    }

                                    $productPrice = $productPrice + $ruleMappingMaster->getAmount();
                                }
                            } else {
                                // percentage amount
                                if ($ruleMappingMaster->getAmount() && $ruleMappingMaster->getAmount() > 0) {
                                    $newAmount = $productPrice * ($ruleMappingMaster->getAmount() / 100);

                                    if (isset($discountedCodePrice) && $discountOrMarkup == 1) {
                                        //check discounted code than chose max discount
                                    if (isset($isMaxDiscountCodeApply) && $isMaxDiscountCodeApply) {
                                        // find max discount from code and rule
                                        $productPrice = $productPrice - max($discountedCodePrice, $newAmount);
                                    } else {
                                        // first apply code discount than apply rule discount

                                        $netPrice = $productPrice - $discountedCodePrice;
                                        $productPrice = $netPrice - ($netPrice * ($ruleMappingMaster->getAmount() / 100));
                                    }
                                    } elseif (isset($discountedCodePrice) && $discountOrMarkup == 2) {
                                        //check discounted code than apply first discount than add markup
                                            $netPrice = $productPrice - $discountedCodePrice;
                                        $productPrice = $netPrice + (($netPrice * $ruleMappingMaster->getAmount())/100);
                                    } else {
                                        //check markup or discount in percentage only
                                            $productPrice = ($discountOrMarkup == 1) ? $productPrice - $newAmount : $productPrice + $newAmount;
                                    }
                                }
                            }
             }
        return array('productPrice' => $productPrice, 'productCode' => $productCode);
    }
    

    protected function applyDiscountCodeOnAllPricing($productDetail)
    {
    	if($productDetail['pricing'])
    	{
    		foreach($productDetail['pricing'] as $priceType => $quantityData)
    		{
    			foreach($quantityData as $quantityIndex => $priceData)
    			{
    				$priceDataWithCodeDiscount = $this->applyDiscountCode($priceData);    				
    				$productDetail['pricing'][$priceType][$quantityIndex] = $priceDataWithCodeDiscount;
    			}
    		}
    	}
    	if($productDetail['pricing_for_other_country'])
    	{
    		foreach($productDetail['pricing_for_other_country'] as $countryCode => $countryPricing)
    		{
    			foreach($countryPricing as $priceType => $quantityData)
	    		{
	    			foreach($quantityData as $quantityIndex => $priceData)
	    			{
	    				 $priceDataWithCodeDiscount = $this->applyDiscountCode($priceData);
	    				 $productDetail['pricing_for_other_country'][$countryCode][$priceType][$quantityIndex] = $priceDataWithCodeDiscount;
	    			}
	    		}
    		}
    	}
    	if($productDetail['variation_pricing'])
    	{
    		foreach($productDetail['variation_pricing'] as $variationId => $variationData)
    		{
    			foreach($variationData['pricing'] as $priceType => $quantityData)
	    		{
	    			foreach($quantityData as $quantityIndex => $priceData)
	    			{
	    				 $priceDataWithCodeDiscount = $this->applyDiscountCode($priceData);
	    				 $productDetail['variation_pricing'][$variationId]['pricing'][$priceType][$quantityIndex] = $priceDataWithCodeDiscount;
	    			}
	    		}
    		}
    	}    	
    	//dump($productDetail['variation_pricing_for_other_country']);
    	if($productDetail['variation_pricing_for_other_country'])
    	{
    		foreach($productDetail['variation_pricing_for_other_country'] as $countryCode => $countryPricing)
    		{
    			foreach($countryPricing as $variationId => $variationData)
	    		{
	    			foreach($variationData['pricing'] as $priceType => $quantityData)
	    			{
	    				foreach($quantityData as $quantityIndex => $priceData)
	    				{
	    					 $priceDataWithCodeDiscount = $this->applyDiscountCode($priceData);
	    					 $productDetail['variation_pricing_for_other_country'][$countryCode][$variationId]['pricing'][$priceType][$quantityIndex] = $priceDataWithCodeDiscount;
	    				}
	    			}
	    		}
    		}
    	}
    	return $productDetail;
    }

    

    public function applyDiscountCode($dataArray)
    {
    	if(isset($this->discountCodes) && is_array($this->discountCodes) && (!(empty($this->discountCodes))))
    	{
    		if(isset($dataArray['net_rate']))
    		{
    			//$dataArray['rate_orig'] = $dataArray['rate'];
    			$dataArray['rate'] = $dataArray['net_rate']; 
    			$dataArray['code_orig'] = $dataArray['code'];
    			$dataArray['code'] = '';
    		}
    		else
    		{
    			$code = strtoupper($dataArray['code']);
    			if(array_key_exists($code, $this->discountCodes) && $this->discountCodes[$code] > 0)
    			{
    				//$dataArray['rate_orig'] = $dataArray['rate'];
    				$dataArray['rate'] = $dataArray['rate'] - ($dataArray['rate'] * ($this->discountCodes[$code] / 100));
    				$dataArray['code_orig'] = $dataArray['code'];
    				$dataArray['code'] = '';
    			}
    		}
    	}
    	return $dataArray;
    }

    
    public function checkRuleForCharges($serviceRuleMappingMaster, $imprintLocation, $imprintMethodLocationArray)
    {
        list($locationKey, $locationId) = explode(":", $imprintLocation);

        $imprintMethodId = $imprintMethodLocationArray['imprint_method_id'];
        $noOfSelectedColor = $imprintMethodLocationArray['no_of_color'];
        $noOfSelectedLocation = 0;
        //check if no of color set in rule
        $searchFilters = $this->applyChargesRuleMapping($serviceRuleMappingMaster->getId(), true);
        $isColorSatisfied = false;
        $isNoLocationSatisfied = false;
        $isMethodSatisfied = true;
        $isLocationSatisfied = false;

        foreach ($searchFilters as $searchFilter) {
            //imprint color
            if ((isset($searchFilter['product_search']['minNoOfSelectedColor'][0]) && $searchFilter['product_search']['minNoOfSelectedColor'][0] > 0
            )
            && (isset($searchFilter['product_search']['maxNoOfSelectedColor'][0])
                    && $searchFilter['product_search']['maxNoOfSelectedColor'][0] > 0
            )) {
                if ($noOfSelectedColor >= $searchFilter['product_search']['minNoOfSelectedColor'][0] && $noOfSelectedColor <= $searchFilter['product_search']['minNoOfSelectedColor'][0]) {
                    $isColorSatisfied = true;
                }
            } elseif (isset($searchFilter['product_search']['minNoOfSelectedColor'][0]) && $searchFilter['product_search']['minNoOfSelectedColor'][0] > 0
            && $noOfSelectedColor >= $searchFilter['product_search']['minNoOfSelectedColor'][0]) {
                $isColorSatisfied = true;
            } elseif (isset($searchFilter['product_search']['maxNoOfSelectedColor'][0]) && $searchFilter['product_search']['maxNoOfSelectedColor'][0] > 0
            && $noOfSelectedColor <= $searchFilter['product_search']['maxNoOfSelectedColor'][0]) {
                $isColorSatisfied = true;
            } elseif (empty($searchFilter['product_search']['maxNoOfSelectedColor']) && empty($searchFilter['product_search']['minNoOfSelectedColor'])) {
                //if no of color not selected in rule than allow to any number of colors selected
                $isColorSatisfied = true;
            }

            //no of locations
            if ((isset($searchFilter['product_search']['minNoOfSelectedLocation'][0]) && $searchFilter['product_search']['minNoOfSelectedLocation'][0] > 0
            )
                    && (isset($searchFilter['product_search']['maxNoOfSelectedLocation'][0])
                            && $searchFilter['product_search']['maxNoOfSelectedLocation'][0] > 0
                    )) {
                if ($noOfSelectedLocation >= $searchFilter['product_search']['minNoOfSelectedLocation'][0] && $noOfSelectedLocation <= $searchFilter['product_search']['minNoOfSelectedLocation'][0]) {
                    $isNoLocationSatisfied = true;
                }
            } elseif (isset($searchFilter['product_search']['minNoOfSelectedLocation'][0]) && $searchFilter['product_search']['minNoOfSelectedLocation'][0] > 0
                    && $noOfSelectedLocation >= $searchFilter['product_search']['minNoOfSelectedLocation'][0]) {
                $isColorSatisfied = true;
            } elseif (isset($searchFilter['product_search']['maxNoOfSelectedLocation'][0]) && $searchFilter['product_search']['maxNoOfSelectedLocation'][0] > 0
                    && $noOfSelectedLocation <= $searchFilter['product_search']['maxNoOfSelectedLocation'][0]) {
                $isNoLocationSatisfied = true;
            } elseif (empty($searchFilter['product_search']['maxNoOfSelectedLocation']) && empty($searchFilter['product_search']['minNoOfSelectedLocation'])) {
                //if no of color not selected in rule than allow to any number of colors selected
                $isNoLocationSatisfied = true;
            }


            //imprint method
            if (isset($searchFilter['product_search']['imprintMethod'][0]) && $searchFilter['product_search']['imprintMethod'][0] == $imprintMethodId) {
                $isMethodSatisfied = true;
            } elseif (isset($searchFilter['product_search']['imprintMethodNot'][0]) && $searchFilter['product_search']['imprintMethodNot'][0] != $imprintMethodId) {
                $isMethodSatisfied = true;
            } elseif (empty($searchFilter['product_search']['imprintMethod'])) {
                $isMethodSatisfied = true;
            }

            //imprint location
            if (isset($searchFilter['product_search']['imprintLocation'][0]) && $searchFilter['product_search']['imprintLocation'][0] == $locationId) {
                $isLocationSatisfied = true;
            } elseif (isset($searchFilter['product_search']['imprintLocationNot'][0]) && $searchFilter['product_search']['imprintLocationNot'][0] != $locationId) {
                $isLocationSatisfied = true;
            } elseif (empty($searchFilter['product_search']['imprintLocation'])) {
                $isLocationSatisfied = true;
            }
        }
        return ($isColorSatisfied && $isMethodSatisfied && $isLocationSatisfied);
    }


    /**
     * @author Employee Id: 4273
     * Description : Delete Rule Mapping
     *
     * @param 1 : Rule Mapping  Id
     *
     * @return type: rule mapping
     *
     * @throws Exception: Null
     * */
    public function deleteRuleMapping($id)
    {
        $ruleMapping = $this->serviceRuleMappingMasterRepository->deleteRuleMappingMaster($id);

        //remove entry if exists with same priority
        if ($ruleMapping) {
            if ($ruleMapping->getMasterRuleType()=='catalogue') {
                $productArrayForMapping = $this->serviceRuleProductPriceRepository->getAllProductsByRuleMappingPriority($ruleMapping->getPriority());
            } elseif ($ruleMapping->getMasterRuleType()=='charges') {
                $productArrayForMapping = $this->serviceRuleChargeProductPriceRepository->getAllProductsByRuleMappingPriority($ruleMapping->getPriority());
            } else {
                $productArrayForMapping = null;
            }

            if (is_array($productArrayForMapping)) {
                // update product in all solr core defined in localization_to_fetch config
                $localizationArray = $this->getLocalization();
                if ($localizationArray && !empty($localizationArray)) {
                    foreach ($localizationArray as $localization) {
                        foreach ($productArrayForMapping as $productId) {
                            exec("php ../app/console office_brain:solr:sync:product --culture=".$localization." --productId=".$productId['productId']."  --projectId=".$this->projectSetting['project_id']." --instanceId=".$this->instanceId." &");
                        }
                    }
                }
            }
            return true;
        } else {
            return false;
        }
    }

    /**
     * @author Employee Id: 4589
     * Description : Get operator sign from text
     *
     * @param 1 : String
     *
     * @return type : String
     *
     * @throws Exception: Null
     */
    protected function getConditionOperator($operatorString)
    {
        switch ($operatorString) {
            case "plus":
                return "+";
                break;
            case "minus":
                return "-";
                break;
            case "multiply":
                return "*";
                break;
            case "divide":
                return "/";
                break;
        }
    }

    /**
     * @author Employee Id: 4589
     * Description : Get discount code value from API
     *
     * @param 1 : Null
     *
     * @return type : codeArray
     *
     * @throws Exception: Null
     */
    public function getDiscountCodeArray()
    {
    	/* Redis cache processing started */
    	$locale=$this->request->getLocale();
    	$cacheSiteKey = array('discountcodeunique090520180542',$locale,$this->projectSetting['instance_id'],$this->container->getParameter('kernel.environment'));
    	//print_r( $cacheSiteKey);exit;
    	$this->moduleCachePrefix='__SiteModuleHomePage__:';
    	$this->statsh_cache_wrapper=RedisCacheService::create();
    	//dump($this->statsh_cache_wrapper);exit;
    	$cacheKey = $this->moduleCachePrefix.RedisCacheService::generateKey($this->statsh_cache_wrapper,$cacheSiteKey);
    	
    	//echo $cacheKey;exit;
    	$cacheData = RedisCacheService::getCacheData($this->statsh_cache_wrapper,$cacheKey);
    	if($cacheData){
    		return $cacheData;
    	}
    	else
    	{
    		/* API processing started */
    		//Add product API request
    		$this->serviceGroupAPiClient->init('list_product_discount_code');
    		$this->serviceGroupAPiClient->doProcess();
    		$return = array();
    		if ($this->serviceGroupAPiClient->isSuccess()) {
    			$data = $this->serviceGroupAPiClient->getResultArray();
    			if (isset($data['status']) && $data['status'] == "error") {
    			} else {
    				/* API processing ended */
    				if(!empty($cacheKey))
    				{
    					RedisCacheService::saveCacheData($this->statsh_cache_wrapper,$cacheKey,$data);
    				}
    				return $data;
    			}
    		}
    	}
    	/* Redis cache processing ended */

       

        return $return;
    }

    public function updatePriceByCountry($productDetailArray, $locale= '')
    {
    	if(empty($locale))
    	{
    		$locale = $this->request->getLocale();
    		
    		if ($this->request->get('culture') != '') {
    			$locale = $this->request->get('culture');
    		}
    	}    	

    	$country_code = explode('_', $locale);
    	$productArray = array();
    	
    	if (isset($productDetailArray['product_id'])) {
    		$productArray[] = $productDetailArray;
    	} elseif (isset($productDetailArray['products'])) {
    		$productArray = (array)$productDetailArray['products'];
    	} else {
    		$productArray = (array)$productDetailArray;
    	}
    	
    	foreach ($productArray as $main_index=>$productDetail) {
    		
    		if (isset($country_code[1]) && isset($productArray[$main_index]['variation_pricing_for_other_country'][$country_code[1]])) {
    			$productArray[$main_index]['variation_pricing'] = $productArray[$main_index]['variation_pricing_for_other_country'][$country_code[1]];
    		}
    		//echo "<pre>";print_R($productDetail);die;
    		if (isset($country_code[1]) && isset($productArray[$main_index]['pricing_for_other_country'][$country_code[1]])) {
    			$productArray[$main_index]['pricing'] = $productArray[$main_index]['pricing_for_other_country'][$country_code[1]];
    			$priceType = 'decorative';
    			$index = 0;;
    			if (isset($productArray[$main_index]['pricing'][$priceType][$index])) {
    				$productArray[$main_index]['unit_price'] = $productArray[$main_index]['pricing'][$priceType][$index]['rate'];
    				$productArray[$main_index]['regular_price'] = $productArray[$main_index]['pricing'][$priceType][$index]['rate'];
    				$productArray[$main_index]['minimum_quantity'] = $productArray[$main_index]['pricing'][$priceType][$index]['from'];
    				$productArray[$main_index]['minimum_quantity_range'] = $productArray[$main_index]['pricing'][$priceType][$index]['from']. "-" . $productArray[$main_index]['pricing'][$priceType][$index]['to'];
    				$productArray[$main_index]['min_price'] = $productArray[$main_index]['pricing'][$priceType][count($productArray[$main_index]['pricing'][$priceType])-1]['rate'];
    				$productArray[$main_index]['code'] = $productArray[$main_index]['pricing'][$priceType][count($productArray[$main_index]['pricing'][$priceType])-1]['code'];
    			}    			
    		}

    		if(isset($this->categoryCustomlabel) && !empty($this->categoryCustomlabel)){
    			foreach ($this->categoryCustomlabel as $pmsId=>$categoryLabel){
    				foreach ($productArray[$main_index]['category'] as $productPmsId=>$productCatvalue){
    					if($productPmsId == $pmsId){
    						$productArray[$main_index]['category'][$productPmsId] = $categoryLabel[$this->languageId];
    					}
    				}
    			}
    		}
    	}
    	
    	if (isset($productDetailArray['product_id'])) {
            $productDetailArray = reset($productArray);
        } elseif (isset($productDetailArray['products'])) {
            $productDetailArray['products'] = $productArray;
        } else {
            $productDetailArray = $productArray;
        }

        unset($country_code);
        unset($productArray);

		return $productDetailArray;    	
    }
    
    
    
    /**
     * @author Employee Id: 4203
     * OB eCommerce Product - Requestquote
     * To total product count added in session
     * @param NULL
     * return totalProduct
     */
    
    public function updateCountryByVariation($productDetailArray, $inputDetail = array())
    {   
		$culture = 'en_us';
    	if(empty($inputDetail))
    	{
    		$inputDetail = $this->request->request->all();
    	}
    	
    	/* For getting input data from request started */
    	$noOfSelectedLocation = 0;
    	if (isset($inputDetail['imprint']) && is_array($inputDetail['imprint'])) {
    		$noOfSelectedLocation = count($inputDetail['imprint']);
    	}
    	if (isset($inputDetail['culture'])) {
    		$culture= $inputDetail['culture'];
    	}
    	/* For getting input data from request ended */
    	
    	$country_code = explode('_', $culture);
    	$productArray = array();
    	
    	if (isset($productDetailArray['product_id'])) {
    		$productArray[] = $productDetailArray;
    	} elseif (isset($productDetailArray['products'])) {
    		$productArray = (array)$productDetailArray['products'];
    	} else {
    		$productArray = (array)$productDetailArray;
    	}
    	
    	foreach ($productArray as $main_index=>$productDetail) {
    		
    		if(isset($productDetail['price_type']) && $productDetail['price_type'] == 'variations')
    		{
    			// empty the country pricing
    			$productArray[$main_index]['pricing_for_other_country'] = array();
    			/* if culture is still null set it to product culture or usa usa */
    			if(trim($culture) == '')
    			{
    				$culture = (isset($productDetail['culture']))?$productDetail['culture']:'en_us';
    				$country_code = explode('_', $culture);
    			}
    			
    			$variationPricingString = $this->printSideAndVariation[$noOfSelectedLocation];
    			if(isset($productArray[$main_index]['variation_matrix_for_other_country'][$country_code[1]][$variationPricingString]))
    			{
    				$variationPricingId = $productArray[$main_index]['variation_matrix_for_other_country'][$country_code[1]][$variationPricingString];
    			}
    			
    			/* Now if we dont get any variation pricing id, start checking every possible price and try assigning it to this variation price id */
    			if(!($variationPricingId > 0))
    			{
    				for($i=0;$i<=10;$i++)
    				{
    					$tempVariationPricingString = $this->printSideAndVariation[$i];
    					if(isset($productArray[$main_index]['variation_matrix_for_other_country'][$country_code[1]][$tempVariationPricingString]))
    					{
    						$variationPricingId = $productArray[$main_index]['variation_matrix_for_other_country'][$country_code[1]][$tempVariationPricingString];
    						// break as soon as we get the price
    						break;
    					}
    				}    				
    			}
    			
    			if (isset($productArray[$main_index]['variation_pricing_for_other_country'][$country_code[1]][$variationPricingId]['pricing'])) {
    				
    				// So for updating the country using variation we first found the variation pricing
    				$productArray[$main_index]['pricing_for_other_country'][$country_code[1]] = $productArray[$main_index]['variation_pricing_for_other_country'][$country_code[1]][$variationPricingId]['pricing'];
    			}
    			
    			// The above code will update pricing of given country only, so we should also update the pricing of other countries as well
    			if($productArray[$main_index]['variation_pricing_country_available'])
    			{
    				// loop through each country
    				foreach($productArray[$main_index]['variation_pricing_country_available'] as $countryCode => $active)
    				{
    					// Now check if the variation country price is already there in normal country price, then dont add it
    					if(isset($productArray[$main_index]['pricing_for_other_country'][$countryCode]))
    					{
    						//echo "<br/>".$countryCode." country price already exists in pricing_for_other_country";
    					}
    					else
    					{
    						//echo "<br/>".$countryCode." country price insertion started";
    						
    						// loop through each print side, and use the very first print side pricing
    						for($i=0;$i<=10;$i++)
    						{
    							$tempVariationPricingString = $this->printSideAndVariation[$i];
    							if(isset($productArray[$main_index]['variation_matrix_for_other_country'][$countryCode][$tempVariationPricingString]))
    							{
    								$variationPricingId = $productArray[$main_index]['variation_matrix_for_other_country'][$countryCode][$tempVariationPricingString];
    								// break as soon as we get the price
    								break;
    							}
    						}
    						
    						if (isset($productArray[$main_index]['variation_pricing_for_other_country'][$countryCode][$variationPricingId]['pricing'])) {
    							
    							// So for updating the country using variation we first found the variation pricing
    							$productArray[$main_index]['pricing_for_other_country'][$countryCode] = $productArray[$main_index]['variation_pricing_for_other_country'][$countryCode][$variationPricingId]['pricing'];
    						}
    					}
    				}
    			}
    		}
    	}
    	
    	if (isset($productDetailArray['product_id'])) {
    		$productDetailArray = reset($productArray);
    	} elseif (isset($productDetailArray['products'])) {
    		$productDetailArray['products'] = $productArray;
    	} else {
    		$productDetailArray = $productArray;
    	}
    	
    	unset($country_code);
    	unset($productArray);
    	
    	return $productDetailArray;
    }
    
    static public function updateMinMaxParametersForVariations($productObject)
    {
    	if(isset($productObject['price_type']) && $productObject['price_type']=='variations')
    	{
    		$minimumPrice = 0;
    		$minimumQtyCode = '';
    		$maximumPrice = 0;
    		$maximumQtyCode = '';
    		$minimumQuantity = 0;
    		$maximumQuantity = 0;
    		$minimumPrices = array();
    		$minimumQuantities = array();
    		$maximumPrices = array();
    		$maximumQuantities = array();
    		//$priceTypes = array('decorative','blank');
    		$priceTypes = array('decorative');
    		$countryCodes = array('us');
    		$variationIndex = 0;
    		if(isset($productObject['variation_pricing_for_other_country']))
    		{
    			foreach($productObject['variation_pricing_for_other_country'] as $countryCode => $countryData)
    			{
    				if(in_array($countryCode,$countryCodes))
    				{
    					foreach($countryData as $variationId => $variationData)
    					{
    						foreach($priceTypes as $priceTypeIndex => $priceTypeName)
    						{
    							if(isset($variationData['pricing'][$priceTypeName]))
    							{
    								foreach($variationData['pricing'][$priceTypeName] as $rangeIndex => $rangeDetails)
    								{
    									if($variationIndex== 0)
    									{
    										if($rangeIndex == 0)
    										{
	    										$productObject['unit_price'] = $rangeDetails['rate'];
	    										$productObject['regular_price'] = $rangeDetails['rate'];
    										}
    									}
    									
    									// block for calculating minimum prices started
    									if(isset($minimumPrices[$priceTypeName]))
    									{
    										if($minimumPrices[$priceTypeName] < $rangeDetails['rate'])
    										{
    											$minimumPrices[$priceTypeName] = $minimumPrices[$priceTypeName];
    											$minimumQtyCode = $minimumQtyCode;
    										}
    										else
    										{
    											$minimumPrices[$priceTypeName] = $rangeDetails['rate'];
    											$minimumQtyCode = $rangeDetails['code'];
    										}
    									}
    									else
    									{
    										$minimumPrices[$priceTypeName] = $rangeDetails['rate'];
    										$minimumQtyCode = $rangeDetails['code'];
    									}
    									// block for calculating minimum prices ended
    									
    									
    									// block for calculating maximum prices started
    									if(isset($maximumPrices[$priceTypeName]))
    									{
    										if($maximumPrices[$priceTypeName] > $rangeDetails['rate'])
    										{
    											$maximumPrices[$priceTypeName] = $maximumPrices[$priceTypeName];
    											$maximumQtyCode = $maximumQtyCode;
    										}
    										else
    										{
    											$maximumPrices[$priceTypeName] = $rangeDetails['rate'];
    											$maximumQtyCode = $rangeDetails['code'];
    										}
    									}
    									else
    									{
    										$maximumPrices[$priceTypeName] = $rangeDetails['rate'];
    										$maximumQtyCode = $rangeDetails['code'];
    									}
    									// block for calculating maximum prices ended        						// block for calculating minimum quantities started
    									if(isset($minimumQuantities[$priceTypeName]))
    									{
    										if($minimumQuantities[$priceTypeName] < $rangeDetails['from_qty'])
    										{
    											$minimumQuantities[$priceTypeName] = $minimumQuantities[$priceTypeName];
    										}
    										else
    										{
    											$minimumQuantities[$priceTypeName] = $rangeDetails['from_qty'];
    										}
    									}
    									else
    									{
    										$minimumQuantities[$priceTypeName] = $rangeDetails['from_qty'];
    									}
    									// block for calculating minimum quantities ended
    									
    									
    									// block for calculating maximum quantities started
    									if(isset($maximumQuantities[$priceTypeName]))
    									{
    										if($maximumQuantities[$priceTypeName] > $rangeDetails['to_qty'])
    										{
    											$maximumQuantities[$priceTypeName] = $maximumQuantities[$priceTypeName];
    										}
    										else
    										{
    											$maximumQuantities[$priceTypeName] = $rangeDetails['to_qty'];
    										}
    									}
    									else
    									{
    										$maximumQuantities[$priceTypeName] = $rangeDetails['to_qty'];
    									}
    									// block for calculating maximum quantities ended
    									
    								}
    							}
    						}
    						$variationIndex++;
    					}
    				}
    				
    			}
    			
    			$minimumPrice = (float) min($minimumPrices);
    			$maximumPrice = (float) max($maximumPrices);
    			$minimumQuantity = (int) min($minimumQuantities);
    			$maximumQuantity = (int) max($maximumQuantities);
    		}
    		
//     		$productObject['min_qty'] = $minimumQuantity;
//     		$productObject['max_qty'] = self::MAX_QTY;
//     		$productObject['min_price'] = $minimumPrice;
//     		$productObject['min_qty_code'] = $minimumQtyCode;
//     		$productObject['max_price'] = $maximumPrice;
//     		$productObject['max_qty_code'] = $maximumQtyCode;
//     		$productObject['code'] = '';    		
    		
    		$productObject['minimum_quantity'] = $minimumQuantity;
    		$productObject['minimum_quantity_range'] = $minimumQuantity;
    		$productObject['min_price'] = $minimumPrice;
    		$productObject['code'] = $minimumQtyCode;
    	}
    	return $productObject;
    }
    
    public function updateAsLowAsPrice($productObject)
    {
    	if(isset($productObject["product_id"]))
    	{
    		$productObject= $this->updateAsLowAsPriceSingle($productObject);
    	}
    	else {
    		
    		if(isset($productObject["products"]))
    		{    			
    			foreach($productObject["products"] as $key=>$productObjectSingle)
    			{
    				if(isset($productObjectSingle["product_id"]))
    				{
    					$productObject["products"][$productObjectSingle["product_id"]]= $this->updateAsLowAsPriceSingle($productObjectSingle);
    				}
    			}
    		}
    		else {
    			foreach($productObject as $key=>$productObjectSingle)
    			{
    				if(isset($productObjectSingle["product_id"]))
    				{
    					$productObject[$productObjectSingle["product_id"]]= $this->updateAsLowAsPriceSingle($productObjectSingle);
    				}
    			}
    		}
    		
    	}    	
    	return $productObject;
    }
    
    public function samplePrice($productObject,$sampleProduct)
    {
    	if(isset($sampleProduct['price']) && $sampleProduct['max_quantity']) {
    		if(isset($productObject["product_id"]))
    		{
    			$productObject['sample_product'] = $sampleProduct;
    		}
    		else {
    			
    			if(isset($productObject["products"]))
    			{
    				foreach($productObject["products"] as $key=>$productObjectSingle)
    				{
    					if(isset($productObjectSingle["product_id"]))
    					{
    						$productObject["products"][$productObjectSingle["product_id"]]['sample_product'] = $sampleProduct;
    					}
    				}
    			}
    			else {
    				foreach($productObject as $key=>$productObjectSingle)
    				{
    					if(isset($productObjectSingle["product_id"]))
    					{
    						$productObject[$productObjectSingle["product_id"]]['sample_product'] = $sampleProduct;
    					}
    				}
    			}
    			
    		}
    	}
    	
    	return $productObject;
    }
    
    public function decideFreeShipping($productObject)
    {
    	if(isset($productObject["product_id"]))
    	{
    		$productObject= $this->decideFreeShippingSingle($productObject);
    	}
    	else {
    		
    		if(isset($productObject["products"]))
    		{
    			foreach($productObject["products"] as $key=>$productObjectSingle)
    			{
    				if(isset($productObjectSingle["product_id"]))
    				{
    					$productObject["products"][$productObjectSingle["product_id"]]= $this->decideFreeShippingSingle($productObjectSingle);
    				}
    			}
    		}
    		else {
    			foreach($productObject as $key=>$productObjectSingle)
    			{
    				if(isset($productObjectSingle["product_id"]))
    				{
    					$productObject[$productObjectSingle["product_id"]]= $this->decideFreeShippingSingle($productObjectSingle);
    				}
    			}
    		}
    		
    	}
    	return $productObject;
    }
    
    /**
     * @author Employee Id: 4505
     * OB eCommerce Product - update product data as low as for both country
     * @param NULL
     * return product array
     */
    
    public function decideFreeShippingSingle($productObject)
    {
    	// Turn off the free shipping
    	$productObject['free_shipping'] = 'off';
    	
    	$freeFreightPMSIDs = $this->serviceContainer->getParameter('free_freight_allow_category_list');
    	$freeFreightNormalIDs = array();
    	
    	// Get normal Ids for pens and pencils for finding its child
    	foreach($freeFreightPMSIDs as $index => $PMSID)
    	{    		
    		$category = $this->entityManager->getRepository('OfficeBrainCategoryBundle:CategoryMapping')->findOneByPmsId($PMSID);
    		if(isset($category) && is_object($category))
    		{
    			$freeFreightNormalIDs[] = (int)$category->getId();
    		}
    	}
    	
    	// Get child pms ids from normal id Ids
    	foreach($freeFreightNormalIDs as $index => $normalid)
    	{
    		$categories = $this->entityManager->getRepository('OfficeBrainCategoryBundle:CategoryMapping')->findByParentId($normalid);
    		foreach($categories as $category)
    		{
    			if(isset($category) && is_object($category))
    			{
    				$freeFreightPMSIDs[] = (int)$category->getPmsId();
    			}
    		}
    	}
    	
    	// Now get product category ids
    	$productCategoryIds = array();
    	if(isset($productObject['category']) && is_array($productObject['category']))
    	{
    		$productCategoryIds = array_keys($productObject['category']);
    	}
    	
    	// Now compare product categories with this normal ids and if found turn on free shipping for this product
    	foreach($productCategoryIds as $index => $productCategoryId)
    	{
    		// If this category id found in product turn on the free shipping and break
    		if(in_array($productCategoryId,$freeFreightPMSIDs))
    		{
    			$productObject['free_shipping'] = 'on';
    			//break;
    		}    		
    	}
    	return $productObject;
    }
    
    /**
     * @author Employee Id: 4505
     * OB eCommerce Product - update product data as low as for both country
     * @param NULL
     * return product array
     */
    
    public function updateAsLowAsPriceSingle($productObject)
    {
    	$countryCodes = array_keys($this->serviceContainer->getParameter("country"));
    	$priceTypes = array('decorative');
    	$newProductDetailArray = array();
    	
  
    	$minimumPrices = array();
    	$minimumQuantities = array();
    	$maximumPrices = array();
    	$maximumQuantities = array();
    	$minimumQtyCode = array();
    	
    	//$test = (array) $productObject;
    	//echo "<pre>";print_r($productObject);exit;
    	if(isset($productObject["country_available"]))
    	{
    		if(isset($productObject['pricing_for_other_country']))
    		{
	    		foreach($productObject['pricing_for_other_country'] as $countryCode => $normalData)
	    		{ 
	    			if(in_array($countryCode,$countryCodes))
	    			{ 
	    				foreach($priceTypes as $priceTypeIndex => $priceTypeName)
	    				{
	    					if(isset($normalData[$priceTypeName]))
	    					{    	
	    						foreach($normalData[$priceTypeName] as $rangeIndex => $rangeDetails)
	    						{
    								if($rangeIndex == 0)
    								{
    									$productObject[$countryCode.'_unit_price'] = $rangeDetails['rate'];
    									$productObject[$countryCode.'_regular_price'] = $rangeDetails['rate'];
    								}
	    							
	    							// block for calculating minimum prices started
	    							if(isset($minimumPrices[$countryCode][$priceTypeName]))
	    							{
	    								if($minimumPrices[$countryCode][$priceTypeName] < $rangeDetails['rate'])
	    								{
	    									$minimumPrices[$countryCode][$priceTypeName] = $minimumPrices[$countryCode][$priceTypeName];
	    									$minimumQtyCode[$countryCode]= $minimumQtyCode[$countryCode];
	    								}
	    								else
	    								{
	    									$minimumPrices[$countryCode][$priceTypeName] = $rangeDetails['rate'];
	    									$minimumQtyCode[$countryCode]= $rangeDetails['code'];
	    								}
	    							}
	    							else
	    							{
	    								$minimumPrices[$countryCode][$priceTypeName] = $rangeDetails['rate'];
	    								$minimumQtyCode[$countryCode]= $rangeDetails['code'];
	    							}
	    							// block for calculating minimum prices ended
	    							
	    							
	    							// block for calculating maximum prices started
	    							if(isset($maximumPrices[$countryCode][$priceTypeName]))
	    							{
	    								if($maximumPrices[$countryCode][$priceTypeName] > $rangeDetails['rate'])
	    								{
	    									$maximumPrices[$countryCode][$priceTypeName] = $maximumPrices[$countryCode][$priceTypeName];
	    									$maximumQtyCode[$countryCode]= $maximumQtyCode;
	    								}
	    								else
	    								{
	    									$maximumPrices[$countryCode][$priceTypeName] = $rangeDetails['rate'];
	    									$maximumQtyCode[$countryCode]= $rangeDetails['code'];
	    								}
	    							}
	    							else
	    							{
	    								$maximumPrices[$countryCode][$priceTypeName] = $rangeDetails['rate'];
	    								$maximumQtyCode[$countryCode]= $rangeDetails['code'];
	    							}
	    							
	    							// block for calculating maximum prices ended        						// block for calculating minimum quantities started
	    							if(isset($minimumQuantities[$countryCode][$priceTypeName]))
	    							{
	    								if($minimumQuantities[$countryCode][$priceTypeName] < $rangeDetails['from'])
	    								{
	    									$minimumQuantities[$countryCode][$priceTypeName] = $minimumQuantities[$countryCode][$priceTypeName];
	    								}
	    								else
	    								{
	    									$minimumQuantities[$countryCode][$priceTypeName] = $rangeDetails['from'];
	    								}
	    							}
	    							else
	    							{
	    								$minimumQuantities[$countryCode][$priceTypeName] = $rangeDetails['from'];
	    							}
	    							// block for calculating minimum quantities ended
	    							
	    							
	    							// block for calculating maximum quantities started
	    							if(isset($maximumQuantities[$countryCode][$priceTypeName]))
	    							{
	    								if($maximumQuantities[$countryCode][$priceTypeName] > $rangeDetails['to'])
	    								{
	    									$maximumQuantities[$countryCode][$priceTypeName] = $maximumQuantities[$countryCode][$priceTypeName];
	    								}
	    								else
	    								{
	    									$maximumQuantities[$countryCode][$priceTypeName] = $rangeDetails['to'];
	    								}
	    							}
	    							else
	    							{
	    								$maximumQuantities[$countryCode][$priceTypeName] = $rangeDetails['to'];
	    							}
	    							// block for calculating maximum quantities ended
	    							
	    						}
	    					}
	    				}
	    				/*********/
	    				$productObject[$countryCode.'_minimum_quantity'] = (int) min($minimumQuantities[$countryCode]);
	    				$productObject[$countryCode.'_minimum_quantity_range'] = (int) min($minimumQuantities[$countryCode]);
	    				$productObject[$countryCode.'_min_price'] = (float) min($minimumPrices[$countryCode]);
	    				$productObject[$countryCode.'_max_price'] = (float) max($minimumPrices[$countryCode]);
	    				$productObject[$countryCode.'_min_qty_code'] = (float) min($minimumQuantities[$countryCode]);
	    				$productObject[$countryCode.'_max_qty_code'] = (float) max($maximumQuantities[$countryCode]);
	    				$productObject[$countryCode.'_code'] = $minimumQtyCode[$countryCode];
	    				/********/
	    			}
	    		}
    		}
    		$newProductDetailArray = $productObject;
    	}
    	else if(isset($productObject["variation_pricing_country_available"]))
    	{
    		if(isset($productObject['pricing_for_other_country']))
    		{
    			foreach($productObject['pricing_for_other_country'] as $countryCode => $countryData)
    			{
    				foreach($priceTypes as $priceTypeIndex => $priceTypeName)
    				{
    					if(isset($countryData[$priceTypeName]))
    					{
    						foreach($countryData[$priceTypeName] as $rangeIndex => $rangeDetails)
    						{
    							if($rangeIndex == 0)
    							{
    								$productObject[$countryCode.'_unit_price'] = $rangeDetails['rate'];
    								$productObject[$countryCode.'_regular_price'] = $rangeDetails['rate'];
    							}
    						}
    					}
    				}
    			}
    		}
    									
    		if(isset($productObject['variation_pricing_for_other_country']))
    		{
	    		foreach($productObject['variation_pricing_for_other_country'] as $countryCode => $countryData)
	    		{
	    			if(in_array($countryCode,$countryCodes))
	    			{
	    				$variationIndex = 0;
	    				foreach($countryData as $variationId => $variationData)
	    				{
	    					
	    					foreach($priceTypes as $priceTypeIndex => $priceTypeName)
	    					{
	    						if(isset($variationData['pricing'][$priceTypeName]))
	    						{
	    							
	    							foreach($variationData['pricing'][$priceTypeName] as $rangeIndex => $rangeDetails)
	    							{    								
	    								if($variationIndex== 0)
	    								{
	    									if($rangeIndex == 0)
	    									{
	    										//$productObject[$countryCode.'_unit_price'] = $rangeDetails['rate'];
	    										//$productObject[$countryCode.'_regular_price'] = $rangeDetails['rate'];
	    									}
	    								}
	    								
	    								// block for calculating minimum prices started
	    								if(isset($minimumPrices[$countryCode][$priceTypeName]))
	    								{
	    									if($minimumPrices[$countryCode][$priceTypeName] < $rangeDetails['rate'])
	    									{
	    										$minimumPrices[$countryCode][$priceTypeName] = $minimumPrices[$countryCode][$priceTypeName];
	    										$minimumQtyCode[$countryCode]= $minimumQtyCode[$countryCode];
	    									}
	    									else
	    									{
	    										$minimumPrices[$countryCode][$priceTypeName] = $rangeDetails['rate'];
	    										$minimumQtyCode[$countryCode]= $rangeDetails['code'];
	    									}
	    								}
	    								else
	    								{
	    									$minimumPrices[$countryCode][$priceTypeName] = $rangeDetails['rate'];
	    									$minimumQtyCode[$countryCode]= $rangeDetails['code'];
	    								}
	    								// block for calculating minimum prices ended
	    								
	    								
	    								// block for calculating maximum prices started
	    								if(isset($maximumPrices[$countryCode][$priceTypeName]))
	    								{
	    									if($maximumPrices[$countryCode][$priceTypeName] > $rangeDetails['rate'])
	    									{
	    										$maximumPrices[$countryCode][$priceTypeName] = $maximumPrices[$countryCode][$priceTypeName];
	    										$maximumQtyCode[$countryCode]= $maximumQtyCode;
	    									}
	    									else
	    									{
	    										$maximumPrices[$countryCode][$priceTypeName] = $rangeDetails['rate'];
	    										$maximumQtyCode[$countryCode]= $rangeDetails['code'];
	    									}
	    								}
	    								else
	    								{
	    									$maximumPrices[$countryCode][$priceTypeName] = $rangeDetails['rate'];
	    									$maximumQtyCode[$countryCode]= $rangeDetails['code'];
	    								}
	    								// block for calculating maximum prices ended        						// block for calculating minimum quantities started
	    								if(isset($minimumQuantities[$countryCode][$priceTypeName]))
	    								{
	    									if($minimumQuantities[$countryCode][$priceTypeName] < $rangeDetails['from_qty'])
	    									{
	    										$minimumQuantities[$countryCode][$priceTypeName] = $minimumQuantities[$countryCode][$priceTypeName];
	    									}
	    									else
	    									{
	    										$minimumQuantities[$countryCode][$priceTypeName] = $rangeDetails['from_qty'];
	    									}
	    								}
	    								else
	    								{
	    									$minimumQuantities[$countryCode][$priceTypeName] = $rangeDetails['from_qty'];
	    								}
	    								// block for calculating minimum quantities ended
	    								
	    								
	    								// block for calculating maximum quantities started
	    								if(isset($maximumQuantities[$countryCode][$priceTypeName]))
	    								{
	    									if($maximumQuantities[$countryCode][$priceTypeName] > $rangeDetails['to_qty'])
	    									{
	    										$maximumQuantities[$countryCode][$priceTypeName] = $maximumQuantities[$countryCode][$priceTypeName];
	    									}
	    									else
	    									{
	    										$maximumQuantities[$countryCode][$priceTypeName] = $rangeDetails['to_qty'];
	    									}
	    								}
	    								else
	    								{
	    									$maximumQuantities[$countryCode][$priceTypeName] = $rangeDetails['to_qty'];
	    								}
	    								// block for calculating maximum quantities ended
	    								
	    							}
	    						}
	    						
	    					}
	    					$variationIndex++;    					
	    				}
	    				/*********/
	    				
	    				if(empty($minimumQuantities)){ $minimumQuantities[$countryCode][] = 0;}
	    				if(empty($maximumQuantities)){ $maximumQuantities[$countryCode][] = 0;}
	    				if(empty($minimumPrices)){ $minimumPrices[$countryCode][] = 0;}
	    				if(empty($minimumQtyCode)){ $minimumQtyCode[$countryCode][] = '';}
	    				
	    				$productObject[$countryCode.'_minimum_quantity'] = (int) min($minimumQuantities[$countryCode]);
	    				$productObject[$countryCode.'_minimum_quantity_range'] = (int) min($minimumQuantities[$countryCode]);
	    				$productObject[$countryCode.'_min_price'] = (float) min($minimumPrices[$countryCode]);
	    				$productObject[$countryCode.'_max_price'] = (float) max($minimumPrices[$countryCode]);
	    				$productObject[$countryCode.'_min_qty_code'] = (float) min($minimumQuantities[$countryCode]);
	    				$productObject[$countryCode.'_max_qty_code'] = (float) max($maximumQuantities[$countryCode]);
	    				$productObject[$countryCode.'_code'] = $minimumQtyCode[$countryCode];
	    				/********/
	    				
	    			}
	    			
	    		}
    		}
    		$newProductDetailArray = $productObject;
    	}
    	else
    	{
    		$newProductDetailArray = $productObject;
    	}
    //	echo "<pre>";    	print_r($productObject);exit;
    	return $newProductDetailArray;
    }
}
