public function confimationProductSold($email_and_content) { $from_name = 'Covanti'; $admin_email = Option::where('meta_key', '=', 'admin_email')->first(); $logo = Option::where('meta_key', '=', 'logo')->first(); $from = $admin_email->meta_value; $subject = 'Konfirmasi Produk Terjual'; foreach ($email_and_content as $email_seller => $order_details) { $to = $email_seller; foreach ($order_details as $key => $order_detail) { $product = Product::find($order_detail->product_id); $order_details[$key]->product_name = $product->name; } $data = array('order_details' => $order_details, 'logo' => $logo->meta_value); $body = view('emails/confirmation_product_sold', $data); $this->send($from_name, $from, $to, $subject, $body); } }
public function delete($id) { $product = Product::find($id); $category = Category::where('id', $product->category_id)->first(); $inOrder = OrderDetail::where('product_id', $id)->where('review', null)->get(); $reviews = Reviews::where('product_id', $id)->get(); $subcategory = Subcategory::where('id', $product->subcategory_id)->first(); if (!$product) { return redirect('master/produk/list')->with('error', 'Data tidak ada'); } else { $image = unserialize($product->image); $path = base_path() . '/storage/photo_product/'; if (count($inOrder) > 0) { $product->status = 'unactive'; if ($product->save()) { return redirect('master/produk/list')->with('success', 'Produk tidak bisa di hapus karena masih dalam order, produk sementara di non aktifkan'); } else { return redirect('master/produk/list')->with('error', '404'); } } elseif (count($inOrder) == 0) { if ($product->delete()) { foreach ($reviews as $review) { $reviews->delete(); } foreach ($inOrder as $order_product) { foreach ($order_product as $orders) { $PaymentConfirmation = PaymentConfirmation::where('order_id', $orders->id)->first(); $PaymentConfirmation->delete(); } $orders = Order::where('id', $order_product->order_id)->get(); $orders->delete(); } $total_product = $category->total_product - 1; $category->total_product = $total_product; $category->save(); $total_subcategory = $subcategory->total_product - 1; $subcategory->total_product = $total_subcategory; $subcategory->save(); if (!$image == NULL) { foreach ($image as $image) { File::delete($path . $image); } } return redirect('master/produk/list')->with('success', 'Produk ' . $product->name . ' Berhasil Dihapus'); } else { return redirect('master/produk/list')->with('error', '404'); } } } }