function w3($args)
 {
     list($id, $name) = $args;
     $obj = ProductCategoryService::getCategory();
     $num = 0;
     foreach ($obj->layer as $key => $val) {
         //key semua ke anak2nya
         foreach ($val as $key2 => $val2) {
             foreach ($val2 as $val3) {
                 if ($id == $val3) {
                     //                            $keys[] = $val3;
                     $parents = $key;
                     $parents2 = $key2;
                 }
             }
         }
     }
     $cats = $obj;
     //create parents and children link
     //1 parents
     //no children
     $namepar = $obj->detail->{$parents};
     $name1 = "<a title='{$namepar}' href='" . _SPPATH . "pr/w1/" . $parents . "/" . urlencode($namepar) . "'>";
     $name1 .= ucwords(strtolower($obj->detail->{$parents}));
     $name1 .= "</a>";
     $namepar2 = $obj->detail->{$parents2};
     $name2 = "<a title='{$namepar2}' href='" . _SPPATH . "pr/w2/" . $parents2 . "/" . urlencode($namepar2) . "'>";
     $name2 .= ucwords(strtolower($obj->detail->{$parents2}));
     $name2 .= "</a>";
     $breadcrumbs = $name1 . " > " . $name2 . " > <span>" . ucwords(strtolower($name)) . "</span>";
     $token = IMBAuth::createOAuth();
     $url = "http://localhost:8888/tbsecom/LLProdWeb/getItemsUsing3rdTag?id=" . $id . "&token=" . $token;
     $url = "http://www.hulx.net/hulx/LLProdWeb/getItemsUsing3rdTag?id=" . $id . "&token=" . $token;
     $contents = file_get_contents($url);
     $obj = json_decode($contents);
     ProductAtCategory::printer($obj, $id, $name, $breadcrumbs, $cats, 3);
 }
    public static function printer($arr)
    {
        $pc = new \ProductAtCategory();
        //            $arr = $data->results;
        $page = 1;
        $limit = 12;
        $begin = ($page - 1) * $limit + 1;
        $end = $begin + $limit - 1;
        $total = count($arr);
        $jmlhpage = ceil($total / $limit);
        $minpage = max(1, $page - 3);
        $maxpage = min($jmlhpage, $page + 3);
        ?>

        <script>

        //untuk product management
        var catKey = [];
        var page = <?php 
        echo $page;
        ?>
;
        var limit = <?php 
        echo $limit;
        ?>
;
        var total = <?php 
        echo $total;
        ?>
;
        var jmlpage = <?php 
        echo $jmlhpage;
        ?>
;
        var homes = [];

        function preloadImg(id){
//                console.log('preload '+id);
            $('#imgloader_'+id).hide();
            $('#imgasli_'+id).show();
        }

        function removeA(arr) {
            var what, a = arguments, L = a.length, ax;
            while (L > 1 && arr.length) {
                what = a[--L];
                while ((ax= arr.indexOf(what)) !== -1) {
                    arr.splice(ax, 1);
                }
            }
            return arr;
        }

        function moveToPage(x){
            page = x;
            printProduct({});
        }

        var arahPrice = "desc";
        function sortByPrice(){
            if(arahPrice == "desc") {
                homes.sort(function (a, b) {
                    return parseFloat(a.SellingPrice) - parseFloat(b.SellingPrice);
                });
                arahPrice = "asc";
            }else{
                arahPrice = "desc";
                homes.sort(function (a, b) {
                    return parseFloat(b.SellingPrice) - parseFloat(a.SellingPrice);
                });
            }

            printProduct({});
        }
        var arahName = "desc";

        function sortByName(){
            if(arahName == "desc") {
                homes.sort(sort_by('BaseArticleNameENG', false, function(a){return a.toUpperCase()}));
                arahName = "asc";
            }else{
                arahName = "desc";
                homes.sort(sort_by('BaseArticleNameENG', true, function(a){return a.toUpperCase()}));
            }
            printProduct({});
        }

        var sort_by = function(field, reverse, primer){
            var key = function (x) {return primer ? primer(x[field]) : x[field]};

            return function (a,b) {
                var A = key(a), B = key(b);
                return ( (A < B) ? -1 : ((A > B) ? 1 : 0) ) * [-1,1][+!!reverse];
            }
        }

        function updateArrSize(){
            var arrSem = homes.slice();
            var arrFiltered = [];
            var range = {
                minprice : $( "#slider" ).slider( "values", 0 ),
                maxprice : $( "#slider" ).slider( "values", 1 )
            };
            var yangMasukRange = 0;
            for(var x=0;x<arrSem.length;x++) {
                var attr = arrSem[x];

                if (range.hasOwnProperty('minprice')) {
                    if (attr['SellingPrice'] < range.minprice)
                        continue;
                }
                if (range.hasOwnProperty('maxprice')) {
                    if (attr['SellingPrice'] > range.maxprice)
                        continue;
                }
                if(catKey.length>0){
                    var lanjut = 0;
                    var cats = attr['TaggingLevel3ID'].split(' ');
//                    console.log(cats);
                    for(var z=0;z<cats.length;z++) {
                        if (jQuery.inArray(cats[z], catKey) > -1) {
                            lanjut = 1;
//                            console.log("lanjut"+cats[z]+attr['VariantID']);
                        }
                    }
                    if(lanjut === 0)
                        continue;
                }

                //search filter
                var search = $("#searchTextVariant").val().toLowerCase();
                if(search != '') {
//                    console.log(search);
//                    console.log(attr['VariantID']+ " "+attr['VariantNameENG']);BaseArticleNameENG
                    if (attr['VariantID'].toLowerCase().indexOf(search) === -1 && attr['VariantNameENG'].toLowerCase().indexOf(search) === -1 && attr['BaseArticleNameENG'].toLowerCase().indexOf(search) === -1) {
                        continue;
                    }
                }


                arrFiltered.push(attr);
                yangMasukRange++;
            }
            total = yangMasukRange;
//            console.log("yangMasukRange "+yangMasukRange);
//            console.log(arrFiltered);
            return arrFiltered;
        }
        function printProduct(option){
            $('#loadingtop').show().fadeOut();
//                console.log(option);

            var arrSem = updateArrSize();

            var range = {
                minprice : $( "#slider" ).slider( "values", 0 ),
                maxprice : $( "#slider" ).slider( "values", 1 )
            };
            var html = '';
            var printed  = 0;

//                var arrSem = homes.slice();

            var end = Math.min(limit,arrSem.length);
//            console.log(arrSem);

            var t =$.now();

            if(page>1) {
                var anzahlremove = 0 - ((page - 1) * limit);
                arrSem.splice(anzahlremove);
            }
//                console.log("anzahlremove "+anzahlremove);
//                console.log(arrSem.length);


            html += createPagination();

//            console.log(arrSem);

            while(printed < end && arrSem.length > 0){
//                for(var x=0;x<12;x++){
                var attr = arrSem.pop();

//                console.log(attr);

                var rand = Math.floor((Math.random() * 100) + 1);
                t = t+rand;

//                if(range.hasOwnProperty('minprice')){
//                    if(attr['SellingPrice']<range.minprice)
//                        continue;
//                }
//                if(range.hasOwnProperty('maxprice')){
//                    if(attr['SellingPrice']>range.maxprice)
//                        continue;
//                }
//                if(catKey.length>0){
//                    if(jQuery.inArray( attr['TaggingLevel3ID'], catKey ) == -1){
//                        continue;
//                    }
//                }

                html += '<div class="product_list_item">';
                html += '<div class="product_list_item_dalaman">';
                html += '<div id="imgloader_'+attr['VariantID']+'_'+t+'" class="img_loader" >';
                html += '<img onload="" src="<?php 
        echo _SPPATH;
        ?>
images/tbs-hor-ajax-loader.gif">';
                html += '</div>';

                var imgurl = '<?php 
        echo $pc->imgURL;
        ?>
'+attr['BaseArticleImageFile'];
                if(attr['BaseArticleImageFile'] == ''){
                    imgurl = '<?php 
        echo $pc->noimage;
        ?>
';
                }

                html += '<div  id="imgasli_'+attr['VariantID']+'_'+t+'" class="product_list_item_img" style="display:none;">';
//                html += '<a title="'+attr['BaseArticleNameENG']+'" href="<?php 
        //=_SPPATH;
        ?>
//pr/p/'+attr['VariantID']+'/'+encodeURIComponent(attr['BaseArticleNameENG'])+'">';
                html += '<img onload="preloadImg(\''+attr['VariantID']+'_'+t+'\');"  src="'+imgurl+'" >';
//                html += '</a>';
                html += '</div>';



                html += '<div class="product_list_item_text">';

                html += '<div class="name">';

                var key = attr['VariantID'];
                var checked = '';
                if(jQuery.inArray( key, checkedVariant ) > -1) {
                    checked = "checked ='true'";
                }


                html += '<input class="variant_check" type="checkbox" id="check_'+attr['VariantID']+'" '+checked+' onchange="checkMe(this,\''+attr['VariantID']+'\');">';
                html += ' ID .'+attr['VariantID']+' <br>';
                html += attr['BaseArticleNameENG'];
                html += '</div>';
                html += '<div class="item_price">'+attr['TaggingLevel3ID']+'</div>';

                html += '<div class="item_price">IDR '+toRp(attr['SellingPrice'])+'</div>';

                html += '<div class="clearfix"></div>';
                html += '</div>';
                html += '</div>';
                html += '</div>';



                if(printed%3 == 2)html += "<div class='clearfix'></div><hr class='dotted'/>";

                printed++;
            }
            html += '<div class="clearfix"></div>';
            html += createPagination();


            $('#product_data').html(html);
//                $('#loadingtop').hide();
        }

        function createPagination(){

            var html = '';
//                $begin = (($page-1)*$limit)+1;
//                $end = $page+$limit-1;
//
//                $total = count($arr);
//                $jmlhpage = ceil($total/$limit);
//
//                $minpage = max(1,$page-3);
//                $maxpage = min($jmlhpage,$page+3);

            var begin = ((page-1)*limit)+1;
            var end = Math.min(begin+limit-1,total);

            var jmltotal = total;
            var jmlpage = Math.ceil(jmltotal/limit);

            var minpage = Math.max(1,page-3);
            var maxpage = Math.min(jmlpage,page+3);


            html += '<div class="product_pagination">';
            html += '<div class="showing">SHOWING <b>'+begin+'</b>-<b>'+end+'</b> OF <b>'+jmltotal+'</b></div>';
            html += '<div class="pages">Pages';
            if(page>1) {
                var mundur = page-1;
                html += '<span onclick="moveToPage('+mundur+');" class="page_nr">«</span>';
            }
            for(var x=minpage;x<=maxpage;x++){
                var sel = '';
                if(page == x)sel = 'page_nr_sel';
                html += '<span onclick="moveToPage('+x+');" class="page_nr '+sel+'">'+x+'</span>';
            }
            if(page<jmlpage){
                var maju = page+1;
                html += '<span onclick="moveToPage('+maju+');" class="page_nr">»</span>';
            }

            html += '&nbsp;&nbsp; &nbsp; <b>'+page+'</b> of <b>'+jmlpage+'</b> displayed </div>';
            html += '</div>';

            return html;
        }

        function toRp(angka){
            var rev     = parseInt(angka, 10).toString().split('').reverse().join('');
            var rev2    = '';
            for(var i = 0; i < rev.length; i++){
                rev2  += rev[i];
                if((i + 1) % 3 === 0 && i !== (rev.length - 1)){
                    rev2 += '.';
                }
            }
            return rev2.split('').reverse().join('');
        }
        var checkedVariant = [];

        function checkMe(obj,key){
//            console.log('checked');

            var jo = $(obj);


            if(obj.checked) {
                //Do stuff

                checkedVariant.push(key);
            }
            else{
//                console.log('in checkme');
//                console.log(checkedVariant);
                //remove element from array
                removeA(checkedVariant, key);
            }
            showHowManySelected();
//            $('#isi_span3_'+activeLokalID).val(checkedVariant.join());

//            updateHiddenCondition();
        }

        function checkedAll(){
            //pick which item is displayed
            //check_variantID
            var arrSem = updateArrSize();
            for(var x=0;x<arrSem.length;x++){
                var attr = arrSem[x];
                var key = attr['VariantID'];
                $('#check_'+attr['VariantID']).prop("checked",true);

                if(jQuery.inArray( key, checkedVariant ) == -1) {
                    checkedVariant.push(key);
                }
            }
            showHowManySelected();
        }

        function unCheckedAll(){
            $('.variant_check').prop("checked",false);
            checkedVariant = [];
            showHowManySelected();
        }
        function unCheckedFiltered(){
            //pick which item is displayed
            //check_variantID
            var arrSem = updateArrSize();
            for(var x=0;x<arrSem.length;x++){
                var attr = arrSem[x];
                var key = attr['VariantID'];
                $('#check_'+attr['VariantID']).prop("checked",false);

                removeA(checkedVariant, key);
            }
            showHowManySelected();
        }

        function showHowManySelected(){
            var len = checkedVariant.length;
            asuccess(len+' selected');
            $('#anzahlSelected').html(len+' selected');
            $('#theSelection').val(checkedVariant.join());

            if(to_update_id!='') {
                $('#' + to_update_id).val(checkedVariant.join());

                //create visual change
                var html = '';
                var ende = checkedVariant.length;
                for(var x=0;x<ende;x++){
                    var attr = checkedVariant[x];
                    var obj = homesWithKey[attr];
                    var cnt = x+1;
                    html += '<div class="condition_item">';
                    html += cnt+". ["+obj['VariantID']+'] '+obj['BaseArticleNameENG'];
                    html += '</div>';
                }
                $('#show_'+to_update_id).html(html);

                if(ende<1){
                    $('#show_'+to_update_id).hide();
                }else{
                    $('#show_'+to_update_id).show();
                }
            }
        }

        function uncheckCategories(){

            //category_check
            $('.category_check').prop("checked",false);
            catKey = [];
        }

        function unsetSearch(){
            $('#searchTextVariant').val('');
        }

        function resetSliderPos(){
            $("#slider").slider('values',0,0); // sets first handle (index 0) to 50
            $("#slider").slider('values',1,1000000); // sets second handle (index 1) to 80
        }

        var to_update_id = '';
        function isiKanValue(update_id){
            to_update_id = update_id;
            var slc = $('#'+update_id).val();
//            console.log("slc "+slc);
            if(slc!='') {

//                var sem  = slc.split(",");
//                var semarr = [];
//                for(var x=0;x<sem.length;x++){
//                    var isikan = parseInt(sem[x]);
//                    semarr.push(isikan);
//                }
//                checkedVariant = semarr;

                checkedVariant = slc.split(",");
//                console.log(checkedVariant);
                printProduct({});
            }

        }

        </script>
        <input type="hidden" id="theSelection">
        <div id="anzahlSelected" style="position: absolute; font-size: 13px; padding: 20px; z-index: 1000000; left: 0px; top: 0px; width: 200px; height: 20px;"></div>
        <div class="col-md-3 wadah_filter"  >
            <div class="filter">
                <h3>Categories</h3>

                <div class="filter_item" id="filter_subcategory" >

                    <div id="filter_subcategory_isi" >
                        <?php 
        \ProductCategoryService::printCategoryFilterAll();
        ?>
                    </div>
                </div>


            </div>
            <style>
                .filter{
                    margin-top: 40px;
                    border: 1px solid #cccccc;
                    color: #666666;
                    padding: 10px;
                }
                .filter h3{
                    padding: 0;
                    margin: 0;
                }
                .filter h5{
                    color: #333333;
                    cursor: pointer;
                }
                .filter_item{
                    border-top: 1px dashed #cccccc;
                    margin-top: 10px;
                }
                .key2{
                    font-size: 14px;
                    margin-top: 7px;
                    margin-bottom: 7px;


                }
                .key2 span{
                    cursor: pointer;
                }
                .key3{
                    font-size: 13px;
                    margin-top: 3px;
                    margin-bottom: 3px;
                }
            </style>
        </div>

        <div class="col-md-9" style="margin-top: 20px;">

        <div class="sort">

            <span style="margin-right: 10px;">SORT</span>
            <span onclick="sortByName();"  class="sort_item">NAME</span>
            <span onclick="sortByPrice();" class="sort_item">PRICE</span>
            <span class="sort_item" ><input id="searchTextVariant" onkeyup="page=1;printProduct({});" type="text" placeholder="Search"></span>
            <span class="sort_item"><button onclick="checkedAll();" class="btn btn-default">Check Filtered</button>
                <button onclick="unCheckedFiltered();" class="btn btn-default">UnCheck Filtered</button>
                <button onclick="unCheckedAll();" class="btn btn-default">UnCheck All</button> </span>
            <div style="float: right; width: 200px;">
                <div id="filter_subcategory_price">
                    <div id="slider"></div>
                    <div id="price"></div>
                    <input type="hidden" id="val_min">
                    <input type="hidden" id="val_max">
                </div>
                <script>
                    $(function() {
                        $( "#slider" ).slider({
                            range: true,
                            values: [ 0, 3000000 ],
                            step : 10000,
                            min: 0,
                            max: 1000000,
                            slide: function( event, ui ) {
                                $( "#price" ).html( "IDR " + toRp(ui.values[ 0 ]) + " - IDR " + toRp(ui.values[ 1 ]) );
//                                $('#val_min').val(ui.values[ 0 ]);
//                                $('#val_max').val(ui.values[ 1 ]);
                            },
                            stop: function( event, ui ) {
//                                homes.sort(function (a, b) {
//                                    return parseFloat(a.SellingPrice) - parseFloat(b.SellingPrice);
//                                });
//                                printProduct({
//                                    minprice : ui.values[ 0 ],
//                                    maxprice : ui.values[ 1 ]
//                                });

                                homes.sort(function (a, b) {
                                    return parseFloat(a.SellingPrice) - parseFloat(b.SellingPrice);
                                });
                                arahPrice = "asc";
                                page = 1;
                                printProduct({});
                            }
                        });

                        $( "#price" ).html( "IDR " + toRp($( "#slider" ).slider( "values", 0 )) +
                        " - IDR " + toRp($( "#slider" ).slider( "values", 1 )) );
//                        $('#val_min').val($( "#slider" ).slider( "values", 0 ));
//                        $('#val_max').val($( "#slider" ).slider( "values", 1 ));
                    });

                    function filterin(){
//                        console.log('filterin');
                        homes.sort(function (a, b) {
                            return parseFloat(a.SellingPrice) - parseFloat(b.SellingPrice);
                        });
                        printProduct({});
                    }
                </script>
            </div>

        </div>
        <style>
            .showing{
                float: left;
                width: 200px;

            }
            .pages{
                text-align: right;
            }
            .page_nr{
                cursor: pointer;
                padding-left: 5px;
                padding-right: 5px;
            }
            .page_nr:hover{
                text-decoration: underline;
            }
            .page_nr_sel{
                font-weight: bold;
                color: #7fb719;
            }
        </style>
        <div id="product_data">
            <div class="product_pagination">
                <div class="showing">SHOWING <b><?php 
        echo $begin;
        ?>
</b>-<b><?php 
        echo $end;
        ?>
</b> OF <b><?php 
        echo count($arr);
        ?>
</b></div>
                <div class="pages">Pages
                    <?php 
        if ($page > 1) {
            ?>
                        <span onclick="moveToPage(<?php 
            echo $page - 1;
            ?>
);" class="page_nr">«</span>
                    <?php 
        }
        ?>
                    <?php 
        for ($x = $minpage; $x <= $maxpage; $x++) {
            ?>
                        <span onclick="moveToPage(<?php 
            echo $x;
            ?>
);" class="page_nr <?php 
            if ($page == $x) {
                echo "page_nr_sel";
            }
            ?>
"><?php 
            echo $x;
            ?>
</span>
                    <?php 
        }
        ?>
                    <?php 
        if ($page < $jmlhpage) {
            ?>
                        <span onclick="moveToPage(<?php 
            echo $page + 1;
            ?>
);" class="page_nr">»</span>
                    <?php 
        }
        ?>
                    &nbsp;&nbsp; &nbsp; <b><?php 
        echo $page;
        ?>
</b> of <b><?php 
        echo $jmlhpage;
        ?>
</b> displayed </div>
            </div>
            <?php 
        $t = time();
        //            pr($arr);
        $num = 0;
        foreach ($arr as $key => $obj) {
            $t = $t . rand(0, 100);
            $imgurl = $pc->imgURL . $obj->BaseArticleImageFile;
            if ($obj->BaseArticleImageFile == "") {
                $imgurl = $pc->noimage;
            }
            ?>
                <div class="product_list_item">
                    <div class="product_list_item_dalaman">
                        <!--                    <div id="imgloader_--><?php 
            //=$obj->VariantID;
            ?>
<!--_--><?php 
            //=$t;
            ?>
<!--" class="img_loader" >-->
                        <!--                        <img src="--><?php 
            //=_SPPATH;
            ?>
<!--images/tbs-hor-ajax-loader.gif">-->
                        <!--                    </div>-->
                        <div id="imgasli_<?php 
            echo $obj->VariantID;
            ?>
_<?php 
            echo $t;
            ?>
" class="product_list_item_img">
<!--                            <a title="--><?php 
            //=$obj->BaseArticleNameENG;
            ?>
<!--" href="--><?php 
            //=_SPPATH;
            ?>
<!--pr/p/--><?php 
            //=$obj->VariantID;
            ?>
<!--/--><?php 
            //=urlencode($obj->BaseArticleNameENG);
            ?>
<!--">-->
                                <img  src="<?php 
            echo $imgurl;
            ?>
" >
<!--                            </a>-->
                        </div>

                        <div class="product_list_item_text">
                            <div class="name">
                                <input class="variant_check" type="checkbox" id="check_<?php 
            echo $obj->VariantID;
            ?>
" onchange="checkMe(this,'<?php 
            echo $obj->VariantID;
            ?>
');">
                                ID . <?php 
            echo $obj->VariantID;
            ?>
 <br>
                                <?php 
            echo $obj->BaseArticleNameENG;
            ?>

                            </div>
                            <div class="item_price"><?php 
            echo $obj->TaggingLevel3ID;
            ?>
</div>
                            <div class="item_price">IDR <?php 
            echo idr($obj->SellingPrice);
            ?>
</div>

                        </div>
                    </div>
                </div>
                <?php 
            //                echo $key;
            if ($num % 3 == 2) {
                echo "<div class='clearfix'></div><hr class='dotted'/>";
            }
            if ($num > 10) {
                break;
            }
            $num++;
        }
        ?>
            <div class="clearfix"></div>
            <div class="product_pagination">
                <div class="showing">SHOWING <b><?php 
        echo $begin;
        ?>
</b>-<b><?php 
        echo $end;
        ?>
</b> OF <b><?php 
        echo count($arr);
        ?>
</b></div>
                <div class="pages">Pages
                    <?php 
        if ($page > 1) {
            ?>
                        <span onclick="moveToPage(<?php 
            echo $page - 1;
            ?>
);" class="page_nr">«</span>
                    <?php 
        }
        ?>
                    <?php 
        for ($x = $minpage; $x <= $maxpage; $x++) {
            ?>
                        <span onclick="moveToPage(<?php 
            echo $x;
            ?>
);" class="page_nr <?php 
            if ($page == $x) {
                echo "page_nr_sel";
            }
            ?>
