Skip to content

Commit

Permalink
Merge pull request #99 from avored/dev
Browse files Browse the repository at this point in the history
dev to master
  • Loading branch information
indpurvesh authored Oct 16, 2019
2 parents cfe56f0 + 8f09ef7 commit 151f6ca
Show file tree
Hide file tree
Showing 54 changed files with 610 additions and 213 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"barryvdh/laravel-dompdf": "^0.8.4",
"laravel/helpers": "^1.1",
"spatie/laravel-view-models": "^1.2",
"laravel/framework" : "^5.8|^6.0"
"laravel/framework" : "^5.8|^6.0|^6.1|^6.2"
},
"require-dev" : {
"phpunit/phpunit": "^7.5",
Expand Down
2 changes: 1 addition & 1 deletion config/avored.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
return [
'admin_url' => 'admin',
'symlink_storage_folder' => 'storage',
'cart' => ['session_key' => 'cart_products'],
'cart' => ['session_key' => 'cart_products', 'promotion_key' => 'cart_discount'],
'model' => [
'user' => App\User::class,
],
Expand Down
4 changes: 4 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<directory suffix=".php">src</directory>
</whitelist>
</filter>

<php>
<env name="DB_CONNECTION" value="testing"/>
</php>

<!--logging>
<log
Expand Down
3 changes: 2 additions & 1 deletion resources/components/cms/menu/MenuSave.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export default {
if (!isNil(this.menuGroup)) {
this.fields.forEach(field => {
this.form.getFieldDecorator(field, {initialValue: this.menuGroup[field]})
console.log(window.x = this)
this.form.getFieldDecorator(field, { 'name' :this.menuGroup[field]})
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions resources/components/system/admin-user/AdminUserSave.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import isNil from 'lodash/isNil';
import isEmpty from 'lodash/isEmpty';
import isNil from 'lodash/isNil'
import isEmpty from 'lodash/isEmpty'
export default {
props: ['adminUser', 'baseUrl', 'token'],
Expand Down
3 changes: 2 additions & 1 deletion resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Vue.component('a-upload', () => import('ant-design-vue/lib/upload'))
Vue.component('a-upload', () => import('ant-design-vue/lib/upload'))
Vue.component('a-input', () => import('ant-design-vue/lib/input'))
Vue.component('a-switch', () => import('ant-design-vue/lib/switch'))
Vue.component('a-tag', () => import('ant-design-vue/lib/tag'))

Vue.prototype.$notification = Notification;
Vue.prototype.$confirm = Modal.confirm;
Expand Down Expand Up @@ -109,7 +110,7 @@ Vue.component('role-index', () => import('../components/system/role/RoleTable.vu
Vue.component('system-role-save', () => import('../components/system/role/RoleSave.vue'))

Vue.component('admin-user-table', () => import('../components/system/admin-user/AdminUserTable.vue'))
Vue.component('admin-user-save', () => import('../components/system/admin-user/AdminUserSave.vue'))
Vue.component('admin-user-save', require('../components/system/admin-user/AdminUserSave.vue').default)

Vue.component('promotion-code-table', () => import('../components/promotion/promotion-code/PromotionCodeTable.vue'))
Vue.component('promotion-code-edit', () => import('../components/promotion/promotion-code/PromotionCodeEdit.vue'))
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en/catalog.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@
],

'cart_success_notification' => 'Product added to cart successfully.',
'promotion_code_success_notification' => 'Promotion code applied to cart successfully.',
'promotion_code_errot_notification' => 'There is an error. Please check your code or contact administrator.',
'cart_variable_product_error_notification' => 'There is an error while adding product to cart.',

];
4 changes: 4 additions & 0 deletions resources/lang/en/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@
'forgot-password-title' => 'Reset password',
'new_password_title' => 'Set New Password',
'password-new-btn' => 'Change Password',
'total-customer' => 'Total Customer',
'total-order' => 'Total Order',
'total-revenue' => 'Total Revenue',
'notification' => [
'store' => ':attribute Created successfully!',
'updated' => ':attribute Updated successfully!',
'delete' => ':attribute delete successfully!',
'upload' => ':attribute successfully uploaded!',
'save' => ':attribute save successfully!',
'approved' => ':attribute approved successfully!',
],
'btn' => [
'save' => 'Save',
Expand Down
26 changes: 21 additions & 5 deletions resources/less/app.less
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@


@primary-color: #1890ff;
@link-color: #dc281e;

@import '~ant-design-vue/dist/antd.less';
@import '~quill/dist/quill.core.css';
@import '~quill/dist/quill.snow.css';
@import 'helper/margin';
@import 'helper/padding';

.dashboard-widget {
.ant-card-head-title {
color: #fff;
}
.amount {
color: #fff;
font-size: 4rem;
margin-bottom: 0px;
line-height: 3rem;
}

&.primary {
background-color: @primary-color;
}
&.warning {
background-color: @warning-color;
}
&.info {
background-color: @info-color;
}
}
.attribute-dropdown .ant-select-arrow{
top: 5px;
right: 0px;
Expand Down
8 changes: 7 additions & 1 deletion resources/views/admin.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
@endsection

@section('content')
<a-row type="flex" justify="center">
<a-row type="flex" :gutter="20" justify="center">
{{ Widget::get('avored-total-order')->render() }}
{{ Widget::get('avored-total-customer')->render() }}
{{ Widget::get('avored-total-revenue')->render() }}

</a-row>
<a-row type="flex" class="mt-1" justify="center">
<a-col :span="24">
<a-card title="Admin Dashboard">
<div>
Expand Down
4 changes: 3 additions & 1 deletion resources/views/cms/menu/_fields.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<input type="hidden" name="menu_json" v-model="menu_json" />
<input type="hidden" name="menu_json" v-model="menu_json" />
<a-col :span="24">
<a-form-item
@if ($errors->has('name'))
Expand All @@ -12,6 +12,7 @@
name="name"
v-decorator="[
'name',
{'initialValue': '{{ $menuGroup->name ?? '' }}'},
{rules:
[
{ required: true,
Expand All @@ -35,6 +36,7 @@
name="identifier"
v-decorator="[
'identifier',
{'initialValue': '{{ $menuGroup->identifier ?? '' }}'},
{rules:
[
{ required: true,
Expand Down
35 changes: 14 additions & 21 deletions resources/views/cms/menu/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,20 @@
method="post"
action="{{ route('admin.menu-group.update', $menuGroup->id) }}">

@csrf
@method('put')
@include('avored::cms.menu._fields')
<a-col class="mt-1" :span="24">
<a-form-item>
<a-button
type="primary"
html-type="submit"
>
{{ __('avored::system.btn.save') }}
</a-button>

<a-button
class="ml-1"
type="default"
v-on:click.prevent="cancelMenu"
>
{{ __('avored::system.btn.cancel') }}
</a-button>
</a-form-item>
</a-col>
@csrf
@method('put')
@include('avored::cms.menu._fields')
<a-col class="mt-1" :span="24">
<a-form-item>
<a-button type="primary" html-type="submit">
{{ __('avored::system.btn.save') }}
</a-button>

<a-button class="ml-1" type="default" v-on:click.prevent="cancelMenu">
{{ __('avored::system.btn.cancel') }}
</a-button>
</a-form-item>
</a-col>
</a-form>
</a-row>
</div>
Expand Down
5 changes: 5 additions & 0 deletions resources/views/widget/total-customer.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<a-col :span="4" :xs="24" :sm="12" :md="6">
<a-card title="{{ __('avored::system.total-customer') }}" class="dashboard-widget mt-1 warning">
<p class="amount">{{ $value }}</p>
</a-card>
</a-col>
5 changes: 5 additions & 0 deletions resources/views/widget/total-order.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<a-col :span="4" :xs="24" :sm="12" :md="6">
<a-card title="{{ __('avored::system.total-order') }}" class="dashboard-widget mt-1 primary">
<p class="amount">{{ $value }}</p>
</a-card>
</a-col>
5 changes: 5 additions & 0 deletions resources/views/widget/total-revenue.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<a-col :span="4" :xs="24" :sm="12" :md="6">
<a-card title="{{ __('avored::system.total-revenue') }}" class="dashboard-widget mt-1 info">
<p class="amount">{{ session()->get('default_currency')->symbol }}{{ $value }}</p>
</a-card>
</a-col>
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
->name('logout');
});

Route::middleware(['web', 'admin.auth'])
Route::middleware(['web', 'admin.auth:admin', 'permission'])
->prefix($baseAdminUrl)
->namespace('AvoRed\Framework')
->name('admin.')
Expand Down
2 changes: 2 additions & 0 deletions src/AvoRedProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use AvoRed\Framework\Support\Middleware\AvoRedCore;
use AvoRed\Framework\Support\Console\InstallCommand;
use AvoRed\Framework\Support\Console\AdminMakeCommand;
use AvoRed\Framework\Support\Middleware\Permission;
use AvoRed\Framework\System\ViewComposers\LayoutComposer;
use AvoRed\Framework\Support\Middleware\RedirectIfAdminAuth;

Expand Down Expand Up @@ -123,6 +124,7 @@ protected function registerMiddleware()
{
$router = $this->app['router'];
$router->aliasMiddleware('admin.auth', AdminAuth::class);
$router->aliasMiddleware('permission', Permission::class);
$router->aliasMiddleware('admin.guest', RedirectIfAdminAuth::class);
$router->aliasMiddleware('avored', AvoRedCore::class);
}
Expand Down
73 changes: 72 additions & 1 deletion src/Cart/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use AvoRed\Framework\Database\Models\Product;
use AvoRed\Framework\Database\Contracts\ProductModelInterface;
use AvoRed\Framework\Database\Contracts\AttributeProductValueModelInterface;
use AvoRed\Framework\Database\Contracts\PromotionCodeModelInterface;
use AvoRed\Framework\Database\Models\PromotionCode;

class Manager
{
Expand All @@ -22,12 +24,30 @@ class Manager
*/
protected $attributeProductValueRepository;

/**
* Promotion Code Repository.
* @var \AvoRed\Framework\Database\Repository\PromotionCodeRepository
*/
protected $promotionCodeRepository;

/**
* Cart Product collection.
* @var \Illuminate\Support\Collection
*/
protected $cartCollection;

/**
* Cart totoal discount.
* @var float $totalDiscount
*/
protected $totalDiscount = 0.00;

/**
* Cart applied coupon list.
* @var @var \Illuminate\Support\Collection
*/
protected $promotionList;

/**
* AvoRed Cart Session Manager.
* @var \Illuminate\Session\SessionManager
Expand All @@ -41,11 +61,37 @@ class Manager
public function __construct(SessionManager $manager)
{
$this->productRepository = app(ProductModelInterface::class);
$this->promotionCodeRepository = app(PromotionCodeModelInterface::class);
$this->attributeProductValueRepository = app(AttributeProductValueModelInterface::class);
$this->sessionManager = $manager;
$this->promotionList = collect();
$this->cartCollection = $this->getSession();
}

/**
* Apply Coupon Discount to Cart
* @param string $code
* @return mixed
*/
public function applyCoupon(string $code)
{
$promotionModel = $this->promotionCodeRepository->findByCode($code);
$this->promotionList->push($promotionModel);

$message = __('avored::catalog.promotion_code_errot_notification');
if ($promotionModel->type === 'FIXED') {
$this->totalDiscount = $promotionModel->amount;
$message = __('avored::catalog.promotion_code_success_notification');
}

$this->sessionManager->put(
$this->getPromotionKey(),
['total' => $this->totalDiscount, 'list' => $this->promotionList]
);

return $message;
}

/**
* Add Product to Cart By Given Slug.
* @param string $slug
Expand All @@ -60,7 +106,7 @@ public function add(string $slug, $qty = 1, $attributes = [])
$product = $this->productRepository->findBySlug($slug);

if ($this->getSession()->has($slug)) {
$cartProduct = $this->cartCollection->get($product);
$cartProduct = $this->cartCollection->get($slug);

$existingQty = $cartProduct->qty() ?? 0;

Expand Down Expand Up @@ -164,6 +210,15 @@ public function getSessionKey()
return config('avored.cart.session_key') ?? 'cart_products';
}

/**
* Get the Session Key for the Session Manager.
* @return string $sessionKey
*/
public function getPromotionKey()
{
return config('avored.cart.promotion_key') ?? 'cart_discount';
}

/**
* Update the Session Collection.
* @return self $this
Expand Down Expand Up @@ -207,6 +262,21 @@ public function toArray()
return $items;
}

/**
* Get the List of All the Current Session Cart Products.
* @return mixed $cartTotal
*/
public function discount($format = true)
{
$discountSessionData = $this->sessionManager->get($this->getPromotionKey());
$total = $discountSessionData['total'];

if ($format === true) {
return number_format($total, 2);
}

return $total;
}
/**
* Get the List of All the Current Session Cart Products.
* @return mixed $cartTotal
Expand All @@ -218,6 +288,7 @@ public function total($format = true)
foreach ($products as $product) {
$total += $product->total();
}
$total = $total - $this->totalDiscount;

if ($format === true) {
return number_format($total, 2);
Expand Down
Loading

0 comments on commit 151f6ca

Please sign in to comment.