function edit($product_id) { $this->load->helper('form'); // get product $this->load->model('products_model'); $product = $this->products_model->get_product($product_id); // first part of form is generated by Admin_form $this->load->library('admin_form'); $form = new Admin_form(); $form->fieldset('Basic Information'); $form->text('Product Name', 'name', $product['name'], 'e.g, "Adidas Cross Trainers", or "CRBO2010 Conference Tickets"', TRUE, FALSE, TRUE); $form->textarea('Description', 'description', $product['description'], 'This description will appear on the product page.', TRUE, 'basic', TRUE); $this->load->model('collections_model'); $collections = $this->collections_model->get_tiered_collections(); $options = array(); $options[0] = 'No collections'; foreach ($collections as $data) { $options[$data['id']] = $data['name']; } $form->dropdown('Collection(s)', 'collections[]', $options, is_array($product['collections']) ? $product['collections'] : array(), TRUE, FALSE, 'Select multiple collections by holding the CTRL or CMD button and selecting multiple options.', TRUE); $form->fieldset('Product Properties'); $form->text('Price (' . setting('currency_symbol') . ')', 'price', $product['price'], FALSE, TRUE, '9.95', FALSE, '60px', 'price'); $form->text('Weight (' . setting('weight_unit') . ')', 'weight', $product['weight'], FALSE, TRUE, '0', FALSE, '60px', 'weight'); $tax = form_checkbox('taxable', '1', $product['is_taxable'] == TRUE ? TRUE : FALSE); $form->value_row(' ', $tax . ' <b><a target="_blank" href="' . site_url('admincp/store/taxes') . '">Tax rules</a> apply to this product</b>'); $require_shipping = form_checkbox('requires_shipping', '1', $product['requires_shipping'] == TRUE ? TRUE : FALSE); $form->value_row(' ', $require_shipping . ' <b>Require a shipping address for this product</b> (not necessary for digital products or services)'); $form->fieldset('Inventory Management'); $form->text('SKU Number', 'sku', $product['sku'], '(Optional) Enter a unique identifier of the product for inventory management.', FALSE, FALSE, FALSE, '200px', 'sku'); $inventory = form_checkbox(array('name' => 'track_inventory', 'value' => '1', 'checked' => $product['track_inventory'] == FALSE ? FALSE : TRUE, 'id' => 'track_inventory')); $form->value_row(' ', $inventory . ' <b>Track inventory for this product?</b>'); $form->text('Quantity in Stock', 'inventory', $product['inventory'], FALSE, FALSE, FALSE, FALSE, '60px', 'inventory'); $options = array('0' => 'Don\'t sell at zero inventory', '1' => 'Sell at zero inventory'); $form->radio(' ', 'inventory_allow_oversell', $options, $product['track_inventory'] == TRUE ? $product['inventory_allow_oversell'] : '1', FALSE, FALSE, FALSE, 'inventory_allow_at_zero'); // custom fields if (setting('products_custom_field_group') != '') { $this->load->library('custom_fields/form_builder'); $this->form_builder->build_form_from_group(setting('products_custom_field_group')); $this->form_builder->set_values($product); $this->form_builder->clear_defaults(); $custom_fields = $this->form_builder->output_admin(); } else { $custom_fields = FALSE; } // load usergroups for membership tiers $this->load->model('users/usergroup_model'); $usergroups = $this->usergroup_model->get_usergroups(); $options = array(); $options[0] = ''; foreach ($usergroups as $group) { $options[$group['id']] = $group['name']; } $usergroups = $options; // get files from product_files $files = $this->map_product_files(); // get product options that might be re-used $this->load->model('store/product_option_model'); $shared_product_options = $this->product_option_model->get_options(array('shared' => '1')); // also, get all product options $product_options = $this->product_option_model->get_options(); $data = array('form' => $form->display(), 'form_action' => site_url('admincp/store/post_product/edit/' . $product['id']), 'form_title' => 'Edit Product', 'usergroups' => $usergroups, 'files' => $files, 'shared_product_options' => $shared_product_options, 'product_options' => $product_options, 'custom_fields' => $custom_fields, 'product' => $product); $this->load->view('product_edit.php', $data); }