Commit 8eb3175a by Angel MAS

info sale product, models cart

parent 3f966f87
......@@ -10,6 +10,7 @@ use Onestartup\Shop\Model\ProductCategoryShop as Category;
use Onestartup\Shop\Model\ProductImageShop as Gallery;
use Onestartup\Shop\Model\ProductShop as Product;
use Onestartup\Shop\Model\ExtraField as Extra;
use Onestartup\Shop\Model\ProductShopInfo as ProductInfo;
class AdminProductController extends Controller
......@@ -72,10 +73,19 @@ class AdminProductController extends Controller
$categories = Category::pluck('name', 'id');
$extras = Extra::where('active', true)->orderBy('variable', 'asc')->get();
if ($product->infoSale != null) {
$info = $product->infoSale;
} else {
$info = new ProductInfo();
}
//return $info;
return view('shop::product.edit')
->with('categories', $categories)
->with('product', $product)
->with('info', $info)
->with('extras', $extras);
}
......@@ -248,4 +258,23 @@ class AdminProductController extends Controller
->with('message_success', 'Información actualizada');
}
public function extraInfo(Request $request)
{
$info = ProductInfo::find($request->product_id);
if ($info == null) {
$info = new ProductInfo();
}
$info->fill($request->all());
$info->save();
return redirect()
->back()
->with('message_success', 'Información de venta actualizada');
}
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateClientShopsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('client_shops', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 455);
$table->string('lastname', 455);
$table->string('email', 455);
$table->string('phone');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('client_shops');
}
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateSaleShopsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('sale_shops', function (Blueprint $table) {
$table->increments('id');
$table->tinyInteger('status');
$table->float('total');
$table->integer('client_id')->unsigned()->nullable();
$table->foreign('client_id')
->references('id')
->on('client_shops')
->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('sale_shops');
}
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateDetailShopsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('detail_shops', function (Blueprint $table) {
$table->increments('id');
$table->integer('quantity');
$table->integer('product_id')->unsigned();
$table->foreign('product_id')
->references('id')
->on('products_shop')
->onDelete('cascade');
$table->integer('sale_id')->unsigned();
$table->foreign('sale_id')
->references('id')
->on('sale_shops')
->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('detail_shops');
}
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProductShopInfosTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('product_shop_infos', function (Blueprint $table) {
$table->increments('id');
$table->string('unity', 355);
$table->float('purchase_price')->nullable();
$table->float('sale_price');
$table->integer('quantity')->nullable();
$table->integer('reserve_amount')->nullable();
$table->integer('product_id')->unsigned();
$table->foreign('product_id')
->references('id')
->on('products_shop')
->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('product_shop_infos');
}
}
<?php
namespace Onestartup\Shop\Model;
use Illuminate\Database\Eloquent\Model;
class ClientShop extends Model
{
protected $table = 'client_shops';
protected $fillable = [
'name',
'lastname',
'email',
'phone'
];
}
<?php
namespace Onestartup\Shop\Model;
use Illuminate\Database\Eloquent\Model;
class DetailShop extends Model
{
protected $table = "detail_shops";
protected $fillable = ['product_id', 'sale_id', 'quantity'];
}
......@@ -45,4 +45,9 @@ class ProductShop extends Model
{
return $this->hasMany('Onestartup\Shop\Model\ProductImageShop', 'product_id');
}
public function infoSale()
{
return $this->hasOne('Onestartup\Shop\Model\ProductShopInfo', 'product_id');
}
}
<?php
namespace Onestartup\Shop\Model;
use Illuminate\Database\Eloquent\Model;
class ProductShopInfo extends Model
{
protected $table = 'product_shop_infos';
protected $fillable = [
'unity',
'purchase_price',
'sale_price',
'quantity',
'reserve_amount',
'product_id'
];
public function product()
{
return $this->belongsTo('Onestartup\Shop\Model\ProductShop', 'product_id');
}
}
<?php
namespace Onestartup\Shop\Model;
use Illuminate\Database\Eloquent\Model;
class SaleShop extends Model
{
protected $table = 'sale_shops';
protected $fillable = ['state', 'total', 'client_id'];
}
......@@ -35,6 +35,10 @@ Route::group(['middleware' => ['web', 'auth', 'is_admin']], function(){
'Onestartup\Shop\Controller\AdminProductController@postVars')
->name('admin-shop-product.store.vars');
Route::post('admin/shop/product-extra',
'Onestartup\Shop\Controller\AdminProductController@extraInfo')
->name('admin-shop-product.extra.info');
});
Route::group(['middleware' => ['web']], function(){
......
......@@ -5,7 +5,7 @@
<div class='col-md-12'>
<div class='box'>
<div class='box-header dark'>
<h2>Actualizar información</h2>
<h2>Agregar nuevo producto</h2>
</div>
<div class='box-body'>
{!! Form::open(['route'=> 'admin.shop.product.store','method'=>'POST', "id"=>"target", 'enctype'=>'multipart/form-data']) !!}
......
<div class="row">
<div class="col-md-6">
<div class="form-group">
{!! Form::label('purchase_price', 'Precio de compra', ['class'=>'control-label'])!!}
{!! Form::text('purchase_price', null, ["class"=>"form-control", "required"=>"required"]) !!}
</div>
</div>
<div class="col-md-6">
<div class="form-group">
{!! Form::label('sale_price', 'Precio de venta', ['class'=>'control-label'])!!}
{!! Form::text('sale_price', null, ["class"=>"form-control", "required"=>"required"]) !!}
</div>
</div>
</div>
<div class='row'>
<div class='col-md-6'>
<div class="form-group" >
{!! Form::label('quantity', 'Cantidad', ['class'=>'control-label'])!!}
{!! Form::text('quantity', null, ["class"=>"form-control", "required"=>"required"]) !!}
</div>
</div>
<div class='col-md-6'>
<div class="form-group" >
{!! Form::label('reserve_amount', 'Cantidad de reserva', ['class'=>'control-label'])!!}
{!! Form::text('reserve_amount', null, ["class"=>"form-control", "required"=>"required"]) !!}
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
{!! Form::label('unity', 'Unidad', ['class'=>'control-label'])!!}
{!! Form::select('unity', ['Pieza'=>'Pieza', 'Kilogramo'=>'Kilogramo','Metro'=>'Metro', 'Litro'=>'Litro', 'Gramo'=>'Gramo'],null, ["class"=>"form-control", "required"=>"required"]) !!}
</div>
</div>
{!! Form::hidden('product_id', $product->id) !!}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment