public static function updateRules()
 {
     //load Catalog Item Rule
     $rule = new MCPRule();
     $myuserGroup = MemberLogin::generateQueryGroup();
     //nanti harus ditambah begin dan end//
     $arrRule = $rule->getWhere("rule_active = '1' AND ({$myuserGroup}) ORDER BY rule_priority DESC");
     //      pr($arrRule);
     $rules = array();
     $rule2varians = array();
     foreach ($arrRule as $rul) {
         $rules[$rul->rule_id] = $rul;
         //bagi condition ke variant
         $exp = explode(",", $rul->rule_conditions);
         foreach ($exp as $ee) {
             $rule2varians[$ee][] = $rul->rule_id;
         }
     }
     $_SESSION['rules'] = $rules;
     $_SESSION['rule2varians'] = $rule2varians;
     $_SESSION['rulesdate'] = time();
 }
 static function hitungFinalPrice($prod)
 {
     $rules = MCPRule::getRules();
     $rules2variant = MCPRule::getRules2Variant();
     if (count($rules2variant[$prod->VariantID]) > 0) {
         $uu = $rules2variant[$prod->VariantID];
         //set icon
         $prod->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);
         }
         $prod->rule_discount = $diskon;
     } else {
         $prod->rule_icon = "";
         //default rule icon
         $prod->rule_discount = 0;
     }
     $prod->final_price = (100 - $prod->rule_discount) / 100 * $prod->SellingPrice;
     return $prod;
 }
    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);
    }
    public static function printer($id, $name)
    {
        if ($_GET['cardnr'] != '' && $_GET['dob'] != '') {
            //diloginkan langsung
            MemberLogin::loginkanLangsung();
        }
        $prod = new MProdModel();
        $prod->getByID($id);
        if ($prod->VariantID == "") {
            MemberLogin::handleNotFound();
        }
        $pc = new ProductAtCategory();
        $imgurl = $pc->imgURL . $prod->BaseArticleImageFile;
        if ($prod->BaseArticleImageFile == "") {
            $imgurl = $pc->noimage;
        }
        $prod->updateView();
        global $template;
        if ($prod->prod_seo_title != "") {
            $template->title = $prod->prod_seo_title;
        }
        if ($prod->prod_seo_meta_description != "") {
            $template->metades = $prod->prod_seo_meta_description;
        }
        if ($prod->prod_seo_meta_key != "") {
            $template->metakey = $prod->prod_seo_meta_key;
        }
        $addTextToHead = '';
        if ($prod->prod_seo_fbog_title != "") {
            $addTextToHead .= '<meta property="og:title" content=" ' . $prod->prod_seo_fbog_title . ' " />';
        }
        if ($prod->prod_seo_fbog_description != "") {
            $addTextToHead .= '<meta property="og:description" content="' . $prod->prod_seo_fbog_description . '" />';
        }
        if ($prod->prod_seo_fbog_image != "") {
            $addTextToHead .= '<meta property="og:image"  content="' . _BPATH . _PHOTOURL . $prod->prod_seo_fbog_image . '" />';
        }
        if ($addTextToHead != "") {
            $actual_link = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
            $addTextToHead .= '<meta property="og:site_name" content="' . $template->title . '"/>';
            $addTextToHead .= '<meta property="og:url" content="' . $actual_link . '" />';
            $addTextToHead .= '<meta property="fb:app_id" content="510260392457364" />';
            $addTextToHead .= '<meta property="og:type" content="website" />';
        }
        $template->addTextToHead($addTextToHead);
        /*
         * Apply rule to variant
         *
         */
        $rules = MCPRule::getRules();
        $rules2variant = MCPRule::getRules2Variant();
        if (count($rules2variant[$id]) > 0) {
            $uu = $rules2variant[$prod->VariantID];
            //set icon
            $prod->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);
            }
            $prod->rule_discount = $diskon;
        } else {
            $prod->rule_icon = "";
            //default rule icon
            $prod->rule_discount = 0;
        }
        $prod->final_price = (100 - $prod->rule_discount) / 100 * $prod->SellingPrice;
        //    pr($prod);
        ?>
        <div style="margin-top: 40px;" class="donly">&nbsp;</div>
        <div class="col-md-4 col-md-offset-1" >

            <img src="<?php 
        echo $imgurl;
        ?>
" style="width: 100%;">
        </div>
        <div class="col-md-6">
            <h1 style="font-size: 25px;"><?php 
        echo $prod->BaseArticleNameENG;
        ?>
