Cart Packages files

This commit is contained in:
prashant-webkul 2018-09-06 11:50:30 +05:30
parent 888dfc6b0f
commit 29d83d7b5f
17 changed files with 330 additions and 34 deletions

View File

@ -56,7 +56,8 @@
"Webkul\\Customer\\": "packages/Webkul/Customer/src",
"Webkul\\Inventory\\": "packages/Webkul/Inventory/src",
"Webkul\\Product\\": "packages/Webkul/Product/src",
"Webkul\\Theme\\": "packages/Webkul/Theme/src"
"Webkul\\Theme\\": "packages/Webkul/Theme/src",
"Webkul\\Cart\\": "packages/Webkul/Cart/src"
}
},
"autoload-dev": {

View File

@ -172,6 +172,8 @@ return [
//Laravel Intervention
Intervention\Image\ImageServiceProvider::class,
//Repository
Prettus\Repository\Providers\RepositoryServiceProvider::class,
//Webkul packages
@ -187,7 +189,8 @@ return [
Webkul\Product\Providers\ProductServiceProvider::class,
Webkul\Shop\Providers\ShopServiceProvider::class,
Webkul\Customer\Providers\CustomerServiceProvider::class,
Webkul\Theme\Providers\ThemeServiceProvider::class
Webkul\Theme\Providers\ThemeServiceProvider::class,
Webkul\Cart\Providers\CartServiceProvider::class,
],
/*

View File

@ -66,7 +66,6 @@ class ProductDataGrid
'primaryKey' => 'prods.attribute_family_id',
'condition' => '=',
'secondaryKey' => 'attfam.id',
'withAttributes' => false
],
//for getting the attribute values.
@ -76,7 +75,12 @@ class ProductDataGrid
'primaryKey' => 'prods.id',
'condition' => '=',
'secondaryKey' => 'pav.product_id',
'withAttributes' => true //use this boolean to select records as columns
'withAttributes' => [
'condition' => [
'attribute_id' => 2,
'select' => 'name',
]
]
],
// for getting the inventory quantity of a product
@ -86,7 +90,6 @@ class ProductDataGrid
'primaryKey' => 'prods.id',
'condition' => '=',
'secondaryKey' => 'pi.product_id',
'withAttributes' => false
],
],
@ -120,17 +123,9 @@ class ProductDataGrid
'name' => 'pi.qty',
'alias' => 'ProductQuantity',
'type' => 'string',
'label' => 'Product Quatity',
'label' => 'Product Quantity',
'sortable' => false,
],
[
'name' => 'pav.attribute_id',
'alias' => 'AttributeID',
'type' => 'string',
'label' => 'Attribute ID',
'sortable' => false,
],
],
'filterable' => [

View File

@ -0,0 +1,26 @@
{
"name": "webkul/laravel-cart",
"description": "Cart Package for customer.",
"license": "MIT",
"authors": [
{
"name": "prashant-webkul",
"email": "prashant.singh852@webkul.com"
}
],
"require": {},
"autoload": {
"psr-4": {
"Webkul\\Cart\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Webkul\\Cart\\Providers\\CartServiceProvider"
],
"aliases": {}
}
},
"minimum-stability": "dev"
}

View File

@ -0,0 +1,38 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCartTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('cart', function (Blueprint $table) {
$table->increments('id');
$table->integer('customer_id')->unsigned()->nullable();
$table->foreign('customer_id')->references('id')->on('customers');
$table->string('session_id')->nullable();
$table->integer('channel_id')->unsigned();
$table->foreign('channel_id')->references('id')->on('channels');
$table->string('coupon_code')->nullable();
$table->boolean('is_gift')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('cart');
}
}

View File

@ -0,0 +1,39 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCartItemsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('cart_items', function (Blueprint $table) {
$table->increments('id');
$table->integer('product_id')->unsigned();
$table->foreign('product_id')->references('id')->on('products');
$table->integer('quantity')->unsigned()->default(1);
$table->integer('cart_id')->unsigned();
$table->foreign('cart_id')->references('id')->on('cart');
$table->integer('tax_category_id')->unsigned()->nullable();
$table->foreign('tax_category_id')->references('id')->on('tax_categories');
$table->string('coupon_code')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('cart_items');
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace Webkul\Cart\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Webkul\Cart\Repositories\CartRepository;
use Webkul\Cart\Repositories\CartItemsRepository;
use Session;
/**
* Cart controller for the customer
* and guest users for adding and
* removing the products in the
* cart.
*
* @author Prashant Singh <prashant.singh852@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class CartController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
protected $_config;
protected $cart;
public function __construct(CartRepository $cart)
{
$this->middleware(['customer', 'guest']);
$this->_config = request('_config');
$this->cart = $cart;
}
public function add() {
return "Adding Items to Cart";
}
}

View File

@ -0,0 +1,12 @@
<?php
namespace Webkul\Cart\Models;
class Cart
{
protected $table = 'cart';
protected $fillable = ['customer_id','session_id','channel_id','coupon_code','is_gift'];
protected $hidden = ['coupon_code'];
}

View File

@ -0,0 +1,10 @@
<?php
namespace Webkul\Cart\Models;
class CartItems
{
protected $table = 'cart_items';
protected $fillable = ['product_id','quantity','cart_id','tax_category_id','coupon_code'];
}

View File

@ -0,0 +1,28 @@
<?php
namespace Webkul\Cart\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Routing\Router;
use Webkul\Customer\Http\Middleware\RedirectIfNotCustomer;
class CartServiceProvider extends ServiceProvider
{
public function boot(Router $router)
{
$router->aliasMiddleware('customer', RedirectIfNotCustomer::class);
$this->loadMigrationsFrom(__DIR__ . '/../Database/migrations');
}
/**
* Register services.
*
* @return void
*/
public function register()
{
// $this->app->bind('datagrid', 'Webkul\Ui\DataGrid\DataGrid');
}
}

View File

@ -0,0 +1,54 @@
<?php
namespace Webkul\Cart\Repositories;
use Webkul\Core\Eloquent\Repository;
/**
* Cart Items Reposotory
*
* @author Prashant Singh <prashant.singh852@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class CartItemsRepository extends Repository
{
/**
* Specify Model class name
*
* @return mixed
*/
function model()
{
return 'Webkul\Cart\Models\CartItems';
}
/**
* @param array $data
* @return mixed
*/
public function create(array $data)
{
$cartitems = $this->model->create($data);
return $cartitems;
}
/**
* @param array $data
* @param $id
* @param string $attribute
* @return mixed
*/
public function update(array $data, $id, $attribute = "id")
{
$cartitems = $this->find($id);
$cartitems->update($data);
return $cartitems;
}
}