"><?php 
            echo $x;
            ?>
</span>
                    <?php 
        }
        ?>
                    <?php 
        if ($page < $jmlhpage) {
            ?>
                        <span onclick="moveToPage(<?php 
            echo $page + 1;
            ?>
);" class="page_nr">»</span>
                    <?php 
        }
        ?>
                    &nbsp;&nbsp; &nbsp; <b><?php 
        echo $page;
        ?>
</b> of <b><?php 
        echo $jmlhpage;
        ?>
</b> displayed </div>
            </div>
        </div>
        <div class="clearfix"></div>


        <script>



            $(document).ready(function(){
                $( "#product_data img" )
                    .error(function() {
                        $( this ).attr( "src", "<?php 
        echo $pc->noimage;
        ?>
" );
                    });
                homes.reverse();

                printProduct({});
            });

            var homesWithKey = {};
            var homes_attr;

            <?php 
        //create javascript objects
        foreach ($arr as $key => $obj) {
            //                unset($obj->VariantNameINA);
            //                unset($obj->VariantNameENG);
            //                unset($obj->VariantINACode);
            unset($obj->HowToUseINA);
            unset($obj->HowToUseENG);
            unset($obj->ArticleInfoINA);
            unset($obj->ProductTipsINA);
            unset($obj->ProductTipsENG);
            unset($obj->ArticleInfoENG);
            unset($obj->IngredientINA);
            unset($obj->IngredientENG);
            //                unset($obj->VariantEAN);
            unset($obj->WhatInsideINA);
            unset($obj->WhatInsideENG);
            ?>
            var el = jQuery.parseJSON('<?php 
            echo addslashes(json_encode($obj));
            ?>
');
            homes.push(el);

            homes_attr = el['VariantID'];
            homesWithKey[homes_attr] = el;
            <?php 
        }
        ?>

        </script><?php 
        ?>
        <style>
            .sort{
                border: 1px solid #cccccc;
                padding: 10px;

                font-size: 12px;
                font-weight: bold;
            }
            .product_pagination{
                padding: 10px;
                margin-bottom: 30px;
                color: #666666;
            }
            .sort_item{
                cursor: pointer;
                padding-left: 10px;
                padding-right: 10px;
                border-left: 1px dashed #cccccc;
                font-weight: normal;
            }
            .product_list_item{
                float: left;
                width: 33%;
                height: 300px;
                border-right: 1px dashed #cccccc;
            }
            .product_list_item_dalaman{
                padding: 10px;
            }
            .product_list_item_img,.img_loader{
                width: 180px;
                height: 180px;
                overflow: hidden;
                margin: auto;
                text-align: center;
            }
            .product_list_item_img img,.img_loader img{
                max-width:100%;
                max-height:100%;
            }
            .img_loader{
                line-height: 180px;
            }

            .product_list_item_text .name{
                font-weight: bold;
                color: #777777;
                height: 40px;
                text-overflow: ellipsis;
                margin-top: 20px;
                overflow:hidden;
                /*white-space:nowrap;*/
                display: -webkit-box;
                -webkit-line-clamp: 2;
                -webkit-box-orient: vertical;

            }
            .product_list_item_text .name a{
                color:#666666;
            }
            .product_list_item_text .name a:hover{
                color: #7fb719;
            }

            /*
            use text ellipsis always with overflow:hidden; and white-space:nowrap;

            for multiple line ..line clamps use
            display: -webkit-box;
                -webkit-line-clamp: 2;
                -webkit-box-orient: vertical;
                and overflow:hidden;
            */
            .rating{
                font-size: 20px;
                margin-top: 10px;
                color: #999999;
            }
            .rating > span:hover:before {
                content: "\2605";
                position: absolute;
            }
            .item_price{
                color: #888888;

            }
            .buy{
                padding: 5px;
                border: 1px solid #cccccc;
                margin-top: 10px;
                height: 40px;

            }
            a.more{
                font-size: 11px;
                text-decoration: underline;
                color: #444444;
                height: 30px;
                line-height: 30px;
            }
            a.add{
                background-color: #e2007a;
                color: white;
                padding: 5px;
                height: 30px;
                line-height: 30px;
            }
            hr.dotted{
                border-top: 1px dashed #cccccc;
                margin-top: 10px;
                margin-bottom: 10px;
                margin-left: 10px;
                margin-right: 10px;
            }

            .breadcrumbs span{
                font-weight: bold;
            }
            .breadcrumbs a{
                color: #666666;
                font-style: italic;
            }

        </style>
        </div>
        <div class="clearfix"></div>
<?php 
        //        pr($data);
    }
    public static function printer($data, $id, $name, $breadcrumbs, $cats, $tipe)
    {
        $pc = new ProductAtCategory();
        $rules = MCPRule::getRules();
        $rule2varians = MCPRule::getRules2Variant();
        //        pr($rules);
        //        pr($rule2varians);
        ?>
<!--        <div class="monly" style="margin-top: 80px;"></div>-->
        <div onclick="$('#kotakfilter').toggle();" class="monly" style="padding:10px;z-index: 1000; border-radius:5px;background-color: #cccccc; color: white; padding-right: 15px; position: absolute; right: -5px; top: 70px;">
            <i class="glyphicon glyphicon-filter"></i>
        </div>
        <div id="kotakfilter" class="col-md-3 wadah_filter donly">
            <div class="filter">
                <h3>Filter By</h3>

                <div class="filter_item" id="filter_subcategory" <?php 
        if ($tipe == 3) {
            ?>
style="display: none;"<?php 
        }
        ?>
 >
                    <h5 onclick="$('#filter_subcategory_isi').toggle();">Sub Category</h5>

                    <div id="filter_subcategory_isi">
                        <?php 
        ProductCategoryService::printCategoryFilter($id, $cats, $tipe);
        ?>
                    </div>
                </div>
                <div class="filter_item" id="filter_price">
                    <h5 onclick="$('#filter_subcategory_price').toggle();">Price</h5>

                    <div id="filter_subcategory_price" style="padding: 10px;">
                        <div id="slider"></div>
                        <div id="price"></div>
                        <input type="hidden" id="val_min">
                        <input type="hidden" id="val_max">
                    </div>
                    <!--                    <button class="btn btn-default" onclick="filterin();">filter</button>-->
                </div>
                <script>
                    $(function () {
                        $("#slider").slider({
                            range: true,
                            values: [0, 3000000],
                            step: 10000,
                            min: 0,
                            max: 1000000,
                            slide: function (event, ui) {
                                $("#price").html("IDR " + toRp(ui.values[0]) + " - IDR " + toRp(ui.values[1]));
//                                $('#val_min').val(ui.values[ 0 ]);
//                                $('#val_max').val(ui.values[ 1 ]);
                            },
                            stop: function (event, ui) {
//                                homes.sort(function (a, b) {
//                                    return parseFloat(a.SellingPrice) - parseFloat(b.SellingPrice);
//                                });
//                                printProduct({
//                                    minprice : ui.values[ 0 ],
//                                    maxprice : ui.values[ 1 ]
//                                });

                                homes.sort(function (a, b) {
                                    return parseFloat(a.SellingPrice) - parseFloat(b.SellingPrice);
                                });
                                arahPrice = "asc";
                                page = 1;
                                printProduct({});
                            }
                        });

                        $("#price").html("IDR " + toRp($("#slider").slider("values", 0)) +
                            " - IDR " + toRp($("#slider").slider("values", 1)));
//                        $('#val_min').val($( "#slider" ).slider( "values", 0 ));
//                        $('#val_max').val($( "#slider" ).slider( "values", 1 ));
                    });

                    function filterin() {
//                        console.log('filterin');
                        homes.sort(function (a, b) {
                            return parseFloat(a.SellingPrice) - parseFloat(b.SellingPrice);
                        });
                        printProduct({});
                    }
                </script>
            </div>
            <style>
                .filter {
                    margin-top: 40px;
                    border: 1px solid #cccccc;
                    color: #666666;
                    padding: 10px;
                }

                .filter h3 {
                    padding: 0;
                    margin: 0;
                }

                .filter h5 {
                    color: #333333;
                    cursor: pointer;
                }

                .filter_item {
                    border-top: 1px dashed #cccccc;
                    margin-top: 10px;
                }

                .key2 {
                    font-size: 14px;
                    margin-top: 7px;
                    margin-bottom: 7px;

                }

                .key2 span {
                    cursor: pointer;
                }

                .key3 {
                    font-size: 13px;
                    margin-top: 3px;
                    margin-bottom: 3px;
                }
            </style>
        </div>
        <div class="col-md-9" style="margin-top: 40px;">

            <div class="breadcrumbs"><?php 
        echo $breadcrumbs;
        ?>
</div>

            <h1 style="color: #333333;"><?php 
        echo urldecode($name);
        ?>
</h1>

            <p style="margin-top: 20px; margin-bottom: 30px; color: #888888;">
                PREP YOUR BODY TO PERFECTION WITH THESE BATHROOM ESSENTIALS. FIND BATH & BODYCARE BRUSHES FOR
                EXFOLIATION AND SUPER-SMOOTH SKIN, FILES FOR HANDS AND FEET, EXFOLIATING MITTS TO LEAVE YOU WITH GLOWING
                SOFT SKIN EVERY DAY. THESE ESSENTIAL BODY ACCESSORIES WILL PAMPER FROM HEAD TO TOE.
            </p>

            <?php 
        if ($data->status_code == "0") {
            ?>
                No products found
                <?php 
        } else {
            $arr = $data->results;
            //durchlaufen the data to get if any diskon, special categorization take effect
            $sudah = array();
            foreach ($arr as $ss) {
                if (!in_array($ss->VariantID, $sudah)) {
                    $sudah[] = $ss->VariantID;
                    //durchlaufen disini ..thd rule
                    if (count($rule2varians[$ss->VariantID]) > 0) {
                        $uu = $rule2varians[$ss->VariantID];
                        //set icon
                        $ss->rule_icon = _SPPATH . _PHOTOURL . $rules[$uu[0]]->rule_icon;
                        //                            pr($uu);
                        //diskon
                        $diskon = 0;
                        foreach ($uu as $ruleygkena) {
                            $r = $rules[$ruleygkena];
                            $diskon = max($r->rule_discount, $diskon);
                        }
                        $ss->rule_discount = $diskon;
                    } else {
                        $ss->rule_icon = "";
                        //default rule icon
                        $ss->rule_discount = 0;
                    }
                    $ss->final_price = (100 - $ss->rule_discount) / 100 * $ss->SellingPrice;
                    //masukan ke sem
                    $sem[$ss->VariantID] = $ss;
                } else {
                    $sem[$ss->VariantID]->TaggingLevel3ID .= " " . $ss->TaggingLevel3ID;
                }
            }
            $arr = $sem;
            $page = 1;
            $limit = 12;
            $total = count($arr);
            $begin = ($page - 1) * $limit + 1;
            $end = $begin + $limit - 1;
            if ($end > $total) {
                $end = $total;
            }
            $jmlhpage = ceil($total / $limit);
            $minpage = max(1, $page - 3);
            $maxpage = min($jmlhpage, $page + 3);
            ?>
                <div class="sort">
                    <span style="margin-right: 20px;">SORT BY</span> <span onclick="sortByName();" class="sort_item">NAME</span>
                    <span onclick="sortByPrice();" class="sort_item">PRICE</span>
                    <hr class="dotted monly">
                    <span class="sort_item" ><input id="searchTextVariant" onkeyup="page=1;printProduct({});" type="text" placeholder="Search"></span>
                </div>
                <style>
                    .showing {
                        float: left;
                        width: 200px;

                    }

                    .pages {
                        text-align: right;
                    }

                    .page_nr {
                        cursor: pointer;
                        padding-left: 5px;
                        padding-right: 5px;
                    }

                    .page_nr:hover {
                        text-decoration: underline;
                    }

                    .page_nr_sel {
                        font-weight: bold;
                        color: #7fb719;
                    }
                </style>
                <div id="product_data">
                    <div class="product_pagination">
                        <div class="showing">SHOWING <b><?php 
            echo $begin;
            ?>
</b>-<b><?php 
            echo $end;
            ?>
</b> OF
                            <b><?php 
            echo $total;
            ?>
</b></div>
                        <div class="clearfix monly"></div>
                        <hr class="dotted monly">
                        <div class="pages">Pages
                            <?php 
            if ($page > 1) {
                ?>
                                <span onclick="moveToPage(<?php 
                echo $page - 1;
                ?>
);" class="page_nr">«</span>
                                <?php 
            }
            ?>
                            <?php 
            for ($x = $minpage; $x <= $maxpage; $x++) {
                ?>
                                <span onclick="moveToPage(<?php 
                echo $x;
                ?>
);"
                                      class="page_nr <?php 
                if ($page == $x) {
                    echo "page_nr_sel";
                }
                ?>
"><?php 
                echo $x;
                ?>
</span>
                                <?php 
            }
            ?>
                            <?php 
            if ($page < $jmlhpage) {
                ?>
                                <span onclick="moveToPage(<?php 
                echo $page + 1;
                ?>
);" class="page_nr">»</span>
                            <?php 
            }
            ?>
                            &nbsp;&nbsp; &nbsp; <b><?php 
            echo $page;
            ?>