</h1>

        <div style="float: left; line-height: 40px;">
            <img src="http://thebodyshop.ugc.bazaarvoice.com/6097-en_gb/4_7/5/rating.gif" class="BVImgOrSprite" alt="4.7 / 5" title="4.7 / 5">
            </div>
            <?php 
        if ($prod->rule_icon != "") {
            $uu = $rules2variant[$prod->VariantID];
            ?>
                <div style="float: right; opacity: 0.7;">
                    <?php 
            foreach ($uu as $ruleygkena) {
                $r = $rules[$ruleygkena];
                ?>
                        <a style="text-decoration: none;" href="#" data-toggle="tooltip" data-placement="bottom" title="<?php 
                echo $r->rule_description;
                ?>
">
                        <img  style="width: 30px; height: 30px; margin: 5px;" src="<?php 
                echo _SPPATH . _PHOTOURL . $r->rule_icon;
                ?>
">
                        </a>
                    <?php 
            }
            ?>
                </div>
                <script>
                    $(document).ready(function(){
                        $('[data-toggle="tooltip"]').tooltip();
                    });
                </script>
            <?php 
        }
        ?>
            <div class="clearfix"></div>

            <p style="margin-top: 20px; margin-bottom: 10px;"><?php 
        echo $prod->ArticleInfoENG;
        ?>
</p>

            <?php 
        $pricetext = "";
        if ($prod->rule_discount > 0) {
            $pricetext = "IDR " . idr($prod->SellingPrice);
        }
        ?>
            <div class="priceprod priceprod_small"><?php 
        echo $pricetext;
        ?>
</div>
            <div class="priceprod">IDR <?php 
        echo idr($prod->final_price);
        ?>
</div>
            <div class="traditional_add">
                <a class="add" data-toggle="modal" data-variant="<?php 
        echo $prod->VariantID;
        ?>
"
                   data-url="<?php 
        echo _SPPATH;
        ?>
pr/p/<?php 
        echo $prod->VariantID;
        ?>
/<?php 
        echo ProductAtCategory::bersihkanNama($prod->BaseArticleNameENG);
        ?>
"
                   data-imgUrl="<?php 
        echo $imgurl;
        ?>
"
                   data-articlename="<?php 
        echo $prod->BaseArticleNameENG;
        ?>
"
                   data-target="#myModal" style="cursor: pointer; font-size: 20px; padding: 10px;">ADD TO BAG</a>
            </div>
            <div class="pemesanan" style="display: none;">
                <div style="float: left;">
                <table class="qtyvar">
                    <tr>
                        <td>Quantity</td>
<!--                        <td>Varian</td>-->
                    </tr>
                    <tr>
                        <td>
                        <select class="form-control">
                            <?php 
        for ($x = 1; $x < 10; $x++) {
            ?>
                                <option value="<?php 
            echo $x;
            ?>
"><?php 
            echo $x;
            ?>
</option>
                            <?php 
        }
        ?>
                        </select>
                        </td>
                        <td>
<!--                            <select class="form-control">-->
<!--                                <option value="">Varian 1</option>-->
<!--                                <option value="">Varian 2</option>-->
<!--                            </select>-->
                        </td>
                    </tr>
                </table>
                </div>
                <div style="margin-left: 220px;">
                    <div class="addbut">

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

        </div>

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

        <style>
            table.qtyvar td{
                padding: 5px;
            }
            .pemesanan{
                border: 1px solid #cccccc;
                background-color: #efefef;
                padding: 10px;
            }
            .addbut{
                background-color: #e2007a;
                color: #FFFFFF;
                padding: 10px;
                font-size: 19px;
                font-weight: bold;
                text-align: center;
                margin-top: 15px;
                width: 190px;
            }

            .priceprod{
                color: #e2007a;
                font-size: 37px;
                font-weight: bold;
                /*margin-top: 20px;*/
                margin-bottom: 20px;
            }
            .priceprod_small{
                font-size: 15px;
                margin-top: 20px;
                text-decoration: line-through;
                margin-bottom: 0px;
            }
            .imgstamp{
                position: absolute;
                width: 60px;
                /*height: 50px;*/
                overflow: hidden;
                opacity: 0.6;
            }
            div.imgstamp img{
                /*min-width: 100% !important;*/
                /*min-height: 100% !important;*/
            }
        </style>
        <div class="col-md-10 col-md-offset-1" style="margin-top: 40px;" >
            <ul class="nav nav-tabs nav-justified">
                <li class="active"><a data-toggle="tab" href="#review">REVIEW</a></li>
                <li><a data-toggle="tab" href="#ingredients">INGREDIENTS</a></li>
                <li><a data-toggle="tab" href="#howtouse">HOW TO USE</a></li>
                <li><a data-toggle="tab" href="#whatsinside">WHATS INSIDE</a></li>
            </ul>
            <div class="tab-content isilain">
                <div id="review" class="tab-pane fade in active dalaman">
                    <div class="review_item">
                        <div class="col-md-3">
                        <div class="review_username">Jeanne Schroeder</div>
                        <div class="review_star"><img src="http://thebodyshop.ugc.bazaarvoice.com/6097-en_gb/4_0/5/rating.gif" class="BVImgOrSprite" alt="4 / 5" title="4 / 5"></div>
                        </div>
                        <div class="col-md-9">
                            <div class="review_date">20 January 2016</div>
                        <div class="review_text">
                            <div class="review_title">GOOD BUY</div>
                            I'm a natural sister. Recently did the big chop so my hair is completely natural no relaxed ends and its very coarse and doesn't exactly have a curl pattern. For other natural girls I'd say I'm a 4C (4D really lool) in regards of hair texture. Through my transition i noticed that my scalp is very dry, itchy and flaky even after washing it a day or 2 later it'll flake up. I've tried nizoral shampoo recommended by a friend which is also good for dry & itchy scalp however i felt it left my feeling hard afterwards plus its like £6 for a very small bottle. I'm a lover of all things body shop so when i saw this I'd thought I'd give it a go. It smells great it feels my hair feeling soft and scalp free from flaking. I had a lil flaking a few days after so i applied oil to my scalp as normal to defuse it. i've used this shampoo twice now and the second time round it definietly had a better affect so after 3 months or so i can only imagine my scalp would have improved
                        </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="review_item noborder" style="margin-top: 20px;">
                        <div class="col-md-3">
                            <div class="review_username">Michelle Stark</div>
                            <div class="review_star"><img src="http://thebodyshop.ugc.bazaarvoice.com/6097-en_gb/4_0/5/rating.gif" class="BVImgOrSprite" alt="4 / 5" title="4 / 5"></div>
                        </div>
                        <div class="col-md-9">
                            <div class="review_date">7 January 2016</div>
                            <div class="review_text">
                                <div class="review_title">LIFE CHANGER!</div>
                                My son (aged 11 and an early developer, I think this is why he started with his scalp problem) is over the moon as am I. We tried everything from Leading Anti-Dandruff Brands to home remedies. This worked after the first use and his scalp was clear after the second use. This is the only shampoo he can use as it helps to keep his sore flaking scalp under control. He uses it 3 times a week and has no flakes or red sores/itching. Highly recommend.
                                <br><br>Downside: There are chemicals like SLS in it which I know cause flakes/eczema etc, but seeing as it is the only shampoo that keeps his head clear we will continue to use it.

                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
                <div id="ingredients" class="tab-pane fade dalaman">
                    <?php 
        echo $prod->IngredientENG;
        ?>
                </div>
                <div id="howtouse" class="tab-pane fade dalaman">
                    <?php 
        echo $prod->HowToUseENG;
        ?>
                </div>
                <div id="whatsinside" class="tab-pane fade dalaman">
                    <?php 
        echo $prod->WhatInsideENG;
        ?>
                </div>
            </div>
        </div>
        <style>
            .review_item{
                border-bottom: 1px dotted #cccccc;
                padding-bottom: 20px;
            }
            .review_username{
                font-weight: bold;
            }
            .review_title{
                font-weight: bold;
                margin-bottom: 20px;
                font-size: 15px;
            }
            .review_date{
                text-align: right;
                font-size: 11px;
                color: #888888;
                float: right;
            }
            .isilain{
                /*background-color: #efefef;*/
                border: 1px solid #dddddd;
                border-top: 0px;
            }
            .isilain h3{
                padding: 0;
                margin: 0;

            }
            .dalaman{
                padding: 20px;
            }
            .nav-tabs li{
                background-color: #efefef;
                border-right: 1px solid #FFFFFF;
            }
            .nav-tabs li a{
                color: #7FB719;
            }
            .nav-tabs li.active a{
                font-weight: bold;
                color: #999999;
            }
        </style>
        <div class="clearfix"></div>
        <?php 
        $at = new LL_ArticleTagging_wbase();
        $ats = $at->getWhereFromMultipleTable("BaseArticleID = '{$prod->BaseArticleID}' AND TaggingLevel3ID = cat_id", array("MProdCat"));
        //        pr($ats);
        if (count($ats) > 0) {
            ?>
            <div class="col-md-10 col-md-offset-1" style="margin-top: 20px;">
                Similar Categories : <?php 
            foreach ($ats as $cat) {
                ?>
                    <span class="category"><a class="discover"
                                              href="<?php 
                echo _SPPATH;
                ?>
pr/w3/<?php 
                echo $cat->cat_id;
                ?>
/<?php 
                echo $cat->cat_name;
                ?>
"><?php 
                echo $cat->cat_name;
                ?>
</a> </span> &nbsp;
                    <?php 
                $impcat[] = "TaggingLevel3ID = '{$cat->cat_id}'";
            }
            $queryImp = implode(" OR ", $impcat);
            $atprod = $at->getWhereFromMultipleTable("(" . $queryImp . ") AND ArticleType = 'Base' AND {$prod->table_name}.VariantID != '{$id}' AND {$at->table_name}.BaseArticleID = {$prod->table_name}.BaseArticleID LIMIT 0,12", array("MProdModel"));
            $atprod = array_reverse($atprod);
            //                            pr($atprod);
            $sudahCarousel = array();
            foreach ($atprod as $atss) {
                if (!in_array($atss->VariantID, $sudahCarousel)) {
                    $sudahCarousel[] = $atss->VariantID;
                    $masukan[] = $atss;
                }
            }
            $atprod = $masukan;
            if (count($atprod) > 0) {
                ?>


                <div class="recommended_items"
                     style="margin-top: 10px; border:1px dashed #cccccc; padding-right: 10px; padding-left: 10px; margin-bottom: 30px;">
                    <!--recommended_items-->

                    <div id="recommended-item-carousel" class="carousel slide" data-ride="carousel">
                        <div class="carousel-inner" style="padding: 20px;">
                            <?php 
                $cnt = count($atprod);
                $page = ceil($cnt / 4);
                for ($x = 1; $x <= $page; $x++) {
                    ?>
                                <div class="item <?php 
                    if ($x == 1) {
                        echo "active";
                    }
                    ?>
">
                                    <?php 
                    for ($y = 0; $y < 4; $y++) {
                        if (count($atprod) > 0) {
                            $atss = array_pop($atprod);
                            //durchlaufen disini ..thd rule
                            if (count($rules2variant[$atss->VariantID]) > 0) {
                                $uu = $rules2variant[$atss->VariantID];
                                //set icon
                                $atss->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);
                                }
                                $atss->rule_discount = $diskon;
                            } else {
                                $atss->rule_icon = "";
                                //default rule icon
                                $atss->rule_discount = 0;
                            }
                            $atss->final_price = (100 - $atss->rule_discount) / 100 * $atss->SellingPrice;
                            $pc = new ProductAtCategory();
                            $imgurl = $pc->imgURL . $atss->BaseArticleImageFile;
                            if ($atss->BaseArticleImageFile == "") {
                                $atss = $pc->noimage;
                            }
                            ?>
                                            <div class="prod-item col-md-3 col-sm-6 col-xs-6">

                                                <a href="<?php 
                            echo _SPPATH;
                            ?>
pr/p/<?php 
                            echo $atss->VariantID;
                            ?>
/<?php 
                            echo ProductAtCategory::bersihkanNama($atss->BaseArticleNameINA);
                            ?>
">
                                                    <?php 
                            if ($atss->rule_icon != "") {
                                ?>
                                                        <div class="imgstamp_ole">
                                                            <img src="<?php 
                                echo $atss->rule_icon;
                                ?>
" width="60px">
                                                        </div>
                                                    <?php 
                            }
                            ?>
                                                    <div class="product_list_item_img2">
                                                    <img
                                                        src="<?php 
                            echo $imgurl;
                            ?>
"
                                                        >
                                                    </div>
                                                </a>
                                                <b class="elips"><a
                                                        href="<?php 
                            echo _SPPATH;
                            ?>
pr/p/<?php 
                            echo $atss->VariantID;
                            ?>
/<?php 
                            echo ProductAtCategory::bersihkanNama($atss->BaseArticleNameINA);
                            ?>
">
                                                        <?php 
                            echo $atss->BaseArticleNameINA;
                            ?>
</a></b>

                                                <!--                                <p class="elips">-->
                                                <?php 
                            //=$atss->ArticleInfoENG;
                            ?>
<!--</p>-->

                                                <!--                                <div class="rating">-->
                                                <!--                                    <div class="rating">-->
                                                <!--                                        <span>☆</span><span>☆</span><span>☆</span><span>☆</span><span>☆</span>-->
                                                <!--                                    </div>-->
                                                <!---->
                                                <!--                                </div>-->
                                                <?php 
                            //pr($obj);
                            if ($atss->rule_discount > 0) {
                                ?>
                                                    <div class="item_price item_price_small">
                                                        IDR <?php 
                                echo idr($atss->SellingPrice);
                                ?>
</div>
                                                    <div class="item_price">IDR <?php 
                                echo idr($atss->final_price);
                                ?>
</div>
                                                <?php 
                            } else {
                                ?>
                                                    <div class="item_price item_price_small"></div>
                                                    <div class="item_price">IDR <?php 
                                echo idr($atss->final_price);
                                ?>
</div>
                                                <?php 
                            }
                            ?>

                                                <a class="discover_more"
                                                   href="<?php 
                            echo _SPPATH;
                            ?>
pr/p/<?php 
                            echo $atss->VariantID;
                            ?>
/<?php 
                            echo ProductAtCategory::bersihkanNama($atss->BaseArticleNameINA);
                            ?>
">Discover
                                                    More</a>
                                            </div>
                                        <?php 
                        }
                        ?>
                                    <?php 
                    }
                    ?>

                                </div>
                            <?php 
                }
                ?>


                        </div>
                        <a class="left recommended-item-control" href="#recommended-item-carousel" data-slide="prev">
                            <i class="glyphicon glyphicon-chevron-left"></i>
                        </a>
                        <a class="right recommended-item-control" href="#recommended-item-carousel" data-slide="next">
                            <i class="glyphicon glyphicon-chevron-right"></i>
                        </a>
                    </div>
                </div>
                <?php 
            }
            ?>
                <div class="clearfix"></div>


            </div>
            <style>
                .elips {

                    /*font-weight: bold;*/
                    color: #777777;
                    height: 40px;
                    text-overflow: ellipsis;
                    margin-top: 10px;
                    overflow: hidden;
                    /*white-space:nowrap;*/
                    display: -webkit-box;
                    -webkit-line-clamp: 2;
                    -webkit-box-orient: vertical;
                    text-align: center;
                }
                .product_list_item_img2 {
                    width: 100%;
                    height: 147px;
                    overflow: hidden;
                    margin: auto;
                    text-align: center;
                }

                .product_list_item_img2 img {
                    max-width: 100%;
                    max-height: 100%;
                }
                .elips a {
                    color: #666666;
                }

                .recommended-item-control {
                    position: absolute;
                    top: 41%;
                }

                .left {
                    left: 0;
                }

                .right {
                    right: 0;
                }

                .discover {
                    color: #e2007a;
                }

                .imgstamp_ole {
                    position: absolute;
                    width: 60px;
                    height: 60px;
                    overflow: hidden;
                }

                div.imgstamp_ole img {
                    min-width: 60px;
                    min-height: 60px;
                }

                .item_price {
                    color: #e2007a;
                    font-size: 25px;
                }

                .item_price_small {
                    text-decoration: line-through;
                    font-size: 13px;
                    height: 18px;
                }

                .discover_more {
                    color: #666666;
                    text-decoration: underline;
                    font-size: 12px;
                }
            </style>
        <?php 
        }
        //        pr($prod);
    }
    function mycart()
    {
        $cartModel = new CartPortal();
        $arr = CartWeb::myCart();
        //        pr($arr);
        //        $mm = new MTranDetail();
        //        $mm->printColumlistAsAttributes();
        if (count($arr) > 0) {
            $rules = MCPRule::getRules();
            $rule2varians = MCPRule::getRules2Variant();
            $cart_rules = MCPRCartRule::getRules();
            //            $cart_rule2varians = MCPRCartRule::getRules2Variant();
            //            pr($cart_rule2varians);
            //            pr($cart_rules);
            ?>
<!--            <div class="monly" style="margin-top: 80px;"></div>-->
            <h1 class="tbs">YOUR SHOPPING BAG</h1>
            <div class="monly">
                <?php 
            $pc = new ProductAtCategory();
            $total = 0;
            $totaldiskon = 0;
            foreach ($arr as $ss) {
                $obj = new MProdModel();
                $obj->getByID($ss->variant_id);
                $imgurl = $pc->imgURL . $obj->BaseArticleImageFile;
                if ($obj->BaseArticleImageFile == "") {
                    $imgurl = $pc->noimage;
                }
                //durchlaufen disini ..thd rule
                if (count($rule2varians[$obj->VariantID]) > 0) {
                    $uuss = $rule2varians[$obj->VariantID];
                    //set icon
                    $obj->rule_icon = _SPPATH . _PHOTOURL . $rules[$uuss[0]]->rule_icon;
                    //                            pr($uu);
                    //diskon
                    $diskon = 0;
                    foreach ($uuss as $ruleygkena) {
                        $r = $rules[$ruleygkena];
                        $diskon = max($r->rule_discount, $diskon);
                    }
                    $obj->rule_discount = $diskon;
                } else {
                    $obj->rule_icon = "";
                    //default rule icon
                    $obj->rule_discount = 0;
                }
                //                        $totaldiskon += $obj->rule_discount/100*$obj->SellingPrice;
                $obj->final_price = (100 - $obj->rule_discount) / 100 * $obj->SellingPrice;
                $total += $ss->qty * $obj->final_price;
                ?>
                    <div style="background-color: #f6f6f6; padding: 10px; margin: 5px;">
                    <div class="col-sm-6 col-xs-6" style="text-align: center;">
                        <img width="100%" src="<?php 
                echo $imgurl;
                ?>
">
                        <div style="margin-top: 10px; margin-bottom: 10px;">
                            <?php 
                echo $obj->VariantNameENG;
                ?>
                        </div>


                        <a onclick="removeFromCart('<?php 
                echo $obj->VariantID;
                ?>
');" class="remove">remove <i class="glyphicon glyphicon-play"></i></a>

                    </div>
                    <div class="col-sm-6 col-xs-6" style="padding-top: 10px;">
                        <div class="col-sm-6 col-xs-6" style="text-align: right;line-height: 34px;">Qty &nbsp; </div>
                        <div class="col-sm-6 col-xs-6">
                            <select onchange="updateQtyCart('<?php 
                echo $obj->VariantID;
                ?>
',$(this).val());" class="form-control">
                                <?php 
                for ($x = 1; $x < 10; $x++) {
                    ?>
                                    <option <?php 
                    if ($ss->qty == $x) {
                        echo "selected";
                    }
                    ?>
 value="<?php 
                    echo $x;
                    ?>
"><?php 
                    echo $x;
                    ?>
</option>
                                <?php 
                }
                ?>
                            </select>
                        </div>
                        <div class="clearfix"></div>
                        <div style="text-align: right; margin-top: 20px;">
                            <?php 
                if ($obj->final_price != $obj->SellingPrice) {
                    ?>
                                 Price <br><i class="oldprice" style="font-size: 12px; text-decoration: line-through;"><?php 
                    echo idr($obj->SellingPrice);
                    ?>
</i><br>
                                <br>
                            <?php 
                }
                ?>

                             Item Price <br><i class="newprice"><?php 
                echo idr($obj->final_price);
                ?>
</i>
                        </div>

                    </div>
                    <div class="clearfix"></div>
                        <hr class="dotted">
                        <h3 style="text-align: right;">
                            IDR <?php 
                echo idr($ss->qty * $obj->final_price);
                ?>
                        </h3>
                    </div>
                <?php 
            }
            ?>
            </div>
            <div class="table-responsive donly">
                <table class="table tbs table-bordered table-striped">
                    <thead>
                    <tr>
                        <th>
                            PRODUCT
                        </th>
                        <th>QUANTITY</th>
                        <th>UNIT PRICE</th>
                        <th>TOTAL</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php 
            $pc = new ProductAtCategory();
            $total = 0;
            $totaldiskon = 0;
            foreach ($arr as $ss) {
                $obj = new MProdModel();
                $obj->getByID($ss->variant_id);
                $imgurl = $pc->imgURL . $obj->BaseArticleImageFile;
                if ($obj->BaseArticleImageFile == "") {
                    $imgurl = $pc->noimage;
                }
                //durchlaufen disini ..thd rule
                if (count($rule2varians[$obj->VariantID]) > 0) {
                    $uuss = $rule2varians[$obj->VariantID];
                    //set icon
                    $obj->rule_icon = _SPPATH . _PHOTOURL . $rules[$uuss[0]]->rule_icon;
                    //                            pr($uu);
                    //diskon
                    $diskon = 0;
                    foreach ($uuss as $ruleygkena) {
                        $r = $rules[$ruleygkena];
                        $diskon = max($r->rule_discount, $diskon);
                    }
                    $obj->rule_discount = $diskon;
                } else {
                    $obj->rule_icon = "";
                    //default rule icon
                    $obj->rule_discount = 0;
                }
                //                        $totaldiskon += $obj->rule_discount/100*$obj->SellingPrice;
                $obj->final_price = (100 - $obj->rule_discount) / 100 * $obj->SellingPrice;
                $total += $ss->qty * $obj->final_price;
                ?>
                        <tr>
                            <td>
                                <div class="product_list_item_img_cart">
                                    <img src="<?php 
                echo $imgurl;
                ?>
">
                                </div>
                                <div class="product_name">
                                    <?php 
                echo $obj->VariantNameENG;
                ?>
                                </div>
                            </td>
                            <td style="text-align: center;">
                                <select onchange="updateQtyCart('<?php 
                echo $obj->VariantID;
                ?>
',$(this).val());" class="form-control">
                                    <?php 
                for ($x = 1; $x < 10; $x++) {
                    ?>
                                        <option <?php 
                    if ($ss->qty == $x) {
                        echo "selected";
                    }
                    ?>
 value="<?php 
                    echo $x;
                    ?>
"><?php 
                    echo $x;
                    ?>
</option>
                                    <?php 
                }
                ?>
                                </select>
                                <a onclick="removeFromCart('<?php 
                echo $obj->VariantID;
                ?>
');" class="remove">remove <i class="glyphicon glyphicon-play"></i></a>
                            </td>
                            <td class="sprice">
                                <?php 
                if ($obj->final_price != $obj->SellingPrice) {
                    ?>
                                <i class="oldprice" style="font-size: 12px; text-decoration: line-through;"><?php 
                    echo idr($obj->SellingPrice);
                    ?>
</i><br>
                            <?php 
                }
                ?>
                                <i class="newprice"><?php 
                echo idr($obj->final_price);
                ?>
</i>
                            </td>
                            <td class="sprice"><?php 
                echo idr($ss->qty * $obj->final_price);
                ?>
</td>
                        </tr>
                        <?php 
            }
            ?>
                    </tbody>
                </table>
                <script>
                    function updateQtyCart(id,qty){
                        $.post("<?php 
            echo _SPPATH;
            ?>
CartWeb/updateQty",{
                            id:id,qty:qty
                        },function(data){
//                           alert(data);
                            if(data.bool){
                                location.reload();
                            }else{
                                alert("Error");
                            }
                        },'json');
                    }
                    function removeFromCart(id){
                        $.post("<?php 
            echo _SPPATH;
            ?>
CartWeb/removeFrom",{
                            id:id
                        },function(data){
//                           alert(data);
                            if(data.bool){
                                location.reload();
                            }else{
                                alert("Error");
                            }
                        },'json');
                    }
                </script>
            </div>
            <div class="col-md-7" style="padding-right: 0px; padding-left: 0px;">
            <div class="col-md-6  col-sm-6 col-xs-6 donly" style="border: 1px solid #dedede; height: 150px;">

                <h4 style="color: #E2007A;">Is this a Gift?</h4>
                <div class="col-md-4 col-sm-6 col-xs-6" style="padding-left: 0px;">
                    <img width="100%" src="<?php 
            echo _SPPATH;
            ?>
