Modified inventory selection during shipment creation

This commit is contained in:
jitendra 2018-12-26 18:34:49 +05:30
commit 0b3ba4f06a
38 changed files with 448 additions and 275 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
{ {
"/js/admin.js": "/js/admin.js?id=c70dacdf945a32e04b77", "/js/admin.js": "/js/admin.js?id=c70dacdf945a32e04b77",
"/css/admin.css": "/css/admin.css?id=ccb086d72702e662082e" "/css/admin.css": "/css/admin.css?id=d40a640933cbcc121f1d"
} }

View File

@ -150,22 +150,22 @@ class AttributeDataGrid
'type' => 'string', 'type' => 'string',
'label' => 'Type', 'label' => 'Type',
], [ ], [
'name' => 'is_required', 'column' => 'is_required',
'alias' => 'attributeIsRequired', 'alias' => 'attributeIsRequired',
'type' => 'boolean', 'type' => 'boolean',
'label' => 'Required', 'label' => 'Required',
], [ ], [
'name' => 'is_unique', 'column' => 'is_unique',
'alias' => 'attributeIsUnique', 'alias' => 'attributeIsUnique',
'type' => 'boolean', 'type' => 'boolean',
'label' => 'Unique', 'label' => 'Unique',
], [ ], [
'name' => 'value_per_locale', 'column' => 'value_per_locale',
'alias' => 'attributeValuePerLocale', 'alias' => 'attributeValuePerLocale',
'type' => 'boolean', 'type' => 'boolean',
'label' => 'Locale based', 'label' => 'Locale based',
], [ ], [
'name' => 'value_per_channel', 'column' => 'value_per_channel',
'alias' => 'attributeValuePerChannel', 'alias' => 'attributeValuePerChannel',
'type' => 'boolean', 'type' => 'boolean',
'label' => 'Channel based', 'label' => 'Channel based',

View File

@ -123,7 +123,7 @@ class ProductDataGrid
'type' => 'string', 'type' => 'string',
'label' => 'Product Quantity', 'label' => 'Product Quantity',
'sortable' => true, 'sortable' => true,
], ]
], ],
'filterable' => [ 'filterable' => [
@ -149,7 +149,7 @@ class ProductDataGrid
'type' => 'string', 'type' => 'string',
'label' => 'Product Type', 'label' => 'Product Type',
], [ ], [
'name' => 'prods.status', 'column' => 'prods.status',
'alias' => 'ProductStatus', 'alias' => 'ProductStatus',
'type' => 'boolean', 'type' => 'boolean',
'label' => 'Status' 'label' => 'Status'

View File

@ -83,7 +83,7 @@ class ConfigurationController extends Controller
$slugs = $this->getDefaultConfigSlugs(); $slugs = $this->getDefaultConfigSlugs();
if(count($slugs)) { if(count($slugs)) {
return redirect()->route('admin.configuration.index', $slugs); return redirect()->route('admin.configuration.index', $slugs);
} }
return view($this->_config['view'], ['config' => $this->configTree]); return view($this->_config['view'], ['config' => $this->configTree]);

View File

@ -76,7 +76,9 @@ class OrderController extends Controller
*/ */
public function cancel($id) public function cancel($id)
{ {
if($this->order->cancel($id)) { $result = $this->order->cancel($id);
if($result) {
session()->flash('success', trans('Order canceled successfully.')); session()->flash('success', trans('Order canceled successfully.'));
} else { } else {
session()->flash('error', trans('Order can not be canceled.')); session()->flash('error', trans('Order can not be canceled.'));

View File

@ -157,7 +157,6 @@ class ShipmentController extends Controller
? $orderItem->child->product ? $orderItem->child->product
: $orderItem->product; : $orderItem->product;
// Check if requested qty is available, if not ship available qty
$inventory = $product->inventories() $inventory = $product->inventories()
->where('inventory_source_id', $data['shipment']['source']) ->where('inventory_source_id', $data['shipment']['source'])
->first(); ->first();

View File

@ -324,6 +324,10 @@ Route::group(['middleware' => ['web']], function () {
//delete backend user //delete backend user
Route::get('/users/delete/{id}', 'Webkul\User\Http\Controllers\UserController@destroy')->name('admin.users.delete'); Route::get('/users/delete/{id}', 'Webkul\User\Http\Controllers\UserController@destroy')->name('admin.users.delete');
Route::post('/confirm/destroy', 'Webkul\User\Http\Controllers\UserController@destroySelf')->defaults('_config', [
'redirect' => 'admin.users.index'
])->name('admin.users.confirm.destroy');
// User Role Routes // User Role Routes
Route::get('/roles', 'Webkul\User\Http\Controllers\RoleController@index')->defaults('_config', [ Route::get('/roles', 'Webkul\User\Http\Controllers\RoleController@index')->defaults('_config', [
'view' => 'admin::users.roles.index' 'view' => 'admin::users.roles.index'

View File

@ -73,24 +73,29 @@ class Product {
$variants = []; $variants = [];
$this->productGrid->create($gridObject); $found = $this->productGrid->findOneByField('product_id', $product->id);
if($product->type == 'configurable') { //extra measure to stop duplicate entries
$variants = $product->variants()->get(); if($found == null) {
$this->productGrid->create($gridObject);
foreach($variants as $variant) { if($product->type == 'configurable') {
$variantObj = [ $variants = $product->variants()->get();
'product_id' => $variant->id,
'sku' => $variant->sku,
'type' => $variant->type,
'attribute_family_name' => $variant->toArray()['attribute_family']['name'],
'name' => $variant->name,
'quantity' => 0,
'status' => $variant->status,
'price' => $variant->price,
];
$this->productGrid->create($variantObj); foreach($variants as $variant) {
$variantObj = [
'product_id' => $variant->id,
'sku' => $variant->sku,
'type' => $variant->type,
'attribute_family_name' => $variant->toArray()['attribute_family']['name'],
'name' => $variant->name,
'quantity' => 0,
'status' => $variant->status,
'price' => $variant->price,
];
$this->productGrid->create($variantObj);
}
} }
} }
@ -254,6 +259,13 @@ class Product {
$gridObject = []; $gridObject = [];
} }
$this->findRepeated();
return true; return true;
} }
public function findRepeated() {
}
} }

View File

@ -50,6 +50,7 @@ return [
'change-password' => 'Change Account Password', 'change-password' => 'Change Account Password',
'current-password' => 'Current Password' 'current-password' => 'Current Password'
], ],
'users' => [ 'users' => [
'forget-password' => [ 'forget-password' => [
'title' => 'Forget Password', 'title' => 'Forget Password',
@ -60,6 +61,7 @@ return [
'back-link-title' => 'Back to Sign In', 'back-link-title' => 'Back to Sign In',
'submit-btn-title' => 'Email Password Reset Link' 'submit-btn-title' => 'Email Password Reset Link'
], ],
'reset-password' => [ 'reset-password' => [
'title' => 'Reset Password', 'title' => 'Reset Password',
'title' => 'Reset Password', 'title' => 'Reset Password',
@ -69,6 +71,7 @@ return [
'back-link-title' => 'Back to Sign In', 'back-link-title' => 'Back to Sign In',
'submit-btn-title' => 'Reset Password' 'submit-btn-title' => 'Reset Password'
], ],
'roles' => [ 'roles' => [
'title' => 'Roles', 'title' => 'Roles',
'add-role-title' => 'Add Role', 'add-role-title' => 'Add Role',
@ -82,6 +85,7 @@ return [
'custom' => 'Custom', 'custom' => 'Custom',
'all' => 'All' 'all' => 'All'
], ],
'users' => [ 'users' => [
'title' => 'User', 'title' => 'User',
'add-user-title' => 'Add User', 'add-user-title' => 'Add User',
@ -95,8 +99,15 @@ return [
'status-and-role' => 'Status and Role', 'status-and-role' => 'Status and Role',
'role' => 'Role', 'role' => 'Role',
'status' => 'Status', 'status' => 'Status',
'account-is-active' => 'Account is Active' 'account-is-active' => 'Account is Active',
'current-password' => 'Enter Current Password',
'confirm-delete' => 'Confirm Delete This Account',
'confirm-delete-title' => 'Confirm password before delete',
'delete-last' => 'At least one admin is required.',
'delete-success' => 'Success! User deleted',
'incorrect-password' => 'The password you entered is incorrect'
], ],
'sessions' => [ 'sessions' => [
'title' => 'Sign In', 'title' => 'Sign In',
'email' => 'Email', 'email' => 'Email',
@ -106,6 +117,7 @@ return [
'submit-btn-title' => 'Sign In' 'submit-btn-title' => 'Sign In'
] ]
], ],
'sales' => [ 'sales' => [
'orders' => [ 'orders' => [
'title' => 'Orders', 'title' => 'Orders',
@ -157,6 +169,7 @@ return [
'total-due' => 'Total Due', 'total-due' => 'Total Due',
'cancel-confirm-msg' => 'Are you sure you want to cancel this order ?' 'cancel-confirm-msg' => 'Are you sure you want to cancel this order ?'
], ],
'invoices' => [ 'invoices' => [
'title' => 'Invoices', 'title' => 'Invoices',
'id' => 'Id', 'id' => 'Id',
@ -178,6 +191,7 @@ return [
'print' => 'Print', 'print' => 'Print',
'order-date' => 'Order Date' 'order-date' => 'Order Date'
], ],
'shipments' => [ 'shipments' => [
'title' => 'Shipments', 'title' => 'Shipments',
'id' => 'Id', 'id' => 'Id',
@ -201,6 +215,7 @@ return [
'view-title' => 'Shipment #:shipment_id' 'view-title' => 'Shipment #:shipment_id'
] ]
], ],
'catalog' => [ 'catalog' => [
'products' => [ 'products' => [
'title' => 'Products', 'title' => 'Products',
@ -232,8 +247,10 @@ return [
'add-variant-title' => 'Add Variant', 'add-variant-title' => 'Add Variant',
'variant-already-exist-message' => 'Variant with same attribute options already exists.', 'variant-already-exist-message' => 'Variant with same attribute options already exists.',
'add-image-btn-title' => 'Add Image', 'add-image-btn-title' => 'Add Image',
'mass-delete-success' => 'All the selected index of products have been deleted successfully' 'mass-delete-success' => 'All the selected index of products have been deleted successfully',
'mass-update-success' => 'All the selected index of products have been updated successfully'
], ],
'attributes' => [ 'attributes' => [
'title' => 'Attributes', 'title' => 'Attributes',
'add-title' => 'Add Attribute', 'add-title' => 'Add Attribute',

View File

@ -10,15 +10,15 @@
$key = $item['key']; $key = $item['key'];
$key = explode(".", $key); $key = explode(".", $key);
array_shift($key);
$firstField = current($key); $firstField = current($key);
$secondField = next($key); $secondField = next($key);
$key = implode(".", $key); $thirdField = end($key);
$name = $item['key'] . '.' . $field['name'];
$name = $key . '.' . $field['name'];
?> ?>
<div class="control-group {{ $field['type'] }}" :class="[errors.has('{{ $firstField }}[{{ $secondField }}][{{ $field['name'] }}]') ? 'has-error' : '']"> <div class="control-group {{ $field['type'] }}" :class="[errors.has('{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]') ? 'has-error' : '']">
<label for="{{ $name }}" {{ !isset($field['validation']) || strpos('required', $field['validation']) < 0 ? '' : 'class=required' }}> <label for="{{ $name }}" {{ !isset($field['validation']) || strpos('required', $field['validation']) < 0 ? '' : 'class=required' }}>
{{ $field['title'] }} {{ $field['title'] }}
@ -44,15 +44,15 @@
@if ($field['type'] == 'text') @if ($field['type'] == 'text')
<input type="text" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name) }}" data-vv-as="&quot;{{ $field['name'] }}&quot;"> <input type="text" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name) }}" data-vv-as="&quot;{{ $field['name'] }}&quot;">
@elseif ($field['type'] == 'textarea') @elseif ($field['type'] == 'textarea')
<textarea v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $field['name'] }}]" data-vv-as="&quot;{{ $field['name'] }}&quot;">{{ old($name) ?: core()->getConfigData($name) }}</textarea> <textarea v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" data-vv-as="&quot;{{ $field['name'] }}&quot;">{{ old($name) ?: core()->getConfigData($name) }}</textarea>
@elseif ($field['type'] == 'select') @elseif ($field['type'] == 'select')
<select v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $field['name'] }}]" data-vv-as="&quot;{{ $field['name'] }}&quot;" > <select v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" data-vv-as="&quot;{{ $field['name'] }}&quot;" >
@foreach($field['options'] as $option) @foreach($field['options'] as $option)
@ -75,5 +75,5 @@
@endif @endif
<span class="control-error" v-if="errors.has('{{ $firstField }}[{{ $secondField }}][{{ $field['name'] }}]')">@{{ errors.first('{!! $firstField !!}[{!! $secondField !!}][{!! $field['name'] !!}]') }}</span> <span class="control-error" v-if="errors.has('{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]')">@{{ errors.first('{!! $firstField !!}[{!! $secondField !!}][{!! $thirdField !!}][{!! $field['name'] !!}]') }}</span>
</div> </div>

View File

@ -0,0 +1,37 @@
@extends('admin::layouts.content')
@section('page_title')
{{ __('admin::app.customers.customers.title') }}
@stop
@section('content')
<div class="content">
<div class="page-header">
<div class="page-title">
<h1>{{ __('admin::app.users.users.confirm-delete-title') }}</h1>
</div>
<div class="page-action">
</div>
</div>
<div class="page-content">
<form action="{{ route('admin.users.confirm.destroy') }}" method="POST" @submit.prevent="onSubmit">
@csrf
<div class="control-group" :class="[errors.has('password') ? 'has-error' : '']">
<label for="password" class="required">
{{ __('admin::app.users.users.current-password') }}
</label>
<input type="password" v-validate="'required'" class="control" id="password" name="password" data-vv-as="&quot;{{ __('admin::app.users.users.password') }}&quot;"/>
<span class="control-error" v-if="errors.has('password')">
@{{ errors.first('password') }}
</span>
</div>
<input type="submit" class="btn btn-md btn-primary" value="{{ __('admin::app.users.users.confirm-delete') }}">
</form>
</div>
</div>
@endsection

View File

@ -30,6 +30,9 @@
<div class="dropdown-container"> <div class="dropdown-container">
<label>Account</label> <label>Account</label>
<ul> <ul>
<li>
<a href="{{ route('shop.home.index') }}" target="_blank">Visit Shop</a>
</li>
<li> <li>
<a href="{{ route('admin.account.edit') }}">My Account</a> <a href="{{ route('admin.account.edit') }}">My Account</a>
</li> </li>

View File

@ -1,8 +1,8 @@
const { mix } = require("laravel-mix"); const { mix } = require("laravel-mix");
require("laravel-mix-merge-manifest"); require("laravel-mix-merge-manifest");
// var publicPath = 'publishable/assets'; var publicPath = 'publishable/assets';
var publicPath = "../../../public/vendor/webkul/admin/assets"; // var publicPath = "../../../public/vendor/webkul/admin/assets";
mix.setPublicPath(publicPath).mergeManifest(); mix.setPublicPath(publicPath).mergeManifest();
mix.disableNotifications(); mix.disableNotifications();

View File

@ -545,8 +545,13 @@ class Core
} }
} }
if(!$coreConfigValue) if (!$coreConfigValue) {
$fields = explode(".", $field);
array_shift($fields);
$field = implode(".", $fields);
return Config::get($field); return Config::get($field);
}
return $coreConfigValue->value; return $coreConfigValue->value;
} }
@ -692,12 +697,7 @@ class Core
if (isset($coreData['fields'])) { if (isset($coreData['fields'])) {
foreach ($coreData['fields'] as $field) { foreach ($coreData['fields'] as $field) {
$key = $coreData['key']; $name = $coreData['key'] . '.' . $field['name'];
$key = explode(".", $key);
array_shift($key);
$key = implode(".", $key);
$name = $key . '.' . $field['name'];
if ($name == $fieldName ) { if ($name == $fieldName ) {
return $field; return $field;

View File

@ -38,83 +38,103 @@ class CoreConfigRepository extends Repository
unset($data['channel']); unset($data['channel']);
} }
foreach ($data as $method => $value) foreach ($data as $method => $fieldData) {
{ $recurssiveData = $this->recuressiveArray($fieldData , $method);
foreach ($value as $key => $formData)
{ foreach ($recurssiveData as $fieldName => $value) {
foreach (array_keys($formData) as $title) $field = core()->getConfigField($fieldName);
$channel_based = false;
$locale_based = false;
if (isset($field['channel_based']) && $field['channel_based']) {
$channel_based = true;
}
if (isset($field['locale_based']) && $field['locale_based']) {
$locale_based = true;
}
if (isset($field['channel_based']) && $field['channel_based'])
{ {
$fieldName = $method . '.' . $key . '.' .$title; if (isset($field['locale_based']) && $field['locale_based'])
$value = $formData[$title]; {
$field = core()->getConfigField($fieldName); $coreConfigValue = $this->model
->where('code', $fieldName)
$channel_based = false; ->where('locale_code', $locale)
$locale_based = false; ->where('channel_code', $channel)
->get();
if (isset($field['channel_based']) && $field['channel_based']) {
$channel_based = true;
} }
else
if (isset($field['locale_based']) && $field['locale_based']) { {
$locale_based = true; $coreConfigValue = $this->model
->where('code', $fieldName)
->where('channel_code', $channel)
->get();
} }
} else
if (isset($field['channel_based']) && $field['channel_based']) {
if (isset($field['locale_based']) && $field['locale_based'])
{ {
if (isset($field['locale_based']) && $field['locale_based']) $coreConfigValue = $this->model
{ ->where('code', $fieldName)
$coreConfigValue = $this->model ->where('locale_code', $locale)
->where('code', $fieldName) ->get();
->where('locale_code', $locale)
->where('channel_code', $channel)
->get();
}
else
{
$coreConfigValue = $this->model
->where('code', $fieldName)
->where('channel_code', $channel)
->get();
}
} else
{
if (isset($field['locale_based']) && $field['locale_based'])
{
$coreConfigValue = $this->model
->where('code', $fieldName)
->where('locale_code', $locale)
->get();
}
else
{
$coreConfigValue = $this->model
->where('code', $fieldName)
->get();
}
} }
else
if (!count($coreConfigValue) > 0)
{ {
$this->model->create([ $coreConfigValue = $this->model
'code' => $fieldName, ->where('code', $fieldName)
'value' => $value, ->get();
'locale_code' => $locale_based ? $locale : null, }
'channel_code' => $channel_based ? $channel : null }
]);
} else
{
$updataData['code'] = $fieldName;
$updataData['value'] = $value;
$updataData['locale_code'] = $locale_based ? $locale : null;
$updataData['channel_code'] = $channel_based ? $channel : null;
foreach ($coreConfigValue as $coreConfig) if (!count($coreConfigValue) > 0)
{ {
$coreConfig->update($updataData); $this->model->create([
} 'code' => $fieldName,
'value' => $value,
'locale_code' => $locale_based ? $locale : null,
'channel_code' => $channel_based ? $channel : null
]);
} else
{
$updataData['code'] = $fieldName;
$updataData['value'] = $value;
$updataData['locale_code'] = $locale_based ? $locale : null;
$updataData['channel_code'] = $channel_based ? $channel : null;
foreach ($coreConfigValue as $coreConfig)
{
$coreConfig->update($updataData);
} }
} }
} }
} }
} }
/**
* @param array $formData
* @param string $method
* @return array
*/
public function recuressiveArray(array $formData, $method) {
static $data =[];
foreach ($formData as $form => $formValue) {
$value = $method . '.' . $form;
if (is_array($formValue)) {
$this->recuressiveArray($formValue, $value);
} else {
$data[$value] = $formValue;
}
}
return $data;
}
} }

View File

@ -68,7 +68,7 @@ abstract class Payment
*/ */
public function getConfigData($field) public function getConfigData($field)
{ {
return core()->getConfigData('paymentmethods.' . $this->getCode() . '.' . $field); return core()->getConfigData('sales.paymentmethods.' . $this->getCode() . '.' . $field);
} }
abstract public function getRedirectUrl(); abstract public function getRedirectUrl();

View File

@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
class CreateProductSalableInventoriesTable extends Migration class CreateProductOrderedInventoriesTable extends Migration
{ {
/** /**
* Run the migrations. * Run the migrations.
@ -13,10 +13,9 @@ class CreateProductSalableInventoriesTable extends Migration
*/ */
public function up() public function up()
{ {
Schema::create('product_salable_inventories', function (Blueprint $table) { Schema::create('product_ordered_inventories', function (Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->integer('qty')->default(0); $table->integer('qty')->default(0);
$table->integer('sold_qty')->default(0);
$table->integer('product_id')->unsigned(); $table->integer('product_id')->unsigned();
$table->integer('channel_id')->unsigned(); $table->integer('channel_id')->unsigned();
@ -33,6 +32,6 @@ class CreateProductSalableInventoriesTable extends Migration
*/ */
public function down() public function down()
{ {
Schema::dropIfExists('product_salable_inventories'); Schema::dropIfExists('product_ordered_inventories');
} }
} }

View File

@ -142,7 +142,6 @@ class ProductController extends Controller
'sku' => ['required', 'unique:products,sku', new \Webkul\Core\Contracts\Validations\Slug] 'sku' => ['required', 'unique:products,sku', new \Webkul\Core\Contracts\Validations\Slug]
]); ]);
//before store of the product //before store of the product
Event::fire('catalog.product.create.before'); Event::fire('catalog.product.create.before');
@ -268,7 +267,7 @@ class ProductController extends Controller
Event::fire('catelog.product.update.after', $product); Event::fire('catelog.product.update.after', $product);
} else if($data['update-options'] == 1 && $data['selected-option-text'] == 'Active') { } else if($data['update-options'] == 1 && $data['selected-option-text'] == 'Active') {
Event::fire('catelog.product.update.before', $productId); Event::fire('catelog.product.update.before', $productId);
$result = $this->product->updateAttribute($product, $attribute, $data['update-options']); $result = $this->product->updateAttribute($product, $attribute, $data['update-options']);
if($result) if($result)
@ -277,7 +276,7 @@ class ProductController extends Controller
} }
} }
session()->flash('success', trans('admin::app.catalog.products.mass-delete-success')); session()->flash('success', trans('admin::app.catalog.products.mass-update-success'));
return redirect()->route($this->_config['redirect']); return redirect()->route($this->_config['redirect']);
} }

View File

@ -77,11 +77,11 @@ class Product extends Model
} }
/** /**
* The salable inventories that belong to the product. * The ordered inventories that belong to the product.
*/ */
public function salable_inventories() public function ordered_inventories()
{ {
return $this->hasMany(ProductSalableInventory::class, 'product_id'); return $this->hasMany(ProductOrderedInventory::class, 'product_id');
} }
/** /**
@ -155,7 +155,9 @@ class Product extends Model
*/ */
public function inventory_source_qty($inventorySource) public function inventory_source_qty($inventorySource)
{ {
return $this->inventories()->where('inventory_source_id', $inventorySource->id)->sum('qty'); return $this->inventories()
->where('inventory_source_id', $inventorySource->id)
->sum('qty');
} }
/** /**
@ -165,16 +167,27 @@ class Product extends Model
*/ */
public function haveSufficientQuantity($qty) public function haveSufficientQuantity($qty)
{ {
$salableInventories = $this->salable_inventories()->get();
$total = 0; $total = 0;
foreach($salableInventories as $inventory) { $channelInventorySourceIds = core()->getCurrentChannel()
if($inventory->channel->id == core()->getCurrentChannel()->id) { ->inventory_sources()
->where('status', 1)
->pluck('id');
foreach ($this->inventories as $inventory) {
if(is_numeric($index = $channelInventorySourceIds->search($inventory->inventory_source_id))) {
$total += $inventory->qty; $total += $inventory->qty;
} }
} }
$orderedInventory = $this->ordered_inventories()
->where('channel_id', core()->getCurrentChannel()->id)
->first();
if ($orderedInventory) {
$total -= $orderedInventory->qty;
}
return $qty <= $total ? true : false; return $qty <= $total ? true : false;
} }

View File

@ -0,0 +1,30 @@
<?php
namespace Webkul\Product\Models;
use Illuminate\Database\Eloquent\Model;
use Webkul\Inventory\Models\InventorySource;
use Webkul\Core\Models\Channel;
class ProductOrderedInventory extends Model
{
public $timestamps = false;
protected $fillable = ['qty', 'product_id', 'channel_id'];
/**
* Get the channel owns the inventory.
*/
public function channel()
{
return $this->belongsTo(Channel::class);
}
/**
* Get the product that owns the product inventory.
*/
public function product()
{
return $this->belongsTo(Product::class);
}
}

View File

@ -4,7 +4,6 @@ namespace Webkul\Product\Repositories;
use Illuminate\Container\Container as App; use Illuminate\Container\Container as App;
use Webkul\Core\Eloquent\Repository; use Webkul\Core\Eloquent\Repository;
use Webkul\Product\Repositories\ProductSalableInventoryRepository as SalableInventoryRepository;
/** /**
* Product Inventory Reposotory * Product Inventory Reposotory
@ -14,30 +13,6 @@ use Webkul\Product\Repositories\ProductSalableInventoryRepository as SalableInve
*/ */
class ProductInventoryRepository extends Repository class ProductInventoryRepository extends Repository
{ {
/**
* ProductSalableInventoryRepository object
*
* @var mixed
*/
protected $salableInventory;
/**
* Create a new repository instance.
*
* @param Webkul\Product\Repositories\ProductSalableInventoryRepository $salableInventory
* @return void
*/
public function __construct(
SalableInventoryRepository $salableInventory,
App $app
)
{
$this->salableInventory = $salableInventory;
parent::__construct($app);
}
/** /**
* Specify Model class name * Specify Model class name
* *
@ -55,6 +30,9 @@ class ProductInventoryRepository extends Repository
*/ */
public function saveInventories(array $data, $product) public function saveInventories(array $data, $product)
{ {
if ($product->type == 'configurable')
return;
$inventorySourceIds = $product->inventory_sources->pluck('id'); $inventorySourceIds = $product->inventory_sources->pluck('id');
if(isset($data['inventories'])) { if(isset($data['inventories'])) {
@ -86,7 +64,5 @@ class ProductInventoryRepository extends Repository
if($inventorySourceIds->count()) { if($inventorySourceIds->count()) {
$product->inventory_sources()->detach($inventorySourceIds); $product->inventory_sources()->detach($inventorySourceIds);
} }
$this->salableInventory->saveInventories($product);
} }
} }

View File

@ -1,64 +0,0 @@
<?php
namespace Webkul\Product\Repositories;
use Illuminate\Container\Container as App;
use Webkul\Core\Eloquent\Repository;
/**
* Product Salable Inventory Reposotory
*
* @author Jitendra Singh <jitendra@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class ProductSalableInventoryRepository extends Repository
{
/**
* Specify Model class name
*
* @return mixed
*/
function model()
{
return 'Webkul\Product\Models\ProductSalableInventory';
}
/**
* @param mixed $product
* @return mixed
*/
public function saveInventories($product)
{
foreach (core()->getAllChannels() as $channel) {
$inventorySourceIds = $channel->inventory_sources()->pluck('inventory_source_id');
$salableQty = 0;
foreach ($product->inventories()->get() as $productInventory) {
if(is_numeric($index = $inventorySourceIds->search($productInventory->inventory_source->id))) {
$salableQty += $productInventory->qty;
}
}
$salableInventory = $this->findOneWhere([
'product_id' => $product->id,
'channel_id' => $channel->id,
]);
if($salableInventory) {
$salableQty -= $salableInventory->sold_qty;
if ($salableQty < 0)
$salableQty = 0;
$this->update(['qty' => $salableQty], $salableInventory->id);
} else {
$this->create([
'qty' => $salableQty,
'product_id' => $product->id,
'channel_id' => $channel->id,
]);
}
}
}
}

View File

@ -78,12 +78,11 @@ class OrderItemRepository extends Repository
return $orderItem; return $orderItem;
} }
/** /**
* @param mixed $orderItem * @param mixed $orderItem
* @return void * @return void
*/ */
public function manageStock($orderItem) public function manageInventory($orderItem)
{ {
if(!$orderedQuantity = $orderItem->qty_ordered) if(!$orderedQuantity = $orderItem->qty_ordered)
return; return;
@ -94,16 +93,45 @@ class OrderItemRepository extends Repository
return; return;
} }
$salableInventory = $product->salable_inventories() $orderedInventory = $product->ordered_inventories()
->where('channel_id', $orderItem->order->channel->id) ->where('channel_id', $orderItem->order->channel->id)
->first(); ->first();
if($salableInventory) { if($orderedInventory) {
$soldQty = $salableInventory->sold_qty + $orderItem->qty_ordered; $orderedInventory->update([
'qty' => $orderedInventory->qty + $orderItem->qty_ordered
]);
} else {
$product->ordered_inventories()->create([
'qty' => $orderItem->qty_ordered,
'product_id' => $product->id,
'channel_id' => $orderItem->order->channel->id,
]);
}
}
$salableInventory->update([ /**
'qty' => ($salableInventory->qty - $orderItem->qty_ordered), * Returns qty to product inventory after order cancelation
'sold_qty' => $soldQty *
* @param mixed $orderItem
* @return void
*/
public function returnQtyToProductInventory($orderItem)
{
if (!$product = $orderItem->product)
return;
$orderedInventory = $product->ordered_inventories()
->where('channel_id', $orderItem->order->channel->id)
->first();
if ($orderedInventory) {
if (($qty = $orderedInventory->qty - $orderItem->qty_to_cancel) < 0) {
$qty = 0;
}
$orderedInventory->update([
'qty' => $qty
]); ]);
} }
} }