</b> of <b><?php 
            echo $jmlhpage;
            ?>
</b> displayed
                        </div>
                    </div>
                    <?php 
            $t = time();
            $num = 0;
            foreach ($arr as $key => $obj) {
                $t = $t . rand(0, 100);
                $imgurl = $pc->imgURL . $obj->BaseArticleImageFile;
                if ($obj->BaseArticleImageFile == "") {
                    $imgurl = $pc->noimage;
                }
                ?>
                        <div class="product_list_item col-md-4 col-sm-6 col-xs-6">
                            <div class="product_list_item_dalaman">
                                <!--                    <div id="imgloader_--><?php 
                //=$obj->VariantID;
                ?>
<!--_--><?php 
                //=$t;
                ?>
<!--" class="img_loader" >-->
                                <!--                        <img src="--><?php 
                //=_SPPATH;
                ?>
<!--images/tbs-hor-ajax-loader.gif">-->
                                <!--                    </div>-->
                                <div id="imgasli_<?php 
                echo $obj->VariantID;
                ?>
_<?php 
                echo $t;
                ?>
" class="product_list_item_img">
                                    <?php 
                if ($obj->rule_icon != "") {
                    ?>
                                        <div class="imgstamp">
                                            <img src="<?php 
                    echo $obj->rule_icon;
                    ?>
">
                                        </div>
                                        <?php 
                }
                ?>
                                    <a title="<?php 
                echo $obj->BaseArticleNameENG;
                ?>
"
                                       href="<?php 
                echo _SPPATH;
                ?>
pr/p/<?php 
                echo $obj->VariantID;
                ?>
/<?php 
                echo self::bersihkanNama($obj->BaseArticleNameENG);
                ?>
">
                                        <img id="imgTarget_<?php 
                echo $obj->VariantID;
                ?>
" src="<?php 
                echo $imgurl;
                ?>
">
                                    </a>
                                </div>

                                <div class="product_list_item_text">
                                    <div class="name">
                                        <a title="<?php 
                echo $obj->BaseArticleNameENG;
                ?>
"
                                           href="<?php 
                echo _SPPATH;
                ?>
pr/p/<?php 
                echo $obj->VariantID;
                ?>
/<?php 
                echo self::bersihkanNama($obj->BaseArticleNameENG);
                ?>
">
                                            <?php 
                echo $obj->BaseArticleNameENG;
                ?>
                                        </a>
                                    </div>
                                    <div class="rating">
                                        <div class="rating">
                                            <span>☆</span><span>☆</span><span>☆</span><span>☆</span><span>☆</span>
                                        </div>

                                    </div>
                                    <?php 
                //pr($obj);
                if ($obj->rule_discount > 0) {
                    ?>
                                            <div class="item_price item_price_small" >IDR <?php 
                    echo idr($obj->SellingPrice);
                    ?>
</div>
                                            <div class="item_price">IDR <?php 
                    echo idr($obj->final_price);
                    ?>
</div>
                                            <?php 
                } else {
                    ?>
                                            <div class="item_price item_price_small" ></div>
                                            <div class="item_price">IDR <?php 
                    echo idr($obj->final_price);
                    ?>
</div>
                                            <?php 
                }
                ?>
                                    <div  class="monly" style="background-color: #e2007a; padding: 5px; text-align: center;">
                                        <div class="add" st data-toggle="modal" data-variant="<?php 
                echo $obj->VariantID;
                ?>
"
                                             data-url="<?php 
                echo _SPPATH;
                ?>
pr/p/<?php 
                echo $obj->VariantID;
                ?>
/<?php 
                echo self::bersihkanNama($obj->BaseArticleNameENG);
                ?>
"
                                             data-imgUrl="<?php 
                echo $imgurl;
                ?>
"
                                             data-articlename="<?php 
                echo $obj->BaseArticleNameENG;
                ?>
"
                                             data-target="#myModal" style="color: white; font-weight: bold;">ADD TO BAG</div>
                                    </div>
                                    <div class="buy donly">
                                        <div style="float: right;" class="donly">
                                            <a class="add" data-toggle="modal" data-variant="<?php 
                echo $obj->VariantID;
                ?>
"
                                               data-url="<?php 
                echo _SPPATH;
                ?>
pr/p/<?php 
                echo $obj->VariantID;
                ?>
/<?php 
                echo self::bersihkanNama($obj->BaseArticleNameENG);
                ?>
"
                                               data-imgUrl="<?php 
                echo $imgurl;
                ?>
"
                                               data-articlename="<?php 
                echo $obj->BaseArticleNameENG;
                ?>
"
                                               data-target="#myModal" style="cursor: pointer">ADD TO BAG</a>
                                        </div>



                                        <a class="more donly" title="<?php 
                echo $obj->BaseArticleNameENG;
                ?>
"
                                           href="<?php 
                echo _SPPATH;
                ?>
pr/p/<?php 
                echo $obj->VariantID;
                ?>
/<?php 
                echo self::bersihkanNama($obj->BaseArticleNameENG);
                ?>
">
                                            more details</a>

                                        <div class="clearfix"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <?php 
                if ($num % 3 == 2) {
                    echo "<div class='clearfix donly'></div><hr class='dotted donly'/>";
                }
                if ($num > 10) {
                    break;
                }
                $num++;
            }
            ?>
                    <div class="clearfix"></div>
                    <div class="product_pagination">
                        <div class="showing">SHOWING <b><?php 
            echo $begin;
            ?>
</b>-<b><?php 
            echo $end;
            ?>
</b> OF
                            <b><?php 
            echo count($arr);
            ?>
</b></div>
                        <div class="clearfix monly"></div>
                        <hr class="dotted monly">
                        <div class="pages">Pages
                            <?php 
            if ($page > 1) {
                ?>
                                <span onclick="moveToPage(<?php 
                echo $page - 1;
                ?>
);" class="page_nr">«</span>
                                <?php 
            }
            ?>
                            <?php 
            for ($x = $minpage; $x <= $maxpage; $x++) {
                ?>
                                <span onclick="moveToPage(<?php 
                echo $x;
                ?>
);"
                                      class="page_nr <?php 
                if ($page == $x) {
                    echo "page_nr_sel";
                }
                ?>
"><?php 
                echo $x;
                ?>
</span>
                                <?php 
            }
            ?>
                            <?php 
            if ($page < $jmlhpage) {
                ?>
                                <span onclick="moveToPage(<?php 
                echo $page + 1;
                ?>
);" class="page_nr">»</span>
                            <?php 
            }
            ?>
                            &nbsp;&nbsp; &nbsp; <b><?php 
            echo $page;
            ?>
</b> of <b><?php 
            echo $jmlhpage;
            ?>
</b> displayed
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
                <script>

                    var catKey = [];


                    var page = <?php 
            echo $page;
            ?>
