PHPize Online / SQLize Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy
Copy Format Clear
<?php public function quickEditProduct($product_id, $column, $value, $lang_id=null, $data=null) { if ($column == 'upc') { $upcRealPrice = (int)$value;//значение из поля в админке $priceRealPrice = $upcRealPrice + ceil($upcRealPrice * 0.25);//умножим и получим процент $column = array('upc', 'price');// список нужных полей $value = //upc = (int)$value, price = $priceRealPrice } $editable = array('manufacturer', 'image', 'model', 'sku', 'upc', 'ean', 'jan', 'mpn', 'isbn', 'location', 'quantity', 'price', 'weight', 'status', 'sort_order', 'tax_class', 'minimum', 'subtract', 'stock_status', 'shipping', 'date_available', 'date_added', 'length', 'width', 'height', 'length_class', 'weight_class', 'points', 'viewed'); $result = false; if (in_array($column, $editable)) { if (in_array($column, array('image', 'model', 'sku', 'upc', 'ean', 'jan', 'mpn', 'isbn', 'location', 'date_available', 'date_added'))) $result = $this->db->query("UPDATE " . DB_PREFIX . "product SET " . $column . " = '" . $this->db->escape($value) . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'"); else if (in_array($column, array('quantity', 'sort_order', 'status', 'minimum', 'subtract', 'shipping', 'points', 'viewed'))) { if (strpos(trim($value), "#") === 0 && preg_match('/^#\s*(?P<operator>[+-\/\*])\s*(?P<operand>-?\d+\.?\d*)(?P<percent>%)?$/', trim($value), $matches) === 1) { list($operator, $operand) = $this->parseExpression($matches); $result = $this->db->query("UPDATE `" . DB_PREFIX . "product` SET `$column` = `$column` $operator '" . (float)$operand . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'"); $query = $this->db->query("SELECT `$column` FROM `" . DB_PREFIX . "product` WHERE product_id = '" . (int)$product_id . "'"); $result = $query->row[$column]; } else { $result = $this->db->query("UPDATE `" . DB_PREFIX . "product` SET `" . $column . "` = '" . (int)$value . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'"); } } else if (in_array($column, array('manufacturer', 'tax_class', 'stock_status', 'length_class', 'weight_class'))) $result = $this->db->query("UPDATE " . DB_PREFIX . "product SET " . $column . "_id = '" . (int)$value . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'"); else { if (strpos(trim($value), "#") === 0 && preg_match('/^#\s*(?P<operator>[+-\/\*])\s*(?P<operand>-?\d+\.?\d*)(?P<percent>%)?$/', trim($value), $matches) === 1) { list($operator, $operand) = $this->parseExpression($matches); $result = $this->db->query("UPDATE `" . DB_PREFIX . "product` SET `$column` = `$column` $operator '" . (float)$operand . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'"); $query = $this->db->query("SELECT `$column` FROM `" . DB_PREFIX . "product` WHERE product_id = '" . (int)$product_id . "'"); $result = $query->row[$column]; } else { $result = $this->db->query("UPDATE `" . DB_PREFIX . "product` SET `" . $column . "` = '" . (float)$value . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'"); } } } else if ($column == 'seo' || $column == 'keywords') { $this->db->query("DELETE FROM " . DB_PREFIX . "seo_url WHERE query = 'product_id=" . (int)$product_id. "'"); if (isset($data['value']) && is_array($data['value'])) { foreach ((array)$data['value'] as $store_id => $language) { foreach ($language as $language_id => $keyword) { if (!empty($keyword)) { $this->db->query("INSERT INTO " . DB_PREFIX . "seo_url SET store_id = '" . (int)$store_id . "', language_id = '" . (int)$language_id . "', query = 'product_id=" . (int)$product_id . "', keyword = '" . $this->db->escape($keyword) . "'"); } } } $result = 1; } else { $result = 1; } } else if (in_array($column, array('name', 'tag'))) { if (isset($data['value']) && is_array($data['value'])) { foreach ((array)$data['value'] as $language_id => $value) { $this->db->query("UPDATE " . DB_PREFIX . "product_description SET " . $column . " = '" . $this->db->escape($value) . "' WHERE product_id = '" . (int)$product_id . "' AND language_id = '" . (int)$language_id . "'"); } $result = 1; } else if ($value) { $result = $this->db->query("UPDATE " . DB_PREFIX . "product_description SET " . $column . " = '" . $this->db->escape($value) . "' WHERE product_id = '" . (int)$product_id . "' AND language_id = '" . (int)$lang_id . "'"); $result = 1; } else { $result = 0; } } else if ($column == 'category') { $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'"); if (isset($data['product_category'])) { foreach ((array)$data['product_category'] as $category_id) { $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_category SET product_id = '" . (int)$product_id . "', category_id = '" . (int)$category_id . "'"); } } $result = 1; } else if ($column == 'store') { $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_store WHERE product_id = '" . (int)$product_id . "'"); if (isset($data['product_store'])) { foreach ((array)$data['product_store'] as $store_id) { $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_store SET product_id = '" . (int)$product_id . "', store_id = '" . (int)$store_id . "'"); } } $result = 1; } else if ($column == 'filter' || $column == 'filters') { $this->db->query("DELETE FROM " . DB_PREFIX . "product_filter WHERE product_id = '" . (int)$product_id . "'"); if (isset($data['product_filter'])) { foreach ((array)$data['product_filter'] as $filter_id) { $this->db->query("INSERT INTO " . DB_PREFIX . "product_filter SET product_id = '" . (int)$product_id . "', filter_id = '" . (int)$filter_id . "'"); } } $result = 1; } else if ($column == 'download' || $column == 'downloads') { $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_download WHERE product_id = '" . (int)$product_id . "'"); if (isset($data['product_download'])) { foreach ((array)$data['product_download'] as $download_id) { $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_download SET product_id = '" . (int)$product_id . "', download_id = '" . (int)$download_id . "'"); } } $result = 1; } else if ($column == 'attributes') { $this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "'"); if (!empty($data['product_attribute'])) { foreach ((array)$data['product_attribute'] as $product_attribute) { if ($product_attribute['attribute_id']) { $this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "'"); foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) { $this->db->query("INSERT INTO " . DB_PREFIX . "product_attribute SET product_id = '" . (int)$product_id . "', attribute_id = '" . (int)$product_attribute['attribute_id'] . "', language_id = '" . (int)$language_id . "', text = '" . $this->db->escape($product_attribute_description['text']) . "'"); } } } } $result = 1; } else if ($column == 'discounts') { $module_admin_quick_edit_price_relative_to = $this->config->get('module_admin_quick_edit_price_relative_to'); if ($module_admin_quick_edit_price_relative_to == 'product') { $query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product_id . "'"); if ($query->num_rows) { $product_price = $query->row['price']; } else { $product_price = 0; } } else { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "'"); $old_discounts = array_remap_key_to_id('product_discount_id', (array)$query->rows); } $this->db->query("DELETE FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "'"); if (isset($data['product_discount'])) { foreach ((array)$data['product_discount'] as $product_discount) { $_value = $product_discount['price']; if (strpos(trim($_value), "#") === 0 && preg_match('/^#\s*(?P<operator>[+-\/\*])\s*(?P<operand>-?\d+\.?\d*)(?P<percent>%)?$/', trim($_value), $matches) === 1) { list($operator, $operand) = $this->parseExpression($matches); $old_value = $module_admin_quick_edit_price_relative_to == 'product' ? $product_price : (isset($product_discount['discount_id']) && isset($old_discounts[$product_discount['discount_id']]) ? $old_discounts[$product_discount['discount_id']]['price'] : 0); eval("\$new_value = (float)$old_value $operator (float)$operand;"); $this->db->query("INSERT INTO " . DB_PREFIX . "product_discount SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$product_discount['customer_group_id'] . "', quantity = '" . (int)$product_discount['quantity'] . "', priority = '" . (int)$product_discount['priority'] . "', price = '" . (float)$new_value . "', date_start = '" . $this->db->escape($product_discount['date_start']) . "', date_end = '" . $this->db->escape($product_discount['date_end']) . "'"); } else { $this->db->query("INSERT INTO " . DB_PREFIX . "product_discount SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$product_discount['customer_group_id'] . "', quantity = '" . (int)$product_discount['quantity'] . "', priority = '" . (int)$product_discount['priority'] . "', price = '" . (float)$product_discount['price'] . "', date_start = '" . $this->db->escape($product_discount['date_start']) . "', date_end = '" . $this->db->escape($product_discount['date_end']) . "'"); } } } $result = 1; } else if ($column == 'images') { $this->db->query("DELETE FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'"); if (isset($data['product_image'])) { foreach ((array)$data['product_image'] as $product_image) { $this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = '" . $this->db->escape(html_entity_decode($product_image['image'], ENT_QUOTES, 'UTF-8')) . "', sort_order = '" . (int)$product_image['sort_order'] . "'"); } } $result = 1; } else if ($column == 'options') { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value WHERE product_id = '" . (int)$product_id . "'"); $old_option_values = array_remap_key_to_id('product_option_value_id', (array)$query->rows); $this->db->query("DELETE FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "'"); $this->db->query("DELETE FROM " . DB_PREFIX . "product_option_value WHERE product_id = '" . (int)$product_id . "'"); if (isset($data['product_option'])) { foreach ($data['product_option'] as $product_option) { if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'checkbox' || $product_option['type'] == 'image') { $query = $this->db->query("SELECT 1 FROM " . DB_PREFIX . "product_option WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "'"); if ($query->num_rows) { $this->db->query("INSERT INTO " . DB_PREFIX . "product_option SET product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', required = '" . (int)$product_option['required'] . "'"); } else { $this->db->query("INSERT INTO " . DB_PREFIX . "product_option SET product_option_id = '" . (int)$product_option['product_option_id'] . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', required = '" . (int)$product_option['required'] . "'"); } $product_option_id = $this->db->getLastId(); if (isset($product_option['product_option_value'])) { foreach ((array)$product_option['product_option_value'] as $product_option_value) { $query = $this->db->query("SELECT 1 FROM " . DB_PREFIX . "product_option_value WHERE product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "'"); $_value = $product_option_value['price']; if ($query->num_rows) { if (strpos(trim($_value), "#") === 0 && preg_match('/^#\s*(?P<operator>[+-\/\*])\s*(?P<operand>-?\d+\.?\d*)(?P<percent>%)?$/', trim($_value), $matches) === 1) { list($operator, $operand) = $this->parseExpression($matches); $old_value = isset($product_option_value['product_option_value_id']) && isset($old_option_values[$product_option_value['product_option_value_id']]) ? $old_option_values[$product_option_value['product_option_value_id']]['price'] : 0; eval("\$new_value = (float)$old_value $operator (float)$operand;"); $this->db->query("INSERT INTO " . DB_PREFIX . "product_option_value SET product_option_id = '" . (int)$product_option_id . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', option_value_id = '" . (int)$product_option_value['option_value_id'] . "', quantity = '" . (int)$product_option_value['quantity'] . "', subtract = '" . (int)$product_option_value['subtract'] . "', price = '" . (float)$new_value . "', price_prefix = '" . $this->db->escape($product_option_value['price_prefix']) . "', points = '" . (int)$product_option_value['points'] . "', points_prefix = '" . $this->db->escape($product_option_value['points_prefix']) . "', weight = '" . (float)$product_option_value['weight'] . "', weight_prefix = '" . $this->db->escape($product_option_value['weight_prefix']) . "'"); } else { $this->db->query("INSERT INTO " . DB_PREFIX . "product_option_value SET product_option_id = '" . (int)$product_option_id . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', option_value_id = '" . (int)$product_option_value['option_value_id'] . "', quantity = '" . (int)$product_option_value['quantity'] . "', subtract = '" . (int)$product_option_value['subtract'] . "', price = '" . (float)$product_option_value['price'] . "', price_prefix = '" . $this->db->escape($product_option_value['price_prefix']) . "', points = '" . (int)$product_option_value['points'] . "', points_prefix = '" . $this->db->escape($product_option_value['points_prefix']) . "', weight = '" . (float)$product_option_value['weight'] . "', weight_prefix = '" . $this->db->escape($product_option_value['weight_prefix']) . "'"); } } else { if (strpos(trim($_value), "#") === 0 && preg_match('/^#\s*(?P<operator>[+-\/\*])\s*(?P<operand>-?\d+\.?\d*)(?P<percent>%)?$/', trim($_value), $matches) === 1) { list($operator, $operand) = $this->parseExpression($matches); $old_value = isset($product_option_value['product_option_value_id']) && isset($old_option_values[$product_option_value['product_option_value_id']]) ? $old_option_values[$product_option_value['product_option_value_id']]['price'] : 0; eval("\$new_value = (float)$old_value $operator (float)$operand;"); $this->db->query("INSERT INTO " . DB_PREFIX . "product_option_value SET product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "', product_option_id = '" . (int)$product_option_id . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', option_value_id = '" . (int)$product_option_value['option_value_id'] . "', quantity = '" . (int)$product_option_value['quantity'] . "', subtract = '" . (int)$product_option_value['subtract'] . "', price = '" . (float)$new_value . "', price_prefix = '" . $this->db->escape($product_option_value['price_prefix']) . "', points = '" . (int)$product_option_value['points'] . "', points_prefix = '" . $this->db->escape($product_option_value['points_prefix']) . "', weight = '" . (float)$product_option_value['weight'] . "', weight_prefix = '" . $this->db->escape($product_option_value['weight_prefix']) . "'"); } else { $this->db->query("INSERT INTO " . DB_PREFIX . "product_option_value SET product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "', product_option_id = '" . (int)$product_option_id . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', option_value_id = '" . (int)$product_option_value['option_value_id'] . "', quantity = '" . (int)$product_option_value['quantity'] . "', subtract = '" . (int)$product_option_value['subtract'] . "', price = '" . (float)$product_option_value['price'] . "', price_prefix = '" . $this->db->escape($product_option_value['price_prefix']) . "', points = '" . (int)$product_option_value['points'] . "', points_prefix = '" . $this->db->escape($product_option_value['points_prefix']) . "', weight = '" . (float)$product_option_value['weight'] . "', weight_prefix = '" . $this->db->escape($product_option_value['weight_prefix']) . "'"); } } } } } else { $query = $this->db->query("SELECT 1 FROM " . DB_PREFIX . "product_option WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "'"); if ($query->num_rows) { $this->db->query("INSERT INTO " . DB_PREFIX . "product_option SET product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', value = '" . $this->db->escape($product_option['value']) . "', required = '" . (int)$product_option['required'] . "'"); } else { $this->db->query("INSERT INTO " . DB_PREFIX . "product_option SET product_option_id = '" . (int)$product_option['product_option_id'] . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', value = '" . $this->db->escape($product_option['value']) . "', required = '" . (int)$product_option['required'] . "'"); } } } } $result = 1; } else if ($column == 'recurrings') { $this->db->query("DELETE FROM `" . DB_PREFIX . "product_recurring` WHERE product_id = " . (int)$product_id); if (isset($data['product_recurrings'])) { foreach ($data['product_recurrings'] as $recurring) { $this->db->query("INSERT INTO `" . DB_PREFIX . "product_recurring` SET `product_id` = " . (int)$product_id . ", customer_group_id = " . (int)$recurring['customer_group_id'] . ", `recurring_id` = " . (int)$recurring['recurring_id']); } } $result = 1; } else if ($column == 'specials') { $module_admin_quick_edit_price_relative_to = $this->config->get('module_admin_quick_edit_price_relative_to'); if ($module_admin_quick_edit_price_relative_to == 'product') { $query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product_id . "'"); if ($query->num_rows) { $product_price = $query->row['price']; } else { $product_price = 0; } } else { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "'"); $old_specials = array_remap_key_to_id('product_special_id', (array)$query->rows); } $this->db->query("DELETE FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "'"); if (isset($data['product_special'])) { foreach ((array)$data['product_special'] as $product_special) { $_value = $product_special['price']; if (strpos(trim($_value), "#") === 0 && preg_match('/^#\s*(?P<operator>[+-\/\*])\s*(?P<operand>-?\d+\.?\d*)(?P<percent>%)?$/', trim($_value), $matches) === 1) { list($operator, $operand) = $this->parseExpression($matches); $old_value = $module_admin_quick_edit_price_relative_to == 'product' ? $product_price : (isset($product_special['special_id']) && isset($old_specials[$product_special['special_id']]) ? $old_specials[$product_special['special_id']]['price'] : 0); eval("\$new_value = (float)$old_value $operator (float)$operand;"); $this->db->query("INSERT INTO " . DB_PREFIX . "product_special SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$product_special['customer_group_id'] . "', priority = '" . (int)$product_special['priority'] . "', price = '" . (float)$new_value . "', date_start = '" . $this->db->escape($product_special['date_start']) . "', date_end = '" . $this->db->escape($product_special['date_end']) . "'"); } else { $this->db->query("INSERT INTO " . DB_PREFIX . "product_special SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$product_special['customer_group_id'] . "', priority = '" . (int)$product_special['priority'] . "', price = '" . (float)$product_special['price'] . "', date_start = '" . $this->db->escape($product_special['date_start']) . "', date_end = '" . $this->db->escape($product_special['date_end']) . "'"); } } } $result = 1; } else if ($column == 'related') { $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'"); $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE related_id = '" . (int)$product_id . "'"); if (isset($data['product_related'])) { foreach ((array)$data['product_related'] as $related_id) { $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "' AND related_id = '" . (int)$related_id . "'"); $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$product_id . "', related_id = '" . (int)$related_id . "'"); $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$related_id . "' AND related_id = '" . (int)$product_id . "'"); $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$related_id . "', related_id = '" . (int)$product_id . "'"); } } $result = 1; } else if ($column == 'descriptions') { foreach ((array)$data['product_description'] as $language_id => $value) { $this->db->query("UPDATE " . DB_PREFIX . "product_description SET description = '" . $this->db->escape($value['description']) . "', meta_title = '" . $this->db->escape($value['meta_title']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "' WHERE product_id = '" . (int)$product_id . "' AND language_id = '" . (int)$language_id . "'"); } $result = 1; } $this->cache->delete('product'); return $result; }
Show:  
Copy