public function testBuilder()
 {
     $expect = "<header>Header</header>\n" + "<article>Content</article>\n" + "<footer>Footer</footer>\n";
     $product = new Product();
     $director = new Director(new ConcreteBuilder($product));
     $director->construct();
     $result = $product->show();
     $this->assertEquals($result, $expect);
 }
Example #2
0
 /**
  * {inheritdoc}
  */
 public static function add($data)
 {
     if ($return = static::db()->insert(static::$table, $data)) {
         $prod_primary = Product::primary();
         foreach (unserialize($data['produk']) as $id => $qty) {
             $product = Product::show([$prod_primary => $id])->fetchOne();
             if (!$return) {
                 break;
             }
             $return = Product::edit(['stok' => $product->stok - $qty], [$prod_primary => $product->id_produk]);
         }
         return $return;
     }
     return false;
 }
Example #3
0
 public function index($alias = null)
 {
     $data = ['pages' => Page::show()->fetch(false)];
     if ($alias !== null) {
         $page = Page::show(['alias' => $alias])->fetchOne();
         if (!$page) {
             return $this->app->show404();
         }
         $data['heading'] = $page->judul;
         $data['content'] = $page->konten;
         return $this->render('page', $data);
     } else {
         $data['heading'] = 'Selamat datang di website resmi ' . conf('app.title');
         $data['products'] = Product::show()->fetch(5);
         $data['slides'] = Banner::show(['tipe' => 'slide', 'aktif' => 1])->fetch(3);
         return $this->render('home', $data);
     }
 }
Example #4
0
 public function cart()
 {
     $items = [];
     if ($_tmp = session('cart-items')) {
         $items = unserialize($_tmp);
     }
     if ($do = get('do')) {
         $id = get('id');
         if ($do != 'clear' and !$id) {
             redirect('shop');
         }
         session('cart-items', serialize(Order::cart($id, $do, $items)));
         return redirect('cart');
     }
     $data = ['items' => $items, 'heading' => 'Keranjang Belanja: ' . ($items ? count($items) . ' Produk' : 'Masih kosong :(')];
     $cartItems = array_keys($items);
     if (count($cartItems) > 0) {
         $data['data'] = Product::show(Product::primary() . ' in (' . implode(',', $cartItems) . ')');
     } else {
         $data['data'] = false;
     }
     return $this->render('cart', $data);
 }
Example #5
0
            <table class="data">
                <thead>
                    <tr>
                        <th>Gambar</th>
                        <th>Nama</th>
                        <th>Qty</th>
                        <th>Harga Satuan (Rp.)</th>
                        <th>Subtotal (Rp.)</th>
                    </tr>
                </thead>
                <tbody id="tbl-produk">
                <?php 
if ($data) {
    $products = unserialize($data->produk);
    $prodKey = Product::primary();
    $ordererProducts = Product::show($prodKey . ' in (' . implode(',', array_keys($products)) . ')');
    if ($ordererProducts->count() > 0) {
        foreach ($ordererProducts->fetch(false) as $product) {
            $prodId = $product->{$prodKey};
            $harga = $product->diskon ?: $product->harga;
            $diskon = $product->diskon ? '<br>(diskon dari: <del>' . format_number($product->harga) . '</del>)' : '';
            $subtotal = $products[$prodId] * $harga;
            ?>
                    <tr>
                        <td><span class="thumb" style="background-image: url(<?php 
            echo site_url('asset/uploads/' . $product->gambar);
            ?>
);"></span></td>
                        <td><?php 
            echo '<strong>' . $product->nama . '</strong><br>' . $product->keterangan;
            ?>
 public function products($do = '', $id = '')
 {
     $this->data['heading'] = 'Administrasi: Produk';
     switch ($do) {
         case 'form':
             if (post('submit')) {
                 $data = [User::primary() => User::current('id'), 'tgl_input' => date('Y-m-d'), 'id_kategori' => post('kategori'), 'nama' => post('nama'), 'gambar' => post('gambar'), 'tgl_masuk' => formatTanggal(post('tgl_masuk'), 'Y-m-d'), 'stok' => post('stok'), 'harga' => post('harga'), 'berat' => post('berat'), 'diskon' => post('diskon') ?: 0, 'keterangan' => post('keterangan', false)];
                 try {
                     $upload = new Upload('gambar');
                     $data['gambar'] = $upload->doUpload();
                 } catch (Exception $e) {
                     setAlert('error', $e->getMessage());
                     return redirect($this->uri->path());
                 }
                 if (Product::save($data, $id)) {
                     if ($id) {
                         setAlert('success', 'Berhasil memperbarui data produk <b>' . $data['nama'] . '</b>');
                     } else {
                         setAlert('success', 'Berhasil menambahkan produk <b>' . $data['nama'] . '</b>');
                     }
                     return redirect('admin-shop/products');
                 }
                 setAlert('error', 'Terjadi kesalahan dalam penyimpanan produk <b>' . $data['nama'] . '</b>');
                 return redirect($this->uri->path());
             }
             if ($id) {
                 $this->data['data'] = Product::show($id)->fetchOne();
             }
             return $this->render('product-form', $this->data);
             break;
         case 'delete':
             if (Product::del($id)) {
                 setAlert('success', 'Produk berhasil terhapus');
             } else {
                 setAlert('error', 'Terjadi kesalahan dalam penghapusan produk');
             }
             return redirect('admin-shop/products');
             break;
         default:
             $this->data['data'] = Product::show([], get('sort'));
             return $this->render('product-table', $this->data);
             break;
     }
 }