コード例 #1
0
ファイル: StoreController.php プロジェクト: vuongabc92/ot
 /**
  * Save product info
  *
  * @param Illuminate\Http\Request $request
  *
  * @return type
  */
 public function ajaxSaveProduct(Request $request)
 {
     //Only accept ajax request
     if ($request->ajax() && $request->isMethod('POST')) {
         if (store() === null) {
             return pong(0, _t('not_found'), 404);
         }
         $store = store();
         $productId = (int) $request->get('id');
         if ($productId) {
             $product = $store->products->find($productId);
         } else {
             $product = new Product();
         }
         if ($product === null) {
             return pong(0, _t('not_found'), 404);
         }
         $rules = $this->_product->getRules();
         $messages = $this->_product->getMessages();
         if ($productId) {
             $rules = remove_rules($rules, 'product_image_1');
         }
         $validator = Validator::make($request->all(), $rules, $messages);
         $tempImages = [$request->get('product_image_1'), $request->get('product_image_2'), $request->get('product_image_3'), $request->get('product_image_4')];
         if ($validator->fails()) {
             return pong(0, $validator->messages(), is_null($product) ? 404 : 403);
         }
         /**
          *  1. Copy product images from temporary folder to product folder.
          *  2. Delete old product image(s).
          *  3. Save product.
          */
         try {
             // 1
             $images = $this->_copyTempProductImages($tempImages);
             // 2
             if ($productId) {
                 $this->_deleteOldImages($images, $product->images);
             }
             // 3
             $product->store_id = $store->id;
             $product->name = $request->get('name');
             $product->price = $request->get('price');
             $product->old_price = $request->get('old_price');
             $product->description = $request->get('description');
             $product->setImages($images);
             $product->save();
         } catch (Exception $ex) {
             return pong(0, _t('opp'), 500);
         }
         return pong(1, ['messages' => _t('saved_info'), 'data' => ['id' => $product->id, 'name' => $product->name, 'price' => product_price($product->price), 'old_price' => product_price($product->old_price), 'image' => ($i = $product->toImage()->image_1) !== null ? product_image($i->medium) : '']]);
     }
 }
コード例 #2
0
ファイル: product.php プロジェクト: rezgroup/project
 <tr>
  <th>ID</th>
  <th>Kode Project</th>
  <th>Image</th>
  <th>Nama</th>
  <th>Framework</th>
  <th>Description</th>
  <th>Edit </th>
 </tr>
 <?php 
if (!isset($q)) {
    exit;
}
if ($q->num_rows() > 0) {
    $no = 1;
    foreach ($q->result() as $row) {
        $id = $row->ID_proj;
        $code = $row->project_code;
        $p_title = $row->project_title;
        $image = $row->image;
        $fw = $row->f_name;
        $img = '<img class="img-rounded" data-src="holder.js/140x140" alt="140x140" src="' . product_image($image) . '" 
			style="max-width: 50px; max-height: 50px;">';
        $desc = anchor('', 'Lihat Diskripsi');
        echo "\n\t\t  <tr>\n\t\t\t  <td>" . $no . "</td>\n\t\t\t  <td>" . $code . "</td>\n\t\t\t  <td>" . $img . "</td>\n\t\t\t  <td>" . $p_title . "</td>\n\t\t\t  <td>" . $fw . "</td>\n\t\t\t  <td>" . $desc . "</td>\n\t\t\t  <td><a class='btn btn-primary' id='button' href='" . site('editProduct_form?id=' . $id) . "'>Edit</a> </td>\n\t\t </tr>";
        $no++;
    }
}
?>
</table>