function saveProduct() { global $toC_Json, $osC_Database, $osC_Language, $osC_Image; $osC_Image = new osC_Image_Admin(); $data = array('products_type' => $_REQUEST['products_type'], 'quantity' => isset($_REQUEST['products_quantity']) ? $_REQUEST['products_quantity'] : 0, 'products_moq' => $_REQUEST['products_moq'], 'products_max_order_quantity' => isset($_REQUEST['products_max_order_quantity']) ? $_REQUEST['products_max_order_quantity'] : -1, 'order_increment' => $_REQUEST['order_increment'], 'quantity_unit_class' => $_REQUEST['quantity_unit_class'], 'price' => $_REQUEST['products_price'], 'weight' => $_REQUEST['products_weight'], 'quantity_discount_groups_id' => $_REQUEST['quantity_discount_groups_id'], 'weight_class' => $_REQUEST['products_weight_class'], 'status' => $_REQUEST['products_status'], 'tax_class_id' => $_REQUEST['products_tax_class_id'], 'manufacturers_id' => $_REQUEST['manufacturers_id'], 'date_available' => $_REQUEST['products_date_available'], 'products_name' => $_REQUEST['products_name'], 'products_short_description' => $_REQUEST['products_short_description'], 'products_description' => $_REQUEST['products_description'], 'products_sku' => $_REQUEST['products_sku'], 'products_model' => $_REQUEST['products_model'], 'products_tags' => $_REQUEST['products_tags'], 'products_url' => $_REQUEST['products_url'], 'products_page_title' => $_REQUEST['products_page_title'], 'products_meta_keywords' => $_REQUEST['products_meta_keywords'], 'products_meta_description' => $_REQUEST['products_meta_description'], 'products_attributes_groups_id' => $_REQUEST['products_attributes_groups_id']); if ($_REQUEST['products_type'] == PRODUCT_TYPE_DOWNLOADABLE) { $data['number_of_downloads'] = $_REQUEST['number_of_downloads']; $data['number_of_accessible_days'] = $_REQUEST['number_of_accessible_days']; } else { if ($_REQUEST['products_type'] == PRODUCT_TYPE_GIFT_CERTIFICATE) { $data['gift_certificates_type'] = $_REQUEST['gift_certificates_type']; $data['gift_certificates_amount_type'] = $_REQUEST['gift_certificates_amount_type']; $data['open_amount_min_value'] = isset($_REQUEST['open_amount_min_value']) ? $_REQUEST['open_amount_min_value'] : 0; $data['open_amount_max_value'] = isset($_REQUEST['open_amount_max_value']) ? $_REQUEST['open_amount_max_value'] : 0; } } $data['products_attributes'] = array(); if (isset($_REQUEST['products_attributes_select']) && is_array($_REQUEST['products_attributes_select'])) { foreach ($_REQUEST['products_attributes_select'] as $id => $value) { foreach ($osC_Language->getAll() as $l) { $data['products_attributes'][] = array('id' => $id, 'value' => $value, 'language_id' => $l['id']); } } } if (isset($_REQUEST['products_attributes_text']) && is_array($_REQUEST['products_attributes_text'])) { foreach ($_REQUEST['products_attributes_text'] as $id => $values) { foreach ($values as $language_id => $value) { $data['products_attributes'][] = array('id' => $id, 'value' => $value, 'language_id' => $language_id); } } } if (isset($_REQUEST['xsell_ids'])) { $xsell_ids = explode(';', $_REQUEST['xsell_ids']); $data['xsell_id_array'] = $xsell_ids; } if (isset($_REQUEST['categories_id'])) { $data['categories'] = explode(',', $_REQUEST['categories_id']); } if (isset($_REQUEST['localimages']) && !empty($_REQUEST['localimages'])) { $localimages = explode(',', $_REQUEST['localimages']); $data['localimages'] = $localimages; } if (isset($_REQUEST['products_variants']) && !empty($_REQUEST['products_variants'])) { $products_variants = explode(';', $_REQUEST['products_variants']); $data['variants_quantity'] = array(); $data['variants_status'] = array(); $data['variants_price'] = array(); $data['variants_sku'] = array(); $data['variants_model'] = array(); $data['variants_weight'] = array(); foreach ($products_variants as $variant) { $variants = explode(':', $variant); $data['variants_quantity'][$variants[0]] = $variants[1]; $data['variants_price'][$variants[0]] = $variants[2]; $data['variants_sku'][$variants[0]] = $variants[3]; $data['variants_model'][$variants[0]] = $variants[4]; $data['variants_weight'][$variants[0]] = $variants[5]; $data['variants_status'][$variants[0]] = $variants[6] == 'true' ? 1 : 0; } } if (osC_Products_Admin::save(isset($_REQUEST['products_id']) && (is_numeric($_REQUEST['products_id']) && $_REQUEST['products_id'] != '-1') ? $_REQUEST['products_id'] : null, $data)) { $response = array('success' => true, 'feedback' => $osC_Language->get('ms_success_action_performed')); } else { $response = array('success' => false, 'feedback' => $osC_Language->get('ms_error_action_not_performed')); } header('Content-Type: text/html'); echo $toC_Json->encode($response); }
function saveProduct() { global $toC_Json, $osC_Database, $osC_Language, $osC_Image; $osC_Image = new osC_Image_Admin(); //search engine friendly urls $formatted_urls = array(); $urls = $_REQUEST['products_friendly_url']; if (is_array($urls) && !empty($urls)) { foreach ($urls as $languages_id => $url) { $url = toc_format_friendly_url($url); if (empty($url)) { $url = toc_format_friendly_url($_REQUEST['products_name'][$languages_id]); } $formatted_urls[$languages_id] = $url; } } $data = array('products_type' => $_REQUEST['products_type'], 'quantity' => isset($_REQUEST['products_quantity']) ? $_REQUEST['products_quantity'] : 0, 'products_moq' => $_REQUEST['products_moq'], 'products_max_order_quantity' => isset($_REQUEST['products_max_order_quantity']) ? $_REQUEST['products_max_order_quantity'] : -1, 'order_increment' => $_REQUEST['order_increment'], 'quantity_unit_class' => $_REQUEST['quantity_unit_class'], 'price' => $_REQUEST['products_price'], 'weight' => $_REQUEST['products_weight'], 'quantity_discount_groups_id' => $_REQUEST['quantity_discount_groups_id'], 'weight_class' => $_REQUEST['products_weight_class'], 'status' => $_REQUEST['products_status'], 'tax_class_id' => $_REQUEST['products_tax_class_id'], 'manufacturers_id' => $_REQUEST['manufacturers_id'], 'date_available' => $_REQUEST['products_date_available'], 'products_name' => $_REQUEST['products_name'], 'products_short_description' => $_REQUEST['products_short_description'], 'products_description' => $_REQUEST['products_description'], 'products_sku' => $_REQUEST['products_sku'], 'products_model' => $_REQUEST['products_model'], 'products_tags' => $_REQUEST['products_tags'], 'products_url' => $_REQUEST['products_url'], 'products_friendly_url' => $formatted_urls, 'products_page_title' => $_REQUEST['products_page_title'], 'products_meta_keywords' => $_REQUEST['products_meta_keywords'], 'products_meta_description' => $_REQUEST['products_meta_description'], 'products_attributes_groups_id' => $_REQUEST['products_attributes_groups_id']); if ($_REQUEST['products_type'] == PRODUCT_TYPE_DOWNLOADABLE) { $data['number_of_downloads'] = $_REQUEST['number_of_downloads']; $data['number_of_accessible_days'] = $_REQUEST['number_of_accessible_days']; } else { if ($_REQUEST['products_type'] == PRODUCT_TYPE_GIFT_CERTIFICATE) { $data['gift_certificates_type'] = $_REQUEST['gift_certificates_type']; $data['gift_certificates_amount_type'] = $_REQUEST['gift_certificates_amount_type']; $data['open_amount_min_value'] = isset($_REQUEST['open_amount_min_value']) ? $_REQUEST['open_amount_min_value'] : 0; $data['open_amount_max_value'] = isset($_REQUEST['open_amount_max_value']) ? $_REQUEST['open_amount_max_value'] : 0; } } $data['products_attributes'] = array(); if (isset($_REQUEST['products_attributes_select']) && is_array($_REQUEST['products_attributes_select'])) { foreach ($_REQUEST['products_attributes_select'] as $id => $value) { foreach ($osC_Language->getAll() as $l) { $data['products_attributes'][] = array('id' => $id, 'value' => $value, 'language_id' => $l['id']); } } } if (isset($_REQUEST['products_attributes_text']) && is_array($_REQUEST['products_attributes_text'])) { foreach ($_REQUEST['products_attributes_text'] as $id => $values) { foreach ($values as $language_id => $value) { $data['products_attributes'][] = array('id' => $id, 'value' => $value, 'language_id' => $language_id); } } } if (isset($_REQUEST['xsell_ids'])) { $xsell_ids = explode(';', $_REQUEST['xsell_ids']); $data['xsell_id_array'] = $xsell_ids; } if (isset($_REQUEST['categories_id'])) { $data['categories'] = explode(',', $_REQUEST['categories_id']); } if (isset($_REQUEST['attachments_ids']) && !empty($_REQUEST['attachments_ids'])) { $data['attachments'] = explode(',', $_REQUEST['attachments_ids']); } if (isset($_REQUEST['accessories_ids']) && !empty($_REQUEST['accessories_ids'])) { $accessories_ids = explode(';', $_REQUEST['accessories_ids']); $data['accessories_ids'] = $accessories_ids; } if (isset($_REQUEST['localimages']) && !empty($_REQUEST['localimages'])) { $localimages = explode(',', $_REQUEST['localimages']); $data['localimages'] = $localimages; } if ($data['products_type'] != PRODUCT_TYPE_GIFT_CERTIFICATE && isset($_REQUEST['products_variants']) && !empty($_REQUEST['products_variants'])) { $products_variants = explode(';', $_REQUEST['products_variants']); $data['variants'] = $products_variants; $data['variants_quantity'] = array(); $data['variants_status'] = array(); $data['variants_price'] = array(); $data['variants_sku'] = array(); $data['variants_model'] = array(); $data['variants_weight'] = array(); $data['variants_change'] = array(); foreach ($products_variants as $variant) { $variants = explode(':', $variant); $data['products_variants_id'][$variants[0]] = $variants[1]; $data['variants_default'][$variants[0]] = $variants[2]; $data['variants_quantity'][$variants[0]] = $_REQUEST['variants_quantity'][$variants[0]]; $data['variants_price'][$variants[0]] = $_REQUEST['variants_net_price'][$variants[0]]; $data['variants_sku'][$variants[0]] = $_REQUEST['variants_sku'][$variants[0]]; $data['variants_model'][$variants[0]] = $_REQUEST['variants_model'][$variants[0]]; $data['variants_weight'][$variants[0]] = $_REQUEST['variants_weight'][$variants[0]]; $data['variants_status'][$variants[0]] = $_REQUEST['variants_status_' . $variants[0]]; $data['variants_image'][$variants[0]] = isset($_REQUEST['variants_image_' . $variants[0]]) ? $_REQUEST['variants_image_' . $variants[0]] : null; if ($data['products_type'] == PRODUCT_TYPE_DOWNLOADABLE) { $data['variants_cache_filename'][$variants[0]] = $variants[2]; } } } $data['customization_fields'] = array(); if (isset($_REQUEST['customization_fields']) && !empty($_REQUEST['customization_fields'])) { $fields = explode(';;', $_REQUEST['customization_fields']); if (sizeof($fields) > 0) { foreach ($fields as $field) { $tmp = explode('::', $field); $data['customization_fields'][] = array('customizations_fields_id' => $tmp[0], 'customizations_type' => $tmp[1], 'customizations_is_required' => $tmp[2], 'customizations_name_data' => $toC_Json->decode($tmp[3])); } } } //search engine friendly urls $return_urls = array(); if (is_array($formatted_urls) && !empty($formatted_urls)) { foreach ($formatted_urls as $languages_id => $url) { $return_urls[] = array('languages_id' => $languages_id, 'url' => $url); } } $products_id = osC_Products_Admin::save(isset($_REQUEST['products_id']) && (is_numeric($_REQUEST['products_id']) && $_REQUEST['products_id'] != '-1') ? $_REQUEST['products_id'] : null, $data); if ($products_id) { $response = array('success' => true, 'feedback' => $osC_Language->get('ms_success_action_performed'), 'productsId' => $products_id, 'urls' => $return_urls); } else { $response = array('success' => false, 'feedback' => $osC_Language->get('ms_error_action_not_performed')); } header('Content-Type: text/html'); echo $toC_Json->encode($response); }
public function __construct() { global $osC_Language, $osC_MessageStack; parent::__construct(); $this->_page_contents = 'edit.php'; if ((osc_empty(CFG_APP_IMAGEMAGICK_CONVERT) || !file_exists(CFG_APP_IMAGEMAGICK_CONVERT)) && !osC_Image_Admin::hasGDSupport()) { $osC_MessageStack->add('header', $osC_Language->get('ms_warning_image_processor_not_available'), 'warning'); } if (isset($_POST['subaction']) && $_POST['subaction'] == 'confirm') { $error = false; $data = array('quantity' => isset($_POST['products_quantity']) ? $_POST['products_quantity'] : 0, 'price' => is_numeric($_POST['products_price']) ? $_POST['products_price'] : 0, 'weight' => isset($_POST['products_weight']) ? $_POST['products_weight'] : 0, 'weight_class' => isset($_POST['products_weight_class']) ? $_POST['products_weight_class'] : '', 'status' => $_POST['products_status'], 'model' => isset($_POST['products_model']) ? $_POST['products_model'] : '', 'tax_class_id' => $_POST['products_tax_class_id'], 'products_name' => $_POST['products_name'], 'products_description' => $_POST['products_description'], 'products_keyword' => $_POST['products_keyword'], 'products_tags' => $_POST['products_tags'], 'products_url' => $_POST['products_url']); if (isset($_POST['attributes'])) { $data['attributes'] = $_POST['attributes']; } if (isset($_POST['categories'])) { $data['categories'] = $_POST['categories']; } if (isset($_POST['localimages'])) { $data['localimages'] = $_POST['localimages']; } if (isset($_POST['variants_tax_class_id'])) { $data['variants_tax_class_id'] = $_POST['variants_tax_class_id']; } if (isset($_POST['variants_price'])) { $data['variants_price'] = $_POST['variants_price']; } if (isset($_POST['variants_model'])) { $data['variants_model'] = $_POST['variants_model']; } if (isset($_POST['variants_quantity'])) { $data['variants_quantity'] = $_POST['variants_quantity']; } if (isset($_POST['variants_combo'])) { $data['variants_combo'] = $_POST['variants_combo']; } if (isset($_POST['variants_combo_db'])) { $data['variants_combo_db'] = $_POST['variants_combo_db']; } if (isset($_POST['variants_weight'])) { $data['variants_weight'] = $_POST['variants_weight']; } if (isset($_POST['variants_weight_class'])) { $data['variants_weight_class'] = $_POST['variants_weight_class']; } if (isset($_POST['variants_status'])) { $data['variants_status'] = $_POST['variants_status']; } if (isset($_POST['variants_default_combo'])) { $data['variants_default_combo'] = $_POST['variants_default_combo']; } foreach ($data['products_keyword'] as $value) { if (empty($value)) { $osC_MessageStack->add($this->_module, $osC_Language->get('ms_error_product_keyword_empty'), 'error'); $error = true; } elseif (preg_match('/^[a-z0-9_-]+$/iD', $value) !== 1) { $osC_MessageStack->add($this->_module, sprintf($osC_Language->get('ms_error_product_keyword_invalid'), osc_output_string_protected($value)), 'error'); $error = true; } if (osC_Products_Admin::getKeywordCount($value, isset($_GET[$this->_module]) && is_numeric($_GET[$this->_module]) ? $_GET[$this->_module] : null) > 0) { $osC_MessageStack->add($this->_module, sprintf($osC_Language->get('ms_error_product_keyword_exists'), osc_output_string_protected($value)), 'error'); $error = true; } } if ($error === false) { if (osC_Products_Admin::save(isset($_GET[$this->_module]) && is_numeric($_GET[$this->_module]) ? $_GET[$this->_module] : null, $data)) { $osC_MessageStack->add($this->_module, $osC_Language->get('ms_success_action_performed'), 'success'); } else { $osC_MessageStack->add($this->_module, $osC_Language->get('ms_error_action_not_performed'), 'error'); } osc_redirect_admin(osc_href_link_admin(FILENAME_DEFAULT, $this->_module . '&cID=' . $_GET['cID'])); } } }