2016-01-04 2 views
1

Прежде всего, я не программист, но я пытаюсь сделать несколько модов в своем интернет-магазине, работающем на opencart, поэтому, пожалуйста, будьте терпеливы со мной :) Я прочитал тонны форумов о функциях и изменениях символов, но до сих пор не удалось найти простой ответ, который поможет мне сделать это. Я пытаюсь сделать все символы строчными, пробелы заменены на «-», а акценты заменены аналогичными символами.Как заменить символы акцента в Opencart для SEO url

Я думаю, что это кусок кода в OpenCart мне нужно изменить, но вопрос заключается в том:

if ($data['keyword']) { $this->db->query("INSERT INTO " . DB_PREFIX . "url_alias SET query = 'product_id=" . (int)$product_id . "', keyword = '" . $this->db->escape($data['keyword']) . "'"); }

если я изменить это: . $this->db->escape($data['keyword']) . "'")

к этому: . $this->db->escape(strtolower(trim(preg_replace('/[^a-zA-Z0-9]+/', '-', $data['keyword']), '-')))

Это часть работы, но следующая задача - заменить все акценты. Я сделал function.php с этим кодом:

<?php \t 
 
function accents($string) 
 
    { 
 
\t //search 
 
    $dia = array('á', 'ä', 'č', 'ď', 'é', 'ě', 'í', 'ľ', 'ĺ', 'ň', 'ó', 'ô', 'ŕ', 'ř', 'š', 'ť', 'ú', 'ů', 'ý', 'ž', 'Á', 'Ä', 'Č', 'Ď', 'É', 'Í', 'Ľ', 'Ĺ', 'Ň', 'Ó', 'Ô', 'Ř', 'Š', 'Ť', 'Ú', 'Ý', 'Ž', ' ','\'','%'); 
 

 
    //replace 
 
    $nodia = array('a', 'a', 'c', 'd', 'e', 'e', 'i', 'l', 'l', 'n', 'o', 'o', 'r', 'r', 's', 't', 'u', 'u', 'y', 'z', 'A', 'A', 'C', 'D', 'E', 'I', 'L', 'L', 'N', 'O', 'O', 'R', 'S', 'T', 'U', 'Y', 'Z', '-','',''); 
 
    
 
    return str_replace($dia, $nodia, $string); 
 
    } 
 
?>

Это должно сделать часть трюка, но я не знаю, как заставить его работать с другой частью код.

Это часть product.php. Файл, где он должен быть aplicated ..

This is the part of product.php Would you please advice me what exactly and where to put? 
 

 
<?php 
 
class ModelCatalogProduct extends Model { 
 
\t public function addProduct($data) { 
 
\t \t $this->event->trigger('pre.admin.product.add', $data); 
 

 
\t \t $this->db->query("INSERT INTO " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', upc = '" . $this->db->escape($data['upc']) . "', ean = '" . $this->db->escape($data['ean']) . "', jan = '" . $this->db->escape($data['jan']) . "', isbn = '" . $this->db->escape($data['isbn']) . "', mpn = '" . $this->db->escape($data['mpn']) . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', minimum = '" . (int)$data['minimum'] . "', subtract = '" . (int)$data['subtract'] . "', stock_status_id = '" . (int)$data['stock_status_id'] . "', date_available = '" . $this->db->escape($data['date_available']) . "', manufacturer_id = '" . (int)$data['manufacturer_id'] . "', shipping = '" . (int)$data['shipping'] . "', price = '" . (float)$data['price'] . "', points = '" . (int)$data['points'] . "', weight = '" . (float)$data['weight'] . "', weight_class_id = '" . (int)$data['weight_class_id'] . "', length = '" . (float)$data['length'] . "', width = '" . (float)$data['width'] . "', height = '" . (float)$data['height'] . "', length_class_id = '" . (int)$data['length_class_id'] . "', status = '" . (int)$data['status'] . "', tax_class_id = '" . (int)$data['tax_class_id'] . "', sort_order = '" . (int)$data['sort_order'] . "', date_added = NOW()"); 
 

 
\t \t $product_id = $this->db->getLastId(); 
 

 
\t \t if (isset($data['image'])) { 
 
\t \t \t $this->db->query("UPDATE " . DB_PREFIX . "product SET image = '" . $this->db->escape($data['image']) . "' WHERE product_id = '" . (int)$product_id . "'"); 
 
\t \t } 
 

 
\t \t foreach ($data['product_description'] as $language_id => $value) { 
 
\t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', description = '" . $this->db->escape($value['description']) . "', tag = '" . $this->db->escape($value['tag']) . "', meta_title = '" . $this->db->escape($value['meta_title']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "'"); 
 
\t \t } 
 

 
\t \t if (isset($data['product_store'])) { 
 
\t \t \t foreach ($data['product_store'] as $store_id) { 
 
\t \t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_store SET product_id = '" . (int)$product_id . "', store_id = '" . (int)$store_id . "'"); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t if (isset($data['product_attribute'])) { 
 
\t \t \t foreach ($data['product_attribute'] as $product_attribute) { 
 
\t \t \t \t if ($product_attribute['attribute_id']) { 
 
\t \t \t \t \t foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) { 
 
\t \t \t \t \t \t $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']) . "'"); 
 
\t \t \t \t \t } 
 
\t \t \t \t } 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t if (isset($data['product_option'])) { 
 
\t \t \t foreach ($data['product_option'] as $product_option) { 
 
\t \t \t \t if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'checkbox' || $product_option['type'] == 'image') { 
 
\t \t \t \t \t if (isset($product_option['product_option_value'])) { 
 
\t \t \t \t \t \t $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'] . "'"); 
 

 
\t \t \t \t \t \t $product_option_id = $this->db->getLastId(); 
 

 
\t \t \t \t \t \t foreach ($product_option['product_option_value'] as $product_option_value) { 
 
\t \t \t \t \t \t \t $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']) . "'"); 
 
\t \t \t \t \t \t } 
 
\t \t \t \t \t } 
 
\t \t \t \t } else { 
 
\t \t \t \t \t $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'] . "'"); 
 
\t \t \t \t } 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t if (isset($data['product_discount'])) { 
 
\t \t \t foreach ($data['product_discount'] as $product_discount) { 
 
\t \t \t \t $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']) . "'"); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t if (isset($data['product_special'])) { 
 
\t \t \t foreach ($data['product_special'] as $product_special) { 
 
\t \t \t \t $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']) . "'"); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t if (isset($data['product_image'])) { 
 
\t \t \t foreach ($data['product_image'] as $product_image) { 
 
\t \t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = '" . $this->db->escape($product_image['image']) . "', sort_order = '" . (int)$product_image['sort_order'] . "'"); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t if (isset($data['product_download'])) { 
 
\t \t \t foreach ($data['product_download'] as $download_id) { 
 
\t \t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_download SET product_id = '" . (int)$product_id . "', download_id = '" . (int)$download_id . "'"); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t if (isset($data['product_category'])) { 
 
\t \t \t foreach ($data['product_category'] as $category_id) { 
 
\t \t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_category SET product_id = '" . (int)$product_id . "', category_id = '" . (int)$category_id . "'"); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t if (isset($data['product_filter'])) { 
 
\t \t \t foreach ($data['product_filter'] as $filter_id) { 
 
\t \t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "product_filter SET product_id = '" . (int)$product_id . "', filter_id = '" . (int)$filter_id . "'"); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t if (isset($data['product_related'])) { 
 
\t \t \t foreach ($data['product_related'] as $related_id) { 
 
\t \t \t \t $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "' AND related_id = '" . (int)$related_id . "'"); 
 
\t \t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$product_id . "', related_id = '" . (int)$related_id . "'"); 
 
\t \t \t \t $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$related_id . "' AND related_id = '" . (int)$product_id . "'"); 
 
\t \t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$related_id . "', related_id = '" . (int)$product_id . "'"); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t if (isset($data['product_reward'])) { 
 
\t \t \t foreach ($data['product_reward'] as $customer_group_id => $product_reward) { 
 
\t \t \t \t if ((int)$product_reward['points'] > 0) { 
 
\t \t \t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "product_reward SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$customer_group_id . "', points = '" . (int)$product_reward['points'] . "'"); 
 
\t \t \t \t } 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t if (isset($data['product_layout'])) { 
 
\t \t \t foreach ($data['product_layout'] as $store_id => $layout_id) { 
 
\t \t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_layout SET product_id = '" . (int)$product_id . "', store_id = '" . (int)$store_id . "', layout_id = '" . (int)$layout_id . "'"); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t if (isset($data['keyword'])) { 
 
\t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "url_alias SET query = 'product_id=" . (int)$product_id . "', keyword = '" . $this->db->escape($this->accents($data['keyword'])) . "'"); 
 
    
 
\t \t } 
 

 
\t \t if (isset($data['product_recurrings'])) { 
 
\t \t \t foreach ($data['product_recurrings'] as $recurring) { 
 
\t \t \t \t $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']); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t $this->cache->delete('product'); 
 

 
\t \t $this->event->trigger('post.admin.product.add', $product_id); 
 

 
\t \t return $product_id; 
 
\t } 
 

 
\t public function editProduct($product_id, $data) { 
 
\t \t $this->event->trigger('pre.admin.product.edit', $data); 
 

 
\t \t $this->db->query("UPDATE " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', upc = '" . $this->db->escape($data['upc']) . "', ean = '" . $this->db->escape($data['ean']) . "', jan = '" . $this->db->escape($data['jan']) . "', isbn = '" . $this->db->escape($data['isbn']) . "', mpn = '" . $this->db->escape($data['mpn']) . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', minimum = '" . (int)$data['minimum'] . "', subtract = '" . (int)$data['subtract'] . "', stock_status_id = '" . (int)$data['stock_status_id'] . "', date_available = '" . $this->db->escape($data['date_available']) . "', manufacturer_id = '" . (int)$data['manufacturer_id'] . "', shipping = '" . (int)$data['shipping'] . "', price = '" . (float)$data['price'] . "', points = '" . (int)$data['points'] . "', weight = '" . (float)$data['weight'] . "', weight_class_id = '" . (int)$data['weight_class_id'] . "', length = '" . (float)$data['length'] . "', width = '" . (float)$data['width'] . "', height = '" . (float)$data['height'] . "', length_class_id = '" . (int)$data['length_class_id'] . "', status = '" . (int)$data['status'] . "', tax_class_id = '" . (int)$data['tax_class_id'] . "', sort_order = '" . (int)$data['sort_order'] . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'"); 
 

 
\t \t if (isset($data['image'])) { 
 
\t \t \t $this->db->query("UPDATE " . DB_PREFIX . "product SET image = '" . $this->db->escape($data['image']) . "' WHERE product_id = '" . (int)$product_id . "'"); 
 
\t \t } 
 

 
\t \t $this->db->query("DELETE FROM " . DB_PREFIX . "product_description WHERE product_id = '" . (int)$product_id . "'"); 
 

 
\t \t foreach ($data['product_description'] as $language_id => $value) { 
 
\t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', description = '" . $this->db->escape($value['description']) . "', tag = '" . $this->db->escape($value['tag']) . "', meta_title = '" . $this->db->escape($value['meta_title']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "'"); 
 
\t \t } 
 

 
\t \t $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_store WHERE product_id = '" . (int)$product_id . "'"); 
 

 
\t \t if (isset($data['product_store'])) { 
 
\t \t \t foreach ($data['product_store'] as $store_id) { 
 
\t \t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_store SET product_id = '" . (int)$product_id . "', store_id = '" . (int)$store_id . "'"); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t $this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "'"); 
 

 
\t \t if (!empty($data['product_attribute'])) { 
 
\t \t \t foreach ($data['product_attribute'] as $product_attribute) { 
 
\t \t \t \t if ($product_attribute['attribute_id']) { 
 
\t \t \t \t \t foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) { 
 
\t \t \t \t \t \t $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']) . "'"); 
 
\t \t \t \t \t } 
 
\t \t \t \t } 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t $this->db->query("DELETE FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "'"); 
 
\t \t $this->db->query("DELETE FROM " . DB_PREFIX . "product_option_value WHERE product_id = '" . (int)$product_id . "'"); 
 

 
\t \t if (isset($data['product_option'])) { 
 
\t \t \t foreach ($data['product_option'] as $product_option) { 
 
\t \t \t \t if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'checkbox' || $product_option['type'] == 'image') { 
 
\t \t \t \t \t if (isset($product_option['product_option_value'])) { 
 
\t \t \t \t \t \t $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'] . "'"); 
 

 
\t \t \t \t \t \t $product_option_id = $this->db->getLastId(); 
 

 
\t \t \t \t \t \t foreach ($product_option['product_option_value'] as $product_option_value) { 
 
\t \t \t \t \t \t \t $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']) . "'"); 
 
\t \t \t \t \t \t } 
 
\t \t \t \t \t } 
 
\t \t \t \t } else { 
 
\t \t \t \t \t $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'] . "'"); 
 
\t \t \t \t } 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t $this->db->query("DELETE FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "'"); 
 

 
\t \t if (isset($data['product_discount'])) { 
 
\t \t \t foreach ($data['product_discount'] as $product_discount) { 
 
\t \t \t \t $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']) . "'"); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t $this->db->query("DELETE FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "'"); 
 

 
\t \t if (isset($data['product_special'])) { 
 
\t \t \t foreach ($data['product_special'] as $product_special) { 
 
\t \t \t \t $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']) . "'"); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t $this->db->query("DELETE FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'"); 
 

 
\t \t if (isset($data['product_image'])) { 
 
\t \t \t foreach ($data['product_image'] as $product_image) { 
 
\t \t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = '" . $this->db->escape($product_image['image']) . "', sort_order = '" . (int)$product_image['sort_order'] . "'"); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_download WHERE product_id = '" . (int)$product_id . "'"); 
 

 
\t \t if (isset($data['product_download'])) { 
 
\t \t \t foreach ($data['product_download'] as $download_id) { 
 
\t \t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_download SET product_id = '" . (int)$product_id . "', download_id = '" . (int)$download_id . "'"); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'"); 
 

 
\t \t if (isset($data['product_category'])) { 
 
\t \t \t foreach ($data['product_category'] as $category_id) { 
 
\t \t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_category SET product_id = '" . (int)$product_id . "', category_id = '" . (int)$category_id . "'"); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t $this->db->query("DELETE FROM " . DB_PREFIX . "product_filter WHERE product_id = '" . (int)$product_id . "'"); 
 

 
\t \t if (isset($data['product_filter'])) { 
 
\t \t \t foreach ($data['product_filter'] as $filter_id) { 
 
\t \t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "product_filter SET product_id = '" . (int)$product_id . "', filter_id = '" . (int)$filter_id . "'"); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'"); 
 
\t \t $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE related_id = '" . (int)$product_id . "'"); 
 

 
\t \t if (isset($data['product_related'])) { 
 
\t \t \t foreach ($data['product_related'] as $related_id) { 
 
\t \t \t \t $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "' AND related_id = '" . (int)$related_id . "'"); 
 
\t \t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$product_id . "', related_id = '" . (int)$related_id . "'"); 
 
\t \t \t \t $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$related_id . "' AND related_id = '" . (int)$product_id . "'"); 
 
\t \t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$related_id . "', related_id = '" . (int)$product_id . "'"); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t $this->db->query("DELETE FROM " . DB_PREFIX . "product_reward WHERE product_id = '" . (int)$product_id . "'"); 
 

 
\t \t if (isset($data['product_reward'])) { 
 
\t \t \t foreach ($data['product_reward'] as $customer_group_id => $value) { 
 
\t \t \t \t if ((int)$value['points'] > 0) { 
 
\t \t \t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "product_reward SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$customer_group_id . "', points = '" . (int)$value['points'] . "'"); 
 
\t \t \t \t } 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_layout WHERE product_id = '" . (int)$product_id . "'"); 
 

 
\t \t if (isset($data['product_layout'])) { 
 
\t \t \t foreach ($data['product_layout'] as $store_id => $layout_id) { 
 
\t \t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_layout SET product_id = '" . (int)$product_id . "', store_id = '" . (int)$store_id . "', layout_id = '" . (int)$layout_id . "'"); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t $this->db->query("DELETE FROM " . DB_PREFIX . "url_alias WHERE query = 'product_id=" . (int)$product_id . "'"); 
 

 
\t \t if ($data['keyword']) { 
 
\t \t \t $this->db->query("INSERT INTO " . DB_PREFIX . "url_alias SET query = 'product_id=" . (int)$product_id . "', keyword = '" . $this->db->escape($this->accents($data['keyword'])) . "'"); 
 

 
\t \t } 
 

 
\t \t $this->db->query("DELETE FROM `" . DB_PREFIX . "product_recurring` WHERE product_id = " . (int)$product_id); 
 

 
\t \t if (isset($data['product_recurring'])) { 
 
\t \t \t foreach ($data['product_recurring'] as $product_recurring) { 
 
\t \t \t \t $this->db->query("INSERT INTO `" . DB_PREFIX . "product_recurring` SET `product_id` = " . (int)$product_id . ", customer_group_id = " . (int)$product_recurring['customer_group_id'] . ", `recurring_id` = " . (int)$product_recurring['recurring_id']); 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t $this->cache->delete('product'); 
 

 
\t \t $this->event->trigger('post.admin.product.edit', $product_id); 
 
\t } 
 

 
\t public function copyProduct($product_id) { 
 
\t \t $query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "'"); 
 

 
\t \t if ($query->num_rows) { 
 
\t \t \t $data = $query->row; 
 

 
\t \t \t $data['sku'] = ''; 
 
\t \t \t $data['upc'] = ''; 
 
\t \t \t $data['viewed'] = '0'; 
 
\t \t \t $data['keyword'] = ''; 
 
\t \t \t $data['status'] = '0'; 
 

 
\t \t \t $data['product_attribute'] = $this->getProductAttributes($product_id); 
 
\t \t \t $data['product_description'] = $this->getProductDescriptions($product_id); 
 
\t \t \t $data['product_discount'] = $this->getProductDiscounts($product_id); 
 
\t \t \t $data['product_filter'] = $this->getProductFilters($product_id); 
 
\t \t \t $data['product_image'] = $this->getProductImages($product_id); 
 
\t \t \t $data['product_option'] = $this->getProductOptions($product_id); 
 
\t \t \t $data['product_related'] = $this->getProductRelated($product_id); 
 
\t \t \t $data['product_reward'] = $this->getProductRewards($product_id); 
 
\t \t \t $data['product_special'] = $this->getProductSpecials($product_id); 
 
\t \t \t $data['product_category'] = $this->getProductCategories($product_id); 
 
\t \t \t $data['product_download'] = $this->getProductDownloads($product_id); 
 
\t \t \t $data['product_layout'] = $this->getProductLayouts($product_id); 
 
\t \t \t $data['product_store'] = $this->getProductStores($product_id); 
 
\t \t \t $data['product_recurrings'] = $this->getRecurrings($product_id); 
 

 
\t \t \t $this->addProduct($data); 
 
\t \t } 
 
\t }

ответ

1

Так как запрос вставки происходит в модели вы можете вызвать его, добавив функцию как метод класса где-то в продукте файл модели .php:

public function accents($string) { 
    //search 
    $dia = array('á', 'ä', 'č', 'ď', 'é', 'ě', 'í', 'ľ', 'ĺ', 'ň', 'ó', 'ô', 'ŕ', 'ř', 'š', 'ť', 'ú', 'ů', 'ý', 'ž', 'Á', 'Ä', 'Č', 'Ď', 'É', 'Í', 'Ľ', 'Ĺ', 'Ň', 'Ó', 'Ô', 'Ř', 'Š', 'Ť', 'Ú', 'Ý', 'Ž', ' ','\'','%'); 

    //replace 
    $nodia = array('a', 'a', 'c', 'd', 'e', 'e', 'i', 'l', 'l', 'n', 'o', 'o', 'r', 'r', 's', 't', 'u', 'u', 'y', 'z', 'A', 'A', 'C', 'D', 'E', 'I', 'L', 'L', 'N', 'O', 'O', 'R', 'S', 'T', 'U', 'Y', 'Z', '-','',''); 

    return str_replace($dia, $nodia, $string); 
} 

И затем вызвать его вставки, как это:

$this->db->escape($this->accents($data['keyword'])) 

Конечно, если вы хотите применить этот preg_replace(), это может стать беспорядочным, и вы можете подумать о его форматировании перед вставкой в ​​шагах для ясности. Вы можете добавить блок, как это, а затем просто оставить запрос в покое - который я мог бы добавить имеет дополнительное преимущество, не нарушая расширения и vQmods, которые могут зависеть от синтаксиса кода по умолчанию:

$data['keyword'] = $this->accents($data['keyword']; 
$data['keyword'] = preg_replace('/[^a-zA-Z0-9]+/', '-', $data['keyword']); 
$data['keyword'] = trim($data['keyword'], '-'); 
$data['keyword'] = strtolower($data['keyword']); 

Вы также можете попробовать просто преобразование в ASCII с iconv(), как это:

$this->db->escape(iconv("UTF-8","ASCII//TRANSLIT",$data['keyword'])) 

Я использовал выше функции для некоторых WebServices вызовов, требующих ASCII, и это работает для меня.

+0

Привет, Билли, большое спасибо за ваш ответ. Сначала я попробовал вариант с iconv, но заменил акценты на «?» Теперь я пытаюсь использовать функцию акцентов, но я делаю что-то неправильно. Я получаю Неустранимая ошибка: вызов неопределенного метода ModelCatalogProduct :: accents() в /home/public_html/web/admin/model/catalog/product.php в строке 270. Я не уверен, как добавить функцию как метод класса где-то в этом файле модели product.php – Magnettoo

+0

Я продемонстрировал это в первом блоке. Просто добавьте его в конец до закрытия класса.Если вы не уверены, внимательно изучите все другие методы и способы их появления. Вам просто нужно добавить его так же, как и все другие методы - как обычную функцию, но просто убедитесь, что она находится внутри класса '{' braces'} ' – billynoah

+0

Сортировка. Работает как шарм. Большое спасибо Билли – Magnettoo

Смежные вопросы