Перейти до вмісту
Пошук в
  • Детальніше...
Шукати результати, які ...
Шукати результати в ...

Хранение цены в магазине в разных валютах.


slvtmn

Recommended Posts

Хранение цены в магазине в разных валютах.

Что-то я нигде это тему не видел, поэтому делюсь своим фиксом + пожелание в следующем релизе его очень хотелось бы его видеть.

Позволит без всяких преобразований и трудностей меняться данными между например 1с.

Итак погнали:

1.

Делаем новое поле+индекс на таблице с продуктами:

ALTER TABLE `oc_product` ADD COLUMN `currency_id` INTEGER(11) NOT NULL DEFAULT '1';
ALTER TABLE `oc_product` ADD INDEX `currency_id` (`currency_id`);

2. Дальше везде где SQL запросом мы получаем цену товара нужно его немного исправить и получать цену и учетом валюты и курса.

2.1 Корзина:

/system/library/cart.php

p.price/pcur.value AS price
- получение цены с учетом курса и обзываем полученное также как и был это чтобы минимум перделок и переписываний.

эту строку нужно добавить после "product p"

"LEFT JOIN " . DB_PREFIX . "currency pcur ON (p.currency_id = pcur.currency_id)"
дальше строки которые я поменял у себя можно копировать и вставлять.

примерно 31 строка

