[Помогите] Разные валюты для разных товаров вручную

Тема в разделе "OpenCart", создана пользователем biolion, 13 май 2015.

  1. biolion

    biolion

    Регистрация:
    27 окт 2013
    Сообщения:
    303
    Симпатии:
    94
    Нужно реализовать следующее:
    Для одного товара цена в USD а для другого в Евро, и так что бы цену вручную можно было вбивать, а не по курсу.
    Например, захожу в товар А - вбиваю цену - выбираю валюту Долл. - на сайте этот товар в долл., а в товаре Б цена в евро.
    Подскажите, пожалуйста, как такое реализовать. Пробовал разные модули, но они просто конвертят одну валюту в другую и выводят в двух валютах, да еще и с опциями не дружат.
    А мне просто банально вручную цену забивать.
     
  2. Ping

    Ping PingWin always win Команда форума

    Регистрация:
    29 окт 2012
    Сообщения:
    443
    Симпатии:
    301
    если не нужны никакие пересчеты валют и конвертация их, а нужно просто вбить в товар нужную валюту, то можно использовать поля EAN ISBN и пр. не используемые поля. Переименовать их и все.
     
    biolion нравится это.
  3. biolion

    biolion

    Регистрация:
    27 окт 2013
    Сообщения:
    303
    Симпатии:
    94
    Но как быть с опциями?
     
  4. Ping

    Ping PingWin always win Команда форума

    Регистрация:
    29 окт 2012
    Сообщения:
    443
    Симпатии:
    301
    а в опциях проставляется цена для каждой отдельно ?
     
  5. biolion

    biolion

    Регистрация:
    27 окт 2013
    Сообщения:
    303
    Симпатии:
    94
    Спасибо за наводку. Взял поле UPC - в нем указал валюту, убрал символы валюты, вставил вывод UPC сразу за ценой - все отлично. Теперь буду займусь добавлением этого кода во все места вывода цены. С опциями тоже работает. Корзины у меня нет, так что то, что нужно
     
  6. skdon

    skdon

    Регистрация:
    28 апр 2015
    Сообщения:
    20
    Симпатии:
    3
    Писал недавно что то подобное на Vqmod. Кому нужно, код ниже.
    HTML:
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Делаем запросы к базе данных
    ALTER TABLE `product` ADD COLUMN `currency_id` INTEGER(11) NOT NULL DEFAULT '1'
    ALTER TABLE `product` ADD COLUMN `base_price` DECIMAL(10,2) NOT NULL DEFAULT '1'
    ALTER TABLE `product_option_value` ADD COLUMN `currency_id` INTEGER(11) NOT NULL DEFAULT '1'
    ALTER TABLE `product_option_value` ADD COLUMN `base_price` DECIMAL(10,2) NOT NULL DEFAULT '1'
    UPDATE `oc_product` SET `base_price` = `price`
    UPDATE oc_product SET currency_id = '4'
    -->
    <modification>
        <id>Цена товара в разных валютах</id>
        <version>1.0.3</version>
        <vqmver>1.0.3</vqmver>
        <author>skdon</author>
      <file name="admin/view/template/catalog/product_form.tpl">
       <operation>
        <search position="replace"  error="log"><![CDATA[<input type="text" name="price" value="<?php echo $price; ?>" />]]></search>
          <add><![CDATA[
                  <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']; ?> | <?php echo $currency['value']; ?></option>
                    <?php } else { ?>
                    <option value="<?php echo $currency['currency_id']; ?>"><?php echo $currency['title']; ?> | <?php echo $currency['value']; ?></option>
                    <?php } ?>
                    <?php } ?>
                    </select>
                  &nbsp;&nbsp;
                   Цена на сайте: <?php echo $price; ?>
                ]]>
            </add>
       </operation>
      </file>
    
    
      <file name="admin/controller/catalog/product.php">
       <operation>
        <search position="iafter"  error="log"><![CDATA[$this->data['product_options'] = array();
        ]]></search>
          <add><![CDATA[
            $this->load->model('localisation/currency');
            $this->data['currencies'] = $this->model_localisation_currency->getCurrencies();
    
            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'] = ' ';
            }
          ]]></add>
       </operation>
      </file>
    
    <!---->
      <file name="admin/model/catalog/product.php">
       <operation>
        <search position="before"  error="log"><![CDATA[public function addProduct
        ]]></search>
          <add><![CDATA[
                  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']);
                }
                }
                }
          ]]></add>
       </operation>
      </file>
    
    
      <file name="admin/controller/catalog/product.php">
       <operation>
        <search position="after" offset="1" error="log"><![CDATA[$this->data['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/controller/catalog/product.php">
       <operation>
        <search position="after"  error="log"><![CDATA[$this->data['entry_price'] = $this->language->get('entry_price');
        ]]></search>
          <add><![CDATA[
             $this->data['entry_currency_id'] = $this->language->get('entry_currency_id');
          ]]></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']) . "', 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 = '" . $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']) . "', 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()");
          ]]></add>
       </operation>
      </file>
    
      <file name="admin/model/catalog/product.php">
       <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']) . "', 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 = '" . $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 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 . "'");
            ]]></add>
       </operation>
      </file>
    
    <!--Вывод базовой валюты в списке продуктов-->
    <file name="admin/view/template/catalog/product_list.tpl">
    <operation>
         <search position="replace" error="log"><![CDATA[
            <?php echo $product['price']; ?>
        ]]></search>
          <add><![CDATA[
                 <?php echo $product['price']; ?>
                 <?php foreach ($currencies as $currency)?>
                    </br>Валюта:
                    <?php foreach ($currencies as $currency)
                    {
                        if ($currency['currency_id'] == $product['currency_id'])
                        {
                            echo $currency['code']." | ".$currency['value'];
                        }
                    } ?>
          ]]></add>
      </operation>
      </file>
    
    
       <file name="admin/controller/catalog/product.php">
       <operation>
        <search position="replace" error="log"><![CDATA[
        'quantity'   => $result['quantity'],
        ]]></search>
          <add><![CDATA['quantity'   => $result['quantity'],
              'currency_id'     => $result['currency_id'],]]></add>
       </operation>
      </file>
    
    
      <file name="admin/controller/catalog/product.php">
       <operation>
        <search position="after" error="log"><![CDATA[
        public function index() {
        ]]></search>
          <add><![CDATA[
              $this->load->model('localisation/currency');
              $this->data['currencies'] = $this->model_localisation_currency->getCurrencies();
          ]]></add>
       </operation>
      </file>
    
    
        <file name="admin/view/template/catalog/product_form.tpl">
       <operation>
        <search position="replace" error="log"><![CDATA[
        value="<?php echo $product_option_value['price']; ?>" size="5" />
        ]]></search>
          <add><![CDATA[
                    value="<?php foreach ($currencies as $currency)
                    {
                        if ($currency['currency_id'] == $currency_id)
                        {
                               echo $product_option_value['price']/$currency['value'];
                            $kurs = $currency['value'];
                            $code = $currency['code'];   
                        }
                    } ?>" size="5" />  <?php echo $code; ?>
            <input type="hidden" name="currency" value="<?php echo $kurs; ?>" />
            <input type="hidden" name="curr_id" value="<?php echo $curr_id; ?>" />
          ]]></add>
       </operation>
      </file>
    <!---->
       <file name="admin/controller/catalog/product.php">
       <operation>
        <search position="replace" error="log"><![CDATA[
        public function update() {
        ]]></search>
          <add><![CDATA[
            public function update() {
                if (isset($this->request->get['currency'])) {
                  $url .= '&currency=' . $this->request->get['currency'];
                  }
                if (isset($this->request->get['curr_id'])) {
                  $url .= '&curr_id=' . $this->request->get['curr_id'];
                  }
              ]]></add>
       </operation>
      </file>
    <!--Запись в базу Опций базовой валюты и базовой цены-->
       <file name="admin/model/catalog/product.php">
       <operation>
        <search position="replace" error="log"><![CDATA[(float)$product_option_value['price']]]></search>
          <add><![CDATA[(float)$product_option_value['price']*$data['currency']]]></add>
       </operation>
       <operation>
        <search position="iafter" error="log"><![CDATA[, weight_prefix = '" . $this->db->escape($product_option_value['weight_prefix']) . "']]></search>
          <add><![CDATA[, currency_id = '" . $data['currency_id'] . "', base_price = '" . (float)$product_option_value['price'] . "']]></add>
       </operation>
      </file>
    <!--Конец Запись в базу Опций базовой валюты и базовой цены--> 
    <!--Пересчет при смене курса валют-->
      <file name="admin/model/localisation/currency.php">
       <operation>
        <search position="after" offset="1" error="log"><![CDATA[$this->db->query("UPDATE " . DB_PREFIX . "currency SET title = '"]]></search>
          <add><![CDATA[
          $this->db->query("UPDATE " . DB_PREFIX . "product SET  price = base_price * '" . $this->db->escape($data['value']). "' WHERE currency_id = '" . (int)$currency_id. "'");
          ]]></add>
       </operation>
       <operation>
       <search position="after" offset="1" error="log"><![CDATA[$this->db->query("UPDATE " . DB_PREFIX . "currency SET title = '"]]></search>
          <add><![CDATA[
          $this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET  price = base_price * '" . $this->db->escape($data['value']). "' WHERE currency_id = '" . (int)$currency_id. "'");
          ]]></add>
       </operation>
      </file>
    <!--Конец Пересчет при смене курса валют-->
    <!---->
     
    
    </modification>
    
    
     
    Ping нравится это.