Example #1
0
function some_product_color_list($array = '')
{
    $color = '';
    if (!empty($array)) {
        $colorArr = product_color_list();
        foreach ($array as $key => $value) {
            $color[$key] = $colorArr[$key];
        }
    }
    return $color;
}
Example #2
0
 public function addEditProductAttribute($product_id = '')
 {
     $this->session->set_userdata(array('log_MODULE' => 'addEditProductAttribute', 'log_MID' => ''));
     $this->load->helper('form');
     $this->data['title'] = 'Add Edit Product Attributes';
     if (empty($product_id)) {
         $this->session->set_flashdata('error', $this->lang->line('error_product_id_not'));
         redirect(base_url() . 'retailer/inventory');
     }
     $product_id = id_decrypt($product_id);
     $userId = $this->session->userdata('userId');
     $productAttr = $this->product_m->product_attribute($product_id);
     $this->custom_log->write_log('custom_log', 'Product attribute list ' . print_r($productAttr, true));
     $attrID = '';
     $attrKey = '';
     $attrVal = '';
     $brand_id = '';
     $segmentID = 0;
     $categoryID = 0;
     $subCat1ID = 0;
     $subCat2ID = 0;
     $subCat3ID = 0;
     $subCat4ID = 0;
     $subCat5ID = 0;
     $subCat6ID = 0;
     $attrNm = $this->product_m->product_data($product_id);
     if (!empty($attrNm)) {
         $attrKey = $attrNm->product_attribute_name;
         $segmentID = $attrNm->segment_id;
         $categoryID = $attrNm->category_id;
         $subCat1ID = $attrNm->sub_category1_id;
         $subCat2ID = $attrNm->sub_category2_id;
         $subCat3ID = $attrNm->sub_category3_id;
         $subCat4ID = $attrNm->sub_category4_id;
         $subCat5ID = $attrNm->sub_category5_id;
         $subCat6ID = $attrNm->sub_category6_id;
     }
     if (!empty($productAttr)) {
         $attrID = $productAttr->product_attribute_id;
         $attrVal = $productAttr->product_attribute_value;
         $brand_id = $productAttr->brand_id;
     }
     $brandErr = '';
     if ($_POST) {
         $product_attr = $attrKey;
         $brand_id = $this->input->post('brand_name');
         $new_brand_name = $this->input->post('new_brand_name');
         if (empty($brand_id) && empty($new_brand_name)) {
             $brandErr = '<div class="error">Please select Brand name OR add new</div>';
         } else {
             $this->custom_log->write_log('custom_log', 'After Form Submit ' . print_r($_POST, true));
             $product_attr = $attrKey;
             if (!empty($product_attr)) {
                 $validation_rules = product_attribute_validation_rule();
                 $this->form_validation->set_rules($validation_rules[$product_attr]);
                 $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
                 if ($this->form_validation->run()) {
                     $brand_name = '';
                     $brand_id = $this->input->post('brand_name');
                     $tax = $this->input->post('tax');
                     if (!empty($new_brand_name)) {
                         $brand_id = $this->brand_m->brand_insert($segmentID, $categoryID, $subCat1ID, $subCat2ID, $subCat3ID, $subCat4ID, $subCat5ID, $subCat6ID, $new_brand_name);
                     }
                     $this->custom_log->write_log('custom_log', 'brand id ' . $brand_id);
                     if (!empty($brand_id)) {
                         $brndRes = $this->segment_cat_m->brand_name($brand_id);
                         $brand_name = $brndRes->brand_name;
                         $this->brand_m->brand_update($segmentID, $categoryID, $subCat1ID, $subCat2ID, $subCat3ID, $subCat4ID, $subCat5ID, $subCat6ID, $brand_id, $brand_name);
                     }
                     if (!empty($brand_id)) {
                         $brndRes = $this->segment_cat_m->brand_name($brand_id);
                         $brand_name = $brndRes->brand_name;
                     }
                     $valArr = array();
                     foreach ($_POST as $key => $value) {
                         if ($key == 'brand_name' || $key == 'new_brand_name') {
                             $valArr['brand_name'] = $brand_name;
                         } else {
                             $valArr[$key] = $value;
                         }
                     }
                     if (!empty($attrID)) {
                         $updateOpt = array('table' => 'product_attribute', 'data' => array('product_attribute_key' => $product_attr, 'product_attribute_value' => json_encode($valArr), 'product_id' => $product_id, 'brand_id' => $brand_id, 'tax' => $tax, 'last_modified_by' => $userId, 'last_modified_time' => $this->currentTimestamp), 'where' => array('product_attribute_id' => $attrID));
                         $this->custom_log->write_log('custom_log', 'update befor data is ' . print_r($updateOpt, true));
                         if ($this->common_model->customUpdate($updateOpt)) {
                             $this->session->set_flashdata('success', $this->lang->line('success_update_product_attribute'));
                             $this->custom_log->write_log('custom_log', $this->lang->line('success_update_product_attribute'));
                             redirect(base_url() . 'retailer/inventory/review/' . id_encrypt($product_id));
                         } else {
                             $this->session->set_flashdata('error', $this->lang->line('error_update_product_attribute'));
                             $this->custom_log->write_log('custom_log', $this->lang->line('error_update_product_attribute'));
                             redirect(base_url() . 'retailer/inventory/addEditProductAttribute/' . id_encrypt($product_id));
                         }
                     } else {
                         $insertOpt = array('table' => 'product_attribute', 'data' => array('product_attribute_key' => $product_attr, 'product_attribute_value' => json_encode($valArr), 'product_id' => $product_id, 'brand_id' => $brand_id, 'tax' => $tax, 'last_modified_by' => $userId, 'last_modified_time' => $this->currentTimestamp));
                         $this->custom_log->write_log('custom_log', 'Inser befor data is ' . print_r($insertOpt, true));
                         $productArrID = $this->common_model->customInsert($insertOpt);
                         $this->custom_log->write_log('custom_log', 'Product attribute id is ' . $productArrID);
                         if ($productArrID) {
                             $this->session->set_flashdata('success', $this->lang->line('success_add_product_attribute'));
                             $this->custom_log->write_log('custom_log', $this->lang->line('success_add_product_attribute'));
                             redirect(base_url() . 'retailer/inventory/review/' . id_encrypt($product_id));
                         } else {
                             $this->session->set_flashdata('error', $this->lang->line('error_add_product_attribute'));
                             $this->custom_log->write_log('custom_log', $this->lang->line('error_add_product_attribute'));
                             redirect(base_url() . 'retailer/inventory/addEditProductAttribute/' . id_encrypt($product_id));
                         }
                     }
                 }
             }
         }
     }
     $this->data['attrKey'] = $attrKey;
     $this->data['brand_id'] = $brand_id;
     $this->data['brand_list'] = $this->brand_m->category_brand_list($segmentID, $categoryID, $subCat1ID, $subCat2ID, $subCat3ID, $subCat4ID, $subCat5ID, $subCat6ID);
     $this->data['attrVal'] = json_decode($attrVal);
     $this->data['colorArr'] = product_color_list();
     $this->data['brandErr'] = $brandErr;
     $this->retailerCustomView('inventory/' . $attrKey, $this->data);
 }