Merge pull request #1021 from prashant-webkul/development

Development
This commit is contained in:
Jitendra Singh 2019-06-13 19:31:53 +05:30 committed by GitHub
commit d370821f7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 174 additions and 102 deletions

View File

@ -821,7 +821,7 @@ return [
'cust-groups' => 'Customer Groups',
'priority' => 'Priority',
'add-condition' => 'Add Conditions',
'disc_amt' => 'Discount Amount',
'disc_amt' => 'Discount Amount(B)',
'disc_percent' => 'Discount Percentage',
'is-coupon' => 'Use Coupon',
'is-coupon-yes' => 'Yes',
@ -844,6 +844,7 @@ return [
'free-shipping' => 'Free Shipping',
'is-guest' => 'For Guests',
'disc_qty' => 'Max. Quantity Allowed To Be Discounted',
'test-mode' => 'Choose how to test conditions'
],
'status' => [

View File

@ -179,13 +179,22 @@
<div class="control-group">
<label for="criteria" class="required">{{ __('admin::app.promotion.general-info.add-condition') }}</label>
<select type="text" class="control" name="criteria" v-model="criteria">
<select type="text" class="control" v-model="criteria">
<option value="cart">Cart Properties</option>
</select>
</div>
</div>
<div class="mt-10 mb-10"><b>Any of the condition is true</b></div>
<div class="control-group">
{{ __('admin::app.promotion.general-info.test-mode') }}
<select class="control" v-model="match_criteria" style="margin-right: 15px;">
{{ $i = 0 }}
@foreach(config('pricerules.test_mode') as $key => $value)
<option value="{{ $key }}">{{ $value }}</option>
{{ $i++ }}
@endforeach
</select>
</div>
<div class="condition-set">
<!-- Cart Attributes -->
@ -418,6 +427,7 @@
free_shipping: null,
all_conditions: [],
match_criteria: 'all_are_true',
code: null,
suffix: null,
@ -441,7 +451,6 @@
actions: @json($cart_rule[0]).actions,
conditions_list:[],
cart_object: {
criteria: null,
attribute: null,
condition: null,
value: []
@ -516,13 +525,17 @@
},
onSubmit: function (e) {
if (this.conditions_list.length != 0) {
this.conditions_list.test_mode = this.match_criteria;
}
this.all_conditions = JSON.stringify(this.conditions_list);
this.$validator.validateAll().then(result => {
if (result) {
e.target.submit();
}
});
this.all_conditions = JSON.stringify(this.conditions_list);
},
addFlashMessages() {

View File

@ -179,13 +179,22 @@
<div class="control-group">
<label for="criteria" class="required">{{ __('admin::app.promotion.general-info.add-condition') }}</label>
<select type="text" class="control" name="criteria" v-model="criteria">
<select type="text" class="control" v-model="criteria">
<option value="cart">Cart Properties</option>
</select>
</div>
</div>
<div class="mt-10 mb-10"><b>Any of the condition is true</b></div>
<div class="control-group">
{{ __('admin::app.promotion.general-info.test-mode') }}
<select class="control" v-model="match_criteria" style="margin-right: 15px;">
{{ $i = 0 }}
@foreach(config('pricerules.test_mode') as $key => $value)
<option value="{{ $key }}">{{ $value }}</option>
{{ $i++ }}
@endforeach
</select>
</div>
<div class="condition-set">
<!-- Cart Attributes -->
@ -405,6 +414,7 @@
free_shipping: null,
all_conditions: null,
match_criteria: 'all_are_true',
code: null,
suffix: null,
@ -427,7 +437,6 @@
actions: @json($cart_rule[0]).actions,
conditions_list:[],
cart_object: {
criteria: null,
attribute: null,
condition: null,
value: []
@ -511,7 +520,6 @@
this.conditions_list.push(this.cart_object);
this.cart_object = {
criteria: null,
attribute: null,
condition: null,
value: []
@ -559,13 +567,20 @@
},
onSubmit: function (e) {
// if (this.conditions_list.length != 0) {
// this.conditions_list.push(this.match_criteria);
// }
console.log(JSON.stringify(this.conditions_list));
this.all_conditions = JSON.stringify(this.conditions_list);
this.$validator.validateAll().then(result => {
if (result) {
e.target.submit();
}
});
this.all_conditions = JSON.stringify(this.conditions_list);
},
addFlashMessages() {

View File

@ -28,7 +28,7 @@ return [
0 => 'admin::app.promotion.catalog.apply-percent',
1 => 'admin::app.promotion.catalog.apply-fixed',
2 => 'admin::app.promotion.catalog.adjust-to-percent',
3 => 'admin::app.promotion.catalog.adjust-to-value'
// 3 => 'admin::app.promotion.catalog.adjust-to-value'
],
'attributes' => [
@ -85,10 +85,6 @@ return [
'<=' => 'Lesser or equals',
'>' => 'Greater than',
'<' => 'Lesser than',
'{}' => 'Contains'
// '!{}' => 'Does not contains',
// '()' => 'Is one of',
// '!()' => 'Not is one of'
],
'text' => [
@ -99,8 +95,6 @@ return [
'<' => 'Lesser than',
'{}' => 'Contains',
'!{}' => 'Does not contains'
// '()' => 'Is one of',
// '!()' => 'Not is one of'
],
'string' => [
@ -111,8 +105,6 @@ return [
'<' => 'Lesser than',
'{}' => 'Contains',
'!{}' => 'Does not contains'
// '()' => 'Is one of',
// '!()' => 'Not is one of'
],
'boolean' => [
@ -171,9 +163,9 @@ return [
],
'test_mode' => [
0 => 'all_are_true',
1 => 'all_are_false',
2 => 'any_of_true',
3 => 'all_of_false'
'all_are_true' => 'All conditions are true',
'all_are_false' => 'All conditions are false',
'any_is_true' => 'Any condition is true',
'any_is_false' => 'Any condition is false'
]
];

View File

@ -114,6 +114,18 @@ class Discount
if ($canBeApplied->count()) {
$this->save(array_first($canBeApplied)['rule']);
$itemId = array_first($canBeApplied);
foreach (\Cart::getCart()->items as $item) {
if ($item->id == $itemId['item_id']) {
$item->update([
'discount_amount' => array_first($canBeApplied)['discount'],
'base_discount_amount' => array_first($canBeApplied)['discount']
]);
break;
}
}
return array_first($canBeApplied);
} else {
@ -307,6 +319,7 @@ class Discount
}
}
$report['item_id'] = $leastWorthItem['id'];
$report['discount'] = $amountDiscounted;
$report['formatted_discount'] = core()->formatPrice($amountDiscounted, $cart->cart_currency_code);
$report['new_grand_total'] = $cart->grand_total - $amountDiscounted;

View File

@ -2,16 +2,10 @@
namespace Webkul\Discount\Http\Controllers;
use Webkul\Attribute\Repositories\AttributeRepository as Attribute;
use Webkul\Attribute\Repositories\AttributeFamilyRepository as AttributeFamily;
use Webkul\Category\Repositories\CategoryRepository as Category;
use Webkul\Product\Repositories\ProductFlatRepository as Product;
use Webkul\Discount\Repositories\CatalogRuleRepository as CatalogRule;
use Webkul\Discount\Repositories\CartRuleRepository as CartRule;
use Webkul\Checkout\Repositories\CartRepository as Cart;
use Webkul\Discount\Repositories\CartRuleLabelsRepository as CartRuleLabels;
use Webkul\Discount\Repositories\CartRuleCouponsRepository as CartRuleCoupons;
use Validator;
/**
* Cart Rule controller
@ -26,26 +20,6 @@ class CartRuleController extends Controller
*/
protected $_config;
/**
* Attribute $attribute
*/
protected $attribute;
/**
* AttributeFamily $attributeFamily
*/
protected $attributeFamily;
/**
* Category $category
*/
protected $category;
/**
* Product $product
*/
protected $product;
/**
* Property for Cart rule application
*/
@ -71,34 +45,47 @@ class CartRuleController extends Controller
*/
protected $cart;
public function __construct(Attribute $attribute, AttributeFamily $attributeFamily, Category $category, Product $product, CatalogRule $catalogRule, CartRule $cartRule, CartRuleCoupons $cartRuleCoupon, CartRuleLabels $cartRuleLabel)
public function __construct(
CartRule $cartRule,
CartRuleCoupons $cartRuleCoupon,
CartRuleLabels $cartRuleLabel
)
{
$this->_config = request('_config');
$this->attribute = $attribute;
$this->attributeFamily = $attributeFamily;
$this->category = $category;
$this->product = $product;
$this->cartRule = $cartRule;
$this->cartRuleCoupon = $cartRuleCoupon;
$this->cartRuleLabel = $cartRuleLabel;
$this->appliedConfig = config('pricerules.cart');
}
/**
* @return view
*/
public function index()
{
return view($this->_config['view']);
}
/**
* @return view
*/
public function create()
{
return view($this->_config['view'])->with('cart_rule', [$this->appliedConfig, $this->fetchOptionableAttributes(), $this->getStatesAndCountries()]);
return view($this->_config['view'])->with('cart_rule', [$this->appliedConfig, [], $this->getStatesAndCountries()]);
}
/**
* @return Redirect
*/
public function store()
{
$data = request()->all();
$validated = Validator::make($data, [
$validated = $this->validate($data, [
'name' => 'required|string',
'description' => 'string',
// 'customer_groups' => 'required|array',
@ -118,15 +105,10 @@ class CartRuleController extends Controller
'label' => 'array|nullable'
]);
$data['usage_limit'] = 0;
$data['per_customer'] = 0;
if ($validated->fails()) {
session()->flash('error', 'Validation failed');
return redirect()->route('admin.cart-rule.create')
->withErrors($validated)
->withInput();
}
$data = [
'usage_limit' => 0,
'per_customer' => 0
];
if ($data['starts_from'] == "" || $data['ends_till'] == "") {
$data['starts_from'] = null;
@ -136,6 +118,7 @@ class CartRuleController extends Controller
unset($data['_token']);
$channels = $data['channels'];
unset($data['channels']);
// $customer_groups = $data['customer_groups'];
@ -143,6 +126,7 @@ class CartRuleController extends Controller
unset($data['criteria']);
$labels = $data['label'];
unset($data['label']);
unset($data['cart_attributes']);
unset($data['attributes']);
@ -170,6 +154,7 @@ class CartRuleController extends Controller
} else {
$data['conditions'] = json_encode($data['all_conditions']);
}
unset($data['all_conditions']);
if ($data['use_coupon']) {
@ -177,6 +162,7 @@ class CartRuleController extends Controller
$data['auto_generation'] = 0;
$coupons['code'] = $data['code'];
unset($data['code']);
// } else {
// $data['auto_generation'] = 1;
@ -207,6 +193,7 @@ class CartRuleController extends Controller
if (isset($labels['global'])) {
foreach (core()->getAllChannels() as $channel) {
$label1['channel_id'] = $channel->id;
foreach($channel->locales as $locale) {
$label1['locale_id'] = $locale->id;
$label1['label'] = $labels['global'];
@ -218,10 +205,11 @@ class CartRuleController extends Controller
} else {
$label2['label'] = $labels['global'];
$label2['cart_rule_id'] = $ruleCreated->id;
$ruleLabelCreated = $this->cartRuleLabel->create($label2);
}
if(isset($coupons)) {
if (isset($coupons)) {
$coupons['cart_rule_id'] = $ruleCreated->id;
$coupons['usage_per_customer'] = $data['per_customer']; //0 is for unlimited usage
@ -243,18 +231,29 @@ class CartRuleController extends Controller
return redirect()->route($this->_config['redirect']);
}
/**
* @return view
*/
public function edit($id)
{
$cart_rule = $this->cartRule->find($id);
return view($this->_config['view'])->with('cart_rule', [$this->appliedConfig, $this->fetchOptionableAttributes(), $this->getStatesAndCountries(), $cart_rule]);
return view($this->_config['view'])->with('cart_rule', [
$this->appliedConfig,
[],
$this->getStatesAndCountries(),
$cart_rule
]);
}
/**
* @return redirect
*/
public function update($id)
{
$types = config('price_rules.cart.validations');
$validated = Validator::make(request()->all(), [
$this->validate(request(), [
'name' => 'required|string',
'description' => 'string',
// 'customer_groups' => 'required|array',
@ -274,18 +273,13 @@ class CartRuleController extends Controller
'label' => 'array|nullable'
]);
$data['usage_limit'] = 0;
$data['per_customer'] = 0;
if ($validated->fails()) {
session()->flash('error', 'Validation failed');
return redirect()->route('admin.cart-rule.create')
->withErrors($validated)
->withInput();
}
$data = [
'usage_limit' => 0,
'per_customer' => 0
];
$data = request()->all();
dd($data);
if ($data['starts_from'] == "" || $data['ends_till'] == "") {
$data['starts_from'] = null;
$data['ends_till'] = null;
@ -294,6 +288,7 @@ class CartRuleController extends Controller
unset($data['_token']);
$channels = $data['channels'];
unset($data['channels']);
// $customer_groups = $data['customer_groups'];
@ -302,6 +297,7 @@ class CartRuleController extends Controller
if (isset($data['label'])) {
$labels = $data['label'];
unset($data['label']);
}
@ -325,6 +321,7 @@ class CartRuleController extends Controller
}
$data['actions'] = json_encode($data['actions']);
if (! isset($data['all_conditions']) || $data['all_conditions'] == "[]") {
$data['conditions'] = null;
} else {
@ -338,6 +335,7 @@ class CartRuleController extends Controller
$data['auto_generation'] = 0;
$coupons['code'] = $data['code'];
unset($data['code']);
// } else {
// $data['auto_generation'] = 1;
@ -413,17 +411,4 @@ class CartRuleController extends Controller
'states' => $states
];
}
public function fetchOptionableAttributes()
{
$attributesWithOptions = array();
foreach($this->attribute->all() as $attribute) {
if (($attribute->type == 'select' || $attribute->type == 'multiselect') && $attribute->code != 'tax_category_id') {
$attributesWithOptions[$attribute->admin_name] = $attribute->options->toArray();
}
}
return $attributesWithOptions;
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
{
"/js/shop.js": "/js/shop.js?id=9a7027b387c171cd0fd3",
"/css/shop.css": "/css/shop.css?id=5d0ffa213eda626b89f6"
}
"/js/shop.js": "/js/shop.js?id=ad1039174ce2c81c8805",
"/css/shop.css": "/css/shop.css?id=0e57754dbdaba7c6eb76"
}

View File

@ -90,6 +90,8 @@ class OnepageController extends Controller
if (Cart::hasError() || !Cart::saveCustomerAddress($data) || ! $rates = Shipping::collectRates())
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
$rule = Cart::applyNonCoupon();
Cart::collectTotals();
return response()->json($rates);
@ -107,6 +109,8 @@ class OnepageController extends Controller
if (Cart::hasError() || !$shippingMethod || !Cart::saveShippingMethod($shippingMethod))
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
$rule = Cart::applyNonCoupon();
Cart::collectTotals();
return response()->json(Payment::getSupportedPaymentMethods());

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 51.1 (57501) - http://www.bohemiancoding.com/sketch -->
<title>Icon-Note-Large</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Icon-Note-Large" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round">
<g id="Group" transform="translate(3.000000, 3.000000)" stroke="#979797" stroke-width="2">
<path d="M0,3 L18,3 L18,15 L12.5,15 C10.5,17 9.5,18 9.5,18 C9.5,18 8.33333333,17 6,15 L0,15 L0,3 Z" id="Rectangle-16"></path>
<path d="M7,2.2522475 C7,0.997673883 8.09454039,4.04787445e-16 9.44472438,0 C10.7949084,-4.04787445e-16 11.8894488,0.997673883 11.8894488,2.22836699 L11.8894488,7.77163301 C11.8894488,9.00232612 10.7949084,10 9.44472438,10 C8.09454039,10 7,9.00232612 7,7.77163301 L7,6.80974897" id="Rectangle-17"></path>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="48px" height="48px" viewBox="0 0 48 48" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 51.1 (57501) - http://www.bohemiancoding.com/sketch -->
<title>Icon-Promition-Active</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Icon-Promition-Active" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round">
<g id="Group" transform="translate(8.000000, 10.000000)" stroke="#0041FF" stroke-width="2">
<polygon id="Rectangle-15" points="5 8.96186626 22 1.91619318 22 26.0838068 5 19.0381337"></polygon>
<path d="M22,0 L22,28" id="Path-17"></path>
<path d="M3.5,9 L5,9 L5,19 L3.5,19 C1.56700338,19 2.36723813e-16,17.4329966 0,15.5 L0,12.5 C-2.36723813e-16,10.5670034 1.56700338,9 3.5,9 Z" id="Rectangle-15"></path>
<path d="M8,21 L8,22.5494015 C8,24.2446714 9.1212786,25.7355564 10.75,26.2058824 L10.75,26.2058824 C12.3703103,26.6737794 14.1023615,25.9901587 14.9663265,24.5417467 L15.5,23.6470588" id="Path-18"></path>
<path d="M26,14.25 L32,14.25" id="Path-19"></path>
<path d="M26,9.24264069 L30.2426407,5" id="Path-19"></path>
<path d="M26,23.1213203 L30.2426407,18.8786797" id="Path-19" transform="translate(28.121320, 21.000000) scale(-1, 1) translate(-28.121320, -21.000000) "></path>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="48px" height="48px" viewBox="0 0 48 48" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 51.1 (57501) - http://www.bohemiancoding.com/sketch -->
<title>Icon-Promition</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Icon-Promition" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round">
<g id="Group" transform="translate(8.000000, 10.000000)" stroke="#979797" stroke-width="2">
<polygon id="Rectangle-15" points="5 8.96186626 22 1.91619318 22 26.0838068 5 19.0381337"></polygon>
<path d="M22,0 L22,28" id="Path-17"></path>
<path d="M3.5,9 L5,9 L5,19 L3.5,19 C1.56700338,19 2.36723813e-16,17.4329966 0,15.5 L0,12.5 C-2.36723813e-16,10.5670034 1.56700338,9 3.5,9 Z" id="Rectangle-15"></path>
<path d="M8,21 L8,22.5494015 C8,24.2446714 9.1212786,25.7355564 10.75,26.2058824 L10.75,26.2058824 C12.3703103,26.6737794 14.1023615,25.9901587 14.9663265,24.5417467 L15.5,23.6470588" id="Path-18"></path>
<path d="M26,14.25 L32,14.25" id="Path-19"></path>
<path d="M26,9.24264069 L30.2426407,5" id="Path-19"></path>
<path d="M26,23.1213203 L30.2426407,18.8786797" id="Path-19" transform="translate(28.121320, 21.000000) scale(-1, 1) translate(-28.121320, -21.000000) "></path>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
{
"/js/ui.js": "/js/ui.js?id=97343143e38eeba34064",
"/css/ui.css": "/css/ui.css?id=f912bd2a6525691bdb61"
"/js/ui.js": "/js/ui.js?id=3cebf9d7b4dc56d1b407",
"/css/ui.css": "/css/ui.css?id=c846938a649c221ac297"
}