View File

@ -0,0 +1,54 @@
<?php
namespace Webkul\Cart\Repositories;
use Webkul\Core\Eloquent\Repository;
/**
* Cart Reposotory
*
* @author Prashant Singh <prashant.singh852@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class CartRepository extends Repository
{
/**
* Specify Model class name
*
* @return mixed
*/
function model()
{
return 'Webkul\Cart\Models\Cart';
}
/**
* @param array $data
* @return mixed
*/
public function create(array $data)
{
$cart = $this->model->create($data);
return $cart;
}
/**
* @param array $data
* @param $id
* @param string $attribute
* @return mixed
*/
public function update(array $data, $id, $attribute = "id")
{
$cart = $this->find($id);
$cart->update($data);
return $cart;
}
}

View File

@ -160,22 +160,6 @@ class TaxCategoryController extends Controller
}
}
/**
* To perform the rollback
* if in anycase the taxMap
* records creates any problem.
*
* @return mixed
*/
public function performRollback($taxRuleId) {
if($this->taxRule->delete($taxRuleId)) {
session()->flash('error', 'Cannot Create Tax Rule');
return redirect()->route('admin.taxrule.index');
}
}
/**
* Destroy a tax rule
*

View File

@ -85,10 +85,10 @@ class ProductForm extends FormRequest
foreach ($attributes as $attribute) {
if($attribute->code == 'sku')
continue;
if($product->type == 'configurable' && in_array($attribute->code, ['price', 'cost', 'special_price', 'special_price_from', 'special_price_to', 'width', 'height', 'depth', 'weight']))
continue;
$validations = [];
if($attribute->is_required) {
array_push($validations, 'required');

View File

@ -1,5 +1,6 @@
<section class="featured-products">
<div class="featured-heading">
{{ $session_id = session()->getId() }}<br/>
New Products<br/>
<span class="featured-seperator" style="color:lightgrey;">_____</span>
</div>
@ -67,7 +68,7 @@
<span><img src="vendor/webkul/shop/assets/images/wishadd.svg" /></span>
</div>
</div>
<div class="product-card">
<div class="product-image">
<img src="vendor/webkul/shop/assets/images/new.png" />

View File

@ -661,6 +661,10 @@ class ProductGrid
// }
// }
// else
if(array_key_exists('withAttributes', $join)) {
$this->query->{$join['join']}($join['table'], $join['primaryKey'], $join['condition'], $join['secondaryKey'])->where('attribute_id','=',2)->addSelect('name as product_name');
}
else
$this->query->{$join['join']}($join['table'], $join['primaryKey'], $join['condition'], $join['secondaryKey']);
}
@ -949,7 +953,7 @@ class ProductGrid
$this->allAttributes = $this->getAttributes();
$this->getDbQueryResults();
// dd($this->results);
dd($this->results);
return view('ui::datagrid.index', [
'css' => $this->css,
'results' => $this->results,

View File

@ -106,6 +106,7 @@
<th class="grid_head" data-column-name="{{ $column->alias }}" data-column-label="{{ $column->label }}">{!! $column->sorting() !!}</th>
@endif
@endforeach
<td>Name</td>
{{-- @if(isset($attribute_columns))
@foreach($attribute_columns as $key => $value)
<th class="grid_head"
@ -140,6 +141,7 @@
<td>{{ $result->{$atc} }}</td>
@endforeach
@endif --}}
<td></td>
<td class="action">
@foreach($actions as $action)