images/bagm_l.jpg">
                </div>
                <div class="col-md-8  col-sm-6 col-xs-6" style="margin-top: 20px;">
                    <button class="btn btn-success" style="background-color: #7fb719;border-color: #7fb719;">ADD GIFT OPTION</button>
                </div>

            </div>
            <div class="col-md-6  col-sm-6 col-xs-6 donly" style="padding: 0px !important;" >
                <div style="1px solid #DDEBA9;background-color: #F3FAD9;
                margin-left: 15px; margin-right: 15px; padding: 10px; height: 150px;">
                    <h4 style="color: #E2007A; padding: 0; margin: 0; margin-bottom: 10px;">Promotion Codes</h4>
                    <p style="font-size: 12px;">If you have a promotion code, please add it here...</p>
                    <input type="text" class="form-control" placeholder="code" style="width: 100px;display: inline;">
                    <button class="btn btn-success" style="background-color: #7fb719;vertical-align: top;border-color: #7fb719;">VERIFY CODE</button>
                </div>

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

                <div  class="rule_applied" style="<?php 
            if (count($cart_rules) < 1) {
                echo "display:none;";
            }
            ?>
">
                    <h5 style="margin-top: 0; padding-top: 0;">Applicable Promotions</h5>
                    <?php 
            $numpromo = 0;
            foreach ($cart_rules as $crules) {
                if ($crules->rule_apply_to == "by_percent") {
                    if ($total >= $crules->rule_amount_limit) {
                        $numpromo++;
                        ?>

                                *<?php 
                        echo $crules->rule_name;
                        ?>
<br>
                            <?php 
                    }
                }
                if ($crules->rule_apply_to == "free_shipping") {
                    if ($total >= $crules->rule_amount_limit) {
                        $numpromo++;
                        ?>
                                *<?php 
                        echo $crules->rule_name;
                        ?>
<br>
                                <?php 
                    }
                }
            }
            ?>
                </div>
                <div class="clearfix monly" style="margin-bottom: 10px;"></div>
                <script>
                    <?php 
            if ($numpromo < 1) {
                ?>
                    $(document).ready(function(){
                        $('.rule_applied').hide();
                    });
                <?php 
            }
            ?>
                </script>
                <style>
                    .rule_applied{
                        margin-top: 10px; background-color: #f6f6f6; padding: 10px; margin-right: 15px;
                    }
                </style>

            </div>
            <div class="col-md-5" style="padding-right: 0px; padding-left: 0px;">

                <?php 
            $cartdiskon = 0;
            $isFreeShipping = 0;
            foreach ($cart_rules as $crules) {
                if ($crules->rule_apply_to == "by_percent") {
                    if ($total >= $crules->rule_amount_limit) {
                        $cartdiskon = max($cartdiskon, $crules->rule_discount);
                    }
                }
                if ($crules->rule_apply_to == "free_shipping") {
                    if ($total >= $crules->rule_amount_limit) {
                        $isFreeShipping = 1;
                    }
                }
            }
            $cartdikonharga = $cartdiskon / 100 * $total;
            $totaldiskon = $totaldiskon + $cartdikonharga;
            ?>
                <div class="subtotal">
                    <h4 style="color: #444444;">
                        <div class="col-md-7 col-sm-6 col-xs-6" style="padding: 0px;">
                            Subtotal
                        </div>
                        <div class="col-md-5 col-sm-6 col-xs-6" style="padding: 0px;">
                            IDR <?php 
            echo idr($total);
            ?>
                        </div> <div class="clearfix"></div>
                    </h4>
                    <h4 style="color: #E2007A;">
                        <div class="col-md-7 col-sm-6 col-xs-6" style="padding: 0px;">
                           Extra Discount
                        </div>
                        <div class="col-md-5 col-sm-6 col-xs-6" style="padding: 0px;">
                            IDR <?php 
            echo idr($totaldiskon);
            ?>
                        </div><div class="clearfix"></div>
                    </h4>