View File

@ -95,7 +95,7 @@ class OrderRepository extends Repository
$orderItem->child = $this->orderItem->create(array_merge($item['child'], ['order_id' => $order->id, 'parent_id' => $orderItem->id])); $orderItem->child = $this->orderItem->create(array_merge($item['child'], ['order_id' => $order->id, 'parent_id' => $orderItem->id]));
} }
$this->orderItem->manageStock($orderItem); $this->orderItem->manageInventory($orderItem);
} }
Event::fire('checkout.order.save.after', $order); Event::fire('checkout.order.save.after', $order);
@ -123,6 +123,8 @@ class OrderRepository extends Repository
foreach($order->items as $item) { foreach($order->items as $item) {
if($item->qty_to_cancel) { if($item->qty_to_cancel) {
$this->orderItem->returnQtyToProductInventory($item);
$item->qty_canceled += $item->qty_to_cancel; $item->qty_canceled += $item->qty_to_cancel;
$item->save(); $item->save();

View File

@ -29,28 +29,36 @@ class ShipmentItemRepository extends Repository
*/ */
public function updateProductInventory($data) public function updateProductInventory($data)
{ {
$salableInventory = $data['product']->salable_inventories() $orderedInventory = $data['product']->ordered_inventories()
->where('channel_id', $data['shipment']->order->channel->id) ->where('channel_id', $data['shipment']->order->channel->id)
->first(); ->first();
if ($orderedInventory) {
if (($orderedQty = $orderedInventory->qty - $data['qty']) < 0) {
$orderedQty = 0;
}
$orderedInventory->update([
'qty' => $orderedQty
]);
} else {
$data['product']->ordered_inventories()->create([
'qty' => $data['qty'],
'product_id' => $data['product']->id,
'channel_id' => $data['shipment']->order->channel->id
]);
}
$inventory = $data['product']->inventories() $inventory = $data['product']->inventories()
->where('inventory_source_id', $data['shipment']->inventory_source_id) ->where('inventory_source_id', $data['shipment']->inventory_source_id)
->first(); ->first();
if (($salableQty = $salableInventory->sold_qty - $data['qty']) < 0) {
$salableQty = 0;
}
$salableInventory->update([
'sold_qty' => $salableQty
]);
if (($qty = $inventory->qty - $data['qty']) < 0) { if (($qty = $inventory->qty - $data['qty']) < 0) {
$qty = 0; $qty = 0;
} }
$inventory->update([ $inventory->update([
'qty' => $data['qty'] 'qty' => $qty
]); ]);
} }
} }

View File

@ -106,10 +106,6 @@ class ShipmentRepository extends Repository
$orderItem = $this->orderItem->find($itemId); $orderItem = $this->orderItem->find($itemId);
$product = ($orderItem->type == 'configurable')
? $orderItem->child->product
: $orderItem->product;
$totalQty += $qty; $totalQty += $qty;
$shipmentItem = $this->shipmentItem->create([ $shipmentItem = $this->shipmentItem->create([
@ -130,6 +126,10 @@ class ShipmentRepository extends Repository
'additional' => $orderItem->additional, 'additional' => $orderItem->additional,
]); ]);
$product = ($orderItem->type == 'configurable')
? $orderItem->child->product
: $orderItem->product;
$this->shipmentItem->updateProductInventory([ $this->shipmentItem->updateProductInventory([
'shipment' => $shipment, 'shipment' => $shipment,
'shipmentItem' => $shipmentItem, 'shipmentItem' => $shipmentItem,
@ -157,19 +157,4 @@ class ShipmentRepository extends Repository
return $shipment; return $shipment;
} }
/**
* @param array $data
* @return integer
*/
public function getTotalQty(array $data)
{
$qty = 0;
foreach ($data['shipment']['items'] as $itemId => $inventorySource) {
$qty += $inventorySource[$data['shipment']['source']];
}
return $qty;
}
} }

View File

@ -69,7 +69,7 @@ abstract class AbstractShipping
*/ */
public function getConfigData($field) public function getConfigData($field)
{ {
return core()->getConfigData('carriers.' . $this->getCode() . '.' . $field); return core()->getConfigData('sales.carriers.' . $this->getCode() . '.' . $field);
} }
} }
?> ?>

