如何在codeigniter中创建产品变体?

时间:2016-09-24 12:01:01

标签: php mysql codeigniter

我想使用codeigniter为任何产品创建产品变体。 我有产品表和产品变体表

产品表

------------------------------------------------------
id | category_id | title | price
------------------------------------------------------
1 | 1            | plstic bucket | 200
2 | 2            | Big storage bucket | 500

产品变体表

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   |

和产品 我的产品变体数组:

color = red, blue, green;
size = small, medium, large;
capacity = 10ltr, 20lts, 30ltr;

我想在mysql中保存新变种:

red-small-10ltrs; red-medium-20ltrs; red-large-30lts, blue-small-10ltrs

等等。

请建议我最好的方法或代码来做到这一点。 我的产品总监:

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');
                    }
                }

我的结果数组是:

$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
    )

)

现在我要生成组合像:

8,12,7,11
8,15,7,11
9,12,7,11
9,15,7,11
13,12,7,11
13,15,7,11

0 个答案:

没有答案