<div class="wrapper">
    <div class="title-head">
        <h2 class="title">Hasil Pencarian: <?= $q ?></h2>
    </div>
    <div class="core">
        <?php $setting = $this->db->get('settings')->row_array(); ?>
        <div class="main-product">
            <?php if ($products->num_rows() > 0) { ?>
                <div id="bodyForShowProduct">
                    <?php foreach ($products->result_array() as $p) : ?>
                        <a href="<?= base_url(); ?>p/<?= $p['slug']; ?>">
                            <div class="item-product">
                                <img src="<?= $p['ex_img'] == 1 ? $p['img'] : base_url() . 'assets/images/product/' . $p['img']; ?>" class="card-img-top">
                                <div class="card-body">
                                    <?php if ($p['discount'] == 0) { ?>
                                        <p class="card-text line-3 mb-0"><?= $p['title']; ?></p>
                                        <p class="newPrice">Rp. <?= str_replace(",", ".", number_format($p['price'])); ?></p>
                                    <?php } else { ?>
                                        <p class="card-text mb-0"><?= $p['title']; ?></p>
                                        <p class="oldPrice mb-0">Rp. <span><?= str_replace(",", ".", number_format($p['price'])); ?></span> <small class="badge badge-danger"><?= $p['discount']; ?>%</small></p>
                                        <?php $diskonnya = ($p['price'] * $p['discount']) / 100 ?>
                                        <p class="newPrice">Rp. <?= str_replace(",", ".", number_format($p['price'] - $diskonnya)); ?></p>
                                    <?php } ?>
                                </div>
                            </div>
                        </a>
                    <?php endforeach; ?>
                </div>
                <div class="clearfix"></div>
            <?php } else { ?>
                <div class="alert alert-warning" style="margin-bottom: 200px">Upss. tidak ada hasil dari <?= $q ?></div>
            <?php } ?>
        </div>
    </div>
</div>