View File

@ -97,5 +97,57 @@ return [
'validation' => 'required' 'validation' => 'required'
] ]
] ]
], [
'key' => 'sales.shipping',
'name' => 'Shipping',
'sort' => 0
], [
'key' => 'sales.shipping.origin',
'name' => 'Origin',
'sort' => 0,
'fields' => [
[
'name' => 'country',
'title' => 'Country',
'type' => 'text',
'validation' => 'required',
'channel_based' => true,
'locale_based' => false
], [
'name' => 'state',
'title' => 'State',
'type' => 'text',
'validation' => 'required',
'channel_based' => true,
'locale_based' => false
], [
'name' => 'address1',
'title' => 'Address Line 1',
'type' => 'text',
'validation' => 'required',
'channel_based' => true,
'locale_based' => false
], [
'name' => 'address2',
'title' => 'Address Line 2',
'type' => 'text',
'channel_based' => true,
'locale_based' => false
], [
'name' => 'zipcode',
'title' => 'Zip',
'type' => 'text',
'validation' => 'required',
'channel_based' => true,
'locale_based' => false
], [
'name' => 'city',
'title' => 'City',
'type' => 'text',
'validation' => 'required',
'channel_based' => true,
'locale_based' => false
]
]
] ]
]; ];

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
{ {
"/js/shop.js": "/js/shop.js?id=dc2ea56a854d779e7089", "/js/shop.js": "/js/shop.js?id=dc2ea56a854d779e7089",
"/css/shop.css": "/css/shop.css?id=c96b5204660def3468d9" "/css/shop.css": "/css/shop.css?id=7aa91d217344fc8f4f53"
} }