;
                    var limit = <?php 
            echo $limit;
            ?>
;
                    var total = <?php 
            echo $total;
            ?>
;
                    var jmlpage = <?php 
            echo $jmlhpage;
            ?>
;

                    function preloadImg(id) {
//                console.log('preload '+id);
                        $('#imgloader_' + id).hide();
                        $('#imgasli_' + id).show();
                    }

                    function removeA(arr) {
                        var what, a = arguments, L = a.length, ax;
                        while (L > 1 && arr.length) {
                            what = a[--L];
                            while ((ax = arr.indexOf(what)) !== -1) {
                                arr.splice(ax, 1);
                            }
                        }
                        return arr;
                    }

                    function moveToPage(x) {
                        page = x;
                        printProduct({});
                    }

                    $(document).ready(function () {
                        $("#product_data img")
                            .error(function () {
                                $(this).attr("src", "<?php 
            echo $pc->noimage;
            ?>
");
                            });
                        homes.reverse();
                    });

                    var homes = [];
                    <?php 
            //create javascript objects
            foreach ($arr as $key => $obj) {
                //                        unset($obj->VariantNameINA);
                //                        unset($obj->VariantNameENG);
                unset($obj->VariantINACode);
                unset($obj->HowToUseINA);
                unset($obj->HowToUseENG);
                unset($obj->ArticleInfoINA);
                unset($obj->ProductTipsINA);
                unset($obj->ProductTipsENG);
                unset($obj->ArticleInfoENG);
                unset($obj->IngredientINA);
                unset($obj->IngredientENG);
                unset($obj->VariantEAN);
                unset($obj->WhatInsideINA);
                unset($obj->WhatInsideENG);
                ?>
                    var el = jQuery.parseJSON('<?php 
                echo addslashes(json_encode($obj));
                ?>
');
                    homes.push(el);
                    <?php 
            }
            ?>
                    var arahPrice = "desc";
                    function sortByPrice() {
                        if (arahPrice == "desc") {
                            homes.sort(function (a, b) {
                                return parseFloat(a.final_price) - parseFloat(b.final_price);
                            });
                            arahPrice = "asc";
                        } else {
                            arahPrice = "desc";
                            homes.sort(function (a, b) {
                                return parseFloat(b.final_price) - parseFloat(a.final_price);
                            });
                        }

                        printProduct({});
                    }
                    var arahName = "desc";

                    function sortByName() {
                        if (arahName == "desc") {
                            homes.sort(sort_by('BaseArticleNameENG', false, function (a) {
                                return a.toUpperCase()
                            }));
                            arahName = "asc";
                        } else {
                            arahName = "desc";
                            homes.sort(sort_by('BaseArticleNameENG', true, function (a) {
                                return a.toUpperCase()
                            }));
                        }
                        printProduct({});
                    }

                    var sort_by = function (field, reverse, primer) {
                        var key = function (x) {
                            return primer ? primer(x[field]) : x[field]
                        };

                        return function (a, b) {
                            var A = key(a), B = key(b);
                            return ( (A < B) ? -1 : ((A > B) ? 1 : 0) ) * [-1, 1][+!!reverse];
                        }
                    }

                    function updateArrSize() {
                        var arrSem = homes.slice();
                        var arrFiltered = [];
                        var range = {
                            minprice: $("#slider").slider("values", 0),
                            maxprice: $("#slider").slider("values", 1)
                        };
                        var yangMasukRange = 0;
                        for (var x = 0; x < arrSem.length; x++) {
                            var attr = arrSem[x];

                            if (range.hasOwnProperty('minprice')) {
                                if (attr['final_price'] < range.minprice)
                                    continue;
                            }
                            if (range.hasOwnProperty('maxprice')) {
                                if (attr['final_price'] > range.maxprice)
                                    continue;
                            }
//                            if (catKey.length > 0) {
//                                if (jQuery.inArray(attr['TaggingLevel3ID'], catKey) == -1) {
//                                    continue;
//                                }
//                            }
                            if(catKey.length>0){
                                var lanjut = 0;
                                var cats = attr['TaggingLevel3ID'].split(' ');
//                    console.log(cats);
                                for(var z=0;z<cats.length;z++) {
                                    if (jQuery.inArray(cats[z], catKey) > -1) {
                                        lanjut = 1;
//                            console.log("lanjut"+cats[z]+attr['VariantID']);
                                    }
                                }
                                if(lanjut === 0)
                                    continue;
                            }

                            //search filter
                            var search = $("#searchTextVariant").val().toLowerCase();
                            if(search != '') {
//                    console.log(search);
//                    console.log(attr['VariantID']+ " "+attr['VariantNameENG']);BaseArticleNameENG
                                if (attr['VariantID'].toLowerCase().indexOf(search) === -1 && attr['VariantNameENG'].toLowerCase().indexOf(search) === -1 && attr['BaseArticleNameENG'].toLowerCase().indexOf(search) === -1) {
                                    continue;
                                }
                            }

                            arrFiltered.push(attr);
                            yangMasukRange++;
                        }
                        total = yangMasukRange;
                        return arrFiltered;
                    }
                    function printProduct(option) {
                        $('#loadingtop').show().fadeOut();
//                console.log(option);

                        var arrSem = updateArrSize();

                        var range = {
                            minprice: $("#slider").slider("values", 0),
                            maxprice: $("#slider").slider("values", 1)
                        };
                        var html = '';
                        var printed = 0;

//                var arrSem = homes.slice();

                        var end = Math.min(limit, arrSem.length);
                        console.log(arrSem);

                        var t = $.now();

                        if (page > 1) {
                            var anzahlremove = 0 - ((page - 1) * limit);
                            arrSem.splice(anzahlremove);
                        }
//                console.log("anzahlremove "+anzahlremove);
//                console.log(arrSem.length);


                        html += createPagination();

                        while (printed < end && arrSem.length > 0) {
//                for(var x=0;x<12;x++){
                            var attr = arrSem.pop();
                            var rand = Math.floor((Math.random() * 100) + 1);
                            t = t + rand;

//                            if (range.hasOwnProperty('minprice')) {
//                                if (attr['SellingPrice'] < range.minprice)
//                                    continue;
//                            }
//                            if (range.hasOwnProperty('maxprice')) {
//                                if (attr['SellingPrice'] > range.maxprice)
//                                    continue;
//                            }
//                            if (catKey.length > 0) {
//                                if (jQuery.inArray(attr['TaggingLevel3ID'], catKey) == -1) {
//                                    continue;
//                                }
//                            }

                            html += '<div class="product_list_item col-md-4 col-sm-6 col-xs-6">';
                            html += '<div class="product_list_item_dalaman">';
                            html += '<div id="imgloader_' + attr['VariantID'] + '_' + t + '" class="img_loader" >';
                            html += '<img onload="" src="<?php 
            echo _SPPATH;
            ?>
images/tbs-hor-ajax-loader.gif">';
                            html += '</div>';

                            var imgurl = '<?php 
            echo $pc->imgURL;
            ?>
' + attr['BaseArticleImageFile'];
                            if (attr['BaseArticleImageFile'] == '') {
                                imgurl = '<?php 
            echo $pc->noimage;
            ?>
';
                            }
                            var linkurl = '<?php 
            echo _SPPATH;
            ?>
pr/p/' + attr['VariantID'] + '/' + urlencode(attr['BaseArticleNameENG'].replace("/"," "));

                            html += '<div  id="imgasli_' + attr['VariantID'] + '_' + t + '" class="product_list_item_img" style="display:none;">';

                            if(attr['rule_icon']!='') {
                                html += '<div class="imgstamp">';
                                html += '<img src="'+attr['rule_icon']+'">';
                                html += '</div>';
                            }

                            html += '<a title="' + attr['BaseArticleNameENG'] + '" href="'+linkurl+'">';
                            html += '<img id="imgTarget_' + attr['VariantID'] + '" onload="preloadImg(\'' + attr['VariantID'] + '_' + t + '\');"  src="' + imgurl + '" >';
                            html += '</a>';
                            html += '</div>';


                            html += '<div class="product_list_item_text">';
                            html += '<div class="name">';
                            html += '<a title="' + attr['BaseArticleNameENG'] + '" href="'+linkurl+'">';
                            html += attr['BaseArticleNameENG'] + '</a>';
                            html += '</div>';
                            html += '<div class="rating">';
                            html += '<div class="rating">';
                            html += '<span>☆</span><span>☆</span><span>☆</span><span>☆</span><span>☆</span>';
                            html += '</div>';

                            html += '</div>';

                            var hargadiskon = '';
                            var diskonnya = parseInt(attr['rule_discount']);

                            if(diskonnya>0){
                                 hargadiskon = 'IDR '+toRp(attr['SellingPrice']);

                            }

                            html += '<div class="item_price item_price_small" >'+hargadiskon+'</div>';


                            html += '<div class="item_price">IDR ' + toRp(attr['final_price']) + '</div>';

                            html += '<div  class="monly" style="background-color: #e2007a; padding: 5px; text-align: center;">';
                            html += '<div class="add" data-toggle="modal" data-variant="' + attr['VariantID'] + '"';
                            html += 'data-url="'+linkurl+'"';
                            html += 'data-imgUrl="'+imgurl+'"';
                            html += 'data-articlename="' + attr['BaseArticleNameENG'] + '"';
                            html += 'data-target="#myModal" style="cursor: pointer;color:white; font-weight:bold;">ADD TO BAG</div>';
                            html += '</div>';


                            html += '<div class="buy donly">';
                            html += '<div style="float: right;">';

                            html += '<a class="add" data-toggle="modal" data-variant="' + attr['VariantID'] + '"';
                            html += 'data-url="'+linkurl+'"';
                            html += 'data-imgUrl="'+imgurl+'"';
                            html += 'data-articlename="' + attr['BaseArticleNameENG'] + '"';
                            html += 'data-target="#myModal" style="cursor: pointer">ADD TO BAG</a>';


//                            html += '<a class="add" href="buy">ADD TO BAG</a>';
                            html += '</div>';
                            html += '<a  class="more" title="' + attr['BaseArticleNameENG'] + '" href="<?php 
            echo _SPPATH;
            ?>
pr/p/' + attr['VariantID'] + '/' + encodeURIComponent(attr['BaseArticleNameENG']) + '">';
                            html += 'more details</a>';
                            html += '<div class="clearfix"></div>';
                            html += '</div>';
                            html += '</div>';
                            html += '</div>';
                            html += '</div>';


                            if (printed % 3 == 2)html += "<div class='clearfix donly'></div><hr class='dotted donly'/>";

                            printed++;
                        }
                        html += '<div class="clearfix"></div>';
                        html += createPagination();


                        $('#product_data').html(html);
//                $('#loadingtop').hide();
                    }

                    function createPagination() {

                        var html = '';
//                $begin = (($page-1)*$limit)+1;
//                $end = $page+$limit-1;
//
//                $total = count($arr);
//                $jmlhpage = ceil($total/$limit);
//
//                $minpage = max(1,$page-3);
//                $maxpage = min($jmlhpage,$page+3);

                        var begin = ((page - 1) * limit) + 1;
                        var end = Math.min(begin + limit - 1, total);

//                        var jmltotal = Math.min(total,end);
                        var jmltotal = total;

                        var jmlpage = Math.ceil(jmltotal / limit);

                        var minpage = Math.max(1, page - 3);
                        var maxpage = Math.min(jmlpage, page + 3);


                        html += '<div class="product_pagination">';
                        html += '<div class="showing">SHOWING <b>' + begin + '</b>-<b>' + end + '</b> OF <b>' + jmltotal + '</b></div>';
                        html += '<div class="clearfix monly"></div> <hr class="dotted monly">';
                        html += '<div class="pages">Pages';
                        if (page > 1) {
                            var mundur = page - 1;
                            html += '<span onclick="moveToPage(' + mundur + ');" class="page_nr">«</span>';
                        }
                        for (var x = minpage; x <= maxpage; x++) {
                            var sel = '';
                            if (page == x)sel = 'page_nr_sel';
                            html += '<span onclick="moveToPage(' + x + ');" class="page_nr ' + sel + '">' + x + '</span>';
                        }
                        if (page < jmlpage) {
                            var maju = page + 1;
                            html += '<span onclick="moveToPage(' + maju + ');" class="page_nr">»</span>';
                        }

                        html += '&nbsp;&nbsp; &nbsp; <b>' + page + '</b> of <b>' + jmlpage + '</b> displayed </div>';
                        html += '</div>';

                        return html;
                    }

                    function toRp(angka) {
                        var rev = parseInt(angka, 10).toString().split('').reverse().join('');
                        var rev2 = '';
                        for (var i = 0; i < rev.length; i++) {
                            rev2 += rev[i];
                            if ((i + 1) % 3 === 0 && i !== (rev.length - 1)) {
                                rev2 += '.';
                            }
                        }
                        return rev2.split('').reverse().join('');
                    }


                </script><?php 
        }
        ?>
            <style>
                .sort {
                    border: 1px solid #cccccc;
                    padding: 10px;

                    font-size: 12px;
                    font-weight: bold;
                }

                .product_pagination {
                    padding: 10px;
                    margin-bottom: 30px;
                    color: #666666;
                }

                .sort_item {
                    cursor: pointer;
                    padding-left: 20px;
                    padding-right: 20px;
                    border-left: 1px dashed #cccccc;
                    font-weight: normal;
                }

                .product_list_item {
                    /*float: left;*/
                    /*width: 33%;*/
                    /*height: 390px;*/
                    border-right: 1px dashed #cccccc;
                }

                .product_list_item_dalaman {
                    padding: 10px;
                }

                .product_list_item_img, .img_loader {
                    width: 180px;
                    height: 180px;
                    overflow: hidden;
                    margin: auto;
                    text-align: center;
                }

                .product_list_item_img img, .img_loader img {
                    max-width: 100%;
                    max-height: 100%;
                }

                .img_loader {
                    line-height: 180px;
                }

                .product_list_item_text .name {
                    font-weight: bold;
                    color: #777777;
                    height: 40px;
                    text-overflow: ellipsis;
                    margin-top: 20px;
                    overflow: hidden;
                    /*white-space:nowrap;*/
                    display: -webkit-box;
                    -webkit-line-clamp: 2;
                    -webkit-box-orient: vertical;

                }

                .product_list_item_text .name a {
                    color: #666666;
                }

                .product_list_item_text .name a:hover {
                    color: #7fb719;
                }
                .imgstamp{
                    position: absolute;
                    width: 80px;
                    height: 80px;
                    overflow: hidden;
                }
                .imgstamp img{
                    min-width: 100%;
                    min-height: 100%;
                }
                /*
                use text ellipsis always with overflow:hidden; and white-space:nowrap;

                for multiple line ..line clamps use
                display: -webkit-box;
                    -webkit-line-clamp: 2;
                    -webkit-box-orient: vertical;
                    and overflow:hidden;
                */
                .rating {
                    font-size: 20px;
                    margin-top: 10px;
                    color: #999999;
                }

                .rating > span:hover:before {
                    content: "\2605";
                    position: absolute;
                }

                .item_price {
                    color: #e2007a;
                    font-size: 25px;
                }
                .item_price_small{
                    text-decoration: line-through; font-size: 13px;height: 18px;
                }

                .buy {
                    padding: 5px;
                    border: 1px solid #cccccc;
                    margin-top: 10px;
                    /*height: 45px;*/
                }

                a.more {
                    font-size: 11px;
                    text-decoration: underline;
                    color: #444444;
                    height: 30px;
                    line-height: 30px;
                }

                a.add {
                    background-color: #e2007a;
                    color: white;
                    padding: 5px;
                    height: 30px;
                    padding-right: 10px;
                    padding-left: 10px;
                    line-height: 30px;
                    text-underline: none;
                }

                a.add:hover {
                    background-color: #C60063;
                    color: white;
                    padding: 5px;
                    height: 30px;
                    padding-right: 10px;
                    padding-left: 10px;
                    line-height: 30px;
                    text-decoration: none;
                }

                button.add {
                    background-color: #e2007a;
                    color: white;
                    padding: 5px;
                    padding-left: 10px;
                    padding-right: 10px;
                    border-color: #e2007a;
                    border-radius: 0px;
                    font-size: 14px;
                }

                .addcancel {
                    border: none;
                    border-radius: 0px;
                    font-size: 14px;
                    color: #777777;
                }

                .addcancel:hover {
                    border: none;
                    border-radius: 0px;
                    font-size: 14px;
                    background-color: transparent;
                    color: #b4b4b4;
                }

                button.add:hover, button.add:active, button.add:focus, button.add:visited {
                    background-color: #C60063;
                    border-color: #C60063;
                    border-radius: 0px;
                }

                @media (min-width: 550px) {
                    .modal-dialog.adddialog {
                        width: 500px;
                        margin: 30px auto
                    }
                }

                hr.dotted {
                    border-top: 1px dashed #cccccc;
                    margin-top: 10px;
                    margin-bottom: 10px;
                    margin-left: 10px;
                    margin-right: 10px;
                }

                .breadcrumbs span {
                    font-weight: bold;
                }

                .breadcrumbs a {
                    color: #666666;
                    font-style: italic;
                }

            </style>
        </div>
        <div class="clearfix"></div>

        <?php 
        //        pr($data);
    }
