R
R
Roman Kuzmenko2016-03-12 12:12:02
PHP
Roman Kuzmenko, 2016-03-12 12:12:02

How to add amount to text option in Opencart?

Good afternoon! I ask for help because the situation is not very clear.
In Opencart, it is possible to add a text option "input type=text" to the product, in which the user can enter arbitrary text. I wanted to add that the price is multiplied by n when using this option, on the product page all good prices are recalculated (using js), but not in the cart, I sort of understood that this procedure should be carried out in the system/library/cart.php file , moved it to a separate "else if" for the text option:

} elseif ($option_query->row['type'] == 'text') {
                $option_data[] = array(
                  'product_option_id'       => $product_option_id,
                  'product_option_value_id' => '',
                  'option_id'               => $option_query->row['option_id'],
                  'option_value_id'         => '',
                  'name'                    => $option_query->row['name'],
                  'option_value'            => $option_value,
                  'type'                    => $option_query->row['type'],
                  'quantity'                => '1',
                  'subtract'                => '0',
                  'price'                   => '2',              // (на что умножаем)
                  'price_prefix'            => '*',           // (у нас умножение)
                  'points'                  => '0',
                  'points_prefix'           => '+',								
                  'weight'                  => '0',
                  'weight_prefix'           => '+'
                );
              }

Unfortunately, nothing is listed in the shopping cart.
Put the entire system/library/cart.php file code here pastebin.com/Ls7DENMX

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Buziks, 2016-03-28
@Buziks

I believe that before this code you need to prescribe logic. For example, this code is written for the radio, select, image options:

if ($option_value_query->num_rows) {
                if ($option_value_query->row['price_prefix'] == '+') {
                  $option_price += $option_value_query->row['price'];
                } elseif ($option_value_query->row['price_prefix'] == '-') {
                  $option_price -= $option_value_query->row['price'];
                }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question