View File

@ -57,7 +57,7 @@ class SliderController extends controller
$this->validate(request(), [ $this->validate(request(), [
'title' => 'string|required', 'title' => 'string|required',
'channel_id' => 'required', 'channel_id' => 'required',
'image' => 'required|mimes:jpeg,bmp,png' 'image.*' => 'required|mimes:jpeg,bmp,png,jpg'
]); ]);
$result = $this->slider->save(request()->all()); $result = $this->slider->save(request()->all());
@ -90,7 +90,7 @@ class SliderController extends controller
$this->validate(request(), [ $this->validate(request(), [
'title' => 'string|required', 'title' => 'string|required',
'channel_id' => 'required', 'channel_id' => 'required',
'image' => 'sometimes|mimes:jpeg,bmp,png' 'image.*' => 'sometimes|mimes:jpeg,bmp,png,jpg'
]); ]);
$result = $this->slider->updateItem(request()->all(), $id); $result = $this->slider->updateItem(request()->all(), $id);

View File

@ -456,7 +456,11 @@ input {
} }
.product-card:hover { .product-card:hover {
box-shadow: 1px 1px 10px #ccc; outline: 1px solid #eaeaec;
box-shadow: 0 1px 2px rgba(0,0,0,0.05);
-webkit-box-shadow: 0px 2px 16px 4px rgba(40, 44, 63, 0.07);
-moz-box-shadow: 0px 2px 16px 4px rgba(40, 44, 63, 0.07);
box-shadow: 0px 2px 16px 4px rgba(40, 44, 63, 0.07);
} }
@media only screen and (max-width: 580px) { @media only screen and (max-width: 580px) {

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
{ {
"/js/ui.js": "/js/ui.js?id=c3ee60fd11e29aca2922", "/js/ui.js": "/js/ui.js?id=c3ee60fd11e29aca2922",
"/css/ui.css": "/css/ui.css?id=014ff883008a2459b5e1" "/css/ui.css": "/css/ui.css?id=0433c5b81c6583e79c04"
} }

View File

@ -567,7 +567,10 @@ class DataGrid
if ($this->aliased) { //aliasing is expected in this case or it will be changed to presence of join bag if ($this->aliased) { //aliasing is expected in this case or it will be changed to presence of join bag
foreach ($parsed as $key=>$value) { foreach ($parsed as $key=>$value) {
if ($key=="sort") { $column_name = $this->findAlias($key);
$column_type = $this->findType($key);
if ($key == "sort") {
//resolve the case with the column helper class //resolve the case with the column helper class
if(substr_count($key,'_') >= 1) if(substr_count($key,'_') >= 1)
$column_name = $this->findAlias($key); $column_name = $this->findAlias($key);
@ -603,18 +606,26 @@ class DataGrid
} }
} else { } else {
foreach ($value as $condition => $filter_value) { foreach ($value as $condition => $filter_value) {
$this->query->where( if($column_type == 'datetime') {
$column_name, $this->query->whereDate(
$this->operators[$condition], $column_name,
$filter_value $this->operators[$condition],
); $filter_value
);
} else {
$this->query->where(
$column_name,
$this->operators[$condition],
$filter_value
);
}
} }
} }
} }
} }
} else { } else {
//this is the case for the non aliasing. //this is the case for the non aliasing.
foreach ($parsed as $key=>$value) { foreach ($parsed as $key => $value) {
if ($key=="sort") { if ($key=="sort") {
@ -631,7 +642,6 @@ class DataGrid
throw new \Exception('Multiple Sort keys Found, Please Resolve the URL Manually.'); throw new \Exception('Multiple Sort keys Found, Please Resolve the URL Manually.');
} }
} elseif ($key=="search") { } elseif ($key=="search") {
$count_keys = count(array_keys($value)); $count_keys = count(array_keys($value));
if($count_keys==1) if($count_keys==1)
$this->query->where(function ($query) use ($parsed) { $this->query->where(function ($query) use ($parsed) {

View File

@ -355,7 +355,7 @@ h2 {
position: relative; position: relative;
display: block; display: block;
vertical-align: middle; vertical-align: middle;
margin: 10px 5px 5px 0px; margin: 0px 5px 5px 0px;
input { input {
left: 0; left: 0;

View File

@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Event;
use Webkul\User\Repositories\AdminRepository as Admin; use Webkul\User\Repositories\AdminRepository as Admin;
use Webkul\User\Repositories\RoleRepository as Role; use Webkul\User\Repositories\RoleRepository as Role;
use Webkul\User\Http\Requests\UserForm; use Webkul\User\Http\Requests\UserForm;
use Hash;
/** /**
* Admin user controller * Admin user controller
@ -94,7 +95,7 @@ class UserController extends Controller
$data['password'] = bcrypt($data['password']); $data['password'] = bcrypt($data['password']);
Event::fire('user.admin.create.before'); Event::fire('user.admin.create.before');
$admin = $this->admin->create($data); $admin = $this->admin->create($data);
Event::fire('user.admin.delete.after', $admin); Event::fire('user.admin.delete.after', $admin);
@ -165,6 +166,10 @@ class UserController extends Controller
} else { } else {
Event::fire('user.admin.delete.before', $id); Event::fire('user.admin.delete.before', $id);
if (auth()->guard('admin')->user()->id == $id) {
return view('admin::customers.confirm-password');
}
$this->admin->delete($id); $this->admin->delete($id);
Event::fire('user.admin.delete.after', $id); Event::fire('user.admin.delete.after', $id);
@ -174,4 +179,36 @@ class UserController extends Controller
return redirect()->back(); return redirect()->back();
} }
/**
* destroy current after confirming
*
* @return mixed
*/
public function destroySelf()
{
$password = request()->input('password');
if(Hash::check($password, auth()->guard('admin')->user()->password)) {
if($this->admin->count() == 1) {
session()->flash('error', trans('admin::app.users.users.delete-last'));
} else {
$id = auth()->guard('admin')->user()->id;
Event::fire('user.admin.delete.before', $id);
$this->admin->delete($id);
Event::fire('user.admin.delete.after', $id);
session()->flash('success', trans('admin::app.users.users.delete-success'));
return redirect()->route('admin.session.create');
}
} else {
session()->flash('warning', trans('admin::app.users.users.incorrect-password'));
return redirect()->route($this->_config['redirect']);
}
}
} }