?>
 
</style>
</head>
<body>
<?php 
MemberLogin::loginAndRegform();
Mold::theme("afterBodyJS");
Mold::theme("ajaxLoader");
?>
<div class="header_mobile monly">
    <!-- Navigation -->
    <nav style="background-color: #000000 !important;" id="myNavmenu" class="navmenu navmenu-default navmenu-fixed-left offcanvas" role="navigation">

        <?php 
ProductCategoryService::processCategoryMobile();
?>

    </nav>
    <div class="navbar navbar-default navbar-fixed-top" style="background-color: #000000 !important;" >
        <div style="float: left; width: 50%; ">
            <?php 
$bgimage = ThemeReg::mod("logo_desktop", _SPPATH . "images/logo_tbs_white.png", "image");
?>
            <div style="margin-top: 15px;margin-left: 10px;">
                <img width="100%" itemprop="logo" src="<?php 
echo $bgimage;
?>
"
                     alt="The Body Shop - Beauty Products inspired by Nature and Ethically made">
            </div>
                <i class="glyphicon glyphicon-log-out"></i>
            </a>
        </div>
            <div id="main_menu">
                <div class="container">
                    <div class="wadah_menu">
                        <div class="menu_item">
                            <a href="<?php 
echo _SPPATH;
?>
">
                                <i class="glyphicon glyphicon-home"></i>
                            </a>
                        </div>
                        <?php 
