Only finding product ids is left then apply them on cart rules
This commit is contained in:
parent
3d53a221ef
commit
2a9b4220d6
|
|
@ -560,7 +560,7 @@
|
|||
|
||||
this.attribute_values = JSON.parse(JSON.parse(data.actions).attribute_conditions).attributes;
|
||||
|
||||
// creating the options and the has option param on the frontend
|
||||
// creating options and has option param on the frontend
|
||||
for (i in this.attribute_values) {
|
||||
for (j in this.attribute_input) {
|
||||
if (this.attribute_input[j].code == this.attribute_values[i].attribute) {
|
||||
|
|
@ -675,7 +675,25 @@
|
|||
this.cats.splice(index, 1);
|
||||
},
|
||||
|
||||
removeAttr(index) {
|
||||
this.attribute_values.splice(index, 1);
|
||||
},
|
||||
|
||||
onSubmit: function (e) {
|
||||
if (this.attribute_values.length > 0 || this.category_values.length > 0) {
|
||||
for (i in this.attribute_values) {
|
||||
delete this.attribute_values[i].options;
|
||||
}
|
||||
|
||||
if (this.category_values.length > 0) {
|
||||
this.all_attributes.categories = this.category_values;
|
||||
}
|
||||
|
||||
this.all_attributes.attributes = this.attribute_values;
|
||||
|
||||
this.all_attributes = JSON.stringify(this.all_attributes);
|
||||
}
|
||||
|
||||
if (this.conditions_list.length != 0) {
|
||||
this.conditions_list.push({'criteria': this.match_criteria});
|
||||
|
||||
|
|
|
|||
|
|
@ -3,29 +3,129 @@
|
|||
namespace Webkul\Discount\Helpers;
|
||||
|
||||
use Webkul\Discount\Repositories\CartRuleRepository as CartRule;
|
||||
use Webkul\Discount\Repositories\CartRuleCartRepository as CartRuleCart;
|
||||
use Carbon\Carbon;
|
||||
use Cart;
|
||||
use Webkul\Attribute\Repositories\AttributeRepository as Attribute;
|
||||
use Webkul\Attribute\Repositories\AttributeOptionRepository as AttributeOption;
|
||||
use Webkul\Category\Repositories\CategoryRepository as Category;
|
||||
use Webkul\Product\Repositories\ProductRepository as Product;
|
||||
|
||||
class ConvertXToProductId
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
/**
|
||||
* CategoryRepository instance
|
||||
*/
|
||||
protected $category;
|
||||
|
||||
/**
|
||||
* AttributeRepository instance
|
||||
*/
|
||||
protected $attribute;
|
||||
|
||||
/**
|
||||
* ProductRepository instance
|
||||
*/
|
||||
protected $product;
|
||||
|
||||
/**
|
||||
* AttributeOptionRepository instance
|
||||
*/
|
||||
protected $attributeOption;
|
||||
|
||||
/**
|
||||
* CartRuleRepository instance
|
||||
*/
|
||||
protected $cartRule;
|
||||
|
||||
public function __construct(
|
||||
Category $category,
|
||||
Attribute $attribute,
|
||||
Product $product,
|
||||
AttributeOption $attributeOption,
|
||||
CartRule $cartRule
|
||||
)
|
||||
{
|
||||
$this->category = $category;
|
||||
|
||||
$this->attribute = $attribute;
|
||||
|
||||
$this->product = $product;
|
||||
|
||||
$this->attributeOption = $attributeOption;
|
||||
|
||||
$this->cartRule = $cartRule;
|
||||
}
|
||||
|
||||
public function convertFromCategory()
|
||||
public function convertX($ruleId, $attribute_conditions)
|
||||
{
|
||||
$attributeConditions = json_decode($attribute_conditions);
|
||||
|
||||
$categoryValues = $attributeConditions->categories;
|
||||
|
||||
$attributeValues = $attributeConditions->attributes;
|
||||
|
||||
if (count($categoryValues)) {
|
||||
$categoryResult = $this->convertFromCategories($categoryValues);
|
||||
}
|
||||
|
||||
if (count($attributeValues)) {
|
||||
$attributeResult = $this->convertFromAttributes($attributeValues);
|
||||
}
|
||||
|
||||
// now call the function that will find all the unique product ids
|
||||
$productIds = $this->findAllUniqueIds($attributeResult, $categoryResult);
|
||||
|
||||
// save the product ids against the cart rules
|
||||
$result = $this->saveIDs($ruleId, $productIds);
|
||||
|
||||
if ($result) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function convertFromAttributeOptions()
|
||||
/**
|
||||
* This method will return product id from the attribute and attribute option params
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function convertFromAttributes($attributes)
|
||||
{
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
public function convertFromAttributes()
|
||||
/**
|
||||
* This method will return product id from the attribute and attribute option params
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function convertFromCategories($categories)
|
||||
{
|
||||
return $categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will remove the duplicates from the array and merge all the items into single array
|
||||
*
|
||||
* @param array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function findAllUniqueIds(...$data)
|
||||
{
|
||||
dd($data, 'product IDS');
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will save the product ids in the datastore
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function saveIDs($ruleId, $productIds)
|
||||
{
|
||||
$cartRule = $this->cartRule->find($ruleId);
|
||||
|
||||
return $cartRule->update([
|
||||
'product_ids' => $productIds
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -32,7 +32,6 @@ class FindProducts
|
|||
|
||||
public function findByConditions($conditions)
|
||||
{
|
||||
dd($conditions);
|
||||
/**
|
||||
* Empty collection instance to hold all the products that satisfy the conditions
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace Webkul\Discount\Http\Controllers;
|
|||
use Webkul\Discount\Repositories\CartRuleRepository as CartRule;
|
||||
use Webkul\Category\Repositories\CategoryRepository as Category;
|
||||
use Webkul\Attribute\Repositories\AttributeRepository as Attribute;
|
||||
use Webkul\Discount\Helpers\ConvertXToProductId as ConvertX;
|
||||
use Webkul\Discount\Repositories\CartRuleLabelsRepository as CartRuleLabels;
|
||||
use Webkul\Discount\Repositories\CartRuleCouponsRepository as CartRuleCoupons;
|
||||
|
||||
|
|
@ -56,12 +57,19 @@ class CartRuleController extends Controller
|
|||
*/
|
||||
protected $cart;
|
||||
|
||||
/**
|
||||
* Convert X To Product ID.
|
||||
*
|
||||
*/
|
||||
protected $convertX;
|
||||
|
||||
public function __construct(
|
||||
CartRule $cartRule,
|
||||
CartRuleCoupons $cartRuleCoupon,
|
||||
CartRuleLabels $cartRuleLabel,
|
||||
Attribute $attribute,
|
||||
Category $category
|
||||
Category $category,
|
||||
ConvertX $convertX
|
||||
)
|
||||
{
|
||||
$this->_config = request('_config');
|
||||
|
|
@ -76,6 +84,8 @@ class CartRuleController extends Controller
|
|||
|
||||
$this->category = $category;
|
||||
|
||||
$this->convertX = $convertX;
|
||||
|
||||
$this->appliedConfig = config('pricerules.cart');
|
||||
}
|
||||
|
||||
|
|
@ -260,6 +270,9 @@ class CartRuleController extends Controller
|
|||
// create a cart rule
|
||||
$ruleCreated = $this->cartRule->create($data);
|
||||
|
||||
// can execute convert x here after when the rule is updated
|
||||
$this->convertX->convertX($ruleUpdated->id, $attribute_conditions);
|
||||
|
||||
// create customer groups for cart rule
|
||||
$ruleGroupCreated = $this->cartRule->CustomerGroupSync($customer_groups, $ruleCreated);
|
||||
|
||||
|
|
@ -355,6 +368,9 @@ class CartRuleController extends Controller
|
|||
// collecting request in $data
|
||||
$data = request()->all();
|
||||
|
||||
$attribute_conditions = $data['all_attributes'];
|
||||
unset($data['all_attributes']);
|
||||
|
||||
// unset request token from $data
|
||||
unset($data['_token']);
|
||||
|
||||
|
|
@ -401,11 +417,22 @@ class CartRuleController extends Controller
|
|||
|
||||
$data['disc_quantity'] = $data['disc_amount'];
|
||||
} else {
|
||||
$data['actions'] = [
|
||||
'action_type' => $data['action_type'],
|
||||
'disc_amount' => $data['disc_amount'],
|
||||
'disc_quantity' => $data['disc_quantity']
|
||||
];
|
||||
if (! isset($attribute_conditions) || $attribute_conditions == "[]" || $attribute_conditions == "") {
|
||||
$data['uses_attribute_conditions'] = 0;
|
||||
|
||||
$data['actions'] = [
|
||||
'action_type' => $data['action_type'],
|
||||
'disc_amount' => $data['disc_amount'],
|
||||
'disc_quantity' => $data['disc_quantity']
|
||||
];
|
||||
} else {
|
||||
$data['actions'] = [
|
||||
'action_type' => $data['action_type'],
|
||||
'disc_amount' => $data['disc_amount'],
|
||||
'disc_quantity' => $data['disc_quantity'],
|
||||
'attribute_conditions' => $attribute_conditions
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// encode php array to json for actions
|
||||
|
|
@ -466,6 +493,9 @@ class CartRuleController extends Controller
|
|||
// update cart rule
|
||||
$ruleUpdated = $this->cartRule->update($data, $id);
|
||||
|
||||
// can execute convert X here after when the rule is updated
|
||||
$this->convertX->convertX($ruleUpdated->id, $attribute_conditions);
|
||||
|
||||
// update customer groups for cart rule
|
||||
$ruleGroupUpdated = $this->cartRule->CustomerGroupSync($customer_groups, $ruleUpdated);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue