diff --git a/public/admin/controller/catalog/product.php b/public/admin/controller/catalog/product.php index 7c2ee2c..5fc917b 100644 --- a/public/admin/controller/catalog/product.php +++ b/public/admin/controller/catalog/product.php @@ -616,6 +616,25 @@ class ControllerCatalogProduct extends Controller { ); + $this->load->model('setting/store'); + + $stores = array(); + $stores[] = array( + 'store_id' => 0, + 'name' => $this->language->get('text_default') + ); + + $store_results = $this->model_setting_store->getStores(); + + foreach ($store_results as $store) { + $stores[] = array( + 'store_id' => $store['store_id'], + 'name' => $store['name'] + ); + } + + $data['stores'] = $stores; + $this->load->model('tool/image'); $product_total = $this->model_catalog_product->getTotalProducts($filter_data); @@ -641,18 +660,34 @@ class ControllerCatalogProduct extends Controller { } } + $product_stores = $this->model_catalog_product->getProductStores($result['product_id']); + $product_prices = $this->model_catalog_product->getProductPrices($result['product_id']); + + $prices_html = ''; + + foreach ($stores as $store) { + $store_id = $store['store_id']; + if (isset($product_prices[$store_id])) { + $p = $this->currency->format($product_prices[$store_id]['price'], $this->config->get('config_currency')); + $p2 = $this->currency->format($product_prices[$store_id]['price_2'], $this->config->get('config_currency')); + $p3 = $this->currency->format($product_prices[$store_id]['price_3'], $this->config->get('config_currency')); + $prices_html .= '
' . $store['name'] . ': ' . $p . ' / ' . $p2 . ' / ' . $p3 . '
'; + } + } + $data['products'][] = array( 'product_id' => $result['product_id'], 'image' => $image, 'name' => $result['name'], - 'model' => $result['model'], 'price' => $this->currency->format($result['price'], $this->config->get('config_currency')), + 'prices_html' => $prices_html, 'special' => $special, 'quantity' => $result['quantity'], 'status' => $result['status'] ? $this->language->get('text_enabled_short') : $this->language->get('text_disabled_short'), 'noindex' => $result['noindex'] ? $this->language->get('text_enabled_short') : $this->language->get('text_disabled_short'), 'href_shop' => HTTP_CATALOG . 'index.php?route=product/product&product_id=' . $result['product_id'], - 'edit' => $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $result['product_id'] . $url, true) + 'edit' => $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $result['product_id'] . $url, true), + 'product_stores' => $product_stores ); } @@ -742,7 +777,6 @@ class ControllerCatalogProduct extends Controller { } $data['sort_name'] = $this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'] . '&sort=pd.name' . $url, true); - $data['sort_model'] = $this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'] . '&sort=p.model' . $url, true); $data['sort_price'] = $this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'] . '&sort=p.price' . $url, true); $data['sort_quantity'] = $this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'] . '&sort=p.quantity' . $url, true); $data['sort_status'] = $this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'] . '&sort=p.status' . $url, true); @@ -1087,6 +1121,14 @@ class ControllerCatalogProduct extends Controller { $data['product_store'] = array(0); } + if (isset($this->request->post['product_prices'])) { + $data['product_prices'] = $this->request->post['product_prices']; + } elseif (isset($this->request->get['product_id'])) { + $data['product_prices'] = $this->model_catalog_product->getProductPrices($this->request->get['product_id']); + } else { + $data['product_prices'] = array(); + } + if (isset($this->request->post['shipping'])) { $data['shipping'] = $this->request->post['shipping']; } elseif (!empty($product_info)) { @@ -1685,10 +1727,6 @@ if (isset($this->request->post['price_3'])) { } } - if ((utf8_strlen($this->request->post['model']) < 1) || (utf8_strlen($this->request->post['model']) > 64)) { - $this->error['model'] = $this->language->get('error_model'); - } - if (isset($this->request->post['product_seo_url']) && is_array($this->request->post['product_seo_url'])) { foreach ($this->request->post['product_seo_url'] as $store_id => &$languages) { foreach ($languages as $language_id => &$keyword) { @@ -1819,6 +1857,36 @@ if (isset($this->request->post['price_3'])) { return !$this->error; } + public function toggleStore() { + $json = array(); + + $this->load->model('catalog/product'); + + if (isset($this->request->get['product_id']) && isset($this->request->get['store_id'])) { + $product_id = (int)$this->request->get['product_id']; + $store_id = (int)$this->request->get['store_id']; + + $product_stores = $this->model_catalog_product->getProductStores($product_id); + + if (in_array($store_id, $product_stores)) { + $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_store WHERE product_id = '" . (int)$product_id . "' AND store_id = '" . (int)$store_id . "'"); + $json['added'] = false; + } else { + $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_store SET product_id = '" . (int)$product_id . "', store_id = '" . (int)$store_id . "'"); + $json['added'] = true; + } + + $this->cache->delete('product'); + + $json['success'] = true; + } else { + $json['error'] = true; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + public function autocomplete() { $json = array(); diff --git a/public/admin/language/ru-ru/catalog/product.php b/public/admin/language/ru-ru/catalog/product.php index f0186eb..c95812f 100644 --- a/public/admin/language/ru-ru/catalog/product.php +++ b/public/admin/language/ru-ru/catalog/product.php @@ -29,8 +29,10 @@ $_['column_manufacturer'] = 'Производитель'; $_['column_model'] = 'Код товара'; $_['column_image'] = 'Изображение'; $_['column_price'] = 'Цена'; +$_['column_prices'] = 'Цены по магазинам'; $_['column_quantity'] = 'Количество'; $_['column_status'] = 'Статус'; +$_['column_stores'] = 'Магазины'; $_['column_noindex'] = 'Индекс'; $_['column_action'] = 'Действие'; @@ -58,6 +60,11 @@ $_['entry_location'] = 'Расположение'; $_['entry_shipping'] = 'Необходима доставка'; $_['entry_manufacturer'] = 'Производитель'; $_['entry_store'] = 'Магазины'; +$_['entry_store_price'] = 'Цена'; +$_['entry_store_price_2'] = 'Второй прокат'; +$_['entry_store_price_3'] = 'Покупка'; +$_['tab_data'] = 'Данные'; +$_['tab_prices'] = 'Цены по магазинам'; $_['entry_date_available'] = 'Дата поступления'; $_['entry_quantity'] = 'Количество'; $_['entry_minimum'] = 'Минимальное количество'; diff --git a/public/admin/model/catalog/product.php b/public/admin/model/catalog/product.php index b802d9a..fb62f3f 100644 --- a/public/admin/model/catalog/product.php +++ b/public/admin/model/catalog/product.php @@ -22,6 +22,9 @@ class ModelCatalogProduct extends Model { } } + $this->load->model('catalog/product_price'); + $this->model_catalog_product_price->addProductPrices($product_id, $data); + if (isset($data['product_attribute'])) { foreach ($data['product_attribute'] as $product_attribute) { if ($product_attribute['attribute_id']) { @@ -180,6 +183,9 @@ class ModelCatalogProduct extends Model { } } + $this->load->model('catalog/product_price'); + $this->model_catalog_product_price->editProductPrices($product_id, $data); + $this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "'"); if (!empty($data['product_attribute'])) { @@ -379,8 +385,9 @@ class ModelCatalogProduct extends Model { $data['product_category'] = $this->getProductCategories($product_id); $data['product_download'] = $this->getProductDownloads($product_id); $data['product_layout'] = $this->getProductLayouts($product_id); - $data['product_store'] = $this->getProductStores($product_id); - $data['product_recurrings'] = $this->getRecurrings($product_id); + $data['product_store'] = $this->getProductStores($product_id); + $data['product_prices'] = $this->getProductPrices($product_id); + $data['product_recurrings'] = $this->getRecurrings($product_id); $this->addProduct($data); } @@ -404,6 +411,7 @@ class ModelCatalogProduct extends Model { $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_download WHERE product_id = '" . (int)$product_id . "'"); $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_layout WHERE product_id = '" . (int)$product_id . "'"); $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_store WHERE product_id = '" . (int)$product_id . "'"); + $this->db->query("DELETE FROM " . DB_PREFIX . "product_prices WHERE product_id = '" . (int)$product_id . "'"); $this->db->query("DELETE FROM " . DB_PREFIX . "product_recurring WHERE product_id = " . (int)$product_id); $this->db->query("DELETE FROM " . DB_PREFIX . "review WHERE product_id = '" . (int)$product_id . "'"); $this->db->query("DELETE FROM " . DB_PREFIX . "seo_url WHERE query = 'product_id=" . (int)$product_id . "'"); @@ -722,6 +730,11 @@ class ModelCatalogProduct extends Model { return $product_store_data; } + + public function getProductPrices($product_id) { + $this->load->model('catalog/product_price'); + return $this->model_catalog_product_price->getProductPrices($product_id); + } public function getProductSeoUrls($product_id) { $product_seo_url_data = array(); diff --git a/public/admin/model/catalog/product_price.php b/public/admin/model/catalog/product_price.php new file mode 100644 index 0000000..436d5c0 --- /dev/null +++ b/public/admin/model/catalog/product_price.php @@ -0,0 +1,40 @@ + $prices) { + $this->db->query("INSERT INTO " . DB_PREFIX . "product_prices SET product_id = '" . (int)$product_id . "', store_id = '" . (int)$store_id . "', price = '" . (float)$prices['price'] . "', price_2 = '" . (float)$prices['price_2'] . "', price_3 = '" . (float)$prices['price_3'] . "'"); + } + } + } + + public function editProductPrices($product_id, $data) { + $this->db->query("DELETE FROM " . DB_PREFIX . "product_prices WHERE product_id = '" . (int)$product_id . "'"); + + if (isset($data['product_prices'])) { + foreach ($data['product_prices'] as $store_id => $prices) { + $this->db->query("INSERT INTO " . DB_PREFIX . "product_prices SET product_id = '" . (int)$product_id . "', store_id = '" . (int)$store_id . "', price = '" . (float)$prices['price'] . "', price_2 = '" . (float)$prices['price_2'] . "', price_3 = '" . (float)$prices['price_3'] . "'"); + } + } + } + + public function getProductPrices($product_id) { + $prices = array(); + + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_prices WHERE product_id = '" . (int)$product_id . "'"); + + foreach ($query->rows as $row) { + $prices[$row['store_id']] = array( + 'price' => $row['price'], + 'price_2' => $row['price_2'], + 'price_3' => $row['price_3'] + ); + } + + return $prices; + } + + public function deleteProductPrices($product_id) { + $this->db->query("DELETE FROM " . DB_PREFIX . "product_prices WHERE product_id = '" . (int)$product_id . "'"); + } +} diff --git a/public/admin/view/template/catalog/product_form.twig b/public/admin/view/template/catalog/product_form.twig index 1582a2b..6129384 100644 --- a/public/admin/view/template/catalog/product_form.twig +++ b/public/admin/view/template/catalog/product_form.twig @@ -27,6 +27,7 @@