diff --git a/composer.json b/composer.json
index 9c16b61f3..d58eb55c2 100755
--- a/composer.json
+++ b/composer.json
@@ -30,8 +30,6 @@
"maatwebsite/excel": "3.1.x-dev",
"nwidart/laravel-modules": "^3.2",
"prettus/l5-repository": "^2.6",
- "propaganistas/laravel-intl": "^2.0",
- "stripe/stripe-php": "6.0",
"tymon/jwt-auth": "dev-develop"
},
"require-dev": {
diff --git a/config/app.php b/config/app.php
index cd7f2f31b..6a6214c1b 100755
--- a/config/app.php
+++ b/config/app.php
@@ -203,7 +203,6 @@ return [
*/
Dimsav\Translatable\TranslatableServiceProvider::class,
- Propaganistas\LaravelIntl\IntlServiceProvider::class,
/*
* Application Service Providers...
diff --git a/packages/Webkul/API/Http/Resources/Checkout/CartAddress.php b/packages/Webkul/API/Http/Resources/Checkout/CartAddress.php
index 65ee44f08..1bed8697c 100644
--- a/packages/Webkul/API/Http/Resources/Checkout/CartAddress.php
+++ b/packages/Webkul/API/Http/Resources/Checkout/CartAddress.php
@@ -22,7 +22,7 @@ class CartAddress extends JsonResource
'email' => $this->email,
'address1' => explode(PHP_EOL, $this->address1),
'country' => $this->country,
- 'country_name' => country()->name($this->country),
+ 'country_name' => core()->country_name($this->country),
'state' => $this->state,
'city' => $this->city,
'postcode' => $this->postcode,
diff --git a/packages/Webkul/API/Http/Resources/Customer/CustomerAddress.php b/packages/Webkul/API/Http/Resources/Customer/CustomerAddress.php
index c22e9b9ed..3b792e195 100644
--- a/packages/Webkul/API/Http/Resources/Customer/CustomerAddress.php
+++ b/packages/Webkul/API/Http/Resources/Customer/CustomerAddress.php
@@ -18,7 +18,7 @@ class CustomerAddress extends JsonResource
'id' => $this->id,
'address1' => explode(PHP_EOL, $this->address1),
'country' => $this->country,
- 'country_name' => country()->name($this->country),
+ 'country_name' => core()->country_name($this->country),
'state' => $this->state,
'city' => $this->city,
'postcode' => $this->postcode,
diff --git a/packages/Webkul/API/Http/Resources/Sales/OrderAddress.php b/packages/Webkul/API/Http/Resources/Sales/OrderAddress.php
index e21e45b10..bb18a5a6a 100644
--- a/packages/Webkul/API/Http/Resources/Sales/OrderAddress.php
+++ b/packages/Webkul/API/Http/Resources/Sales/OrderAddress.php
@@ -21,7 +21,7 @@ class OrderAddress extends JsonResource
'last_name' => $this->last_name,
'address1' => explode(PHP_EOL, $this->address1),
'country' => $this->country,
- 'country_name' => country()->name($this->country),
+ 'country_name' => core()->country_name($this->country),
'state' => $this->state,
'city' => $this->city,
'postcode' => $this->postcode,
diff --git a/packages/Webkul/Admin/src/Resources/lang/en/app.php b/packages/Webkul/Admin/src/Resources/lang/en/app.php
index 2cb5f3ca3..beb544e03 100755
--- a/packages/Webkul/Admin/src/Resources/lang/en/app.php
+++ b/packages/Webkul/Admin/src/Resources/lang/en/app.php
@@ -771,7 +771,10 @@ return [
'edit-help-title' => 'Edit Customer',
'delete-help-title' => 'Delete Customer',
'mass-destroy-success' => 'Customers deleted successfully',
- 'mass-update-success' => 'Customers updated successfully'
+ 'mass-update-success' => 'Customers updated successfully',
+ 'status' => 'Status',
+ 'active' => 'Active',
+ 'in-active' => 'Inactive'
],
'reviews' => [
diff --git a/packages/Webkul/Admin/src/Resources/views/customers/edit.blade.php b/packages/Webkul/Admin/src/Resources/views/customers/edit.blade.php
index 8be4e87a4..ebc3aabee 100755
--- a/packages/Webkul/Admin/src/Resources/views/customers/edit.blade.php
+++ b/packages/Webkul/Admin/src/Resources/views/customers/edit.blade.php
@@ -58,12 +58,21 @@
diff --git a/packages/Webkul/Admin/src/Resources/views/sales/address.blade.php b/packages/Webkul/Admin/src/Resources/views/sales/address.blade.php
index 97489eebb..1bf6bffe2 100755
--- a/packages/Webkul/Admin/src/Resources/views/sales/address.blade.php
+++ b/packages/Webkul/Admin/src/Resources/views/sales/address.blade.php
@@ -2,5 +2,5 @@
{{ $address->address1 }}
{{ $address->city }}
{{ $address->state }}
-{{ country()->name($address->country) }} {{ $address->postcode }}
+{{ core()->country_name($address->country) }} {{ $address->postcode }}
{{ __('shop::app.checkout.onepage.contact') }} : {{ $address->phone }}
\ No newline at end of file
diff --git a/packages/Webkul/Admin/src/Resources/views/sales/invoices/pdf.blade.php b/packages/Webkul/Admin/src/Resources/views/sales/invoices/pdf.blade.php
index 020ca4384..8e481faa9 100755
--- a/packages/Webkul/Admin/src/Resources/views/sales/invoices/pdf.blade.php
+++ b/packages/Webkul/Admin/src/Resources/views/sales/invoices/pdf.blade.php
@@ -114,7 +114,7 @@
{{ $invoice->order->billing_address->address1 }}
{{ $invoice->order->billing_address->city }}
{{ $invoice->order->billing_address->state }}
-
{{ country()->name($invoice->order->billing_address->country) }} {{ $invoice->order->billing_address->postcode }}
+
{{ core()->country_name($invoice->order->billing_address->country) }} {{ $invoice->order->billing_address->postcode }}
{{ __('shop::app.checkout.onepage.contact') }} : {{ $invoice->order->billing_address->phone }}
@@ -122,7 +122,7 @@
{{ $invoice->order->shipping_address->address1 }}
{{ $invoice->order->shipping_address->city }}
{{ $invoice->order->shipping_address->state }}
- {{ country()->name($invoice->order->shipping_address->country) }} {{ $invoice->order->shipping_address->postcode }}
+ {{ core()->country_name($invoice->order->shipping_address->country) }} {{ $invoice->order->shipping_address->postcode }}
{{ __('shop::app.checkout.onepage.contact') }} : {{ $invoice->order->shipping_address->phone }}
|
diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php
index d5e023ae1..795d7557c 100755
--- a/packages/Webkul/Checkout/src/Cart.php
+++ b/packages/Webkul/Checkout/src/Cart.php
@@ -635,12 +635,12 @@ class Cart {
$option = $attribute->options()->where('id', $product->{$attribute->code})->first();
$data['attributes'][$attribute->code] = [
- 'attribute_name' => $attribute->name,
+ 'attribute_name' => $attribute->name ? $attribute->name : $attribute->admin_name,
'option_id' => $option->id,
'option_label' => $option->label,
];
- $labels[] = $attribute->name . ' : ' . $option->label;
+ $labels[] = ($attribute->name ? $attribute->name : $attribute->admin_name) . ' : ' . $option->label;
}
$data['html'] = implode(', ', $labels);
diff --git a/packages/Webkul/Checkout/src/Models/CartShippingRate.php b/packages/Webkul/Checkout/src/Models/CartShippingRate.php
index a9d15e8b6..6ecf168cb 100755
--- a/packages/Webkul/Checkout/src/Models/CartShippingRate.php
+++ b/packages/Webkul/Checkout/src/Models/CartShippingRate.php
@@ -7,6 +7,8 @@ use Webkul\Checkout\Contracts\CartShippingRate as CartShippingRateContract;
class CartShippingRate extends Model implements CartShippingRateContract
{
+ protected $fillable = ['carrier', 'carrier_title', 'method', 'method_title', 'method_description', 'price', 'base_price'];
+
/**
* Get the post that owns the comment.
*/
diff --git a/packages/Webkul/Core/src/Core.php b/packages/Webkul/Core/src/Core.php
index 861fd674f..8ff4aa314 100755
--- a/packages/Webkul/Core/src/Core.php
+++ b/packages/Webkul/Core/src/Core.php
@@ -394,9 +394,9 @@ class Core
if (is_null($amount))
$amount = 0;
- $currencyCode = $this->getCurrentCurrency()->code;
+ $formater = new \NumberFormatter( app()->getLocale(), \NumberFormatter::CURRENCY );
- return currency($this->convertPrice($amount), $currencyCode);
+ return $formater->formatCurrency($this->convertPrice($amount), $this->getCurrentCurrency()->code);
}
/**
@@ -407,11 +407,10 @@ class Core
*/
public function currencySymbol($code)
{
- try {
- return currency()->symbol($code);
- } catch (\Exception $e) {
- return $code;
- }
+
+ $formatter = new \NumberFormatter(app()->getLocale() . '@currency=' . $code, \NumberFormatter::CURRENCY);
+
+ return $formatter->getSymbol(\NumberFormatter::CURRENCY_SYMBOL);
}
/**
@@ -425,7 +424,9 @@ class Core
if (is_null($price))
$price = 0;
- return currency($price, $currencyCode);
+ $formater = new \NumberFormatter( app()->getLocale(), \NumberFormatter::CURRENCY );
+
+ return $formater->formatCurrency($price, $currencyCode);
}
/**
@@ -438,8 +439,10 @@ class Core
{
if (is_null($price))
$price = 0;
+
+ $formater = new \NumberFormatter( app()->getLocale(), \NumberFormatter::CURRENCY );
- return currency($price, $this->getBaseCurrencyCode());
+ return $formater->formatCurrency($price, $this->getBaseCurrencyCode());
}
/**
@@ -616,6 +619,19 @@ class Core
return $this->countryRepository->all();
}
+ /**
+ * Returns country name by code
+ *
+ * @param string $code
+ * @return string
+ */
+ public function country_name($code)
+ {
+ $country = $this->countryRepository->findOneByField('code', $code);
+
+ return $country ? $country->name : '';
+ }
+
/**
* Retrieve all country states
*
diff --git a/packages/Webkul/Discount/src/Actions/Action.php b/packages/Webkul/Discount/src/Actions/Action.php
index 053a3e7ea..62268aa18 100644
--- a/packages/Webkul/Discount/src/Actions/Action.php
+++ b/packages/Webkul/Discount/src/Actions/Action.php
@@ -5,4 +5,6 @@ namespace Webkul\Discount\Actions;
abstract class Action
{
abstract public function calculate($rule, $item, $cart);
+
+ abstract public function calculateOnShipping($cart);
}
\ No newline at end of file
diff --git a/packages/Webkul/Discount/src/Actions/BuyAGetB.php b/packages/Webkul/Discount/src/Actions/BuyAGetB.php
index 21d8a5475..f1e47aa90 100644
--- a/packages/Webkul/Discount/src/Actions/BuyAGetB.php
+++ b/packages/Webkul/Discount/src/Actions/BuyAGetB.php
@@ -37,4 +37,16 @@ class BuyAGetB extends Action
return $report;
}
+
+ /**
+ * Calculates the impact on the shipping amount if the rule is apply_to_shipping enabled
+ */
+ public function calculateOnShipping($cart)
+ {
+ $percentOfDiscount = ($cart->base_discount_amount * 100) / $cart->base_grand_total;
+
+ $discountOnShipping = ($percentOfDiscount / 100) * $cart->selected_shipping_rate->base_price;
+
+ return $discountOnShipping;
+ }
}
\ No newline at end of file
diff --git a/packages/Webkul/Discount/src/Actions/FixedAmount.php b/packages/Webkul/Discount/src/Actions/FixedAmount.php
index 8ff965281..2b5a200f9 100644
--- a/packages/Webkul/Discount/src/Actions/FixedAmount.php
+++ b/packages/Webkul/Discount/src/Actions/FixedAmount.php
@@ -37,4 +37,16 @@ class FixedAmount extends Action
return $report;
}
+
+ /**
+ * Calculates the impact on the shipping amount if the rule is apply_to_shipping enabled
+ */
+ public function calculateOnShipping($cart)
+ {
+ $percentOfDiscount = ($cart->base_discount_amount * 100) / $cart->base_grand_total;
+
+ $discountOnShipping = ($percentOfDiscount / 100) * $cart->selected_shipping_rate->base_price;
+
+ return $discountOnShipping;
+ }
}
\ No newline at end of file
diff --git a/packages/Webkul/Discount/src/Actions/PercentOfProduct.php b/packages/Webkul/Discount/src/Actions/PercentOfProduct.php
index 07e004591..79683be5e 100644
--- a/packages/Webkul/Discount/src/Actions/PercentOfProduct.php
+++ b/packages/Webkul/Discount/src/Actions/PercentOfProduct.php
@@ -34,4 +34,16 @@ class PercentOfProduct extends Action
return $report;
}
+
+ /**
+ * Calculates the impact on the shipping amount if the rule is apply_to_shipping enabled
+ */
+ public function calculateOnShipping($cart)
+ {
+ $percentOfDiscount = ($cart->base_discount_amount * 100) / $cart->base_grand_total;
+
+ $discountOnShipping = ($percentOfDiscount / 100) * $cart->selected_shipping_rate->base_price;
+
+ return $discountOnShipping;
+ }
}
\ No newline at end of file
diff --git a/packages/Webkul/Discount/src/Helpers/CouponAbleRule.php b/packages/Webkul/Discount/src/Helpers/CouponAbleRule.php
index 7ae8a2585..f46c4c5f9 100644
--- a/packages/Webkul/Discount/src/Helpers/CouponAbleRule.php
+++ b/packages/Webkul/Discount/src/Helpers/CouponAbleRule.php
@@ -18,17 +18,10 @@ class CouponAbleRule extends Discount
{
$cart = Cart::getCart();
- if (auth()->guard('customer')->check()) {
- $rules = $this->cartRule->findWhere([
- 'use_coupon' => 1,
- 'status' => 1
- ]);
- } else {
- $rules = $this->cartRule->findWhere([
- 'use_coupon' => 1,
- 'status' => 1
- ]);
- }
+ $rules = $this->cartRule->findWhere([
+ 'use_coupon' => 1,
+ 'status' => 1
+ ]);
$applicableRule = null;
@@ -53,15 +46,22 @@ class CouponAbleRule extends Discount
$impact = $actionInstance->calculate($applicableRule, $item, $cart);
+ if ($impact['discount'] == 0) {
+ return false;
+ }
+
+ // avoid applying the same rule
$ifAlreadyApplied = $this->cartRuleCart->findWhere([
'cart_id' => $cart->id,
'cart_rule_id' => $applicableRule->id
]);
if ($ifAlreadyApplied->count() == 1) {
+ // can give a message that coupon is already applied
return false;
}
+ // if the rule ain't same
$ifAlreadyApplied = $this->cartRuleCart->findWhere([
'cart_id' => $cart->id,
]);
@@ -72,35 +72,43 @@ class CouponAbleRule extends Discount
return $impact;
}
- $alreadyAppliedRule = $ifAlreadyApplied->first()->cart_rule;
-
- if ($alreadyAppliedRule->priority < $rule->priority) {
+ // the only case where a non couponable rule defeats couponable rule
+ if ($ifAlreadyApplied->first()->cart_rule->use_coupon == 0 && $ifAlreadyApplied->first()->cart_rule->end_other_rules == 1) {
return false;
- } else if ($alreadyAppliedRule->priority == $applicableRule->priority) {
- // tie breaker case
+ }
- // end other rules
- if ($alreadyAppliedRule->end_other_rules) {
+ if ($ifAlreadyApplied->first()->cart_rule->use_coupon == 1 && $ifAlreadyApplied->first()->cart_rule->end_other_rules == 1) {
+ return false;
+ }
+
+ if ($ifAlreadyApplied->first()->cart_rule->use_coupon == 1) {
+ $alreadyAppliedRule = $ifAlreadyApplied->first()->cart_rule;
+
+ if ($alreadyAppliedRule->priority < $applicableRule->priority) {
return false;
- }
+ } else if ($alreadyAppliedRule->priority == $applicableRule->priority) {
+ $actionInstance = new $this->rules[$alreadyAppliedRule->action_type];
- $actionInstance = new $this->rules[$alreadyAppliedRule->action_type];
+ $alreadyAppliedRuleImpact = $actionInstance->calculate($alreadyAppliedRule, $item, $cart);
- $alreadyAppliedRuleImpact = $actionInstance->calculate($alreadyAppliedRule, $item, $cart);
-
- if ($alreadyAppliedRule['discount'] > $impact['discount']) {
- return false;
- } else if ($alreadyAppliedRule['discount'] < $impact['discount']) {
- $this->save($applicableRule);
-
- return $impact;
- } else {
- // least id case
- if ($applicableRule->id < $alreadyAppliedRule->id) {
+ if ($alreadyAppliedRule['discount'] > $impact['discount']) {
+ return false;
+ } else if ($alreadyAppliedRule['discount'] < $impact['discount']) {
$this->save($applicableRule);
return $impact;
+ } else {
+ // least id case
+ if ($applicableRule->id < $alreadyAppliedRule->id) {
+ $this->save($applicableRule);
+
+ return $impact;
+ }
}
+ } else {
+ $this->save($applicableRule);
+
+ return $impact;
}
} else {
$this->save($applicableRule);
@@ -126,32 +134,28 @@ class CouponAbleRule extends Discount
]);
if ($existingRule->count()) {
- if ($existingRule->first()->cart_rule->use_coupon) {
- $existingRule->first()->delete();
+ $existingRule->first()->delete();
- foreach ($cart->items as $item) {
- if ($item->discount_amount > 0) {
- $item->update([
- 'discount_amount' => 0,
- 'base_discount_amount' => 0,
- 'discount_percent' => 0,
- 'coupon_code' => NULL
- ]);
- }
+ foreach ($cart->items as $item) {
+ if ($item->discount_amount > 0) {
+ $item->update([
+ 'discount_amount' => 0,
+ 'base_discount_amount' => 0,
+ 'discount_percent' => 0,
+ 'coupon_code' => NULL
+ ]);
}
-
- $cart->update([
- 'coupon_code' => NULL,
- 'discount_amount' => 0,
- 'base_discount_amount' => 0
- ]);
-
- Cart::collectTotals();
-
- return true;
- } else {
- return false;
}
+
+ $cart->update([
+ 'coupon_code' => NULL,
+ 'discount_amount' => 0,
+ 'base_discount_amount' => 0
+ ]);
+
+ Cart::collectTotals();
+
+ return true;
} else {
return false;
}
diff --git a/packages/Webkul/Discount/src/Helpers/Discount.php b/packages/Webkul/Discount/src/Helpers/Discount.php
index 704f15631..5890daabf 100644
--- a/packages/Webkul/Discount/src/Helpers/Discount.php
+++ b/packages/Webkul/Discount/src/Helpers/Discount.php
@@ -213,17 +213,17 @@ abstract class Discount
if ($rule->action_type == 'percent_of_product') {
$item->update([
'discount_percent' => $rule->discount_amount,
- 'discount_amount' => $impact['discount'],
+ 'discount_amount' => core()->convertPrice($impact['discount'], $cart->cart_currency_code),
'base_discount_amount' => $impact['discount']
]);
} else {
$item->update([
- 'discount_amount' => $impact['discount'],
+ 'discount_amount' => core()->convertPrice($impact['discount'], $cart->cart_currency_code),
'base_discount_amount' => $impact['discount']
]);
}
- // save coupon if rule has it
+ // save coupon if rule use it
if ($rule->use_coupon) {
$coupon = $rule->coupons->code;
@@ -287,6 +287,7 @@ abstract class Discount
foreach ($cart->items as $item) {
if ($item->base_total > $maxValue) {
$maxValue = $item->total;
+
$maxWorthItem = [
'id' => $item->id,
'price' => $item->price,
diff --git a/packages/Webkul/Discount/src/Helpers/NonCouponAbleRule.php b/packages/Webkul/Discount/src/Helpers/NonCouponAbleRule.php
index 035c67232..11c54d095 100644
--- a/packages/Webkul/Discount/src/Helpers/NonCouponAbleRule.php
+++ b/packages/Webkul/Discount/src/Helpers/NonCouponAbleRule.php
@@ -19,17 +19,10 @@ class NonCouponAbleRule extends Discount
$applicableRules = array();
- if (auth()->guard('customer')->check()) {
- $rules = $this->cartRule->findWhere([
- 'use_coupon' => 0,
- 'status' => 1
- ]);
- } else {
- $rules = $this->cartRule->findWhere([
- 'use_coupon' => 0,
- 'status' => 1
- ]);
- }
+ $rules = $this->cartRule->findWhere([
+ 'use_coupon' => 0,
+ 'status' => 1
+ ]);
$alreadyAppliedCartRuleCart = $this->cartRuleCart->findWhere([
'cart_id' => $cart->id,
@@ -47,11 +40,11 @@ class NonCouponAbleRule extends Discount
// all discount is cleared fro mthe cart and cart items table
$this->clearDiscount();
- return null;
+ return false;
}
if ($alreadyAppliedRule->use_coupon) {
- return null;
+ return false;
}
}
@@ -202,7 +195,7 @@ class NonCouponAbleRule extends Discount
return array_first($applicableRules)['impact'];
} else {
- return null;
+ return false;
}
}
}
\ No newline at end of file
diff --git a/packages/Webkul/Discount/src/Helpers/ValidatesDiscount.php b/packages/Webkul/Discount/src/Helpers/ValidatesDiscount.php
index 92c1899bd..51e8de8b5 100644
--- a/packages/Webkul/Discount/src/Helpers/ValidatesDiscount.php
+++ b/packages/Webkul/Discount/src/Helpers/ValidatesDiscount.php
@@ -2,12 +2,31 @@
namespace Webkul\Discount\Helpers;
-use Webkul\Discount\Helpers\Discount;
+use Webkul\Discount\Repositories\CartRuleCartRepository as CartRuleCart;
class ValidatesDiscount
{
+ /**
+ * CartRuleCartRepository instance
+ */
+ protected $cartRuleCart;
+
+ /**
+ * Initializes type hinted dependencies
+ *
+ * @param CartRuleCart $cartRuleCart
+ */
+ public function __construct(CartRuleCart $cartRuleCart)
+ {
+ $this->cartRuleCart = $cartRuleCart;
+ }
+
/**
* Validates the currently applied cart rule on the current cart
+ *
+ * @param $cart instance
+ *
+ * @return mixed
*/
public function validate($cart)
{
@@ -18,7 +37,158 @@ class ValidatesDiscount
if ($appliedRule->count()) {
$appliedRule = $appliedRule->first()->cart_rule;
- $applicability = $this->checkApplicability($appliedRule);
+ if ($appliedRule->status == 1) {
+ $applicability = $this->checkApplicability($appliedRule);
+
+ if (! $applicability) {
+ return $this->remove();
+ } else {
+ if ($appliedRule->free_shipping && $cart->selected_shipping_rate->base_price > 0) {
+ $cart->selected_shipping_rate->update([
+ 'price' => 0,
+ 'base_price' => 0
+ ]);
+ } else if ($appliedRule->free_shipping == 0 && $appliedRule->apply_to_shipping && $cart->selected_shipping_rate->base_price > 0) {
+ $actionType = config('discount-rules')[$appliedRule->action_type];
+
+ if ($appliedRule->apply_to_shipping) {
+ $actionInstance = new $actionType;
+
+ $discountOnShipping = $actionInstance->calculateOnShipping($cart);
+
+ $cart->selected_shipping_rate->update([
+ 'price' => $cart->selected_shipping_rate->base_price - $discountOnShipping,
+ 'base_price' => $cart->selected_shipping_rate->price - core()->convertPrice($discountOnShipping, $cart->cart_currency_code)
+ ]);
+ }
+ }
+ }
+ } else {
+ return $this->remove();
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Checks whether coupon is getting applied on current cart instance or not
+ *
+ * @return boolean
+ */
+ public function checkApplicability($rule)
+ {
+ $cart = \Cart::getCart();
+
+ $timeBased = false;
+
+ // time based constraints
+ if ($rule->starts_from != null && $rule->ends_till == null) {
+ if (Carbon::parse($rule->starts_from) < now()) {
+ $timeBased = true;
+ }
+ } else if ($rule->starts_from == null && $rule->ends_till != null) {
+ if (Carbon::parse($rule->ends_till) > now()) {
+ $timeBased = true;
+ }
+ } else if ($rule->starts_from != null && $rule->ends_till != null) {
+ if (Carbon::parse($rule->starts_from) < now() && now() < Carbon::parse($rule->ends_till)) {
+ $timeBased = true;
+ }
+ } else {
+ $timeBased = true;
+ }
+
+ $channelBased = false;
+
+ // channel based constraints
+ foreach ($rule->channels as $channel) {
+ if ($channel->channel_id == core()->getCurrentChannel()->id) {
+ $channelBased = true;
+ }
+ }
+
+ $customerGroupBased = false;
+
+ // customer groups based constraints
+ if (auth()->guard('customer')->check()) {
+ foreach ($rule->customer_groups as $customer_group) {
+ if (auth()->guard('customer')->user()->group->exists()) {
+ if ($customer_group->customer_group_id == auth()->guard('customer')->user()->group->id) {
+ $customerGroupBased = true;
+ }
+ }
+ }
+ } else {
+ foreach ($rule->customer_groups as $customer_group) {
+ if ($customer_group->customer_group->code == 'guest') {
+ $customerGroupBased = true;
+ }
+ }
+ }
+
+ $conditionsBased = true;
+
+ //check conditions
+ if ($rule->conditions != null) {
+ $conditions = json_decode(json_decode($rule->conditions));
+
+ $test_mode = array_last($conditions);
+
+ if ($test_mode->criteria == 'any_is_true') {
+ $conditionsBased = $this->testIfAnyConditionIsTrue($conditions, $cart);
+ }
+
+ if ($test_mode->criteria == 'all_are_true') {
+ $conditionsBased = $this->testIfAllConditionAreTrue($conditions, $cart);
+ }
+ }
+
+ if ($timeBased && $channelBased && $customerGroupBased && $conditionsBased) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Removes the already applied coupon on the current cart instance
+ *
+ * @return boolean
+ */
+ public function remove()
+ {
+ $cart = Cart::getCart();
+
+ $existingRule = $this->cartRuleCart->findWhere([
+ 'cart_id' => $cart->id
+ ]);
+
+ if ($existingRule->count()) {
+ $existingRule->first()->delete();
+
+ foreach ($cart->items as $item) {
+ if ($item->discount_amount > 0) {
+ $item->update([
+ 'discount_amount' => 0,
+ 'base_discount_amount' => 0,
+ 'discount_percent' => 0,
+ 'coupon_code' => NULL
+ ]);
+ }
+ }
+
+ $cart->update([
+ 'coupon_code' => NULL,
+ 'discount_amount' => 0,
+ 'base_discount_amount' => 0
+ ]);
+
+ Cart::collectTotals();
+
+ return true;
+ } else {
+ return false;
}
}
}
\ No newline at end of file
diff --git a/packages/Webkul/Shop/src/Http/Controllers/OnepageController.php b/packages/Webkul/Shop/src/Http/Controllers/OnepageController.php
index 7981eae97..a2306085b 100755
--- a/packages/Webkul/Shop/src/Http/Controllers/OnepageController.php
+++ b/packages/Webkul/Shop/src/Http/Controllers/OnepageController.php
@@ -232,7 +232,7 @@ class OnepageController extends Controller
{
$cart = Cart::getCart();
- // $this->validatesDiscount->validate($cart);
+ $this->validatesDiscount->validate($cart);
if (! $cart->shipping_address) {
throw new \Exception(trans('Please check shipping address.'));
diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php
index 2ba29bc61..2112e890d 100755
--- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php
+++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php
@@ -488,7 +488,9 @@
error_message: null,
- couponChanged: false
+ couponChanged: false,
+
+ changeCount: 0
}
},
@@ -531,8 +533,15 @@
},
changeCoupon: function() {
- if (this.couponChanged == true) {
+ console.log('called');
+ if (this.couponChanged == true && this.changeCount == 0) {
+ this.changeCount++;
+
+ this.error_message = null;
+
this.couponChanged = false;
+ } else {
+ this.changeCount = 0;
}
},
diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/onepage/review.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/onepage/review.blade.php
index d696a7e3c..d77d27bc9 100755
--- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage/review.blade.php
+++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage/review.blade.php
@@ -19,7 +19,7 @@
{{ $billingAddress->address1 }},
{{ $billingAddress->state }}
- {{ country()->name($billingAddress->country) }} {{ $billingAddress->postcode }}
+ {{ core()->country_name($billingAddress->country) }} {{ $billingAddress->postcode }}
@@ -47,7 +47,7 @@
{{ $shippingAddress->address1 }},
{{ $shippingAddress->state }}
- {{ country()->name($shippingAddress->country) }} {{ $shippingAddress->postcode }}
+ {{ core()->country_name($shippingAddress->country) }} {{ $shippingAddress->postcode }}
diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php
index 2993f1dad..64c3a6f70 100755
--- a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php
+++ b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php
@@ -70,7 +70,8 @@
-
@{{ error_message }}
+
+
* @{{ error_message }}
diff --git a/packages/Webkul/Shop/src/Resources/views/customers/account/address/index.blade.php b/packages/Webkul/Shop/src/Resources/views/customers/account/address/index.blade.php
index cfbf08299..3a397ea24 100755
--- a/packages/Webkul/Shop/src/Resources/views/customers/account/address/index.blade.php
+++ b/packages/Webkul/Shop/src/Resources/views/customers/account/address/index.blade.php
@@ -57,7 +57,7 @@
- {{ country()->name($address->country) }} {{ $address->postcode }}
+ {{ core()->country_name($address->country) }} {{ $address->postcode }}
diff --git a/packages/Webkul/Shop/src/Resources/views/customers/account/orders/pdf.blade.php b/packages/Webkul/Shop/src/Resources/views/customers/account/orders/pdf.blade.php
index 4b8b548c3..c5378930e 100755
--- a/packages/Webkul/Shop/src/Resources/views/customers/account/orders/pdf.blade.php
+++ b/packages/Webkul/Shop/src/Resources/views/customers/account/orders/pdf.blade.php
@@ -114,7 +114,7 @@
{{ $invoice->order->billing_address->address1 }}
{{ $invoice->order->billing_address->city }}
{{ $invoice->order->billing_address->state }}
- {{ country()->name($invoice->order->billing_address->country) }} {{ $invoice->order->billing_address->postcode }}
+ {{ core()->country_name($invoice->order->billing_address->country) }} {{ $invoice->order->billing_address->postcode }}
{{ __('shop::app.customer.account.order.view.contact') }} : {{ $invoice->order->billing_address->phone }}
@@ -122,7 +122,7 @@
{{ $invoice->order->shipping_address->address1 }}
{{ $invoice->order->shipping_address->city }}
{{ $invoice->order->shipping_address->state }}
- {{ country()->name($invoice->order->shipping_address->country) }} {{ $invoice->order->shipping_address->postcode }}
+ {{ core()->country_name($invoice->order->shipping_address->country) }} {{ $invoice->order->shipping_address->postcode }}
{{ __('shop::app.customer.account.order.view.contact') }} : {{ $invoice->order->shipping_address->phone }}
|
diff --git a/packages/Webkul/Shop/src/Resources/views/emails/sales/new-admin-order.blade.php b/packages/Webkul/Shop/src/Resources/views/emails/sales/new-admin-order.blade.php
index c9aa7618b..e5bdd6b27 100644
--- a/packages/Webkul/Shop/src/Resources/views/emails/sales/new-admin-order.blade.php
+++ b/packages/Webkul/Shop/src/Resources/views/emails/sales/new-admin-order.blade.php
@@ -43,7 +43,7 @@
- {{ country()->name($order->shipping_address->country) }} {{ $order->shipping_address->postcode }}
+ {{ core()->country_name($order->shipping_address->country) }} {{ $order->shipping_address->postcode }}
- {{ country()->name($order->billing_address->country) }} {{ $order->billing_address->postcode }}
+ {{ core()->country_name($order->billing_address->country) }} {{ $order->billing_address->postcode }}
- {{ country()->name($order->shipping_address->country) }} {{ $order->shipping_address->postcode }}
+ {{ core()->country_name($order->shipping_address->country) }} {{ $order->shipping_address->postcode }}
- {{ country()->name($order->billing_address->country) }} {{ $order->billing_address->postcode }}
+ {{ core()->country_name($order->billing_address->country) }} {{ $order->billing_address->postcode }}
- {{ country()->name($order->shipping_address->country) }} {{ $order->shipping_address->postcode }}
+ {{ core()->country_name($order->shipping_address->country) }} {{ $order->shipping_address->postcode }}
- {{ country()->name($order->billing_address->country) }} {{ $order->billing_address->postcode }}
+ {{ core()->country_name($order->billing_address->country) }} {{ $order->billing_address->postcode }}
- {{ country()->name($order->shipping_address->country) }} {{ $order->shipping_address->postcode }}
+ {{ core()->country_name($order->shipping_address->country) }} {{ $order->shipping_address->postcode }}
- {{ country()->name($order->billing_address->country) }} {{ $order->billing_address->postcode }}
+ {{ core()->country_name($order->billing_address->country) }} {{ $order->billing_address->postcode }}
- {{ country()->name($order->shipping_address->country) }} {{ $order->shipping_address->postcode }}
+ {{ core()->country_name($order->shipping_address->country) }} {{ $order->shipping_address->postcode }}
- {{ country()->name($order->billing_address->country) }} {{ $order->billing_address->postcode }}
+ {{ core()->country_name($order->billing_address->country) }} {{ $order->billing_address->postcode }}