public static function save($id = null, $data) { global $lC_Database, $lC_Language, $lC_Image, $lC_CategoryTree; $error = false; $lC_Database->startTransaction(); if (is_numeric($id)) { $Qproduct = $lC_Database->query('update :table_products set parent_id = :parent_id, products_quantity = :products_quantity, products_cost = :products_cost, products_price = :products_price, products_msrp = :products_msrp, products_model = :products_model, products_sku = :products_sku, products_weight = :products_weight, products_weight_class = :products_weight_class, products_status = :products_status, groups_pricing_enable = :groups_pricing_enable, qpb_pricing_enable = :qpb_pricing_enable, specials_pricing_enable = :specials_pricing_enable, products_tax_class_id = :products_tax_class_id, products_last_modified = now(), products_sort_order = :products_sort_order where products_id = :products_id'); $Qproduct->bindInt(':products_id', $id); } else { $Qproduct = $lC_Database->query('insert into :table_products (parent_id, products_quantity, products_cost, products_price, products_msrp, products_model, products_sku, products_weight, products_weight_class, products_status, products_tax_class_id, products_ordered, products_date_added, groups_pricing_enable, qpb_pricing_enable, specials_pricing_enable, products_sort_order) values (:parent_id, :products_quantity, :products_cost, :products_price, :products_msrp, :products_model, :products_sku, :products_weight, :products_weight_class, :products_status, :products_tax_class_id, :products_ordered, :products_date_added, :groups_pricing_enable, :qpb_pricing_enable, :specials_pricing_enable, :products_sort_order)'); $Qproduct->bindRaw(':products_date_added', 'now()'); $Qproduct->bindInt(':products_ordered', $data['products_ordered']); } // set parent status if (isset($_POST['products_status']) && $_POST['products_status'] == 'active') { $data['status'] = 1; } if (isset($_POST['products_status']) && $_POST['products_status'] == 'inactive') { $data['status'] = -1; } if (isset($_POST['products_status']) && $_POST['products_status'] == 'recurring') { $data['status'] = 0; } $Qproduct->bindTable(':table_products', TABLE_PRODUCTS); $Qproduct->bindInt(':parent_id', $data['parent_id']); $Qproduct->bindInt(':products_quantity', $data['quantity']); $Qproduct->bindFloat(':products_cost', $data['cost']); $Qproduct->bindFloat(':products_price', $data['price']); $Qproduct->bindFloat(':products_msrp', $data['msrp']); $Qproduct->bindValue(':products_model', $data['model']); $Qproduct->bindValue(':products_sku', $data['sku']); $Qproduct->bindFloat(':products_weight', $data['weight']); $Qproduct->bindInt(':products_weight_class', $data['weight_class']); $Qproduct->bindInt(':products_tax_class_id', $data['tax_class_id']); $Qproduct->bindInt(':products_status', $data['status']); $Qproduct->bindInt(':groups_pricing_enable', $data['groups_pricing_switch']); $Qproduct->bindInt(':qpb_pricing_enable', $data['qpb_pricing_switch']); $Qproduct->bindInt(':specials_pricing_enable', $data['specials_pricing_switch']); $Qproduct->bindInt(':products_sort_order', $data['products_sort_order']); $Qproduct->setLogging($_SESSION['module'], $id); $Qproduct->execute(); if (is_numeric($id)) { $products_id = $id; } else { $products_id = $lC_Database->nextID(); } // products to categories if ($lC_Database->isError()) { $error = true; } else { $Qcategories = $lC_Database->query('delete from :table_products_to_categories where products_id = :products_id'); $Qcategories->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES); $Qcategories->bindInt(':products_id', $products_id); $Qcategories->setLogging($_SESSION['module'], $products_id); $Qcategories->execute(); if ($lC_Database->isError()) { $error = true; } else { if (isset($data['categories']) && !empty($data['categories'])) { foreach ($data['categories'] as $category_id) { $Qp2c = $lC_Database->query('insert into :table_products_to_categories (products_id, categories_id) values (:products_id, :categories_id)'); $Qp2c->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES); $Qp2c->bindInt(':products_id', $products_id); $Qp2c->bindInt(':categories_id', $category_id); $Qp2c->setLogging($_SESSION['module'], $products_id); $Qp2c->execute(); if ($lC_Database->isError()) { $error = true; break; } } } } } // product images if ($error === false) { $images = array(); $products_image = new upload('products_image'); $products_image->set_extensions(array('gif', 'jpg', 'jpeg', 'png')); if ($products_image->exists()) { $products_image->set_destination(realpath('../images/products/originals')); if ($products_image->parse() && $products_image->save()) { $images[] = $products_image->filename; } } if (isset($data['localimages'])) { foreach ($data['localimages'] as $image) { $image = basename($image); if (@file_exists('../images/products/_upload/' . $image)) { copy('../images/products/_upload/' . $image, '../images/products/originals/' . $image); @unlink('../images/products/_upload/' . $image); $images[] = $image; } } } $default_flag = 1; foreach ($images as $image) { $Qimage = $lC_Database->query('insert into :table_products_images (products_id, image, default_flag, sort_order, date_added) values (:products_id, :image, :default_flag, :sort_order, :date_added)'); $Qimage->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES); $Qimage->bindInt(':products_id', $products_id); $Qimage->bindValue(':image', $image); $Qimage->bindInt(':default_flag', $default_flag); $Qimage->bindInt(':sort_order', 0); $Qimage->bindRaw(':date_added', 'now()'); $Qimage->setLogging($_SESSION['module'], $products_id); $Qimage->execute(); if ($lC_Database->isError()) { $error = true; } else { foreach ($lC_Image->getGroups() as $group) { if ($group['id'] != '1') { $lC_Image->resize($image, $group['id']); } } } $default_flag = 0; } } // product description if ($error === false) { if (isset($data['categories']) && !empty($data['categories'])) { $cPath = $lC_CategoryTree->getcPath($data['categories'][0]); } else { $cPath = $category_id != '' ? $lC_CategoryTree->getcPath($category_id) : 0; } foreach ($lC_Language->getAll() as $l) { // this code will be revisited // if (self::validatePermalink($data['products_keyword'][$l['id']], $id, 2, $l['id']) != 1) { // $data['products_keyword'][$l['id']] = $data['products_keyword'][$l['id']] . '-link'; // } // check to see if the DB entry exists for the selected language $Qchk1 = $lC_Database->query('select products_description from :table_products_description where products_id = :products_id and language_id = :language_id limit 1'); $Qchk1->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION); $Qchk1->bindInt(':products_id', $products_id); $Qchk1->bindInt(':language_id', $l['id']); $Qchk1->execute(); if (is_numeric($id) && $Qchk1->numberOfRows() == 1) { $Qpd = $lC_Database->query('update :table_products_description set products_name = :products_name, products_blurb = :products_blurb, products_description = :products_description, products_keyword = :products_keyword, products_tags = :products_tags, products_url = :products_url where products_id = :products_id and language_id = :language_id'); } else { $Qpd = $lC_Database->query('insert into :table_products_description (products_id, language_id, products_name, products_blurb, products_description, products_keyword, products_tags, products_url) values (:products_id, :language_id, :products_name, :products_blurb, :products_description, :products_keyword, :products_tags, :products_url)'); } $Qchk1->freeResult(); $Qpd->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION); $Qpd->bindInt(':products_id', $products_id); $Qpd->bindInt(':language_id', $l['id']); $Qpd->bindValue(':products_name', $data['products_name'][$l['id']]); $Qpd->bindValue(':products_blurb', $data['products_blurb'][$l['id']]); $Qpd->bindValue(':products_description', $data['products_description'][$l['id']]); $Qpd->bindValue(':products_keyword', $data['products_keyword'][$l['id']]); $Qpd->bindValue(':products_tags', $data['products_tags'][$l['id']]); $Qpd->bindValue(':products_url', $data['products_url'][$l['id']]); $Qpd->setLogging($_SESSION['module'], $products_id); $Qpd->execute(); if ($lC_Database->isError()) { $error = true; break; } // check to see if the DB entry exists for the selected language $Qchk2 = $lC_Database->query('select products_description from :table_permalinks where item_id = :item_id and language_id = :language_id limit 1'); $Qchk2->bindTable(':table_permalinks', TABLE_PERMALINKS); $Qchk2->bindInt(':item_id', $products_id); $Qchk2->bindInt(':language_id', $l['id']); $Qchk2->execute(); // added for permalink if (is_numeric($id) && $Qchk2->numberOfRows() == 1) { $Qpl = $lC_Database->query('update :table_permalinks set permalink = :permalink, query = :query where item_id = :item_id and type = :type and language_id = :language_id'); } else { $Qpl = $lC_Database->query('insert into :table_permalinks (item_id, language_id, type, query, permalink) values (:item_id, :language_id, :type, :query, :permalink)'); } $Qchk2->freeResult(); $Qpl->bindTable(':table_permalinks', TABLE_PERMALINKS); $Qpl->bindInt(':item_id', $products_id); $Qpl->bindInt(':language_id', $l['id']); $Qpl->bindInt(':type', 2); $Qpl->bindValue(':query', 'cPath=' . $cPath); $Qpl->bindValue(':permalink', $data['products_keyword'][$l['id']]); $Qpl->setLogging($_SESSION['module'], $products_id); $Qpl->execute(); if ($lC_Database->isError()) { $error = true; break; } } } // product attributes if ($error === false) { if (isset($data['attributes']) && !empty($data['attributes'])) { foreach ($data['attributes'] as $attributes_id => $value) { if (is_array($value)) { } elseif (!empty($value) && $value != 'NULL') { $Qcheck = $lC_Database->query('select id from :table_product_attributes where products_id = :products_id and id = :id limit 1'); $Qcheck->bindTable(':table_product_attributes', TABLE_PRODUCT_ATTRIBUTES); $Qcheck->bindInt(':products_id', $products_id); $Qcheck->bindInt(':id', $attributes_id); $Qcheck->execute(); if ($Qcheck->numberOfRows() === 1) { $Qattribute = $lC_Database->query('update :table_product_attributes set value = :value, value2 = :value2 where products_id = :products_id and id = :id'); } else { $Qattribute = $lC_Database->query('insert into :table_product_attributes (id, products_id, languages_id, value, value2) values (:id, :products_id, :languages_id, :value, :value2)'); $Qattribute->bindInt(':languages_id', $lC_Language->getID()); } // support for 2nd value such as end date $value2 = isset($data['attributes2'][$attributes_id]) && $data['attributes2'][$attributes_id] != null ? $data['attributes2'][$attributes_id] : ''; $Qattribute->bindTable(':table_product_attributes', TABLE_PRODUCT_ATTRIBUTES); $Qattribute->bindValue(':value', $value); $Qattribute->bindValue(':value2', $value2); $Qattribute->bindInt(':products_id', $products_id); $Qattribute->bindInt(':id', $attributes_id); $Qattribute->execute(); if ($lC_Database->isError()) { $error = true; break; } } } } } // simple options if ($error === false) { // delete the simple options $Qdel = $lC_Database->query('delete from :table_products_simple_options where products_id = :products_id'); $Qdel->bindTable(':table_products_simple_options', TABLE_PRODUCTS_SIMPLE_OPTIONS); $Qdel->bindInt(':products_id', $products_id); $Qdel->setLogging($_SESSION['module'], $products_id); $Qdel->execute(); // delete the simple options values $Qdel = $lC_Database->query('delete from :table_products_simple_options_values where products_id = :products_id'); $Qdel->bindTable(':table_products_simple_options_values', TABLE_PRODUCTS_SIMPLE_OPTIONS_VALUES); $Qdel->bindInt(':products_id', $products_id); $Qdel->setLogging($_SESSION['module'], $products_id); $Qdel->execute(); // if values are set, save them if (isset($data['simple_options_group_name']) && !empty($data['simple_options_group_name'])) { foreach ($data['simple_options_group_name'] as $group_id => $value) { // add the new option $Qoptions = $lC_Database->query('insert into :table_products_simple_options (options_id, products_id, sort_order, status) values (:options_id, :products_id, :sort_order, :status)'); $Qoptions->bindTable(':table_products_simple_options', TABLE_PRODUCTS_SIMPLE_OPTIONS); $Qoptions->bindInt(':options_id', $group_id); $Qoptions->bindInt(':products_id', $products_id); $Qoptions->bindInt(':sort_order', $data['simple_options_group_sort_order'][$group_id]); $Qoptions->bindInt(':status', $data['simple_options_group_status'][$group_id]); $Qoptions->setLogging($_SESSION['module'], $products_id); $Qoptions->execute(); if ($lC_Database->isError()) { $error = true; break; } // add the new option values if (is_array($data['simple_options_entry_price_modifier'])) { foreach ($data['simple_options_entry_price_modifier'] as $customers_group_id => $options) { foreach ($options as $options_id => $option_value) { if ($options_id == $group_id) { foreach ($option_value as $values_id => $price_modifier) { // Added for simple options values sort order // based for now on variants values sort order globally across all products $Qsortorder = $lC_Database->query('select sort_order FROM :table_products_variants_values where id = :id'); $Qsortorder->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES); $Qsortorder->bindInt(':id', $values_id); $Qsortorder->execute(); $Qoptval = $lC_Database->query('insert into :table_products_simple_options_values (products_id, values_id, options_id, customers_group_id, price_modifier, sort_order) values (:products_id, :values_id, :options_id, :customers_group_id, :price_modifier, :sort_order)'); $Qoptval->bindTable(':table_products_simple_options_values', TABLE_PRODUCTS_SIMPLE_OPTIONS_VALUES); $Qoptval->bindInt(':products_id', $products_id); $Qoptval->bindInt(':values_id', $values_id); $Qoptval->bindInt(':options_id', $options_id); $Qoptval->bindInt(':customers_group_id', $customers_group_id); $Qoptval->bindInt(':sort_order', $Qsortorder->valueInt('sort_order')); $Qoptval->bindFloat(':price_modifier', (double) $price_modifier); $Qoptval->setLogging($_SESSION['module'], $products_id); $Qoptval->execute(); if ($lC_Database->isError()) { $error = true; break 4; } } } } } } } } } // specials pricing if ($error === false) { if ($data['specials_pricing_switch'] == 1) { $specials_id = self::hasSpecial($products_id); $specials_data = array('specials_id' => (int) $specials_id, 'products_id' => (int) $products_id, 'specials_price' => $data['products_special_price1'], 'specials_start_date' => $data['products_special_start_date1'], 'specials_expires_date' => $data['products_special_expires_date1'], 'specials_status' => $data['products_special_pricing_enable1'] != '' ? 1 : 0); lC_Specials_Admin::save((int) $specials_id, $specials_data); } } if ($error === false) { $lC_Database->commitTransaction(); lC_Cache::clear('categories'); lC_Cache::clear('category_tree'); lC_Cache::clear('also_purchased'); return $products_id; // Return the products id for use with the save_close buttons } $lC_Database->rollbackTransaction(); return false; }
public static function batchDelete($batch) { foreach ($batch as $id) { lC_Specials_Admin::delete($id); } return true; }
public static function getTaxClass() { $result = lC_Specials_Admin::getTax($_GET['pid']); $result['rpcStatus'] = RPC_STATUS_SUCCESS; echo json_encode($result); }