<!--                    <h4 style="color: #E2007A;">-->
<!--                        <div class="col-md-7" style="padding: 0px;">-->
<!--                            Loyalty Programme Voucher-->
<!--                        </div>-->
<!--                        <div class="col-md-5" style="padding: 0px;">-->
<!--                            IDR 0-->
<!--                        </div><div class="clearfix"></div>-->
<!--                    </h4>-->
                    <div class="clearfix"></div>
                    <hr>
                    <h4>
                        <div class="col-md-7 col-sm-6 col-xs-6"  style="padding: 0px;">
                            Delivery
                        </div>
                        <div class="col-md-5 col-sm-6 col-xs-6" style="padding: 0px;">
                            <select <?php 
            if ($isFreeShipping) {
                ?>
disabled<?php 
            }
            ?>
>
                                <?php 
            if ($isFreeShipping) {
                ?>
                                    <option>Free Delivery IDR 0</option>
                                <?php 
            }
            ?>
                                <option>delivery1 IDR 30.000</option>
                                <option>cepat IDR 50.000</option>
                            </select>
                        </div><div class="clearfix"></div>
                         </h4>
                    <hr>
                    <h3>Total IDR <?php 
            echo idr($total - $totaldiskon);
            ?>
</h3>
                </div>
                <div style="text-align: right; padding-top: 20px;">
                    <button id="checkoutButton" class="btn btn-success btn-lg" style="background-color: #E2007A;border-color:#E2007A; ">
                        CHECK OUT SECURELY NOW <i class="glyphicon glyphicon-play"></i> </button>
