问题
i want to create product variant for any product using codeigniter. i have product table and product variant table
product table
------------------------------------------------------
id | category_id | title | price
------------------------------------------------------
1 | 1 | plstic bucket | 200
2 | 2 | Big storage bucket | 500
product variant table
variant_id | product_id | title | price
------------------------------------------------------
1 | 1 | plstic bucket red small |
2 | 1 | plstic bucket red big |
3 | 1 | plstic bucket blue small |
4 | 1 | plstic bucket blue big |
and product my product variant array:
color = red, blue, green;
size = small, medium, large;
capacity = 10ltr, 20lts, 30ltr;
i want the save new variants in mysql:
red-small-10ltrs; red-medium-20ltrs; red-large-30lts, blue-small-10ltrs
and so on.
please suggest me best way or code to do it. my product controller:
foreach($this->input->post('product_variant') as $value){
$variant_group_id = $this->Product_model->get_variant_group_by_variant_id($value)[0]->group_id;
$variant_data = array(
'product_id' => $id,
'category_id' => $this->input->post('product_category'),
'variant_group_id' => $variant_group_id,
'variant_value_id' => $value,
'product_variant_title' => $this->input->post('product_name').' '.$this->Product_model->get_variant_group_by_variant_id($value)[0]->value,
'mrp_price' => '',
'price' =>'',
'slug' => url_title($this->input->post('product_name').'-'.$this->Product_model->get_variant_group_by_variant_id($value)[0]->value, 'dash', true),
'status' =>'',
);
if($this->Product_model->add_product_variant($id, $variant_group_id, $value, $variant_data)){
$this->session->set_flashdata('product_variant_added', 'Product Variant Created Succesfully');
}
}
my resulted array is:
$first = $this->input->post('product_variant');
Array
(
[12] => Array
(
[0] => 8
[1] => 9
[2] => 13
)
[13] => Array
(
[0] => 12
[1] => 15
)
[15] => Array
(
[0] => 7
)
[16] => Array
(
[0] => 11
)
)
now what i want to generate combination Like:
8,12,7,11
8,15,7,11
9,12,7,11
9,15,7,11
13,12,7,11
13,15,7,11
来源:https://stackoverflow.com/questions/39676108/how-can-i-create-product-variant-in-codeigniter