D
D
Damir Dautov2018-07-20 23:30:48
opencart
Damir Dautov, 2018-07-20 23:30:48

How to add the selected option to the alert when ordering a product Opencart 2.3?

Hello, I would like to add a feature to my site. When adding a product with an option, the selected option was shown in the notification (that the product was added to the cart).
Tell me what to fix in the file:
controller\checkout\cart.php

$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']), $product_info['name'], $this->url->link('checkout/cart'));

So that when choosing the option 2-3 years, it would be something like this
5b5244fb48b83568345130.png5b5245037d431964414352.png
. One of the forums advised this way out:
Replace:
$option_data = array();

        foreach ($product['option'] as $option) {
          if ($option['type'] != 'file') {
            $value = $option['value'];
          } else {
            $upload_info = $this->model_tool_upload->getUploadByCode($option['value']);

            if ($upload_info) {
              $value = $upload_info['name'];
            } else {
              $value = '';
            }
          }

          $option_data[] = array(
            'name'  => $option['name'],
            'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value)
          );
        }

on this
$option_data = array();	
    foreach ($product_options as $product_option) {
          if ($product_option['required'] && empty($option[$product_option['product_option_id']])) {
            $json['error']['option'][$product_option['product_option_id']] = sprintf($this->language->get('error_required'), $product_option['name']);
          }
          if(!empty($option[$product_option['product_option_id']])){
        foreach($product_option as $k => $p_o){
            if($k == 'product_option_value'){
          foreach($p_o as $v_p_o){
              if(is_array($option[$product_option['product_option_id']])){
            foreach($option[$product_option['product_option_id']] as $val){
                if($val == $v_p_o['product_option_value_id']){
              $option_data[] = $v_p_o['name'];
                }
            }
              }else{
            if($option[$product_option['product_option_id']] == $v_p_o['product_option_value_id']){
                 $option_data[] = $v_p_o['name'];
            }
              }
          }
            }
        }
          }
      }

+
$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']), $product_info['name'] . '(' . implode(',',$option_data) . ')', $this->url->link('checkout/cart'));

But it gives an error:
5b524588172e1577354443.jpeg5b5245900c2da198866660.jpeg

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question