ProductCategoryService::processCategory();
?>
                        <!--                <div class="menu_item">-->
                        <!--                    NEW-->
                        <!--                </div>-->
                        <!--                <div class="menu_item">-->
                        <!--                    BODY-->
                        <!--                </div>-->
                        <!--                <div class="menu_item">-->
                        <!--                    FACE-->
                        <!--                </div>-->
                        <!--                <div class="menu_item">-->
                        <!--                    MAKE UP-->
                        <!--                </div>-->
                        <div class="clearfix"></div>
                    </div>
    public static function printCategoryFilterAll()
    {
        $cats = ProductCategoryService::getCategory();
        foreach ($cats->layer as $key => $val) {
            //key semua ke anak2nya
            ?>
                <div onclick="$('.<?php 
            echo $key;
            ?>
').toggle();" class="key" style="font-weight: bold; cursor: pointer; padding-top: 5px; padding-bottom: 5px;" ><span ><?php 
            echo strform($cats->detail->{$key});
            ?>
</span></div>
                <?php 
            foreach ($val as $key2 => $val2) {
                //diprint
                ?>
                        <div class="key2 <?php 
                echo $key;
                ?>
" style="cursor: pointer; display: none;" >&nbsp; <span onclick="$('.<?php 
                echo $key2;
                ?>
').toggle();"><?php 
                echo strform($cats->detail->{$key2});
                ?>
</span></div>
                        <?php 
                foreach ($val2 as $val3) {
                    //diprint
                    ?>
                            <div class="key3 <?php 
                    echo $key2;
                    ?>
" style="display: none;"> &nbsp; &nbsp; <input class="category_check" id="check_<?php 
                    echo $val3;
                    ?>
" type="checkbox" > &nbsp; <?php 
                    echo strform($cats->detail->{$val3});
                    ?>
</div>
                            <script>
                                $("#check_<?php 
                    echo $val3;
                    ?>
").change(function() {
                                    var key = '<?php 
                    echo $val3;
                    ?>
';
                                    if(this.checked) {
                                        //Do stuff

                                        catKey.push(key);
                                    }
                                    else{
                                        //remove element from array
                                        removeA(catKey, key);
                                    }
                                    page = 1;
                                    printProduct({});
                                });
                            </script>
                        <?php 
                }
            }
        }
    }
 static function convertToTree()
 {
     $obj = ProductCategoryService::getCategory();
     $m = new MProdCat();
     if ($_POST['radio'] == "truncate") {
         $m->truncate();
     }
     //
     //        pr($obj);
     $num = 0;
     $gagal = 0;
     $gagalArr = array();
     foreach ($obj->layer as $key => $val) {
         $name = trim(rtrim($obj->detail->{$key}));
         $urutan = $obj->urutan->{$key};
         $mp = new MProdCat();
         $mp->cat_name = $name;
         $mp->cat_id = $key;
         $mp->cat_parent_id = 0;
         $mp->cat_urutan = $urutan;
         if ($mp->save(1)) {
             $num++;
         } else {
             $gagal++;
             $gagalArr[] = $key;
         }
         //key semua ke anak2nya
         foreach ($val as $key2 => $val2) {
             $name2 = trim(rtrim($obj->detail->{$key2}));
             $urutan2 = $obj->urutan->{$key2};
             $mp2 = new MProdCat();
             $mp2->cat_id = $key2;
             $mp2->cat_name = $name2;
             $mp2->cat_parent_id = $key;
             $mp2->cat_urutan = $urutan2;
             if ($mp2->save(1)) {
                 $num++;
             } else {
                 $gagal++;
                 $gagalArr[] = $key2;
             }
             foreach ($val2 as $val3) {
                 $name3 = trim(rtrim($obj->detail->{$val3}));
                 $urutan3 = $obj->urutan->{$val3};
                 $mp3 = new MProdCat();
                 $mp3->cat_id = $val3;
                 $mp3->cat_name = $name3;
                 $mp3->cat_parent_id = $key2;
                 $mp3->cat_urutan = $urutan3;
                 if ($mp3->save(1)) {
                     $num++;
                 } else {
                     $gagal++;
                     $gagalArr[] = $val3;
                 }
             }
         }
         $json['success'] = $num;
         $json['failed'] = $gagal;
         $json['failed_arr'] = $gagalArr;
         echo json_encode($json);
         die;
     }
 }