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",
"/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',
'label' => 'Type',
], [
'name' => 'is_required',
'column' => 'is_required',
'alias' => 'attributeIsRequired',
'type' => 'boolean',
'label' => 'Required',
], [
'name' => 'is_unique',
'column' => 'is_unique',
'alias' => 'attributeIsUnique',
'type' => 'boolean',
'label' => 'Unique',
], [
'name' => 'value_per_locale',
'column' => 'value_per_locale',
'alias' => 'attributeValuePerLocale',
'type' => 'boolean',
'label' => 'Locale based',
], [
'name' => 'value_per_channel',
'column' => 'value_per_channel',
'alias' => 'attributeValuePerChannel',
'type' => 'boolean',
'label' => 'Channel based',

View File

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

View File

@ -83,7 +83,7 @@ class ConfigurationController extends Controller
$slugs = $this->getDefaultConfigSlugs();
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]);

View File

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

View File

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

View File

@ -324,6 +324,10 @@ Route::group(['middleware' => ['web']], function () {
//delete backend user
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
Route::get('/roles', 'Webkul\User\Http\Controllers\RoleController@index')->defaults('_config', [
'view' => 'admin::users.roles.index'

View File

@ -73,24 +73,29 @@ class Product {
$variants = [];
$this->productGrid->create($gridObject);
$found = $this->productGrid->findOneByField('product_id', $product->id);
if($product->type == 'configurable') {
$variants = $product->variants()->get();
//extra measure to stop duplicate entries
if($found == null) {
$this->productGrid->create($gridObject);
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,
];
if($product->type == 'configurable') {
$variants = $product->variants()->get();
$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 = [];
}
$this->findRepeated();
return true;
}
public function findRepeated() {
}
}

View File

@ -50,6 +50,7 @@ return [
'change-password' => 'Change Account Password',
'current-password' => 'Current Password'
],
'users' => [
'forget-password' => [
'title' => 'Forget Password',
@ -60,6 +61,7 @@ return [
'back-link-title' => 'Back to Sign In',
'submit-btn-title' => 'Email Password Reset Link'
],
'reset-password' => [
'title' => 'Reset Password',
'title' => 'Reset Password',
@ -69,6 +71,7 @@ return [
'back-link-title' => 'Back to Sign In',
'submit-btn-title' => 'Reset Password'
],
'roles' => [
'title' => 'Roles',
'add-role-title' => 'Add Role',
@ -82,6 +85,7 @@ return [
'custom' => 'Custom',
'all' => 'All'
],
'users' => [
'title' => 'User',
'add-user-title' => 'Add User',
@ -95,8 +99,15 @@ return [
'status-and-role' => 'Status and Role',
'role' => 'Role',
'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' => [
'title' => 'Sign In',
'email' => 'Email',
@ -106,6 +117,7 @@ return [
'submit-btn-title' => 'Sign In'
]
],
'sales' => [
'orders' => [
'title' => 'Orders',
@ -157,6 +169,7 @@ return [
'total-due' => 'Total Due',
'cancel-confirm-msg' => 'Are you sure you want to cancel this order ?'
],
'invoices' => [
'title' => 'Invoices',
'id' => 'Id',
@ -178,6 +191,7 @@ return [
'print' => 'Print',
'order-date' => 'Order Date'
],
'shipments' => [
'title' => 'Shipments',
'id' => 'Id',
@ -201,6 +215,7 @@ return [
'view-title' => 'Shipment #:shipment_id'
]
],
'catalog' => [
'products' => [
'title' => 'Products',
@ -232,8 +247,10 @@ return [
'add-variant-title' => 'Add Variant',
'variant-already-exist-message' => 'Variant with same attribute options already exists.',
'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' => [
'title' => 'Attributes',
'add-title' => 'Add Attribute',

View File

@ -10,15 +10,15 @@
$key = $item['key'];
$key = explode(".", $key);
array_shift($key);
$firstField = current($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' }}>
{{ $field['title'] }}
@ -44,15 +44,15 @@
@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')
<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')
<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)
@ -75,5 +75,5 @@
@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>

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">
<label>Account</label>
<ul>
<li>
<a href="{{ route('shop.home.index') }}" target="_blank">Visit Shop</a>
</li>
<li>
<a href="{{ route('admin.account.edit') }}">My Account</a>
</li>

View File

@ -1,8 +1,8 @@
const { mix } = require("laravel-mix");
require("laravel-mix-merge-manifest");
// var publicPath = 'publishable/assets';
var publicPath = "../../../public/vendor/webkul/admin/assets";
var publicPath = 'publishable/assets';
// var publicPath = "../../../public/vendor/webkul/admin/assets";
mix.setPublicPath(publicPath).mergeManifest();
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 $coreConfigValue->value;
}
@ -692,12 +697,7 @@ class Core
if (isset($coreData['fields'])) {
foreach ($coreData['fields'] as $field) {
$key = $coreData['key'];
$key = explode(".", $key);
array_shift($key);
$key = implode(".", $key);
$name = $key . '.' . $field['name'];
$name = $coreData['key'] . '.' . $field['name'];
if ($name == $fieldName ) {
return $field;

View File

@ -38,83 +38,103 @@ class CoreConfigRepository extends Repository
unset($data['channel']);
}
foreach ($data as $method => $value)
{
foreach ($value as $key => $formData)
{
foreach (array_keys($formData) as $title)
foreach ($data as $method => $fieldData) {
$recurssiveData = $this->recuressiveArray($fieldData , $method);
foreach ($recurssiveData as $fieldName => $value) {
$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;
$value = $formData[$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'])
{
$coreConfigValue = $this->model
->where('code', $fieldName)
->where('locale_code', $locale)
->where('channel_code', $channel)
->get();
}
if (isset($field['locale_based']) && $field['locale_based']) {
$locale_based = true;
else
{
$coreConfigValue = $this->model
->where('code', $fieldName)
->where('channel_code', $channel)
->get();
}
if (isset($field['channel_based']) && $field['channel_based'])
} else
{
if (isset($field['locale_based']) && $field['locale_based'])
{
if (isset($field['locale_based']) && $field['locale_based'])
{
$coreConfigValue = $this->model
->where('code', $fieldName)
->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();
}
$coreConfigValue = $this->model
->where('code', $fieldName)
->where('locale_code', $locale)
->get();
}
if (!count($coreConfigValue) > 0)
else
{
$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;
$coreConfigValue = $this->model
->where('code', $fieldName)
->get();
}
}
foreach ($coreConfigValue as $coreConfig)
{
$coreConfig->update($updataData);
}
if (!count($coreConfigValue) > 0)
{
$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)
{
return core()->getConfigData('paymentmethods.' . $this->getCode() . '.' . $field);
return core()->getConfigData('sales.paymentmethods.' . $this->getCode() . '.' . $field);
}
abstract public function getRedirectUrl();

View File

@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProductSalableInventoriesTable extends Migration
class CreateProductOrderedInventoriesTable extends Migration
{
/**
* Run the migrations.
@ -13,10 +13,9 @@ class CreateProductSalableInventoriesTable extends Migration
*/
public function up()
{
Schema::create('product_salable_inventories', function (Blueprint $table) {
Schema::create('product_ordered_inventories', function (Blueprint $table) {
$table->increments('id');
$table->integer('qty')->default(0);
$table->integer('sold_qty')->default(0);
$table->integer('product_id')->unsigned();
$table->integer('channel_id')->unsigned();
@ -33,6 +32,6 @@ class CreateProductSalableInventoriesTable extends Migration
*/
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]
]);
//before store of the product
Event::fire('catalog.product.create.before');
@ -268,7 +267,7 @@ class ProductController extends Controller
Event::fire('catelog.product.update.after', $product);
} else if($data['update-options'] == 1 && $data['selected-option-text'] == 'Active') {
Event::fire('catelog.product.update.before', $productId);
$result = $this->product->updateAttribute($product, $attribute, $data['update-options']);
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']);
}

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)
{
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)
{
$salableInventories = $this->salable_inventories()->get();
$total = 0;
foreach($salableInventories as $inventory) {
if($inventory->channel->id == core()->getCurrentChannel()->id) {
$channelInventorySourceIds = core()->getCurrentChannel()
->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;
}
}
$orderedInventory = $this->ordered_inventories()
->where('channel_id', core()->getCurrentChannel()->id)
->first();
if ($orderedInventory) {
$total -= $orderedInventory->qty;
}
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 Webkul\Core\Eloquent\Repository;
use Webkul\Product\Repositories\ProductSalableInventoryRepository as SalableInventoryRepository;
/**
* Product Inventory Reposotory
@ -14,30 +13,6 @@ use Webkul\Product\Repositories\ProductSalableInventoryRepository as SalableInve
*/
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
*
@ -55,6 +30,9 @@ class ProductInventoryRepository extends Repository
*/
public function saveInventories(array $data, $product)
{
if ($product->type == 'configurable')
return;
$inventorySourceIds = $product->inventory_sources->pluck('id');
if(isset($data['inventories'])) {
@ -86,7 +64,5 @@ class ProductInventoryRepository extends Repository
if($inventorySourceIds->count()) {
$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;
}
/**
* @param mixed $orderItem
* @return void
*/
public function manageStock($orderItem)
public function manageInventory($orderItem)
{
if(!$orderedQuantity = $orderItem->qty_ordered)
return;
@ -94,16 +93,45 @@ class OrderItemRepository extends Repository
return;
}
$salableInventory = $product->salable_inventories()
$orderedInventory = $product->ordered_inventories()
->where('channel_id', $orderItem->order->channel->id)
->first();
if($salableInventory) {
$soldQty = $salableInventory->sold_qty + $orderItem->qty_ordered;
if($orderedInventory) {
$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),
'sold_qty' => $soldQty
/**
* Returns qty to product inventory after order cancelation
*
* @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]));
}
$this->orderItem->manageStock($orderItem);
$this->orderItem->manageInventory($orderItem);
}
Event::fire('checkout.order.save.after', $order);
@ -123,6 +123,8 @@ class OrderRepository extends Repository
foreach($order->items as $item) {
if($item->qty_to_cancel) {
$this->orderItem->returnQtyToProductInventory($item);
$item->qty_canceled += $item->qty_to_cancel;
$item->save();

View File

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

View File

@ -106,10 +106,6 @@ class ShipmentRepository extends Repository
$orderItem = $this->orderItem->find($itemId);
$product = ($orderItem->type == 'configurable')
? $orderItem->child->product
: $orderItem->product;
$totalQty += $qty;
$shipmentItem = $this->shipmentItem->create([
@ -130,6 +126,10 @@ class ShipmentRepository extends Repository
'additional' => $orderItem->additional,
]);
$product = ($orderItem->type == 'configurable')
? $orderItem->child->product
: $orderItem->product;
$this->shipmentItem->updateProductInventory([
'shipment' => $shipment,
'shipmentItem' => $shipmentItem,
@ -157,19 +157,4 @@ class ShipmentRepository extends Repository
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)
{
return core()->getConfigData('carriers.' . $this->getCode() . '.' . $field);
return core()->getConfigData('sales.carriers.' . $this->getCode() . '.' . $field);
}
}
?>

View File

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

View File

@ -456,7 +456,11 @@ input {
}
.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) {

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",
"/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
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
if(substr_count($key,'_') >= 1)
$column_name = $this->findAlias($key);
@ -603,18 +606,26 @@ class DataGrid
}
} else {
foreach ($value as $condition => $filter_value) {
$this->query->where(
$column_name,
$this->operators[$condition],
$filter_value
);
if($column_type == 'datetime') {
$this->query->whereDate(
$column_name,
$this->operators[$condition],
$filter_value
);
} else {
$this->query->where(
$column_name,
$this->operators[$condition],
$filter_value
);
}
}
}
}
}
} else {
//this is the case for the non aliasing.
foreach ($parsed as $key=>$value) {
foreach ($parsed as $key => $value) {
if ($key=="sort") {
@ -631,7 +642,6 @@ class DataGrid
throw new \Exception('Multiple Sort keys Found, Please Resolve the URL Manually.');
}
} elseif ($key=="search") {
$count_keys = count(array_keys($value));
if($count_keys==1)
$this->query->where(function ($query) use ($parsed) {

View File

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

View File

@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Event;
use Webkul\User\Repositories\AdminRepository as Admin;
use Webkul\User\Repositories\RoleRepository as Role;
use Webkul\User\Http\Requests\UserForm;
use Hash;
/**
* Admin user controller
@ -94,7 +95,7 @@ class UserController extends Controller
$data['password'] = bcrypt($data['password']);
Event::fire('user.admin.create.before');
$admin = $this->admin->create($data);
Event::fire('user.admin.delete.after', $admin);
@ -165,6 +166,10 @@ class UserController extends Controller
} else {
Event::fire('user.admin.delete.before', $id);
if (auth()->guard('admin')->user()->id == $id) {
return view('admin::customers.confirm-password');
}
$this->admin->delete($id);
Event::fire('user.admin.delete.after', $id);
@ -174,4 +179,36 @@ class UserController extends Controller
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']);
}
}
}