sarga/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php

430 lines
14 KiB
PHP
Raw Normal View History

Cart rule inside promotions, various improvements and fixes. (#964) * Some syntax issue fixes * Adding discount things inside promotions in admin * routes updated for creating discount rules * fixed customer profile redirect parameter issue * added cart and catalog rule routes to admin section * migrations for discount almost to be finished, final revision left * migrations for discounts complete * catalog rule form underway * catalog rule * Made some dynamic form fields in catalog rule create form * made some changes for custom validations used in ProductForm request class * working on prepopulating the values fields in conditions * need another revisit on discount rules tables and then prepare for actions * removed discounts table * catalog rule form changed to muliti attribute set for single condition * new icons added for promotion and customer note. new action for customer added to take notes on the customers * catalog and cart rule designs stable, now moving towards validations on client side and backend * catalog rules migrations added * catalog rule models added with contracts and proxies * fixed customer group bug in customer registration controller * fixed customer registration bug due to last fix * fixed product card image not found issue * catalog rule translations added * Added migrations for cart rules and catalog rule products their contracts and remaining necessary files related to them. * making cart attributes for cart rules * Added more fields for cart rules * working on conditions for cart rule form * minor changes in migrations related to price rules * currency and locale switcher now only available for a channel on storefront when more than on locale and currency are assigned to that channel * part of conditions on the cart rule form added * daily sync * cart rate migrations updated * Added select and multi select attributes options fetching with ajax on catalog rule form * changed some migrations and data being populated at runtime inside catalog rule form * catalog rule create complete, migrations changes, translations added * catalog rule edit form complete * catalog rule form complete, now moving towards catalog rule products * added delete functionality for catalog rules * added cart rule preferences for coupon codes * cart rule submission problem due to repository issue * Cart rule form and migrations complete * Models and Repositories updated for cart rule usage * base sync with master * designing process to get suitable discount rules * cart rule form completed * added helpers in cart and discount to apply rules on cart at checkout or not * cart rule coupon implementation in progress for discount coupon in shop checkout pages * cart rules working * added coupon box on checkout screen * removed the conditions empty bug * Nearing to completion of coupon based rules * made some changes in cart rule coupon application on checkout related to new designs * some bug fixes * calculation for automatic cart rules complete * non couponable cart rules implemented, now moving on to binding them on frontend * some conditions improvements in couponable cart rules * some bug fixes * removed some bugs from summary blade for cart rule * added the table for cart rule cart for managing rules with cart and removed various bug fixes * some bug fixes * Removed bugs and added coupon based cart rule removal functionality * some bug fixes * cart rule labels refactoring in midway * Cart rule labels bug fixed * removed margin classes from shop to UI * Refactoring cart rule on front end * added checks * Discount rule implemented. * cart rule bug fixes * provision to remove the couponable and non couponable rule had been added * Cart rule frontend work done * altered some frontend variables on onepage checkout * Altered cart rules to some extent
2019-06-10 07:49:05 +00:00
<?php
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
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class CartRuleController extends Controller
{
/**
* Initialize _config, a default request parameter with route
*/
protected $_config;
/**
* Attribute $attribute
*/
protected $attribute;
/**
* AttributeFamily $attributeFamily
*/
protected $attributeFamily;
/**
* Category $category
*/
protected $category;
/**
* Product $product
*/
protected $product;
/**
* Property for Cart rule application
*/
protected $appliedConfig;
/**
* To hold Cart repository instance
*/
protected $cartRule;
/**
* To hold Rule Label repository instance
*/
protected $cartRuleLabel;
/**
* To hold Coupons Repository instance
*/
protected $cartRuleCoupon;
/**
* To hold the cart repository instance
*/
protected $cart;
public function __construct(Attribute $attribute, AttributeFamily $attributeFamily, Category $category, Product $product, CatalogRule $catalogRule, 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');
}
public function index()
{
return view($this->_config['view']);
}
public function create()
{
return view($this->_config['view'])->with('cart_rule', [$this->appliedConfig, $this->fetchOptionableAttributes(), $this->getStatesAndCountries()]);
}
public function store()
{
$data = request()->all();
$validated = Validator::make($data, [
'name' => 'required|string',
'description' => 'string',
// 'customer_groups' => 'required|array',
'channels' => 'required|array',
'status' => 'required|boolean',
'use_coupon' => 'boolean|required',
// 'usage_limit' => 'numeric|min:0',
// 'per_customer' => 'numeric|min:0',
'action_type' => 'required|string',
'disc_amount' => 'required|numeric',
'disc_quantity' => 'numeric',
'disc_threshold' => 'numeric',
'free_shipping' => 'required|boolean',
'apply_to_shipping' => 'required|boolean',
'code' => 'string|required_if:auto_generation,0',
'all_conditions' => 'sometimes|nullable',
'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();
}
if ($data['starts_from'] == "" || $data['ends_till'] == "") {
$data['starts_from'] = null;
$data['ends_till'] = null;
}
unset($data['_token']);
$channels = $data['channels'];
unset($data['channels']);
2019-06-10 09:51:45 +00:00
// $customer_groups = $data['customer_groups'];
// unset($data['customer_groups']);
Cart rule inside promotions, various improvements and fixes. (#964) * Some syntax issue fixes * Adding discount things inside promotions in admin * routes updated for creating discount rules * fixed customer profile redirect parameter issue * added cart and catalog rule routes to admin section * migrations for discount almost to be finished, final revision left * migrations for discounts complete * catalog rule form underway * catalog rule * Made some dynamic form fields in catalog rule create form * made some changes for custom validations used in ProductForm request class * working on prepopulating the values fields in conditions * need another revisit on discount rules tables and then prepare for actions * removed discounts table * catalog rule form changed to muliti attribute set for single condition * new icons added for promotion and customer note. new action for customer added to take notes on the customers * catalog and cart rule designs stable, now moving towards validations on client side and backend * catalog rules migrations added * catalog rule models added with contracts and proxies * fixed customer group bug in customer registration controller * fixed customer registration bug due to last fix * fixed product card image not found issue * catalog rule translations added * Added migrations for cart rules and catalog rule products their contracts and remaining necessary files related to them. * making cart attributes for cart rules * Added more fields for cart rules * working on conditions for cart rule form * minor changes in migrations related to price rules * currency and locale switcher now only available for a channel on storefront when more than on locale and currency are assigned to that channel * part of conditions on the cart rule form added * daily sync * cart rate migrations updated * Added select and multi select attributes options fetching with ajax on catalog rule form * changed some migrations and data being populated at runtime inside catalog rule form * catalog rule create complete, migrations changes, translations added * catalog rule edit form complete * catalog rule form complete, now moving towards catalog rule products * added delete functionality for catalog rules * added cart rule preferences for coupon codes * cart rule submission problem due to repository issue * Cart rule form and migrations complete * Models and Repositories updated for cart rule usage * base sync with master * designing process to get suitable discount rules * cart rule form completed * added helpers in cart and discount to apply rules on cart at checkout or not * cart rule coupon implementation in progress for discount coupon in shop checkout pages * cart rules working * added coupon box on checkout screen * removed the conditions empty bug * Nearing to completion of coupon based rules * made some changes in cart rule coupon application on checkout related to new designs * some bug fixes * calculation for automatic cart rules complete * non couponable cart rules implemented, now moving on to binding them on frontend * some conditions improvements in couponable cart rules * some bug fixes * removed some bugs from summary blade for cart rule * added the table for cart rule cart for managing rules with cart and removed various bug fixes * some bug fixes * Removed bugs and added coupon based cart rule removal functionality * some bug fixes * cart rule labels refactoring in midway * Cart rule labels bug fixed * removed margin classes from shop to UI * Refactoring cart rule on front end * added checks * Discount rule implemented. * cart rule bug fixes * provision to remove the couponable and non couponable rule had been added * Cart rule frontend work done * altered some frontend variables on onepage checkout * Altered cart rules to some extent
2019-06-10 07:49:05 +00:00
unset($data['criteria']);
$labels = $data['label'];
unset($data['label']);
unset($data['cart_attributes']);
unset($data['attributes']);
if (isset($data['disc_amount']) && $data['action_type'] == config('pricerules.cart.validations.2')) {
$data['actions'] = [
'action_type' => $data['action_type'],
'disc_amount' => $data['disc_amount'],
'disc_threshold' => $data['disc_threshold']
];
$data['disc_quantity'] = $data['disc_amount'];
} else {
$data['actions'] = [
'action_type' => $data['action_type'],
'disc_amount' => $data['disc_amount'],
'disc_quantity' => $data['disc_quantity']
];
}
$data['actions'] = json_encode($data['actions']);
if (! isset($data['all_conditions']) || $data['all_conditions'] == "[]") {
$data['conditions'] = null;
} else {
$data['conditions'] = json_encode($data['all_conditions']);
}
unset($data['all_conditions']);
if ($data['use_coupon']) {
// if (isset($data['auto_generation']) && $data['auto_generation']) {
$data['auto_generation'] = 0;
$coupons['code'] = $data['code'];
unset($data['code']);
// } else {
// $data['auto_generation'] = 1;
// }
// if (isset($data['prefix'])) {
// $coupons['prefix'] = $data['prefix'];
// unset($data['prefix']);
// }
// if (isset($data['suffix'])) {
// $coupons['suffix'] = $data['suffix'];
// unset($data['suffix']);
// }
2019-06-10 12:58:17 +00:00
$coupons['limit'] = 0;
Cart rule inside promotions, various improvements and fixes. (#964) * Some syntax issue fixes * Adding discount things inside promotions in admin * routes updated for creating discount rules * fixed customer profile redirect parameter issue * added cart and catalog rule routes to admin section * migrations for discount almost to be finished, final revision left * migrations for discounts complete * catalog rule form underway * catalog rule * Made some dynamic form fields in catalog rule create form * made some changes for custom validations used in ProductForm request class * working on prepopulating the values fields in conditions * need another revisit on discount rules tables and then prepare for actions * removed discounts table * catalog rule form changed to muliti attribute set for single condition * new icons added for promotion and customer note. new action for customer added to take notes on the customers * catalog and cart rule designs stable, now moving towards validations on client side and backend * catalog rules migrations added * catalog rule models added with contracts and proxies * fixed customer group bug in customer registration controller * fixed customer registration bug due to last fix * fixed product card image not found issue * catalog rule translations added * Added migrations for cart rules and catalog rule products their contracts and remaining necessary files related to them. * making cart attributes for cart rules * Added more fields for cart rules * working on conditions for cart rule form * minor changes in migrations related to price rules * currency and locale switcher now only available for a channel on storefront when more than on locale and currency are assigned to that channel * part of conditions on the cart rule form added * daily sync * cart rate migrations updated * Added select and multi select attributes options fetching with ajax on catalog rule form * changed some migrations and data being populated at runtime inside catalog rule form * catalog rule create complete, migrations changes, translations added * catalog rule edit form complete * catalog rule form complete, now moving towards catalog rule products * added delete functionality for catalog rules * added cart rule preferences for coupon codes * cart rule submission problem due to repository issue * Cart rule form and migrations complete * Models and Repositories updated for cart rule usage * base sync with master * designing process to get suitable discount rules * cart rule form completed * added helpers in cart and discount to apply rules on cart at checkout or not * cart rule coupon implementation in progress for discount coupon in shop checkout pages * cart rules working * added coupon box on checkout screen * removed the conditions empty bug * Nearing to completion of coupon based rules * made some changes in cart rule coupon application on checkout related to new designs * some bug fixes * calculation for automatic cart rules complete * non couponable cart rules implemented, now moving on to binding them on frontend * some conditions improvements in couponable cart rules * some bug fixes * removed some bugs from summary blade for cart rule * added the table for cart rule cart for managing rules with cart and removed various bug fixes * some bug fixes * Removed bugs and added coupon based cart rule removal functionality * some bug fixes * cart rule labels refactoring in midway * Cart rule labels bug fixed * removed margin classes from shop to UI * Refactoring cart rule on front end * added checks * Discount rule implemented. * cart rule bug fixes * provision to remove the couponable and non couponable rule had been added * Cart rule frontend work done * altered some frontend variables on onepage checkout * Altered cart rules to some extent
2019-06-10 07:49:05 +00:00
}
// if(isset($data['usage_limit'])) {
// $coupons['limit'] = $data['usage_limit'];
// }
Cart rule inside promotions, various improvements and fixes. (#964) * Some syntax issue fixes * Adding discount things inside promotions in admin * routes updated for creating discount rules * fixed customer profile redirect parameter issue * added cart and catalog rule routes to admin section * migrations for discount almost to be finished, final revision left * migrations for discounts complete * catalog rule form underway * catalog rule * Made some dynamic form fields in catalog rule create form * made some changes for custom validations used in ProductForm request class * working on prepopulating the values fields in conditions * need another revisit on discount rules tables and then prepare for actions * removed discounts table * catalog rule form changed to muliti attribute set for single condition * new icons added for promotion and customer note. new action for customer added to take notes on the customers * catalog and cart rule designs stable, now moving towards validations on client side and backend * catalog rules migrations added * catalog rule models added with contracts and proxies * fixed customer group bug in customer registration controller * fixed customer registration bug due to last fix * fixed product card image not found issue * catalog rule translations added * Added migrations for cart rules and catalog rule products their contracts and remaining necessary files related to them. * making cart attributes for cart rules * Added more fields for cart rules * working on conditions for cart rule form * minor changes in migrations related to price rules * currency and locale switcher now only available for a channel on storefront when more than on locale and currency are assigned to that channel * part of conditions on the cart rule form added * daily sync * cart rate migrations updated * Added select and multi select attributes options fetching with ajax on catalog rule form * changed some migrations and data being populated at runtime inside catalog rule form * catalog rule create complete, migrations changes, translations added * catalog rule edit form complete * catalog rule form complete, now moving towards catalog rule products * added delete functionality for catalog rules * added cart rule preferences for coupon codes * cart rule submission problem due to repository issue * Cart rule form and migrations complete * Models and Repositories updated for cart rule usage * base sync with master * designing process to get suitable discount rules * cart rule form completed * added helpers in cart and discount to apply rules on cart at checkout or not * cart rule coupon implementation in progress for discount coupon in shop checkout pages * cart rules working * added coupon box on checkout screen * removed the conditions empty bug * Nearing to completion of coupon based rules * made some changes in cart rule coupon application on checkout related to new designs * some bug fixes * calculation for automatic cart rules complete * non couponable cart rules implemented, now moving on to binding them on frontend * some conditions improvements in couponable cart rules * some bug fixes * removed some bugs from summary blade for cart rule * added the table for cart rule cart for managing rules with cart and removed various bug fixes * some bug fixes * Removed bugs and added coupon based cart rule removal functionality * some bug fixes * cart rule labels refactoring in midway * Cart rule labels bug fixed * removed margin classes from shop to UI * Refactoring cart rule on front end * added checks * Discount rule implemented. * cart rule bug fixes * provision to remove the couponable and non couponable rule had been added * Cart rule frontend work done * altered some frontend variables on onepage checkout * Altered cart rules to some extent
2019-06-10 07:49:05 +00:00
$ruleCreated = $this->cartRule->create($data);
// $ruleGroupCreated = $this->cartRule->CustomerGroupSync($customer_groups, $ruleCreated);
Cart rule inside promotions, various improvements and fixes. (#964) * Some syntax issue fixes * Adding discount things inside promotions in admin * routes updated for creating discount rules * fixed customer profile redirect parameter issue * added cart and catalog rule routes to admin section * migrations for discount almost to be finished, final revision left * migrations for discounts complete * catalog rule form underway * catalog rule * Made some dynamic form fields in catalog rule create form * made some changes for custom validations used in ProductForm request class * working on prepopulating the values fields in conditions * need another revisit on discount rules tables and then prepare for actions * removed discounts table * catalog rule form changed to muliti attribute set for single condition * new icons added for promotion and customer note. new action for customer added to take notes on the customers * catalog and cart rule designs stable, now moving towards validations on client side and backend * catalog rules migrations added * catalog rule models added with contracts and proxies * fixed customer group bug in customer registration controller * fixed customer registration bug due to last fix * fixed product card image not found issue * catalog rule translations added * Added migrations for cart rules and catalog rule products their contracts and remaining necessary files related to them. * making cart attributes for cart rules * Added more fields for cart rules * working on conditions for cart rule form * minor changes in migrations related to price rules * currency and locale switcher now only available for a channel on storefront when more than on locale and currency are assigned to that channel * part of conditions on the cart rule form added * daily sync * cart rate migrations updated * Added select and multi select attributes options fetching with ajax on catalog rule form * changed some migrations and data being populated at runtime inside catalog rule form * catalog rule create complete, migrations changes, translations added * catalog rule edit form complete * catalog rule form complete, now moving towards catalog rule products * added delete functionality for catalog rules * added cart rule preferences for coupon codes * cart rule submission problem due to repository issue * Cart rule form and migrations complete * Models and Repositories updated for cart rule usage * base sync with master * designing process to get suitable discount rules * cart rule form completed * added helpers in cart and discount to apply rules on cart at checkout or not * cart rule coupon implementation in progress for discount coupon in shop checkout pages * cart rules working * added coupon box on checkout screen * removed the conditions empty bug * Nearing to completion of coupon based rules * made some changes in cart rule coupon application on checkout related to new designs * some bug fixes * calculation for automatic cart rules complete * non couponable cart rules implemented, now moving on to binding them on frontend * some conditions improvements in couponable cart rules * some bug fixes * removed some bugs from summary blade for cart rule * added the table for cart rule cart for managing rules with cart and removed various bug fixes * some bug fixes * Removed bugs and added coupon based cart rule removal functionality * some bug fixes * cart rule labels refactoring in midway * Cart rule labels bug fixed * removed margin classes from shop to UI * Refactoring cart rule on front end * added checks * Discount rule implemented. * cart rule bug fixes * provision to remove the couponable and non couponable rule had been added * Cart rule frontend work done * altered some frontend variables on onepage checkout * Altered cart rules to some extent
2019-06-10 07:49:05 +00:00
$ruleChannelCreated = $this->cartRule->ChannelSync($channels, $ruleCreated);
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'];
$label1['cart_rule_id'] = $ruleCreated->id;
$ruleLabelCreated = $this->cartRuleLabel->create($label1);
}
}
} else {
$label2['label'] = $labels['global'];
$label2['cart_rule_id'] = $ruleCreated->id;
$ruleLabelCreated = $this->cartRuleLabel->create($label2);
}
if(isset($coupons)) {
$coupons['cart_rule_id'] = $ruleCreated->id;
$coupons['usage_per_customer'] = $data['per_customer']; //0 is for unlimited usage
$couponCreated = $this->cartRuleCoupon->create($coupons);
}
2019-06-10 11:14:39 +00:00
if ($ruleCreated && $ruleChannelCreated) {
Cart rule inside promotions, various improvements and fixes. (#964) * Some syntax issue fixes * Adding discount things inside promotions in admin * routes updated for creating discount rules * fixed customer profile redirect parameter issue * added cart and catalog rule routes to admin section * migrations for discount almost to be finished, final revision left * migrations for discounts complete * catalog rule form underway * catalog rule * Made some dynamic form fields in catalog rule create form * made some changes for custom validations used in ProductForm request class * working on prepopulating the values fields in conditions * need another revisit on discount rules tables and then prepare for actions * removed discounts table * catalog rule form changed to muliti attribute set for single condition * new icons added for promotion and customer note. new action for customer added to take notes on the customers * catalog and cart rule designs stable, now moving towards validations on client side and backend * catalog rules migrations added * catalog rule models added with contracts and proxies * fixed customer group bug in customer registration controller * fixed customer registration bug due to last fix * fixed product card image not found issue * catalog rule translations added * Added migrations for cart rules and catalog rule products their contracts and remaining necessary files related to them. * making cart attributes for cart rules * Added more fields for cart rules * working on conditions for cart rule form * minor changes in migrations related to price rules * currency and locale switcher now only available for a channel on storefront when more than on locale and currency are assigned to that channel * part of conditions on the cart rule form added * daily sync * cart rate migrations updated * Added select and multi select attributes options fetching with ajax on catalog rule form * changed some migrations and data being populated at runtime inside catalog rule form * catalog rule create complete, migrations changes, translations added * catalog rule edit form complete * catalog rule form complete, now moving towards catalog rule products * added delete functionality for catalog rules * added cart rule preferences for coupon codes * cart rule submission problem due to repository issue * Cart rule form and migrations complete * Models and Repositories updated for cart rule usage * base sync with master * designing process to get suitable discount rules * cart rule form completed * added helpers in cart and discount to apply rules on cart at checkout or not * cart rule coupon implementation in progress for discount coupon in shop checkout pages * cart rules working * added coupon box on checkout screen * removed the conditions empty bug * Nearing to completion of coupon based rules * made some changes in cart rule coupon application on checkout related to new designs * some bug fixes * calculation for automatic cart rules complete * non couponable cart rules implemented, now moving on to binding them on frontend * some conditions improvements in couponable cart rules * some bug fixes * removed some bugs from summary blade for cart rule * added the table for cart rule cart for managing rules with cart and removed various bug fixes * some bug fixes * Removed bugs and added coupon based cart rule removal functionality * some bug fixes * cart rule labels refactoring in midway * Cart rule labels bug fixed * removed margin classes from shop to UI * Refactoring cart rule on front end * added checks * Discount rule implemented. * cart rule bug fixes * provision to remove the couponable and non couponable rule had been added * Cart rule frontend work done * altered some frontend variables on onepage checkout * Altered cart rules to some extent
2019-06-10 07:49:05 +00:00
if (isset($couponCreated) && $couponCreated) {
session()->flash('success', trans('admin::app.promotion.status.success-coupon'));
}
session()->flash('success', trans('admin::app.promotion.status.success'));
} else {
session()->flash('success', trans('admin::app.promotion.status.success'));
return redirect()->back();
}
return redirect()->route($this->_config['redirect']);
}
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]);
}
public function update($id)
{
$types = config('price_rules.cart.validations');
$validated = Validator::make(request()->all(), [
'name' => 'required|string',
'description' => 'string',
// 'customer_groups' => 'required|array',
'channels' => 'required|array',
'status' => 'required|boolean',
'use_coupon' => 'boolean|required',
// 'usage_limit' => 'numeric|min:0',
// 'per_customer' => 'numeric|min:0',
'action_type' => 'required|string',
'disc_amount' => 'required|numeric',
'disc_quantity' => 'required|numeric',
'disc_threshold' => 'required|numeric',
'free_shipping' => 'required|boolean',
'apply_to_shipping' => 'required|boolean',
'code' => 'string|required_if:user_coupon,1',
'all_conditions' => 'present',
'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 = request()->all();
if ($data['starts_from'] == "" || $data['ends_till'] == "") {
$data['starts_from'] = null;
$data['ends_till'] = null;
}
unset($data['_token']);
$channels = $data['channels'];
unset($data['channels']);
// $customer_groups = $data['customer_groups'];
// unset($data['customer_groups']);
// unset($data['criteria']);
if (isset($data['label'])) {
$labels = $data['label'];
unset($data['label']);
}
unset($data['cart_attributes']);
unset($data['attributes']);
if (isset($data['disc_amount']) && $data['action_type'] == config('pricerules.cart.validations.2')) {
$data['actions'] = [
'action_type' => $data['action_type'],
'disc_amount' => $data['disc_amount'],
'disc_threshold' => $data['disc_threshold']
];
$data['disc_quantity'] = $data['disc_amount'];
} else {
$data['actions'] = [
'action_type' => $data['action_type'],
'disc_amount' => $data['disc_amount'],
'disc_quantity' => $data['disc_quantity']
];
}
$data['actions'] = json_encode($data['actions']);
if (! isset($data['all_conditions']) || $data['all_conditions'] == "[]") {
$data['conditions'] = null;
} else {
$data['conditions'] = json_encode($data['all_conditions']);
}
unset($data['all_conditions']);
if ($data['use_coupon']) {
// if (isset($data['auto_generation']) && $data['auto_generation']) {
$data['auto_generation'] = 0;
$coupons['code'] = $data['code'];
unset($data['code']);
// } else {
// $data['auto_generation'] = 1;
// }
// if (isset($data['prefix'])) {
// $coupons['prefix'] = $data['prefix'];
// unset($data['prefix']);
// }
// if (isset($data['suffix'])) {
// $coupons['suffix'] = $data['suffix'];
// unset($data['suffix']);
// }
2019-06-10 12:58:17 +00:00
$coupons['limit'] = 0;
Cart rule inside promotions, various improvements and fixes. (#964) * Some syntax issue fixes * Adding discount things inside promotions in admin * routes updated for creating discount rules * fixed customer profile redirect parameter issue * added cart and catalog rule routes to admin section * migrations for discount almost to be finished, final revision left * migrations for discounts complete * catalog rule form underway * catalog rule * Made some dynamic form fields in catalog rule create form * made some changes for custom validations used in ProductForm request class * working on prepopulating the values fields in conditions * need another revisit on discount rules tables and then prepare for actions * removed discounts table * catalog rule form changed to muliti attribute set for single condition * new icons added for promotion and customer note. new action for customer added to take notes on the customers * catalog and cart rule designs stable, now moving towards validations on client side and backend * catalog rules migrations added * catalog rule models added with contracts and proxies * fixed customer group bug in customer registration controller * fixed customer registration bug due to last fix * fixed product card image not found issue * catalog rule translations added * Added migrations for cart rules and catalog rule products their contracts and remaining necessary files related to them. * making cart attributes for cart rules * Added more fields for cart rules * working on conditions for cart rule form * minor changes in migrations related to price rules * currency and locale switcher now only available for a channel on storefront when more than on locale and currency are assigned to that channel * part of conditions on the cart rule form added * daily sync * cart rate migrations updated * Added select and multi select attributes options fetching with ajax on catalog rule form * changed some migrations and data being populated at runtime inside catalog rule form * catalog rule create complete, migrations changes, translations added * catalog rule edit form complete * catalog rule form complete, now moving towards catalog rule products * added delete functionality for catalog rules * added cart rule preferences for coupon codes * cart rule submission problem due to repository issue * Cart rule form and migrations complete * Models and Repositories updated for cart rule usage * base sync with master * designing process to get suitable discount rules * cart rule form completed * added helpers in cart and discount to apply rules on cart at checkout or not * cart rule coupon implementation in progress for discount coupon in shop checkout pages * cart rules working * added coupon box on checkout screen * removed the conditions empty bug * Nearing to completion of coupon based rules * made some changes in cart rule coupon application on checkout related to new designs * some bug fixes * calculation for automatic cart rules complete * non couponable cart rules implemented, now moving on to binding them on frontend * some conditions improvements in couponable cart rules * some bug fixes * removed some bugs from summary blade for cart rule * added the table for cart rule cart for managing rules with cart and removed various bug fixes * some bug fixes * Removed bugs and added coupon based cart rule removal functionality * some bug fixes * cart rule labels refactoring in midway * Cart rule labels bug fixed * removed margin classes from shop to UI * Refactoring cart rule on front end * added checks * Discount rule implemented. * cart rule bug fixes * provision to remove the couponable and non couponable rule had been added * Cart rule frontend work done * altered some frontend variables on onepage checkout * Altered cart rules to some extent
2019-06-10 07:49:05 +00:00
}
// if (isset($data['usage_limit'])) {
// $coupons['limit'] = $data['usage_limit'];
// }
Cart rule inside promotions, various improvements and fixes. (#964) * Some syntax issue fixes * Adding discount things inside promotions in admin * routes updated for creating discount rules * fixed customer profile redirect parameter issue * added cart and catalog rule routes to admin section * migrations for discount almost to be finished, final revision left * migrations for discounts complete * catalog rule form underway * catalog rule * Made some dynamic form fields in catalog rule create form * made some changes for custom validations used in ProductForm request class * working on prepopulating the values fields in conditions * need another revisit on discount rules tables and then prepare for actions * removed discounts table * catalog rule form changed to muliti attribute set for single condition * new icons added for promotion and customer note. new action for customer added to take notes on the customers * catalog and cart rule designs stable, now moving towards validations on client side and backend * catalog rules migrations added * catalog rule models added with contracts and proxies * fixed customer group bug in customer registration controller * fixed customer registration bug due to last fix * fixed product card image not found issue * catalog rule translations added * Added migrations for cart rules and catalog rule products their contracts and remaining necessary files related to them. * making cart attributes for cart rules * Added more fields for cart rules * working on conditions for cart rule form * minor changes in migrations related to price rules * currency and locale switcher now only available for a channel on storefront when more than on locale and currency are assigned to that channel * part of conditions on the cart rule form added * daily sync * cart rate migrations updated * Added select and multi select attributes options fetching with ajax on catalog rule form * changed some migrations and data being populated at runtime inside catalog rule form * catalog rule create complete, migrations changes, translations added * catalog rule edit form complete * catalog rule form complete, now moving towards catalog rule products * added delete functionality for catalog rules * added cart rule preferences for coupon codes * cart rule submission problem due to repository issue * Cart rule form and migrations complete * Models and Repositories updated for cart rule usage * base sync with master * designing process to get suitable discount rules * cart rule form completed * added helpers in cart and discount to apply rules on cart at checkout or not * cart rule coupon implementation in progress for discount coupon in shop checkout pages * cart rules working * added coupon box on checkout screen * removed the conditions empty bug * Nearing to completion of coupon based rules * made some changes in cart rule coupon application on checkout related to new designs * some bug fixes * calculation for automatic cart rules complete * non couponable cart rules implemented, now moving on to binding them on frontend * some conditions improvements in couponable cart rules * some bug fixes * removed some bugs from summary blade for cart rule * added the table for cart rule cart for managing rules with cart and removed various bug fixes * some bug fixes * Removed bugs and added coupon based cart rule removal functionality * some bug fixes * cart rule labels refactoring in midway * Cart rule labels bug fixed * removed margin classes from shop to UI * Refactoring cart rule on front end * added checks * Discount rule implemented. * cart rule bug fixes * provision to remove the couponable and non couponable rule had been added * Cart rule frontend work done * altered some frontend variables on onepage checkout * Altered cart rules to some extent
2019-06-10 07:49:05 +00:00
$ruleUpdated = $this->cartRule->update($data, $id);
// $ruleGroupUpdated = $this->cartRule->CustomerGroupSync($customer_groups, $ruleUpdated);
$ruleChannelUpdated = $this->cartRule->ChannelSync($channels, $ruleUpdated);
$labelsUpdated = $this->cartRule->LabelSync($labels, $ruleUpdated);
if (isset($coupons)) {
$coupons['cart_rule_id'] = $ruleUpdated->id;
$coupons['usage_per_customer'] = $data['per_customer']; //0 is for unlimited usage
$couponUpdated = $ruleUpdated->coupons->update($coupons);
}
if ($ruleUpdated && $ruleChannelUpdated) {
if (isset($couponUpdated) && $couponUpdated) {
session()->flash('info', trans('admin::app.promotion.status.success-coupon'));
}
session()->flash('info', trans('admin::app.promotion.status.update-success'));
} else {
session()->flash('info', trans('admin::app.promotion.status.update-success'));
return redirect()->back();
}
return redirect()->route($this->_config['redirect']);
}
public function destroy($id)
{
$cartRule = $this->cartRule->findOrFail($id);
if ($cartRule->delete()) {
session()->flash('success', trans('admin::app.promotion.status.delete-success'));
return response()->json(['message' => true], 200);
} else {
session()->flash('success', trans('admin::app.promotion.status.delete-failed'));
return response()->json(['message' => false], 400);
}
}
public function getStatesAndCountries()
{
$countries = core()->countries()->toArray();
$states = core()->groupedStatesByCountries();
return [
'countries' => $countries,
'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;
}
}