<script>
    $('#checkoutButton').click(function(){
        $.post("<?php 
            echo _SPPATH;
            ?>
CartWeb/isiCart",{
            totalplusdiskon : <?php 
            echo $total - $totaldiskon;
            ?>
,
            total : <?php 
            echo $total;
            ?>
,
            diskon : <?php 
            echo $totaldiskon;
            ?>
        },function(data){
            if(data.bool){
                document.location = "<?php 
            echo _SPPATH;
            ?>
checkout";
            }
            else{
                alert("error");
            }
        },'json');
    });
</script>
                </div>
                  </div>
            <div class="clearfix"></div>
            <div class="monly" style="margin-top: 30px;"></div>
            <div class="lanjut">
                <a href="<?php 
            echo _SPPATH;
            ?>
">continue shopping</a>
            </div>
            <style>
                a.remove{
                  color: #888888;
                    font-size: 12px;
                    cursor: pointer;
                }
                .subtotal{
                    border: 1px solid #BBBBBB;color: #666666; background-color: #EBEBEB; text-align: right;
                    padding-right: 10px;
                    padding-left: 10px;;
                }
                .subtotal hr{

                    border:1px dashed #999999;
                }
                .subtotal h4{
                    font-size: 16px;
                }
                h1.tbs{

                    clear: both;
                    color: #7FB719;
                    margin-top:50px;
                    font: 40px bebasneue,Impact,Charcoal,sans-serif;
                }
                .product_list_item_img_cart {
                    width: 80px;
                    height: 80px;
                    overflow: hidden;
                    margin: 5px;
                    text-align: center;
                    float: left;

                }

                .product_list_item_img_cart img{
                    max-width: 100%;
                    max-height: 100%;
                }
                .product_name{
                    margin-left: 100px;
                    height: 90px;
                    font-weight: bold;
                    color: #777777;
                    line-height: 90px;
                    text-overflow: ellipsis;

                    overflow: hidden;
                    /*white-space:nowrap;*/
                    display: -webkit-box;
                    -webkit-line-clamp: 1;
                    -webkit-box-orient: vertical;
                }
                table.tbs thead{
                    background-color: #dedede;

                }
                table.tbs thead th{
                    text-align: center;
                }
                .table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th{
                    vertical-align: middle;
                }
                .sprice{

                    text-align: right;
                    font-weight: bold;
                    color :#888888;

                }
            </style>
        <?php 
        } else {
            ?>
            <h1 style="margin-top: 50px; margin-bottom: 50px; text-align: center">Empty BAG</h1>

        <?php 
        }
    }