$product_query = $this->db->query("SELECT *, p.price/pcur.value AS price, wcd.unit AS weight_class, mcd.unit AS length_class FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "currency pcur ON (p.currency_id = pcur.currency_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "weight_class wc ON (p.weight_class_id = wc.weight_class_id) LEFT JOIN " . DB_PREFIX . "weight_class_description wcd ON (wc.weight_class_id = wcd.weight_class_id) LEFT JOIN " . DB_PREFIX . "length_class mc ON (p.length_class_id = mc.length_class_id) LEFT JOIN " . DB_PREFIX . "length_class_description mcd ON (mc.length_class_id = mcd.length_class_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'");

дальше все аналогично сторока ~79

$product_discount_query = $this->db->query("SELECT pdis.price/pcur.value AS price FROM " . DB_PREFIX . "product AS p, " . DB_PREFIX . "currency as pcur, " . DB_PREFIX . "product_discount AS pdis WHERE (p.product_id=pdis.product_id)and(p.currency_id=pcur.currency_id)and pdis.product_id = '" . (int)$product_id . "' AND pdis.customer_group_id = '" . (int)$customer_group_id . "' AND pdis.quantity <= '" . (int)$discount_quantity . "' AND ((pdis.date_start = '0000-00-00' OR pdis.date_start < NOW()) AND (pdis.date_end = '0000-00-00' OR pdis.date_end > NOW())) ORDER BY pdis.quantity DESC, pdis.priority ASC, price ASC LIMIT 1");

2.2 Продукты:

catalog/model/catalog/product.php

~5 строка функция getProduct

$query = $this->db->query("SELECT DISTINCT *, p.price/pcur.value AS price, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, p.currency_id AS currency FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "currency pcur ON (p.currency_id = pcur.currency_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'");

~10 строка функция getProducts

$query = $this->db->query("SELECT DISTINCT *, p.price/pcur.value AS price, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, wcd.unit AS weight_class FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "currency pcur ON (p.currency_id = pcur.currency_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "weight_class_description wcd ON (p.weight_class_id = wcd.weight_class_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'");

~15 строка функция getProductsByCategoryId

$sql = "SELECT *, p.price/pcur.value AS price, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "currency pcur ON (p.currency_id = pcur.currency_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'";
ну и дальше все запросы почти один в один

getProductsByManufacturerId:

$sql = "SELECT *,p.price/pcur.value AS price, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "currency pcur ON (p.currency_id = pcur.currency_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id. "'";
getProductsByKeyword:

$sql = "SELECT *,p.price/pcur.value AS price, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "currency pcur ON (p.currency_id = pcur.currency_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "'";

getProductDiscount:

$query = $this->db->query("SELECT pdis.price/pcur.value AS price FROM " . DB_PREFIX . "product AS p, " . DB_PREFIX . "currency as pcur ," . DB_PREFIX . "product_discount AS pdis WHERE (p.product_id=pdis.product_id)and(p.currency_id=pcur.currency_id)and pdis.product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND pdis.quantity = '1' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY pdis.priority ASC, price ASC LIMIT 1");

getProductDiscounts:

$query = $this->db->query("SELECT pdis.*,pdis.price/pcur.value AS price FROM " . DB_PREFIX . "product AS p, " . DB_PREFIX . "currency as pcur ," . DB_PREFIX . "product_discount AS pdis WHERE (p.product_id=pdis.product_id)and(p.currency_id=pcur.currency_id)and pdis.product_id = '" . (int)$product_id . "' AND pdis.customer_group_id = '" . (int)$customer_group_id . "' AND pdis.quantity > 1 AND ((pdis.date_start = '0000-00-00' OR pdis.date_start < NOW()) AND (pdis.date_end = '0000-00-00' OR pdis.date_end > NOW())) ORDER BY pdis.quantity ASC, pdis.priority ASC, price ASC");

getProductSpecial:

$query = $this->db->query("SELECT pspec.price/pcur.value AS price FROM " . DB_PREFIX . "product_special AS pspec, " . DB_PREFIX . "product AS p, " . DB_PREFIX . "currency as pcur  WHERE (p.product_id=pspec.product_id)and(p.currency_id=pcur.currency_id)and pspec.product_id = '" . (int)$product_id . "' AND pspec.customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR pspec.date_start < NOW()) AND (pspec.date_end = '0000-00-00' OR pspec.date_end > NOW())) ORDER BY pspec.priority ASC, price ASC LIMIT 1");

getProductSpecials:

$sql = "SELECT *, pd.name AS name, p.price/pcur.value AS price, (SELECT ps2.price FROM " . DB_PREFIX . "product_special ps2 WHERE p.product_id = ps2.product_id AND ps2.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps2.date_start = '0000-00-00' OR ps2.date_start < NOW()) AND (ps2.date_end = '0000-00-00' OR ps2.date_end > NOW())) ORDER BY ps2.priority ASC, ps2.price ASC LIMIT 1) AS special, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "currency pcur ON (p.currency_id = pcur.currency_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "product_special ps ON (p.product_id = ps.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW())AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) AND ps.product_id NOT IN (SELECT pd2.product_id FROM " . DB_PREFIX . "product_discount pd2 WHERE p.product_id = pd2.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW()))) GROUP BY p.product_id";

Уф-уф, яя! вроде все еcли что-то пропустил то дописать по аналогии...

3. редактирование товара в админке, добавление выпадающего списка c валютами.

3.1

файл:

admin/controller/catalog/product.php

строка ~500 можно в любом месте я поставил после

$this->data['entry_price'] = $this->language->get('entry_price');

добавляем

$this->data['entry_currency_id'] = $this->language->get('entry_currency_id');

_________

строка ~550 проверяем что перед " if (isset($this->error['warning'])) { "

есть 2 строки

$this->load->model('localisation/currency');
		$this->data['currencies'] = $this->model_localisation_currency->getCurrencies();
я просто не помню добавлял я их или нет, поэтому - проверить и добавить если нет.

____________

Строка ~702 после ,блока

if (isset($this->request->post['keyword'])) {

$this->data['keyword'] = $this->request->post['keyword'];

} elseif (isset($product_info)) {

$this->data['keyword'] = $product_info['keyword'];

} else {

$this->data['keyword'] = '';

}

надо дописать

if (isset($this->request->post['currency'])) {
$this->data['currency_id'] = $this->request->post['currency_id'];
} elseif (isset($product_info)) {
$this->data['currency_id'] = $product_info['currency_id'];
} else {
$this->data['currency_id'] = '1';
}

файл:

admin/model/catalog/product.php

~4 строка функция addProduct нужно добавить новое поле при создании базы ( currency_id = '" . (int)$data['currency_id'] )

готовая строка:

$this->db->query("INSERT INTO " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', minimum = '" . (int)$data['minimum'] . "', subtract = '" . (int)$data['subtract'] . "', currency_id = '" . (int)$data['currency_id'] . "', 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'] . "', cost = '" . (float)$data['cost'] . "', 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()");
~104 строка функция editProduct

$this->db->query("UPDATE " . DB_PREFIX . "product SET currency_id = '" . (int)$data['currency_id'] . "', model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', 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'] . "', cost = '" . (float)$data['cost'] . "', 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 . "'");

Файл:

admin/view/template/catalog/product_form.tpl

Лепим после

<td><input type="text" name="cost" value="<?php echo $cost; ?>" /></td>

</tr>

<tr>

Строка ~96:

Вот этот блок:

<td><?php echo $entry_currency_id; ?></td>
            <td><select name="currency_id">
                <?php foreach ($currencies as $currency) { ?>
                <?php if ($currency['currency_id'] == $currency_id) { ?>
                <option value="<?php echo $currency['currency_id']; ?>" selected="selected"><?php echo $currency['title']; ?></option>
                <?php } else { ?>
                <option value="<?php echo $currency['currency_id']; ?>"><?php echo $currency['title']; ?></option>
                <?php } ?>
                <?php } ?>
              </select></td>
          </tr>

4. Все вроде готовченко.

  • +1 4
Надіслати
Поділитися на інших сайтах


  • 5 months later...

Спасибо! :rolleyes:

Работает и в мультимагазине!

Очень-очень нужна была такая доработка!

Единственно, кто ставит - еще дописать пересчет в модулях "последние поступления" и "рекомендуем".

Смайла "браво" не нашла...... :wub:

Надіслати
Поділитися на інших сайтах


Я что-то не совсем понял, в админке вводится цена и выбирается какая это валюта, я правильно понял?

да, в описании продукта рядышком проставляется валюта. А на сайте выводится все в одной.
Надіслати
Поділитися на інших сайтах


  • 4 weeks later...

это получается у каждой валюты есть код

и если взять заливочный файл (экспорт-импорт) то там выставляется код языка

правильно ли я понимаю, после преобразований указанных выше, заливка товаров тоже может производится через

выбор кода валюты?

если нет, то возможна ли подобная реализация?*

Надіслати
Поділитися на інших сайтах


  • 6 months later...
  • 2 months later...

здравствуйте, ребята, всё получилось кроме пункта 2.2, всё что связано с catalog/model/catalog/product.php не могу победить, поставил версию 1.5.3.1 , а там что-то сложновато для меня... кто победил отзовитесь

Надіслати
Поділитися на інших сайтах


  • 4 weeks later...
  • 4 weeks later...

Подскажите, плз, как в данном случае правильно заполнить массив данных для сортировки:

$sort_data = array(
'pd.name',
'p.sort_order',
'special',
'rating',
'p.price',
'p.model'
);

Вопрос решён! Чтобы после таких модификаций у вас правильно работала сортировка по цене, нужно найти все места где встречается код

$sort_data = array(
'pd.name',
'p.sort_order',
'special',
'rating',
'p.price',
'p.model'
);

а после него, соответсвенно встречается

if (in_array($sort, $sort_data)) {
if ($sort == 'pd.name' || $sort == 'p.model') {
$sql .= " ORDER BY LCASE(" . $sort . ")";
} else {
$sql .= " ORDER BY " . $sort;
}
} else {
$sql .= " ORDER BY p.sort_order";
}

Вот тут и надо внести модификации по следующему образцу (или попросту заменить на нижеследующий код)

if (in_array($sort, $sort_data)) {
if ($sort == 'pd.name' || $sort == 'p.model') {
$sql .= " ORDER BY LCASE(" . $sort . ")";
} else {
if ($sort == 'p.price') {
$sql .= " ORDER BY price ";
}
else {
$sql .= " ORDER BY " . $sort;
}
}
} else {
$sql .= " ORDER BY p.sort_order";
}
  • +1 1
Надіслати
Поділитися на інших сайтах


  • 1 month later...
  • 3 weeks later...

<!-- Created using vQmod XML Generator by UKSB - http://www.opencart-extensions.co.uk //-->
<modification>
<id><![CDATA[sL Crurrency]]></id>
<version><![CDATA[1.0]]></version>
<vqmver><![CDATA[]]></vqmver>
<author><![CDATA[slava911]]></author>
<file name="system/library/cart.php">
<operation>
<search position="after" error="log"><![CDATA[class Cart {]]></search>
<add><![CDATA[p.price/pcur.value AS price]]></add>
</operation>
<operation>
<search position="replace" error="log"><![CDATA[$product_query = $this->db->query("SELECT * 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') . "' AND p.date_available <= NOW() AND p.status = '1'");]]></search>
<add><![CDATA[$product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product p "LEFT JOIN " . DB_PREFIX . "currency pcur ON (p.currency_id = pcur.currency_id)" 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') . "' AND p.date_available <= NOW() AND p.status = '1'");]]></add>
</operation>
<operation>
<search position="replace" error="log"><![CDATA[$product_discount_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND quantity <= '" . (int)$discount_quantity . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity DESC, priority ASC, price ASC LIMIT 1");]]></search>
<add><![CDATA[$product_discount_query = $this->db->query("SELECT pdis.price/pcur.value AS price price FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND quantity <= '" . (int)$discount_quantity . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity DESC, priority ASC, price ASC LIMIT 1");
]]></add>
</operation>
</file>
<file name="catalog/model/catalog/product.php">
<operation>
<search position="replace" error="log"><![CDATA[$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");]]></search>
<add><![CDATA[$query = $this->db->query("SELECT DISTINCT *, p.price/pcur.value AS price, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p "LEFT JOIN " . DB_PREFIX . "currency pcur ON (p.currency_id = pcur.currency_id)" LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");]]></add>
</operation>
<operation>
<search position="replace" error="log"><![CDATA[$sql = "SELECT p.product_id, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id)";]]></search>
<add><![CDATA[$sql = "SELECT p.product_id, p.price/pcur.value AS price, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "currency pcur ON (p.currency_id = pcur.currency_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id)";]]></add>
</operation>
<operation>
<search position="replace" error="log"><![CDATA[$sql = "SELECT DISTINCT ps.product_id, (SELECT AVG(rating) FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = ps.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating FROM " . DB_PREFIX . "product_special ps LEFT JOIN " . DB_PREFIX . "product p ON (ps.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) GROUP BY ps.product_id";]]></search>
<add><![CDATA[$sql = "SELECT DISTINCT ps.product_id, p.price/pcur.value AS price, (SELECT AVG(rating) FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = ps.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating FROM " . DB_PREFIX . "product_special ps LEFT JOIN " . DB_PREFIX . "product p ON (ps.product_id = p.product_id)LEFT JOIN " . DB_PREFIX . "currency pcur ON (p.currency_id = pcur.currency_id), LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) GROUP BY ps.product_id";]]></add>
</operation>
</file>
<file name="admin/controller/catalog/product.php">
<operation>
<search position="after" error="log"><![CDATA[$this->data['entry_name'] = $this->language->get('entry_name');]]></search>
<add><![CDATA[$this->data['entry_price'] = $this->language->get('entry_price');
$this->data['entry_currency_id'] = $this->language->get('entry_currency_id');]]></add>
</operation>
<operation>
<search position="before" error="log"><![CDATA[if (isset($this->error['warning'])) {]]></search>
<add><![CDATA[$this->load->model('localisation/currency');
$this->data['currencies'] = $this->model_localisation_currency->getCurrencies();]]></add>
</operation>
<operation>
<search position="after" offset="6"><![CDATA[if (isset($this->request->post['keyword'])) {]]></search>
<add><![CDATA[
if (isset($this->request->post['currency'])) {
$this->data['currency_id'] = $this->request->post['currency_id'];
} elseif (isset($product_info)) {
$this->data['currency_id'] = $product_info['currency_id'];
} else {
$this->data['currency_id'] = '1';}]]></add>
</operation>
</file>
<file name="admin/model/catalog/product.php">
<operation>
<search position="replace" error="log"><![CDATA[$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']) . "', 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 = '" . $this->db->escape($data['tax_class_id']) . "', sort_order = '" . (int)$data['sort_order'] . "', date_added = NOW()");]]></search>
<add><![CDATA[$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']) . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', minimum = '" . (int)$data['minimum'] . "', subtract = '" . (int)$data['subtract'] . "', currency_id = '" . (int)$data['currency_id'] . "', 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 = '" . $this->db->escape($data['tax_class_id']) . "', sort_order = '" . (int)$data['sort_order'] . "', date_added = NOW()");]]></add>
</operation>
<operation>
<search position="replace" error="log"><![CDATA[$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']) . "', 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 = '" . $this->db->escape($data['tax_class_id']) . "', sort_order = '" . (int)$data['sort_order'] . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'");]]></search>
<add><![CDATA[$this->db->query("UPDATE " . DB_PREFIX . "product SET currency_id = '" . (int)$data['currency_id'] . "', model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', upc = '" . $this->db->escape($data['upc']) . "', 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 = '" . $this->db->escape($data['tax_class_id']) . "', sort_order = '" . (int)$data['sort_order'] . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'");]]></add>
</operation>
</file>
<file name="admin/view/template/catalog/product_form.tpl">
<operation>
<search position="after" offset="2" error="log"><![CDATA[<td><?php echo $entry_price; ?></td>]]></search>
<add><![CDATA[if (isset($this->request->post['currency'])) {
$this->data['currency_id'] = $this->request->post['currency_id'];
} elseif (isset($product_info)) {
$this->data['currency_id'] = $product_info['currency_id'];
} else {
$this->data['currency_id'] = '1';
}]]></add>
</operation>
</file>
</modification>

Надіслати
Поділитися на інших сайтах

  • 2 weeks later...
  • 2 months later...

Теперь интересно, как сделать, чтобы при редактировании заказа в админке, корректно выводилась стоимость в основной валюте

Ап. вопрос все ещё не решён.

Надіслати
Поділитися на інших сайтах


  • 3 months later...

Теперь интересно, как сделать, чтобы при редактировании заказа в админке, корректно выводилась стоимость в основной валюте

 

И снова ап!

 

полгода прошло о_0

первая мысль: вы и сами бы за это время уже могли разобраться  :lol:

 

Ну а если времени не хватает, то попробуйте тему в разделе услуг создать

Мне кажется, что тут значительные правки могут потребоваться, а значит вероятность того, что кто-то просто возьмёт и за просто так это сделает, крайне мала

Надіслати
Поділитися на інших сайтах

  • 7 months later...

Изучила данную тему для применения для своих клиентов... ничего меня не устроило. Пришлось написать свой модуль

https://opencartforum.com/files/file/1645-%D0%B2%D0%B0%D0%BB%D1%8E%D1%82%D0%B0-%D0%BF%D0%BB%D1%8E%D1%81/

Надіслати
Поділитися на інших сайтах

  • 1 year later...

Мой вариант, на основе топикстартера:

 

1.добавляем в таблицу __product два поля -> currency_id(int,10,NOT NULL,index),base_price(DECIMAL,10,2);

2.редактируем -> admin/model/catalog/product.php:

-сразу после объявления класса, добавляет функцию:

public function setDefaultCurrency($price,$currency) {
if(!empty($price)) {
$query = $this->db->query("SELECT value FROM " . DB_PREFIX . "currency WHERE currency_id = '" .(int)$currency. "'");
if ($query->num_rows) {
return $final_price = ($price * $query->row['value']);
}
}
}

-редактируем функцию addProduct, меняя запрос к БД на этот:

		$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 = '" .$this->setDefaultCurrency($data['base_price'],$data['currency_id']). "', currency_id = '" . (int)$data['currency_id'] . "',base_price = '" . (float)$data['base_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 = '" . $this->db->escape($data['tax_class_id']) . "', sort_order = '" . (int)$data['sort_order'] . "', date_added = NOW()");

-редактируем функцию editProduct, меняя запрос к БД:

		$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 = '" .$this->setDefaultCurrency($data['base_price'],$data['currency_id']). "', currency_id = '" . (int)$data['currency_id'] . "', base_price = '" . (float)$data['base_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 = '" . $this->db->escape($data['tax_class_id']) . "', sort_order = '" . (int)$data['sort_order'] . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'");

3.редактируем  -> admin/controller/catalog/product.php.

В функцию getForm() добавим:


if (isset($this->request->post['base_price'])) {
$this->data['base_price'] = $this->request->post['base_price'];
} elseif (!empty($product_info)) {
$this->data['base_price'] = $product_info['base_price'];
} else {
$this->data['base_price'] = ' ';
}
 

$this->load->model('localisation/currency'); $this->data['currencies'] = $this->model_localisation_currency->getCurrencies(); 

4.редактируем -> admin/catalog/view/template/catalog/product_form.tpl . Ищем строку таблицы, примерно выглядит вот так:

<tr>
<td><?php echo $entry_price; ?></td>
<td><input type="text" name="price" value="<?php echo $price; ?>" />
.....
</tr>

и меняем ее на эту:

<tr>
                <td><?php echo $entry_price; ?></td>
                <td><input type="text" name="base_price" value="<?php echo $base_price; ?>" />
				<select name="currency_id">
                <?php foreach ($currencies as $currency) { ?>
                <?php if ($currency['currency_id'] == $currency_id) { ?>
                <option value="<?php echo $currency['currency_id']; ?>" selected="selected"><?php echo $currency['title']; ?></option>
                <?php } else { ?>
                <option value="<?php echo $currency['currency_id']; ?>"><?php echo $currency['title']; ?></option>
                <?php } ?>
                <?php } ?>
              </select></td>
            </tr>

Всё. Настраиваем курсы и список валют в настройках магазина. Цены корректно отображаются в coolfilter,latest и т.п.

Проверено на 1.5.6.4.

В своем проекте я еще добавил автообновление цен при изменении курса, и вывод цены с валютой в админке, в режиме просмотра списка товаров + изменил некоторые типы ячеек БД, отвечающих за вывод продуктов.

  • +1 1
Надіслати
Поділитися на інших сайтах


  • 1 year later...

Для OpenCart 2.x:

Пока со второй версией не работал, т.к. не было такой задачи. По-быстрому посмотрел, есть пару отличий от 1.х версий которые нужно учесть:
- во второй версии переписан контроллер вывода шаблона. теперь в качестве аргумента используется простой массив, а не свойство класса (было $this->data, стало $data). Поэтому, в admin/controller/catalog/product.php в функцию getForm() добавляем после $data['price']:

if (isset($this->request->post['base_price'])) {
			$data['base_price'] = $this->request->post['base_price'];
		} elseif (!empty($product_info['base_price'])) {
			$data['base_price'] = $product_info['base_price'];
		} else {
			$data['base_price'] = ' ';
		}
		
		$this->load->model('localisation/currency');
		$data['currencies'] = $this->model_localisation_currency->getCurrencies();

if (isset($this->request->post['currency_id'])) {
			$data['currency_id'] = $this->request->post['currency_id'];
		} elseif (!empty($product_info)) {
			$data['currency_id'] = $product_info['currency_id'];
		} else {
			$data['currency_id'] = '';
		}

- в admin/model/catalog/product.php в самое начало (после объявления класса) добавляем:
private function setDefaultCurrency($price = 0, $currency = 0) {
		if($price > 0) {
			$query = $this->db->query("SELECT value FROM " . DB_PREFIX . "currency WHERE currency_id = '" .(int)$currency. "'");
			return $final_price = ($query->num_rows)? ((float)$price * (int)$query->row['value']):0;
		}
		return 0;
}
Там же, в функцию addProduct в самое начало:
$currency_id = (isset($data['currency_id']))?(int)$data['currency_id']:0;
$base_price = (isset($data['base_price']))?(float)$data['base_price']:0;
И меняем первый запрос на:
$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 = '" . $this->setDefaultCurrency($base_price, $currency_id) . "',
							currency_id = '" . $currency_id . "',
							base_price = '" . $base_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()" );
Там же, в функции editProduct(), в самое начало:
$currency_id = (isset($data['currency_id']))?(int)$data['currency_id']:0;
$base_price = (isset($data['base_price']))?(float)$data['base_price']:0;
И меняем первый запрос:
$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 = '" . $this->setDefaultCurrency($base_price, $currency_id) . "',
							currency_id = '" . $currency_id . "',
							base_price = '" . $base_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()
							WHERE product_id = '" . (int)$product_id . "'");
- Дальше в шаблоне (product_form.tpl) меняем строчку в которой находится инпут с текущей ценой на:
 <div class="form-group">
                <label class="col-sm-2 control-label" for="input-price"><?php echo $entry_price; ?></label>
                <div class="col-sm-5">
                  <input type="text" name="base_price" value="<?=$base_price; ?>" class="form-control" />
                </div>
				<div class="col-sm-5">
					<select name="currency_id" class="form-control">
						<?php foreach ($currencies as $currency):?>
							<?php if ($currency['currency_id'] == $currency_id) { ?>
								<option value="<?=$currency['currency_id']; ?>" selected="selected"><?=$currency['title']; ?></option>
							<?php } else { ?>
								<option value="<?=$currency['currency_id']; ?>"><?=$currency['title']; ?></option>
							<?php } ?>
						<?php endforeach;?>
					</select>
				</div>
              </div>
Дальше обязательно чистим кэш (я делал через модули, очистить модификаторы).
Проверил у себя - все работает. ОпенКарт - Version 2.1.0.2 (rs.1)

 

Надіслати
Поділитися на інших сайтах


  • 5 months later...

Я новичок в opencart поэтому могу ошибаться.

 

Для того чтобы заработали изменения для версий 2.Х с последнего поста нужно не забыть добавить столбцы в базу данных (там про это не упомянуто и можно новичку не сориентироватся)

 

добавляем в таблицу __product два поля -> currency_id(int,10,NOT NULL,index),base_price(DECIMAL,10,2);

 

далее при пересчёте стоимости товара почему-то используется значение курса валют int? хотя курсы обычно не целое число

  1. private function setDefaultCurrency($price = 0, $currency = 0) {
  2.         if($price > 0) {
  3.             $query = $this->db->query("SELECT value FROM " . DB_PREFIX . "currency WHERE currency_id = '" .(int)$currency. "'");
  4.             return $final_price = ($query->num_rows)? ((float)$price * (int)$query->row['value']):0;
  5.         }
  6.         return 0;
  7. }

поэтому полагаю что нужно так

 

  1. private function setDefaultCurrency($price = 0, $currency = 0) {
  2.         if($price > 0) {
  3.             $query = $this->db->query("SELECT value FROM " . DB_PREFIX . "currency WHERE currency_id = '" .(int)$currency. "'");
  4.             return $final_price = ($query->num_rows)? ((float)$price * (float)$query->row['value']):0;
  5.         }
  6.         return 0;
  7. }

И ещё необходимо придумать как автоматически изменять цены всех товаров при изменении курса. Т.к. цена пересчитывается только тогда когда сохраняешь товар.

Надіслати
Поділитися на інших сайтах


  • 2 weeks later...

Для ocStore 2.1.0.2.1

Изменения описанные выше + пересчитывает цены по курсу при изменении курса.

Не забудьте создать столбцы currency_id(int,10,NOT NULL,index),base_price(DECIMAL,10,2);

скачать

Надіслати
Поділитися на інших сайтах


Створіть аккаунт або увійдіть для коментування

Ви повинні бути користувачем, щоб залишити коментар

Створити обліковий запис

Зареєструйтеся для отримання облікового запису. Це просто!

Зареєструвати аккаунт

Вхід

Уже зареєстровані? Увійдіть тут.

Вхід зараз
  • Зараз на сторінці   0 користувачів

    • Ні користувачів, які переглядиють цю сторінку
×
×
  • Створити...

Important Information

На нашому сайті використовуються файли cookie і відбувається обробка деяких персональних даних користувачів, щоб поліпшити користувальницький інтерфейс. Щоб дізнатися для чого і які персональні дані ми обробляємо перейдіть за посиланням . Якщо Ви натиснете «Я даю згоду», це означає, що Ви розумієте і приймаєте всі умови, зазначені в цьому Повідомленні про конфіденційність.