Skip to content

Instantly share code, notes, and snippets.

@alexbowers
Created July 29, 2016 00:16
Show Gist options
  • Save alexbowers/82c1b9fd7ff376cfe536a279d7f2ab29 to your computer and use it in GitHub Desktop.
Save alexbowers/82c1b9fd7ff376cfe536a279d7f2ab29 to your computer and use it in GitHub Desktop.
Refactor to Collection Example for Adam
<?php
foreach($data['rules'] as &$rule) {
if($rule['type'] == RulesModel::$types['category']) {
$category = Category::getList($rule['simple_model_id']);
if(!empty($category)) {
$data['categories'][] = $category;
} else {
$rules_removed['categories']++;
$rules_removed['total']++;
$rule = null;
}
}
if($rule['type'] == RulesModel::$types['country']) {
$country = Country::getList($rule['simple_model_id']);
if(!empty($country)) {
$data['countries'][] = $country;
} else {
$rules_removed['countries']++;
$rules_removed['total']++;
$rule = null;
}
}
if($rule['type'] == RulesModel::$types['brand']) {
$brand = Brand::getList($rule['simple_model_id']);
if(!empty($brand)) {
$data['brands'][] = $brand;
} else {
$rules_removed['brands']++;
$rules_removed['total']++;
$rule = null;
}
}
if($rule['type'] == RulesModel::$types['product']) {
$product = Product::getList($rule['simple_model_id']);
if(!empty($product)) {
$data['products'][] = $product;
} else {
$rules_removed['products']++;
$rules_removed['total']++;
$rule = null;
}
}
if($rule['type'] == RulesModel::$types['group']) {
$product_group = Group::getList($rule['simple_model_id']);
if(!empty($product_group)) {
$data['groups'][] = $product_group;
} else {
$rules_removed['groups']++;
$rules_removed['total']++;
$rule = null;
}
}
if($rule['include'] == \app\models\Rules::$class['include']) {
$data['include_condition'] = $rule['condition'];
} else {
$data['exclude_condition'] = $rule['condition'];
}
if($rule['type'] == RulesModel::$types['product_option']) {
$attribute = Attribute::getList($rule['option_value']);
$attribute_value = AttributeValue::getList($rule['option_value_value']);
if(!empty($attribute) && !empty($attribute_value)) {
$data['attributes'][] = $attribute;
$data['attribute_values'][] = $attribute_value;
} else {
$rules_removed['product_options']++;
$rules_removed['total']++;
$rule = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment